mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-23 07:21:04 +01:00
Merge 5b8045236d
into 8519e26532
This commit is contained in:
commit
f7e3249d67
12 changed files with 236 additions and 23 deletions
|
@ -4,7 +4,7 @@ sequenceOf(
|
|||
"api",
|
||||
"common",
|
||||
"paper",
|
||||
"sponge-8",
|
||||
"sponge-9",
|
||||
"currency-money",
|
||||
"test"
|
||||
).forEach {
|
||||
|
|
0
sponge-8/.gitignore → sponge-9/.gitignore
vendored
0
sponge-8/.gitignore → sponge-9/.gitignore
vendored
|
@ -5,9 +5,7 @@ plugins {
|
|||
dependencies {
|
||||
implementation(project(":lighteco-common"))
|
||||
|
||||
compileOnly("org.spongepowered:spongeapi:8.0.0")
|
||||
|
||||
//implementation("dev.jorel:commandapi-sponge-shade:9.1.0")
|
||||
compileOnly("org.spongepowered:spongeapi:9.0.0")
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.28")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
||||
|
@ -17,8 +15,6 @@ dependencies {
|
|||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
relocate("dev.jorel.commandapi", "dev.xhyrom.lighteco.libraries.commandapi")
|
||||
|
||||
// common
|
||||
relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs")
|
||||
relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator")
|
|
@ -7,9 +7,14 @@ import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap;
|
|||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
||||
|
||||
import dev.xhyrom.lighteco.sponge.logger.SpongeLogger;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -18,15 +23,33 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Plugin("lighteco-sponge")
|
||||
|
||||
public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap {
|
||||
private final SpongeLightEcoPlugin plugin;
|
||||
private final SpongeLightEcoPlugin plugin = new SpongeLightEcoPlugin(this);
|
||||
|
||||
@Getter
|
||||
private final SpongeLightEcoLoader loader;
|
||||
|
||||
@Getter
|
||||
private final PluginLogger logger;
|
||||
|
||||
@Getter
|
||||
private final SchedulerAdapter scheduler;
|
||||
|
||||
private final Game game;
|
||||
private final PluginContainer pluginContainer;
|
||||
|
||||
@Inject
|
||||
private Logger logger;
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path configDirectory;
|
||||
|
||||
public SpongeLightEcoBootstrap() {
|
||||
this.plugin = new SpongeLightEcoPlugin(this);
|
||||
public SpongeLightEcoBootstrap(SpongeLightEcoLoader loader) {
|
||||
this.loader = loader;
|
||||
this.logger = new SpongeLogger(this.plugin, loader.getLogger());
|
||||
this.scheduler = new SpongeSchedulerAdapter(this);
|
||||
|
||||
this.game = loader.getInjector().getInstance(Game.class);
|
||||
this.pluginContainer = loader.getInjector().getInstance(PluginContainer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,17 +69,17 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
|
||||
@Override
|
||||
public Object getLoader() {
|
||||
return null;
|
||||
return this.loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginLogger getLogger() {
|
||||
return null;
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerAdapter getScheduler() {
|
||||
return null;
|
||||
return this.scheduler;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +89,7 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
return this.pluginContainer.metadata().version().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,12 +104,12 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
|
||||
@Override
|
||||
public List<UUID> getOnlinePlayers() {
|
||||
return null;
|
||||
return game.server().onlinePlayers().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceStream(String filename) {
|
||||
return null;
|
||||
return getClass().getClassLoader().getResourceAsStream(filename);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -0,0 +1,40 @@
|
|||
package dev.xhyrom.lighteco.sponge;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
|
||||
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
|
||||
@Plugin("lighteco-sponge")
|
||||
public class SpongeLightEcoLoader {
|
||||
private final SpongeLightEcoBootstrap bootstrap;
|
||||
@Getter
|
||||
private final Injector injector;
|
||||
|
||||
@Getter
|
||||
@Inject
|
||||
public Logger logger;
|
||||
|
||||
@Inject
|
||||
public SpongeLightEcoLoader(Injector injector) {
|
||||
this.injector = injector;
|
||||
this.bootstrap = new SpongeLightEcoBootstrap(this);
|
||||
}
|
||||
|
||||
@Listener(order = Order.FIRST)
|
||||
public void onEnable(ConstructPluginEvent event) {
|
||||
this.bootstrap.onLoad();
|
||||
this.bootstrap.onEnable();
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onDisable(StoppingEngineEvent<Server> event) {
|
||||
this.bootstrap.onDisable();
|
||||
}
|
||||
}
|
|
@ -9,6 +9,8 @@ import dev.xhyrom.lighteco.common.manager.user.StandardUserManager;
|
|||
import dev.xhyrom.lighteco.common.messaging.MessagingFactory;
|
||||
import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin;
|
||||
|
||||
import dev.xhyrom.lighteco.sponge.manager.SpongeCommandManager;
|
||||
import dev.xhyrom.lighteco.sponge.manager.SpongeContextManager;
|
||||
import lombok.Getter;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
@ -44,8 +46,8 @@ public class SpongeLightEcoPlugin extends AbstractLightEcoPlugin {
|
|||
public void setupManagers() {
|
||||
this.userManager = new StandardUserManager(this);
|
||||
this.currencyManager = new StandardCurrencyManager(this);
|
||||
// this.commandManager = new BukkitCommandManager(this);
|
||||
// this.contextManager = new BukkitContextManager();
|
||||
this.commandManager = new SpongeCommandManager(this);
|
||||
this.contextManager = new SpongeContextManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,10 +56,7 @@ public class SpongeLightEcoPlugin extends AbstractLightEcoPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void registerApiOnPlatform(LightEco api) {
|
||||
// this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api,
|
||||
// this.getBootstrap(), ServicePriority.Normal);
|
||||
}
|
||||
protected void registerApiOnPlatform(LightEco api) {}
|
||||
|
||||
@Override
|
||||
protected void registerPlatformHooks() {}
|
|
@ -0,0 +1,46 @@
|
|||
package dev.xhyrom.lighteco.sponge;
|
||||
|
||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter;
|
||||
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerTask;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.scheduler.ScheduledTask;
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SpongeSchedulerAdapter implements SchedulerAdapter {
|
||||
private final Executor async;
|
||||
|
||||
protected SpongeSchedulerAdapter(SpongeLightEcoBootstrap bootstrap) {
|
||||
this.async = runnable -> Sponge.asyncScheduler().submit(Task.builder().execute(runnable).build());
|
||||
}
|
||||
|
||||
private SchedulerTask submitAsyncTask(Runnable runnable, Consumer<Task.Builder> config) {
|
||||
Task.Builder builder = Task.builder();
|
||||
config.accept(builder);
|
||||
|
||||
Task task = builder
|
||||
.execute(runnable)
|
||||
.build();
|
||||
|
||||
ScheduledTask scheduledTask = Sponge.asyncScheduler().submit(task);
|
||||
return scheduledTask::cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor async() {
|
||||
return this.async;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerTask asyncLater(Runnable runnable, long delay, TimeUnit unit) {
|
||||
return submitAsyncTask(runnable, builder -> builder.delay(delay, unit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchedulerTask asyncRepeating(Runnable runnable, long interval, TimeUnit unit) {
|
||||
return submitAsyncTask(runnable, builder -> builder.delay(interval, unit).interval(interval, unit));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package dev.xhyrom.lighteco.sponge.logger;
|
||||
|
||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class SpongeLogger implements PluginLogger {
|
||||
private final LightEcoPlugin plugin;
|
||||
private final Logger logger;
|
||||
|
||||
public SpongeLogger(LightEcoPlugin plugin, Logger logger) {
|
||||
this.plugin = plugin;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
this.logger.info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message, Object... args) {
|
||||
this.logger.info(String.format(message, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
if (!this.plugin.getConfig().debug) return;
|
||||
|
||||
info(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String message, Object... args) {
|
||||
if (!this.plugin.getConfig().debug) return;
|
||||
|
||||
info(message, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message) {
|
||||
this.logger.log(Level.WARN, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message, Object... args) {
|
||||
this.logger.log(Level.WARN, String.format(message, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message, Throwable throwable) {
|
||||
this.logger.log(Level.WARN, message, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String message, Throwable throwable, Object... args) {
|
||||
this.logger.log(Level.WARN, String.format(message, args), throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message) {
|
||||
this.logger.error(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Object... args) {
|
||||
this.logger.error(String.format(message, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Throwable throwable) {
|
||||
this.logger.log(Level.ERROR, message, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String message, Throwable throwable, Object... args) {
|
||||
this.logger.log(Level.ERROR, String.format(message, args), throwable);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package dev.xhyrom.lighteco.sponge.manager;
|
||||
|
||||
import dev.xhyrom.lighteco.common.command.CommandManager;
|
||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||
|
||||
public class SpongeCommandManager extends CommandManager {
|
||||
public SpongeCommandManager(LightEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package dev.xhyrom.lighteco.sponge.manager;
|
||||
|
||||
import dev.xhyrom.lighteco.api.manager.ContextManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpongeContextManager implements ContextManager<Player> {
|
||||
@Override
|
||||
public @NonNull UUID getPlayerUniqueId(@NonNull Player player) {
|
||||
return player.uniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Class<?> getPlayerClass() {
|
||||
return Player.class;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue