1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-23 15:21:06 +01:00
This commit is contained in:
Jozef Steinhübl 2024-11-21 23:58:37 +01:00 committed by GitHub
commit f7e3249d67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 236 additions and 23 deletions

View file

@ -4,7 +4,7 @@ sequenceOf(
"api", "api",
"common", "common",
"paper", "paper",
"sponge-8", "sponge-9",
"currency-money", "currency-money",
"test" "test"
).forEach { ).forEach {

View file

@ -5,9 +5,7 @@ plugins {
dependencies { dependencies {
implementation(project(":lighteco-common")) implementation(project(":lighteco-common"))
compileOnly("org.spongepowered:spongeapi:8.0.0") compileOnly("org.spongepowered:spongeapi:9.0.0")
//implementation("dev.jorel:commandapi-sponge-shade:9.1.0")
compileOnly("org.projectlombok:lombok:1.18.28") compileOnly("org.projectlombok:lombok:1.18.28")
annotationProcessor("org.projectlombok:lombok:1.18.28") annotationProcessor("org.projectlombok:lombok:1.18.28")
@ -17,8 +15,6 @@ dependencies {
} }
tasks.shadowJar { tasks.shadowJar {
relocate("dev.jorel.commandapi", "dev.xhyrom.lighteco.libraries.commandapi")
// common // common
relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs") relocate("eu.okaeri.configs", "dev.xhyrom.lighteco.libraries.okaeri.configs")
relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator") relocate("eu.okaeri.validator", "dev.xhyrom.lighteco.libraries.okaeri.validator")

View file

@ -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.logger.PluginLogger;
import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; 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 net.kyori.adventure.audience.Audience;
import org.apache.logging.log4j.Logger; 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 org.spongepowered.plugin.builtin.jvm.Plugin;
import java.io.InputStream; import java.io.InputStream;
@ -18,15 +23,33 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@Plugin("lighteco-sponge")
public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstrap { 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 @Inject
private Logger logger; @ConfigDir(sharedRoot = false)
private Path configDirectory;
public SpongeLightEcoBootstrap() { public SpongeLightEcoBootstrap(SpongeLightEcoLoader loader) {
this.plugin = new SpongeLightEcoPlugin(this); 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 @Override
@ -46,17 +69,17 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
@Override @Override
public Object getLoader() { public Object getLoader() {
return null; return this.loader;
} }
@Override @Override
public PluginLogger getLogger() { public PluginLogger getLogger() {
return null; return this.logger;
} }
@Override @Override
public SchedulerAdapter getScheduler() { public SchedulerAdapter getScheduler() {
return null; return this.scheduler;
} }
@Override @Override
@ -66,7 +89,7 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
@Override @Override
public String getVersion() { public String getVersion() {
return null; return this.pluginContainer.metadata().version().toString();
} }
@Override @Override
@ -81,12 +104,12 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
@Override @Override
public List<UUID> getOnlinePlayers() { public List<UUID> getOnlinePlayers() {
return null; return game.server().onlinePlayers().size();
} }
@Override @Override
public InputStream getResourceStream(String filename) { public InputStream getResourceStream(String filename) {
return null; return getClass().getClassLoader().getResourceAsStream(filename);
} }
@Override @Override

View file

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

View file

@ -9,6 +9,8 @@ import dev.xhyrom.lighteco.common.manager.user.StandardUserManager;
import dev.xhyrom.lighteco.common.messaging.MessagingFactory; import dev.xhyrom.lighteco.common.messaging.MessagingFactory;
import dev.xhyrom.lighteco.common.plugin.AbstractLightEcoPlugin; 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 lombok.Getter;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@ -44,8 +46,8 @@ public class SpongeLightEcoPlugin extends AbstractLightEcoPlugin {
public void setupManagers() { public void setupManagers() {
this.userManager = new StandardUserManager(this); this.userManager = new StandardUserManager(this);
this.currencyManager = new StandardCurrencyManager(this); this.currencyManager = new StandardCurrencyManager(this);
// this.commandManager = new BukkitCommandManager(this); this.commandManager = new SpongeCommandManager(this);
// this.contextManager = new BukkitContextManager(); this.contextManager = new SpongeContextManager();
} }
@Override @Override
@ -54,10 +56,7 @@ public class SpongeLightEcoPlugin extends AbstractLightEcoPlugin {
} }
@Override @Override
protected void registerApiOnPlatform(LightEco api) { protected void registerApiOnPlatform(LightEco api) {}
// this.getBootstrap().getServer().getServicesManager().register(LightEco.class, api,
// this.getBootstrap(), ServicePriority.Normal);
}
@Override @Override
protected void registerPlatformHooks() {} protected void registerPlatformHooks() {}

View file

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

View file

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

View file

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

View file

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