1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-25 08:11:04 +01:00

feat: sponge 9

This commit is contained in:
Jozef Steinhübl 2023-09-02 23:23:27 +02:00
parent 670f2b5dbd
commit 15e23dd047
No known key found for this signature in database
GPG key ID: E944BC293F5FF7E7
10 changed files with 153 additions and 30 deletions

View file

@ -5,7 +5,7 @@ sequenceOf(
"common",
"bukkit",
"bukkittest",
"sponge-8",
"sponge-9",
"currency-money"
).forEach {
include("lighteco-$it")

View file

@ -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")

View file

@ -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;

View file

@ -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<Server> event) {
this.bootstrap.onDisable();
}
}

View file

@ -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<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 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));
}
}

View file

@ -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);
}
}