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

feat: more sponge things

This commit is contained in:
Jozef Steinhübl 2024-08-27 16:22:50 +02:00
parent 240b6a3f3f
commit 5b8045236d
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
8 changed files with 110 additions and 31 deletions

View file

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

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.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

View file

@ -1,6 +1,8 @@
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;
@ -12,11 +14,16 @@ 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;
public SpongeLightEcoLoader() {
@Inject
public SpongeLightEcoLoader(Injector injector) {
this.injector = injector;
this.bootstrap = new SpongeLightEcoBootstrap(this);
}

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.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() {}

View file

@ -14,8 +14,6 @@ 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());
}
@ -31,6 +29,11 @@ public class SpongeSchedulerAdapter implements SchedulerAdapter {
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));

View file

@ -1,12 +1,16 @@
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(Logger logger) {
public SpongeLogger(LightEcoPlugin plugin, Logger logger) {
this.plugin = plugin;
this.logger = logger;
}
@ -17,27 +21,41 @@ public class SpongeLogger implements PluginLogger {
@Override
public void info(String message, Object... args) {
this.logger.info(message, 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.warn(message);
this.logger.log(Level.WARN, message);
}
@Override
public void warn(String message, Object... args) {
this.logger.warn(message, args);
this.logger.log(Level.WARN, String.format(message, args));
}
@Override
public void warn(String message, Throwable throwable) {
this.logger.warn(message, throwable);
this.logger.log(Level.WARN, message, throwable);
}
@Override
public void warn(String message, Throwable throwable, Object... args) {
this.logger.warn(String.format(message, args), throwable);
this.logger.log(Level.WARN, String.format(message, args), throwable);
}
@Override
@ -47,16 +65,16 @@ public class SpongeLogger implements PluginLogger {
@Override
public void error(String message, Object... args) {
this.logger.error(message, args);
this.logger.error(String.format(message, args));
}
@Override
public void error(String message, Throwable throwable) {
this.logger.error(message, throwable);
this.logger.log(Level.ERROR, message, throwable);
}
@Override
public void error(String message, Throwable throwable, Object... args) {
this.logger.error(String.format(message, args), throwable);
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;
}
}