From 15e23dd047d4eb6bc54e4e7f7515918342b94e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl=20=28xHyroM=29?= Date: Sat, 2 Sep 2023 23:23:27 +0200 Subject: [PATCH] feat: sponge 9 --- settings.gradle.kts | 2 +- {sponge-8 => sponge-9}/.gitignore | 0 {sponge-8 => sponge-9}/README.md | 0 {sponge-8 => sponge-9}/build.gradle.kts | 6 +- .../sponge/SpongeLightEcoBootstrap.java | 37 ++++------- .../lighteco/sponge/SpongeLightEcoLoader.java | 33 ++++++++++ .../lighteco/sponge/SpongeLightEcoPlugin.java | 0 .../sponge/SpongeSchedulerAdapter.java | 43 +++++++++++++ .../lighteco/sponge/logger/SpongeLogger.java | 62 +++++++++++++++++++ .../resources/META-INF/sponge_plugins.json | 0 10 files changed, 153 insertions(+), 30 deletions(-) rename {sponge-8 => sponge-9}/.gitignore (100%) rename {sponge-8 => sponge-9}/README.md (100%) rename {sponge-8 => sponge-9}/build.gradle.kts (82%) rename {sponge-8 => sponge-9}/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java (65%) create mode 100644 sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoLoader.java rename {sponge-8 => sponge-9}/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoPlugin.java (100%) create mode 100644 sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeSchedulerAdapter.java create mode 100644 sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/logger/SpongeLogger.java rename {sponge-8 => sponge-9}/src/main/resources/META-INF/sponge_plugins.json (100%) diff --git a/settings.gradle.kts b/settings.gradle.kts index 854271b..327bd3f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ sequenceOf( "common", "bukkit", "bukkittest", - "sponge-8", + "sponge-9", "currency-money" ).forEach { include("lighteco-$it") diff --git a/sponge-8/.gitignore b/sponge-9/.gitignore similarity index 100% rename from sponge-8/.gitignore rename to sponge-9/.gitignore diff --git a/sponge-8/README.md b/sponge-9/README.md similarity index 100% rename from sponge-8/README.md rename to sponge-9/README.md diff --git a/sponge-8/build.gradle.kts b/sponge-9/build.gradle.kts similarity index 82% rename from sponge-8/build.gradle.kts rename to sponge-9/build.gradle.kts index 0984a16..1eb08fb 100644 --- a/sponge-8/build.gradle.kts +++ b/sponge-9/build.gradle.kts @@ -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") diff --git a/sponge-8/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java similarity index 65% rename from sponge-8/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java rename to sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java index 469ab9f..307e62e 100644 --- a/sponge-8/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java +++ b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoBootstrap.java @@ -1,27 +1,31 @@ package dev.xhyrom.lighteco.sponge; -import com.google.inject.Inject; import dev.xhyrom.lighteco.common.plugin.bootstrap.LightEcoBootstrap; 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 org.apache.logging.log4j.Logger; -import org.spongepowered.plugin.builtin.jvm.Plugin; +import dev.xhyrom.lighteco.sponge.logger.SpongeLogger; +import lombok.Getter; import java.io.InputStream; import java.nio.file.Path; import java.util.List; import java.util.UUID; -@Plugin("lighteco-sponge") public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap { - private final SpongeLightEcoPlugin plugin; + private final SpongeLightEcoPlugin plugin = new SpongeLightEcoPlugin(this); - @Inject - private Logger logger; + @Getter + private final SpongeLightEcoLoader loader; + @Getter + private final PluginLogger logger; + @Getter + private final SchedulerAdapter scheduler; - public SpongeLightEcoBootstrap() { - this.plugin = new SpongeLightEcoPlugin(this); + public SpongeLightEcoBootstrap(SpongeLightEcoLoader loader) { + this.loader = loader; + this.logger = new SpongeLogger(loader.logger); + this.scheduler = new SpongeSchedulerAdapter(this); } @Override @@ -39,21 +43,6 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr this.plugin.disable(); } - @Override - public Object getLoader() { - return null; - } - - @Override - public PluginLogger getLogger() { - return null; - } - - @Override - public SchedulerAdapter getScheduler() { - return null; - } - @Override public Path getDataDirectory() { return null; diff --git a/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoLoader.java b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoLoader.java new file mode 100644 index 0000000..e1ecde4 --- /dev/null +++ b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoLoader.java @@ -0,0 +1,33 @@ +package dev.xhyrom.lighteco.sponge; + +import com.google.inject.Inject; +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; + + @Inject + public Logger logger; + + public SpongeLightEcoLoader() { + 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 event) { + this.bootstrap.onDisable(); + } +} diff --git a/sponge-8/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoPlugin.java b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoPlugin.java similarity index 100% rename from sponge-8/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoPlugin.java rename to sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeLightEcoPlugin.java diff --git a/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeSchedulerAdapter.java b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeSchedulerAdapter.java new file mode 100644 index 0000000..98397a9 --- /dev/null +++ b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/SpongeSchedulerAdapter.java @@ -0,0 +1,43 @@ +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.plugin = bootstrap.getLoader(); + + this.async = runnable -> Sponge.asyncScheduler().submit(Task.builder().execute(runnable).build()); + } + + private SchedulerTask submitAsyncTask(Runnable runnable, Consumer 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 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)); + } +} diff --git a/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/logger/SpongeLogger.java b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/logger/SpongeLogger.java new file mode 100644 index 0000000..7cf37a6 --- /dev/null +++ b/sponge-9/src/main/java/dev/xhyrom/lighteco/sponge/logger/SpongeLogger.java @@ -0,0 +1,62 @@ +package dev.xhyrom.lighteco.sponge.logger; + +import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger; +import org.apache.logging.log4j.Logger; + +public class SpongeLogger implements PluginLogger { + private final Logger logger; + + public SpongeLogger(Logger logger) { + this.logger = logger; + } + + @Override + public void info(String message) { + this.logger.info(message); + } + + @Override + public void info(String message, Object... args) { + this.logger.info(message, args); + } + + @Override + public void warn(String message) { + this.logger.warn(message); + } + + @Override + public void warn(String message, Object... args) { + this.logger.warn(message, args); + } + + @Override + public void warn(String message, Throwable throwable) { + this.logger.warn(message, throwable); + } + + @Override + public void warn(String message, Throwable throwable, Object... args) { + this.logger.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(message, args); + } + + @Override + public void error(String message, Throwable throwable) { + this.logger.error(message, throwable); + } + + @Override + public void error(String message, Throwable throwable, Object... args) { + this.logger.error(String.format(message, args), throwable); + } +} diff --git a/sponge-8/src/main/resources/META-INF/sponge_plugins.json b/sponge-9/src/main/resources/META-INF/sponge_plugins.json similarity index 100% rename from sponge-8/src/main/resources/META-INF/sponge_plugins.json rename to sponge-9/src/main/resources/META-INF/sponge_plugins.json