mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-24 07:41:05 +01:00
feat: more sponge things
This commit is contained in:
parent
240b6a3f3f
commit
5b8045236d
8 changed files with 110 additions and 31 deletions
|
@ -4,7 +4,7 @@ sequenceOf(
|
||||||
"api",
|
"api",
|
||||||
"common",
|
"common",
|
||||||
"paper",
|
"paper",
|
||||||
"sponge-8",
|
"sponge-9",
|
||||||
"currency-money",
|
"currency-money",
|
||||||
"test"
|
"test"
|
||||||
).forEach {
|
).forEach {
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package dev.xhyrom.lighteco.sponge;
|
package dev.xhyrom.lighteco.sponge;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import lombok.Getter;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.spongepowered.api.Server;
|
import org.spongepowered.api.Server;
|
||||||
import org.spongepowered.api.event.Listener;
|
import org.spongepowered.api.event.Listener;
|
||||||
|
@ -12,11 +14,16 @@ import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||||
@Plugin("lighteco-sponge")
|
@Plugin("lighteco-sponge")
|
||||||
public class SpongeLightEcoLoader {
|
public class SpongeLightEcoLoader {
|
||||||
private final SpongeLightEcoBootstrap bootstrap;
|
private final SpongeLightEcoBootstrap bootstrap;
|
||||||
|
@Getter
|
||||||
|
private final Injector injector;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@Inject
|
@Inject
|
||||||
public Logger logger;
|
public Logger logger;
|
||||||
|
|
||||||
public SpongeLightEcoLoader() {
|
@Inject
|
||||||
|
public SpongeLightEcoLoader(Injector injector) {
|
||||||
|
this.injector = injector;
|
||||||
this.bootstrap = new SpongeLightEcoBootstrap(this);
|
this.bootstrap = new SpongeLightEcoBootstrap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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() {}
|
||||||
|
|
|
@ -14,8 +14,6 @@ public class SpongeSchedulerAdapter implements SchedulerAdapter {
|
||||||
private final Executor async;
|
private final Executor async;
|
||||||
|
|
||||||
protected SpongeSchedulerAdapter(SpongeLightEcoBootstrap bootstrap) {
|
protected SpongeSchedulerAdapter(SpongeLightEcoBootstrap bootstrap) {
|
||||||
this.plugin = bootstrap.getLoader();
|
|
||||||
|
|
||||||
this.async = runnable -> Sponge.asyncScheduler().submit(Task.builder().execute(runnable).build());
|
this.async = runnable -> Sponge.asyncScheduler().submit(Task.builder().execute(runnable).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +29,11 @@ public class SpongeSchedulerAdapter implements SchedulerAdapter {
|
||||||
return scheduledTask::cancel;
|
return scheduledTask::cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Executor async() {
|
||||||
|
return this.async;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SchedulerTask asyncLater(Runnable runnable, long delay, TimeUnit unit) {
|
public SchedulerTask asyncLater(Runnable runnable, long delay, TimeUnit unit) {
|
||||||
return submitAsyncTask(runnable, builder -> builder.delay(delay, unit));
|
return submitAsyncTask(runnable, builder -> builder.delay(delay, unit));
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package dev.xhyrom.lighteco.sponge.logger;
|
package dev.xhyrom.lighteco.sponge.logger;
|
||||||
|
|
||||||
|
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||||
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
public class SpongeLogger implements PluginLogger {
|
public class SpongeLogger implements PluginLogger {
|
||||||
|
private final LightEcoPlugin plugin;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
public SpongeLogger(Logger logger) {
|
public SpongeLogger(LightEcoPlugin plugin, Logger logger) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,27 +21,41 @@ public class SpongeLogger implements PluginLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void info(String message, Object... args) {
|
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
|
@Override
|
||||||
public void warn(String message) {
|
public void warn(String message) {
|
||||||
this.logger.warn(message);
|
this.logger.log(Level.WARN, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warn(String message, Object... args) {
|
public void warn(String message, Object... args) {
|
||||||
this.logger.warn(message, args);
|
this.logger.log(Level.WARN, String.format(message, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warn(String message, Throwable throwable) {
|
public void warn(String message, Throwable throwable) {
|
||||||
this.logger.warn(message, throwable);
|
this.logger.log(Level.WARN, message, throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void warn(String message, Throwable throwable, Object... args) {
|
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
|
@Override
|
||||||
|
@ -47,16 +65,16 @@ public class SpongeLogger implements PluginLogger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message, Object... args) {
|
public void error(String message, Object... args) {
|
||||||
this.logger.error(message, args);
|
this.logger.error(String.format(message, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message, Throwable throwable) {
|
public void error(String message, Throwable throwable) {
|
||||||
this.logger.error(message, throwable);
|
this.logger.log(Level.ERROR, message, throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String message, Throwable throwable, Object... args) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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