From 4a966cb2007a1d3e3109ccd0d6146aa5ff2ac074 Mon Sep 17 00:00:00 2001 From: Nathan Martin Date: Tue, 28 Mar 2023 11:45:28 -0400 Subject: [PATCH 1/6] Fix NullPointerException during plugin death. --- .../rustyconnector/core/lib/database/Redis.java | 16 ++++------------ .../core/lib/lang_messaging/Lang.java | 10 +++++----- .../rustyconnector/plugin/paper/Engine.java | 11 ++++++----- .../plugin/paper/PaperRustyConnector.java | 9 ++++++--- plugin.yml | 2 +- velocity-plugin.json | 2 +- .../rustyconnector/plugin/velocity/Engine.java | 10 ++++++---- .../plugin/velocity/VelocityRustyConnector.java | 10 +++++++--- 8 files changed, 36 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java index 761a24129..faf972bff 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java @@ -27,9 +27,6 @@ public class Redis { public Redis() {} - /** - * Sets the connection - */ public void setConnection(String host, int port, String password, String dataChannel) { this.host = host; this.port = port; @@ -37,10 +34,8 @@ public void setConnection(String host, int port, String password, String dataCha this.dataChannel = dataChannel; } - /** - * Tests the connection to the provided Redis server - */ - public void connect(RustyConnector plugin) throws ExceptionInInitializerError{ + + public void connect(RustyConnector plugin) throws ExceptionInInitializerError { try{ if(!(this.client == null)) return; @@ -50,6 +45,7 @@ public void connect(RustyConnector plugin) throws ExceptionInInitializerError{ final JedisPoolConfig poolConfig = new JedisPoolConfig(); this.pool = new JedisPool(poolConfig, this.host, this.port, 0); + this.jedisSubscriber = this.pool.getResource(); this.jedisSubscriber.auth(this.password); this.subscriber = new Subscriber(plugin); @@ -72,9 +68,6 @@ protected void publish(String message) throws IllegalArgumentException { this.client.publish(this.dataChannel, message); } - /** - * When redis disconnects - */ public void disconnect() throws ExceptionInInitializerError { try { this.subscriber.unsubscribe(); @@ -121,6 +114,5 @@ public void onMessage(String channel, String rawMessage) { * @param parameters Additional parameters * @throws IllegalArgumentException If message parameters contains parameters: `pk`, `type`, or `ip` */ - public void sendMessage(String privateKey, RedisMessageType type, InetSocketAddress address, Map parameters) throws IllegalArgumentException { - } + public void sendMessage(String privateKey, RedisMessageType type, InetSocketAddress address, Map parameters) throws IllegalArgumentException {} } diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java index 3aaac7ba6..f2d7c22fd 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java @@ -168,7 +168,7 @@ default void send(Logger sender) { sender.send( join( newlines(), - text(""), + text("RustyConnector:"), build() ) ); @@ -181,7 +181,7 @@ default void send(Logger sender, A1 arg1) { sender.send( join( JoinConfiguration.separator(newline()), - text(""), + text("RustyConnector:"), build(arg1) ) ); @@ -194,7 +194,7 @@ default void send(Logger sender, A1 arg1, A2 arg2) { sender.send( join( newlines(), - text(""), + text("RustyConnector:"), build(arg1, arg2) ) ); @@ -207,7 +207,7 @@ default void send(Logger sender, A1 arg1, A2 arg2, A3 arg3) { sender.send( join( newlines(), - text(""), + text("RustyConnector:"), build(arg1, arg2, arg3) ) ); @@ -220,7 +220,7 @@ default void send(Logger sender, A1 arg1, A2 arg2, A3 arg3, A4 arg4) { sender.send( join( newlines(), - text(""), + text("RustyConnector:"), build(arg1, arg2, arg3, arg4) ) ); diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java index e2a341100..980381779 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java @@ -29,12 +29,13 @@ public static boolean start() { } public static void stop() { PaperRustyConnector plugin = PaperRustyConnector.getInstance(); - - plugin.getVirtualServer().unregisterFromProxy(); - DefaultConfig.empty(); - plugin.getVirtualServer().killRedis(); + if(plugin.getVirtualServer() != null) { + plugin.getVirtualServer().unregisterFromProxy(); + + plugin.getVirtualServer().killRedis(); + } plugin.getCommandManager().deleteRootCommand("rc"); } @@ -47,7 +48,7 @@ private static boolean initConfigs(PaperRustyConnector plugin) { } defaultConfig.register(); - plugin.setServer(PaperServer.init(defaultConfig)); + plugin.setVirtualServer(PaperServer.init(defaultConfig)); Lang.WORDMARK_RUSTY_CONNECTOR.send(plugin.logger()); diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java index c71425cdc..ff988b1fe 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java @@ -15,7 +15,6 @@ public final class PaperRustyConnector extends JavaPlugin implements Listener, R private PluginLogger logger; private PaperServer server; private PaperCommandManager commandManager; - public boolean hasRegistered = false; public static PaperRustyConnector getInstance() { return PaperRustyConnector.instance; } @@ -40,7 +39,7 @@ public PaperCommandManager getCommandManager() { * Set the PaperServer handler for the plugin. Once this is set it cannot be changed. * @param server The PaperServer to set. */ - public void setServer(PaperServer server) throws IllegalStateException { + public void setVirtualServer(PaperServer server) throws IllegalStateException { if(this.server != null) throw new IllegalStateException("This has already been set! You can't set this twice!"); this.server = server; } @@ -57,7 +56,11 @@ public void onEnable() { @Override public void onDisable() { - Engine.stop(); + try { + Engine.stop(); + } catch (Exception e) { + this.logger().log("RustyConnector: " + e.getMessage()); + } } @Override diff --git a/plugin.yml b/plugin.yml index 60d0aada6..f9b5146bf 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: rustyconnector-paper -version: '0.4.0' +version: '0.4.1' main: group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector api-version: 1.16 authors: [ Sivin ] diff --git a/velocity-plugin.json b/velocity-plugin.json index 8b3a945d5..237015d4d 100644 --- a/velocity-plugin.json +++ b/velocity-plugin.json @@ -1,7 +1,7 @@ { "id":"rustyconnector-velocity", "name":"RustyConnector", - "version":"0.4.0", + "version":"0.4.1", "description":"A player and server connection manager for Velocity based Minecraft Networks!", "authors":["sivin"], "main":"group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector", diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java index 966972e85..03acb27cf 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java @@ -58,9 +58,11 @@ public static void stop() { FamilyConfig.empty(); LoggerConfig.empty(); - plugin.getVirtualServer().killHeartbeats(); - plugin.getVirtualServer().killRedis(); - plugin.unsetProxy(); + if(plugin.getVirtualServer() != null) { + plugin.getVirtualServer().killHeartbeats(); + plugin.getVirtualServer().killRedis(); + plugin.unsetVirtualServer(); + } plugin.getVelocityServer().getCommandManager().unregister("rc"); @@ -86,7 +88,7 @@ private static boolean initConfigs(VelocityRustyConnector plugin) { loggerConfig.register(); PluginLogger.init(loggerConfig); - plugin.setProxy(Proxy.init(defaultConfig)); + plugin.setVirtualServer(Proxy.init(defaultConfig)); return true; } catch (NoOutputException ignore) { diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java index a6b5c6964..064bd520f 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java @@ -27,11 +27,11 @@ public class VelocityRustyConnector implements RustyConnector { * Set the proxy for Velocity. Once this is set it cannot be changed. * @param proxy The proxy to set. */ - public void setProxy(Proxy proxy) throws IllegalStateException { + public void setVirtualServer(Proxy proxy) throws IllegalStateException { if(this.proxy != null) throw new IllegalStateException("This has already been set! You can't set this twice!"); this.proxy = proxy; } - public void unsetProxy() { + public void unsetVirtualServer() { this.proxy = null; } @@ -54,7 +54,11 @@ public void onLoad(ProxyInitializeEvent event) { @Subscribe public void onUnload(ProxyShutdownEvent event) { - this.uninit(); + try { + this.uninit(); + } catch (Exception e) { + this.logger().log("RustyConnector: " + e.getMessage()); + } } public void init() { From 53e284cfaec24a3ad4292cbed5001aaae8ef169d Mon Sep 17 00:00:00 2001 From: Nathan Martin Date: Fri, 31 Mar 2023 00:19:35 -0400 Subject: [PATCH 2/6] Rewrite root plugin core and API --- README.md | 4 +- .../rustyconnector/core/RustyConnector.java | 34 ---- .../core/central/PluginAPI.java | 22 ++ .../core/central/PluginLifecycle.java | 18 ++ .../Logger.java => central/PluginLogger.java} | 5 +- .../core/central/PluginRuntime.java | 15 ++ .../core/lib/database/Redis.java | 16 +- .../DuplicateLifecycleException.java | 7 + .../core/lib/lang_messaging/Lang.java | 11 +- .../model/{Server.java => PlayerServer.java} | 2 +- .../core/lib/model/VirtualProcessor.java | 4 + .../core/lib/util/WeightedQuickSort.java | 4 +- paper/pom.xml | 16 ++ .../rustyconnector/plugin/paper/Engine.java | 91 --------- .../plugin/paper/PaperRustyConnector.java | 99 +++------ .../plugin/paper/PluginLogger.java | 4 +- .../plugin/paper/central/PaperAPI.java | 99 +++++++++ .../plugin/paper/central/PaperLifecycle.java | 100 +++++++++ .../plugin/paper/commands/CommandRusty.java | 36 ++-- ...erver.java => VirtualServerProcessor.java} | 36 ++-- .../paper/lib/config/DefaultConfig.java | 6 +- .../plugin/paper/lib/config/YAML.java | 27 +-- .../plugin/paper/lib/database/Redis.java | 22 +- .../plugin/paper/lib/events/OnPlayerJoin.java | 9 +- .../paper/lib/events/OnPlayerLeave.java | 9 +- .../lib/message/handling/PingHandler.java | 6 +- .../message/handling/ServerRegAllHandler.java | 11 +- .../handling/ServerRegFamilyHandler.java | 13 +- .../handling/TPAQueuePlayerHandler.java | 9 +- .../plugin/paper/lib/tpa/TPARequest.java | 10 +- .../paper/lib/tpa/TeleportRunnable.java | 22 -- plugin.yml | 5 +- .../plugin/velocity/PluginLogger.java | 10 +- .../velocity/VelocityRustyConnector.java | 88 +++----- .../plugin/velocity/central/VelocityAPI.java | 100 +++++++++ .../VelocityLifecycle.java} | 93 +++++---- .../velocity/commands/CommandRusty.java | 168 +++++++-------- .../plugin/velocity/commands/CommandTPA.java | 65 +++--- .../plugin/velocity/lib/Clock.java | 5 +- .../velocity/lib/config/DefaultConfig.java | 15 +- .../velocity/lib/config/WhitelistConfig.java | 6 +- .../plugin/velocity/lib/config/YAML.java | 15 +- .../plugin/velocity/lib/database/Redis.java | 48 +++-- .../lib/events/OnPlayerChangeServer.java | 20 +- .../events/OnPlayerChooseInitialServer.java | 11 +- .../lib/events/OnPlayerDisconnect.java | 7 +- .../velocity/lib/events/OnPlayerKicked.java | 7 +- .../lib/lang_messaging/VelocityLang.java | 9 +- .../lib/load_balancing/LeastConnection.java | 9 +- .../PaperServerLoadBalancer.java | 16 +- .../velocity/lib/managers/ServerManager.java | 14 +- .../lib/message/handling/PongHandler.java | 20 +- .../message/handling/SendPlayerHandler.java | 7 +- .../message/handling/ServerRegHandler.java | 4 +- .../message/handling/ServerUnRegHandler.java | 5 +- .../{PaperServer.java => PlayerServer.java} | 21 +- .../velocity/lib/module/ServerFamily.java | 58 +++--- ...{Proxy.java => VirtualProxyProcessor.java} | 192 +++++++++--------- .../plugin/velocity/lib/module/Whitelist.java | 12 +- .../plugin/velocity/lib/tpa/TPARequest.java | 11 +- 60 files changed, 1040 insertions(+), 768 deletions(-) delete mode 100644 core/src/main/java/group/aelysium/rustyconnector/core/RustyConnector.java create mode 100644 core/src/main/java/group/aelysium/rustyconnector/core/central/PluginAPI.java create mode 100644 core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLifecycle.java rename core/src/main/java/group/aelysium/rustyconnector/core/{lib/lang_messaging/Logger.java => central/PluginLogger.java} (72%) create mode 100644 core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java create mode 100644 core/src/main/java/group/aelysium/rustyconnector/core/lib/exception/DuplicateLifecycleException.java rename core/src/main/java/group/aelysium/rustyconnector/core/lib/model/{Server.java => PlayerServer.java} (91%) create mode 100644 core/src/main/java/group/aelysium/rustyconnector/core/lib/model/VirtualProcessor.java delete mode 100644 paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java create mode 100644 paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java create mode 100644 paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java rename paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/{PaperServer.java => VirtualServerProcessor.java} (83%) delete mode 100644 paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TeleportRunnable.java create mode 100644 velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java rename velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/{Engine.java => central/VelocityLifecycle.java} (51%) rename velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/{PaperServer.java => PlayerServer.java} (90%) rename velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/{Proxy.java => VirtualProxyProcessor.java} (72%) diff --git a/README.md b/README.md index daaaccf2f..4001bcf68 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ # [Modrinth](https://modrinth.com/plugin/rustyconnector) | [Paper Forums](https://forums.papermc.io/threads/rustyconnector-advanced-velocity-server-and-player-connection-manager.663/) | [Hangar](https://hangar.papermc.io/nathan-i-martin/RustyConnector) --- - ### ✅ Built for large networks -- ### ✅ Register brand new servers to the proxy during runtime +- ### ✅ Register brand new servers to the virtualProxyProcessor during runtime - ### ✅ Blazing fast data transmission with Redis integration - ### ✅ Create pre-defined whitelist configs and activate them dynamically - ### ✅ Register similar servers into families with family-level whitelists and load balancing -- ### ✅ Automatically unregister frozen servers from the proxy +- ### ✅ Automatically unregister frozen servers from the virtualProxyProcessor - ### ✅ Set soft and hard player limits for servers - ### ✅ Whitelist players based on permission, Username, UUID, or IP Address - ### ✅ Works with LuckPerms-Velocity diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/RustyConnector.java b/core/src/main/java/group/aelysium/rustyconnector/core/RustyConnector.java deleted file mode 100644 index 72476ebac..000000000 --- a/core/src/main/java/group/aelysium/rustyconnector/core/RustyConnector.java +++ /dev/null @@ -1,34 +0,0 @@ -package group.aelysium.rustyconnector.core; - -import group.aelysium.rustyconnector.core.lib.database.Redis; -import group.aelysium.rustyconnector.core.lib.lang_messaging.Logger; - -import java.io.File; -import java.io.InputStream; - -public interface RustyConnector { - RustyConnector instance = null; - Redis redis = null; - - static RustyConnector getInstance() { - return instance; - } - - /** - * Get's the data folder containing the configuration files for this plugin. - * @return The data folder - */ - File getDataFolder(); - - /** - * - */ - InputStream getResourceAsStream(String filename); - - /** - * Reload the plugin - */ - void reload(); - - Logger logger(); -} diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginAPI.java b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginAPI.java new file mode 100644 index 000000000..08b515200 --- /dev/null +++ b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginAPI.java @@ -0,0 +1,22 @@ +package group.aelysium.rustyconnector.core.central; + +import group.aelysium.rustyconnector.core.lib.model.VirtualProcessor; + +import java.io.InputStream; + +public abstract class PluginAPI { + /** + * Gets a resource by name and returns it as a stream. + * @param filename The name of the resource to get. + * @return The resource as a stream. + */ + abstract public InputStream getResourceAsStream(String filename); + + abstract public S getScheduler(); + + abstract public PluginLogger getLogger(); + + abstract public VirtualProcessor getVirtualProcessor(); + + abstract public String getDataFolder(); +} diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLifecycle.java b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLifecycle.java new file mode 100644 index 000000000..9bcb537a5 --- /dev/null +++ b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLifecycle.java @@ -0,0 +1,18 @@ +package group.aelysium.rustyconnector.core.central; + +import group.aelysium.rustyconnector.core.lib.exception.DuplicateLifecycleException; + +public abstract class PluginLifecycle { + protected boolean isRunning = false; + + public boolean isRunning() { + return this.isRunning; + } + + public abstract boolean start() throws DuplicateLifecycleException; + public abstract void stop(); + + protected abstract boolean loadConfigs(); + protected abstract boolean loadCommands(); + protected abstract boolean loadEvents(); +} diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Logger.java b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLogger.java similarity index 72% rename from core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Logger.java rename to core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLogger.java index c7a52fbac..92910804b 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Logger.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginLogger.java @@ -1,8 +1,9 @@ -package group.aelysium.rustyconnector.core.lib.lang_messaging; +package group.aelysium.rustyconnector.core.central; +import group.aelysium.rustyconnector.core.lib.lang_messaging.LoggerGate; import net.kyori.adventure.text.Component; -public interface Logger { +public interface PluginLogger { LoggerGate getGate(); void log(String message); diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java new file mode 100644 index 000000000..1b552258c --- /dev/null +++ b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java @@ -0,0 +1,15 @@ +package group.aelysium.rustyconnector.core.central; + +import group.aelysium.rustyconnector.core.lib.database.Redis; + +public interface PluginRuntime> { + Redis redis = null; + + static PluginAPI getAPI() { + return null; + } + + static PluginLifecycle getLifecycle() { + return null; + } +} diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java index faf972bff..688a1687f 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/database/Redis.java @@ -1,5 +1,7 @@ package group.aelysium.rustyconnector.core.lib.database; +import group.aelysium.rustyconnector.core.central.PluginAPI; +import group.aelysium.rustyconnector.core.central.PluginLogger; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessageType; import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; import net.kyori.adventure.text.Component; @@ -8,7 +10,7 @@ import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisPubSub; -import group.aelysium.rustyconnector.core.RustyConnector; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import java.net.InetSocketAddress; import java.util.Map; @@ -35,7 +37,7 @@ public void setConnection(String host, int port, String password, String dataCha } - public void connect(RustyConnector plugin) throws ExceptionInInitializerError { + public void connect(PluginAPI api) throws ExceptionInInitializerError { try{ if(!(this.client == null)) return; @@ -48,7 +50,7 @@ public void connect(RustyConnector plugin) throws ExceptionInInitializerError { this.jedisSubscriber = this.pool.getResource(); this.jedisSubscriber.auth(this.password); - this.subscriber = new Subscriber(plugin); + this.subscriber = new Subscriber(api); this.subscriberThread = new Thread(() -> { try { @@ -60,7 +62,7 @@ public void connect(RustyConnector plugin) throws ExceptionInInitializerError { this.subscriberThread.start(); } catch (Exception e) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("REDIS: "+ e.getMessage()), NamedTextColor.RED); + Lang.BOXED_MESSAGE_COLORED.send(api.getLogger(), Component.text("REDIS: "+ e.getMessage()), NamedTextColor.RED); } } @@ -90,10 +92,10 @@ public void disconnect() throws ExceptionInInitializerError { public void onMessage(String rawMessage) {} public class Subscriber extends JedisPubSub { - private RustyConnector plugin; + private PluginAPI api; - public Subscriber(RustyConnector plugin) { - this.plugin = plugin; + public Subscriber(PluginAPI api) { + this.api = api; } @Override diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/exception/DuplicateLifecycleException.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/exception/DuplicateLifecycleException.java new file mode 100644 index 000000000..60af5d8fc --- /dev/null +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/exception/DuplicateLifecycleException.java @@ -0,0 +1,7 @@ +package group.aelysium.rustyconnector.core.lib.exception; + +public class DuplicateLifecycleException extends Exception { + public DuplicateLifecycleException(String errorMessage) { + super(errorMessage); + } +} diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java index f2d7c22fd..eef7af771 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/lang_messaging/Lang.java @@ -1,5 +1,6 @@ package group.aelysium.rustyconnector.core.lib.lang_messaging; +import group.aelysium.rustyconnector.core.central.PluginLogger; import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; @@ -164,7 +165,7 @@ static JoinConfiguration newlines() { interface Message { Component build(); - default void send(Logger sender) { + default void send(PluginLogger sender) { sender.send( join( newlines(), @@ -177,7 +178,7 @@ default void send(Logger sender) { interface ParameterizedMessage1 { Component build(A1 arg1); - default void send(Logger sender, A1 arg1) { + default void send(PluginLogger sender, A1 arg1) { sender.send( join( JoinConfiguration.separator(newline()), @@ -190,7 +191,7 @@ default void send(Logger sender, A1 arg1) { interface ParameterizedMessage2 { Component build(A1 arg1, A2 arg2); - default void send(Logger sender, A1 arg1, A2 arg2) { + default void send(PluginLogger sender, A1 arg1, A2 arg2) { sender.send( join( newlines(), @@ -203,7 +204,7 @@ default void send(Logger sender, A1 arg1, A2 arg2) { interface ParameterizedMessage3 { Component build(A1 arg1, A2 arg2, A3 arg3); - default void send(Logger sender, A1 arg1, A2 arg2, A3 arg3) { + default void send(PluginLogger sender, A1 arg1, A2 arg2, A3 arg3) { sender.send( join( newlines(), @@ -216,7 +217,7 @@ default void send(Logger sender, A1 arg1, A2 arg2, A3 arg3) { interface ParameterizedMessage4 { Component build(A1 arg1, A2 arg2, A3 arg3, A4 arg4); - default void send(Logger sender, A1 arg1, A2 arg2, A3 arg3, A4 arg4) { + default void send(PluginLogger sender, A1 arg1, A2 arg2, A3 arg3, A4 arg4) { sender.send( join( newlines(), diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/Server.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/PlayerServer.java similarity index 91% rename from core/src/main/java/group/aelysium/rustyconnector/core/lib/model/Server.java rename to core/src/main/java/group/aelysium/rustyconnector/core/lib/model/PlayerServer.java index d1e5f9c11..096ef1721 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/Server.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/PlayerServer.java @@ -1,6 +1,6 @@ package group.aelysium.rustyconnector.core.lib.model; -public interface Server extends Sortable { +public interface PlayerServer extends Sortable { /** * Get the number of players on this server diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/VirtualProcessor.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/VirtualProcessor.java new file mode 100644 index 000000000..b8d90ae61 --- /dev/null +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/model/VirtualProcessor.java @@ -0,0 +1,4 @@ +package group.aelysium.rustyconnector.core.lib.model; + +public interface VirtualProcessor { +} diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/lib/util/WeightedQuickSort.java b/core/src/main/java/group/aelysium/rustyconnector/core/lib/util/WeightedQuickSort.java index 7471cc489..2b7c93707 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/lib/util/WeightedQuickSort.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/lib/util/WeightedQuickSort.java @@ -1,6 +1,6 @@ package group.aelysium.rustyconnector.core.lib.util; -import group.aelysium.rustyconnector.core.lib.lang_messaging.Logger; +import group.aelysium.rustyconnector.core.central.PluginLogger; import group.aelysium.rustyconnector.core.lib.model.Sortable; import java.util.*; @@ -12,7 +12,7 @@ public class WeightedQuickSort { * Assumes that start is 0 and the final index is equal to size. * @param array The array to sort. */ - public static void sort(List array, Logger logger) { + public static void sort(List array) { QuickSort.sort(array); // Put array in order of index. // Pull out different weight levels and put them into their own lists. diff --git a/paper/pom.xml b/paper/pom.xml index 670c54d93..3f34baf3e 100644 --- a/paper/pom.xml +++ b/paper/pom.xml @@ -45,6 +45,22 @@ + + dev.folia + folia-api + 1.19.4-R0.1-SNAPSHOT + provided + + + com.google.code.gson + gson + + + net.kyori + adventure-text-serializer-gson + + + group.aelysium.rustyconnector core diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java deleted file mode 100644 index 980381779..000000000 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/Engine.java +++ /dev/null @@ -1,91 +0,0 @@ -package group.aelysium.rustyconnector.plugin.paper; - -import cloud.commandframework.execution.CommandExecutionCoordinator; -import cloud.commandframework.paper.PaperCommandManager; -import group.aelysium.rustyconnector.core.lib.config.MigrationDirections; -import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; -import group.aelysium.rustyconnector.plugin.paper.commands.CommandRusty; -import group.aelysium.rustyconnector.plugin.paper.lib.PaperServer; -import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig; -import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerJoin; -import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerLeave; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; - -import java.io.File; -import java.util.function.Function; - -public class Engine { - public static boolean start() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); - - MigrationDirections.init(); - - if(!initConfigs(plugin)) return false; - if(!initCommands(plugin)) return false; - if(!initEvents(plugin)) return false; - - return true; - } - public static void stop() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); - DefaultConfig.empty(); - - if(plugin.getVirtualServer() != null) { - plugin.getVirtualServer().unregisterFromProxy(); - - plugin.getVirtualServer().killRedis(); - } - - plugin.getCommandManager().deleteRootCommand("rc"); - } - - private static boolean initConfigs(PaperRustyConnector plugin) { - try { - DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(plugin.getDataFolder(), "config.yml"), "paper_config_template.yml"); - if(!defaultConfig.generate()) { - throw new IllegalStateException("Unable to load or create config.yml!"); - } - defaultConfig.register(); - - plugin.setVirtualServer(PaperServer.init(defaultConfig)); - - Lang.WORDMARK_RUSTY_CONNECTOR.send(plugin.logger()); - - if(defaultConfig.isRegisterOnBoot()) { - Lang.BOXED_MESSAGE.send(plugin.logger(), Component.text("Sent a registration request over the data-channel...", NamedTextColor.GREEN)); - plugin.getVirtualServer().registerToProxy(); - } - - DefaultConfig.empty(); - - return true; - } catch (Exception e) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text(e.getMessage()), NamedTextColor.RED); - return false; - } - } - private static boolean initCommands(PaperRustyConnector plugin) { - try { - plugin.setCommandManager(new PaperCommandManager<>( - plugin, - CommandExecutionCoordinator.simpleCoordinator(), - Function.identity(), - Function.identity() - )); - - CommandRusty.create(plugin.getCommandManager()); - - return true; - } catch (Exception e) { - plugin.logger().log(e.getMessage()); - return false; - } - } - - private static boolean initEvents(PaperRustyConnector plugin) { - plugin.getServer().getPluginManager().registerEvents(new OnPlayerJoin(), plugin); - plugin.getServer().getPluginManager().registerEvents(new OnPlayerLeave(), plugin); - return true; - } -} diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java index ff988b1fe..36904ee96 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java @@ -1,92 +1,59 @@ package group.aelysium.rustyconnector.plugin.paper; -import cloud.commandframework.paper.PaperCommandManager; -import group.aelysium.rustyconnector.core.RustyConnector; -import group.aelysium.rustyconnector.plugin.paper.lib.PaperServer; +import group.aelysium.rustyconnector.core.central.PluginRuntime; +import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.paper.central.PaperLifecycle; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; +import group.aelysium.rustyconnector.plugin.paper.lib.VirtualServerProcessor; import group.aelysium.rustyconnector.plugin.paper.lib.bstats.Metrics; -import org.bukkit.command.CommandSender; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -import java.io.*; +public final class PaperRustyConnector extends JavaPlugin implements Listener, PluginRuntime { + private static PaperLifecycle lifecycle; + private static PaperAPI api; -public final class PaperRustyConnector extends JavaPlugin implements Listener, RustyConnector { - private static PaperRustyConnector instance; - private PluginLogger logger; - private PaperServer server; - private PaperCommandManager commandManager; - - public static PaperRustyConnector getInstance() { return PaperRustyConnector.instance; } - - /** - * Set the CommandManager for the plugin. Once this is set it cannot be changed. - * @param commandManager The CommandManager to set. - */ - public void setCommandManager(PaperCommandManager commandManager) throws IllegalStateException { - if(this.commandManager != null) throw new IllegalStateException("This has already been set! You can't set this twice!"); - this.commandManager = commandManager; - } - - /** - * Get the command manager for the plugin - * @return The command manager. - */ - public PaperCommandManager getCommandManager() { - return this.commandManager; + public static PaperAPI getAPI() { + return api; } - - /** - * Set the PaperServer handler for the plugin. Once this is set it cannot be changed. - * @param server The PaperServer to set. - */ - public void setVirtualServer(PaperServer server) throws IllegalStateException { - if(this.server != null) throw new IllegalStateException("This has already been set! You can't set this twice!"); - this.server = server; + public static PaperLifecycle getLifecycle() { + return lifecycle; } @Override public void onEnable() { - instance = this; - this.logger = new PluginLogger(this.getSLF4JLogger()); - - Metrics metrics = new Metrics(this, 17973); + try { + api = new PaperAPI(this, this.getSLF4JLogger()); + + if (!lifecycle.start()) { + this.killPlugin(); + return; + } + + try { + new Metrics(this, 17973); + } catch (Exception e) { + getAPI().getLogger().log("Failed to register to bstats!"); + } + } catch (Exception e) { + e.printStackTrace(); + this.killPlugin(); + } - if(!Engine.start()) this.killPlugin(); } @Override public void onDisable() { try { - Engine.stop(); + lifecycle.stop(); } catch (Exception e) { - this.logger().log("RustyConnector: " + e.getMessage()); + getAPI().getLogger().log("RustyConnector: " + e.getMessage()); } } - @Override - public InputStream getResourceAsStream(String filename) { - return this.getResource(filename); - } - - @Override - public void reload() { - Engine.stop(); - - if(!Engine.start()) this.killPlugin(); - } - - public PaperServer getVirtualServer() { return this.server; } - - @Override - public PluginLogger logger() { - return this.logger; - } - private void killPlugin() { this.getPluginLoader().disablePlugin(this); } - - public void registerToProxy() { - this.getVirtualServer().registerToProxy(); - } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PluginLogger.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PluginLogger.java index 633a18c5b..953a0549b 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PluginLogger.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PluginLogger.java @@ -4,7 +4,7 @@ import net.kyori.adventure.text.Component; import org.slf4j.Logger; -public class PluginLogger implements group.aelysium.rustyconnector.core.lib.lang_messaging.Logger { +public class PluginLogger implements group.aelysium.rustyconnector.core.central.PluginLogger { private final LoggerGate gate = new LoggerGate(); private final Logger logger; @@ -57,6 +57,6 @@ public void error(String message, Throwable e) { @Override public void send(Component message) { - PaperRustyConnector.getInstance().getServer().getConsoleSender().sendMessage(message); + PaperRustyConnector.getAPI().getServer().getConsoleSender().sendMessage(message); } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java new file mode 100644 index 000000000..9b288d67d --- /dev/null +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java @@ -0,0 +1,99 @@ +package group.aelysium.rustyconnector.plugin.paper.central; + +import cloud.commandframework.Command; +import cloud.commandframework.CommandManager; +import cloud.commandframework.execution.CommandExecutionCoordinator; +import cloud.commandframework.paper.PaperCommandManager; +import group.aelysium.rustyconnector.core.central.PluginAPI; +import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.lib.VirtualServerProcessor; +import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig; +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitScheduler; +import org.slf4j.Logger; + +import java.io.InputStream; +import java.io.SyncFailedException; +import java.lang.reflect.InvocationTargetException; +import java.util.function.Function; + +public class PaperAPI extends PluginAPI { + private final PaperCommandManager commandManager; + private final PaperRustyConnector plugin; + private VirtualServerProcessor virtualProcessor = null; + private final PluginLogger pluginLogger; + + + public PaperAPI(PaperRustyConnector plugin, Logger logger) throws Exception { + this.plugin = plugin; + this.pluginLogger = new PluginLogger(logger); + this.commandManager = new PaperCommandManager<>( + plugin, + CommandExecutionCoordinator.simpleCoordinator(), + Function.identity(), + Function.identity() + ); + } + + @Override + public InputStream getResourceAsStream(String filename) { + return getClass().getClassLoader().getResourceAsStream(filename); + } + + @Override + public BukkitScheduler getScheduler() { + return Bukkit.getScheduler(); + } + + @Override + public PluginLogger getLogger() { + return this.pluginLogger; + } + + @Override + public VirtualServerProcessor getVirtualProcessor() { + return this.virtualProcessor; + } + + @Override + public String getDataFolder() { + return plugin.getDataFolder().getPath(); + } + + /** + * Get the paper server + */ + public Server getServer() { + return this.plugin.getServer(); + } + + /** + * Attempt to access the plugin instance directly. + * @return The plugin instance. + * @throws SyncFailedException If the plugin is currently running. + */ + public PaperRustyConnector accessPlugin() throws SyncFailedException { + if(PaperRustyConnector.getLifecycle().isRunning()) throw new SyncFailedException("You can't get the plugin instance while the plugin is running!"); + return this.plugin; + } + + public PaperCommandManager getCommandManager() { + return commandManager; + } + + public void configureProcessor(DefaultConfig config) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { + if(this.virtualProcessor != null) throw new IllegalAccessException("Attempted to configure the processor while it's already running!"); + this.virtualProcessor = VirtualServerProcessor.init(config); + } + + public boolean isFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionisedServer"); + return true; + } catch (ClassNotFoundException ignore) {} + return false; + } +} diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java new file mode 100644 index 000000000..f0fc0da1a --- /dev/null +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java @@ -0,0 +1,100 @@ +package group.aelysium.rustyconnector.plugin.paper.central; + +import group.aelysium.rustyconnector.core.central.PluginLifecycle; +import group.aelysium.rustyconnector.core.lib.config.MigrationDirections; +import group.aelysium.rustyconnector.core.lib.exception.DuplicateLifecycleException; +import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.commands.CommandRusty; +import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig; +import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerJoin; +import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerLeave; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.io.File; + +public class PaperLifecycle extends PluginLifecycle { + + public boolean start() throws DuplicateLifecycleException { + if(this.isRunning()) throw new DuplicateLifecycleException("RustyConnector-Velocity is already running! You can't start it a second time!"); + + MigrationDirections.init(); + + if(!loadConfigs()) return false; + if(!loadCommands()) return false; + if(!loadEvents()) return false; + + return true; + } + public void stop() { + PaperAPI api = PaperRustyConnector.getAPI(); + + DefaultConfig.empty(); + + if(api.getVirtualProcessor() != null) { + api.getVirtualProcessor().unregisterFromProxy(); + + api.getVirtualProcessor().killRedis(); + } + + api.getCommandManager().deleteRootCommand("rc"); + } + + protected boolean loadConfigs() { + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + try { + DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(api.getDataFolder(), "config.yml"), "paper_config_template.yml"); + if(!defaultConfig.generate()) { + throw new IllegalStateException("Unable to load or create config.yml!"); + } + defaultConfig.register(); + + api.configureProcessor(defaultConfig); + + Lang.WORDMARK_RUSTY_CONNECTOR.send(logger); + + if(defaultConfig.isRegisterOnBoot()) { + Lang.BOXED_MESSAGE.send(logger, Component.text("Sent a registration request over the data-channel...", NamedTextColor.GREEN)); + api.getVirtualProcessor().registerToProxy(); + } + + DefaultConfig.empty(); + + return true; + } catch (Exception e) { + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text(e.getMessage()), NamedTextColor.RED); + return false; + } + } + protected boolean loadCommands() { + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + try { + + CommandRusty.create(api.getCommandManager()); + + return true; + } catch (Exception e) { + logger.log(e.getMessage()); + return false; + } + } + + protected boolean loadEvents() { + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + try { + api.getServer().getPluginManager().registerEvents(new OnPlayerJoin(), api.accessPlugin()); + api.getServer().getPluginManager().registerEvents(new OnPlayerLeave(), api.accessPlugin()); + + return true; + } catch (Exception e) { + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text(e.getMessage()), NamedTextColor.RED); + return false; + } + } +} diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/commands/CommandRusty.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/commands/CommandRusty.java index 94c4584e2..07de4544d 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/commands/CommandRusty.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/commands/CommandRusty.java @@ -9,17 +9,19 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage; import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; public final class CommandRusty { public static void create(PaperCommandManager manager) { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); - final Command.Builder builder = manager.commandBuilder("rc","rc", "rusty","rustyconnector"); + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + final Command.Builder builder = api.getCommandManager().commandBuilder("rc","rc", "rusty","rustyconnector"); manager.command(builder.literal("message") .senderType(ConsoleCommandSender.class) @@ -29,15 +31,15 @@ public static void create(PaperCommandManager manager) { try { final Long snowflake = commandContext.get("snowflake"); - MessageCache messageCache = PaperRustyConnector.getInstance().getVirtualServer().getMessageCache(); + MessageCache messageCache = api.getVirtualProcessor().getMessageCache(); CacheableMessage message = messageCache.getMessage(snowflake); - PaperLang.RC_MESSAGE_GET_MESSAGE.send(plugin.logger(), message.getSnowflake(), message.getDate(), message.getContents()); + PaperLang.RC_MESSAGE_GET_MESSAGE.send(logger, message.getSnowflake(), message.getDate(), message.getContents()); } catch (NullPointerException e) { - plugin.logger().log("That message either doesn't exist or is no-longer available in the cache!"); + logger.log("That message either doesn't exist or is no-longer available in the cache!"); } catch (Exception e) { - plugin.logger().log("An error stopped us from getting that message!", e); + logger.log("An error stopped us from getting that message!", e); } }).execute()) ).command(builder.literal("send") @@ -50,11 +52,11 @@ public static void create(PaperCommandManager manager) { final Player player = commandContext.get("player"); final String familyName = commandContext.get("family-name"); - plugin.getVirtualServer().sendToOtherFamily(player,familyName); + api.getVirtualProcessor().sendToOtherFamily(player,familyName); } catch (NullPointerException e) { - PaperLang.RC_SEND_USAGE.send(plugin.logger()); + PaperLang.RC_SEND_USAGE.send(logger); } catch (Exception e) { - plugin.logger().log("An error stopped us from processing the request!", e); + logger.log("An error stopped us from processing the request!", e); } }).execute()) ).command(builder.literal("register") @@ -62,9 +64,9 @@ public static void create(PaperCommandManager manager) { .handler(context -> manager.taskRecipe().begin(context) .synchronous(commandContext -> { try { - plugin.getVirtualServer().registerToProxy(); + api.getVirtualProcessor().registerToProxy(); } catch (Exception e) { - plugin.logger().log("An error stopped us from sending your request!", e); + logger.log("An error stopped us from sending your request!", e); } }).execute()) ).command(builder.literal("unregister") @@ -72,9 +74,9 @@ public static void create(PaperCommandManager manager) { .handler(context -> manager.taskRecipe().begin(context) .synchronous(commandContext -> { try { - plugin.getVirtualServer().unregisterFromProxy(); + api.getVirtualProcessor().unregisterFromProxy(); } catch (Exception e) { - plugin.logger().log("An error stopped us from sending your request!", e); + logger.log("An error stopped us from sending your request!", e); } }).execute()) ).command(builder.literal("sendmessage") @@ -85,9 +87,9 @@ public static void create(PaperCommandManager manager) { try { final String message = commandContext.get("message"); - plugin.getVirtualServer().sendMessage(message); + api.getVirtualProcessor().sendMessage(message); } catch (Exception e) { - plugin.logger().log("There was an error sending that!"); + logger.log("There was an error sending that!"); } }).execute()) ); diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/PaperServer.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/VirtualServerProcessor.java similarity index 83% rename from paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/PaperServer.java rename to paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/VirtualServerProcessor.java index daf578208..252df08c1 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/PaperServer.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/VirtualServerProcessor.java @@ -5,8 +5,11 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessageType; import group.aelysium.rustyconnector.core.lib.hash.MD5; import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache; -import group.aelysium.rustyconnector.core.lib.model.Server; +import group.aelysium.rustyconnector.core.lib.model.PlayerServer; +import group.aelysium.rustyconnector.core.lib.model.VirtualProcessor; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig; import group.aelysium.rustyconnector.plugin.paper.lib.database.Redis; import group.aelysium.rustyconnector.plugin.paper.lib.tpa.TPAQueue; @@ -14,12 +17,12 @@ import java.net.InetSocketAddress; -public class PaperServer implements Server { - private TPAQueue tpaQueue = new TPAQueue(); +public class VirtualServerProcessor implements PlayerServer, VirtualProcessor { + private final TPAQueue tpaQueue = new TPAQueue(); private MessageCache messageCache; - private Redis redis; - private String family; - private int weight = 0; + private final Redis redis; + private final String family; + private final int weight = 0; private int softPlayerCap = 20; private int hardPlayerCap = 30; private final String name; @@ -27,7 +30,7 @@ public class PaperServer implements Server { private final String privateKey; private final InetSocketAddress address; - public PaperServer(String name, String privateKey, String address, String family, Redis redis) { + public VirtualServerProcessor(String name, String privateKey, String address, String family, Redis redis) { if(name.equals("")) { name = MD5.generatePrivateKey(); // Generate a custom string to be the server's name } @@ -69,7 +72,7 @@ public MessageCache getMessageCache() { @Override public int getPlayerCount() { - return PaperRustyConnector.getInstance().getServer().getOnlinePlayers().size(); + return PaperRustyConnector.getAPI().getServer().getOnlinePlayers().size(); } @Override @@ -102,13 +105,15 @@ public void killRedis() { * @param hardPlayerCap The hard player cap */ public void setPlayerCap(int softPlayerCap, int hardPlayerCap) { + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); - PaperRustyConnector.getInstance().getServer().setMaxPlayers(hardPlayerCap); + api.getServer().setMaxPlayers(hardPlayerCap); if(softPlayerCap >= hardPlayerCap) { this.hardPlayerCap = hardPlayerCap; this.softPlayerCap = hardPlayerCap; - PaperRustyConnector.getInstance().logger().log("soft-player-cap was set to be larger than hard-player-cap. Running in `player-limit` mode."); + logger.log("soft-player-cap was set to be larger than hard-player-cap. Running in `player-limit` mode."); return; } this.hardPlayerCap = hardPlayerCap; @@ -179,10 +184,11 @@ public void pong() { registrationMessage.dispatchMessage(this.redis); } - public static PaperServer init(DefaultConfig config) throws IllegalAccessException { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + public static VirtualServerProcessor init(DefaultConfig config) throws IllegalAccessException { + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); - plugin.logger().log("Preparing Redis..."); + logger.log("Preparing Redis..."); Redis redis = new Redis(); redis.setConnection( @@ -191,9 +197,9 @@ public static PaperServer init(DefaultConfig config) throws IllegalAccessExcepti config.getRedis_password(), config.getRedis_dataChannel() ); - redis.connect(plugin); + redis.connect(api); - PaperServer server = new PaperServer( + VirtualServerProcessor server = new VirtualServerProcessor( config.getServer_name(), config.getPrivate_key(), config.getServer_address(), diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java index 4174374bd..ace9cb4dc 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java @@ -2,6 +2,8 @@ import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -107,7 +109,7 @@ public static void empty() { } public void register() throws IllegalStateException { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PluginLogger logger = PaperRustyConnector.getAPI().getLogger(); try { this.processVersion(); @@ -133,7 +135,7 @@ public void register() throws IllegalStateException { this.server_playerCap_soft = this.getNode(this.data,"server.player-cap.soft",Integer.class); this.server_playerCap_hard = this.getNode(this.data,"server.player-cap.hard",Integer.class); if(this.server_playerCap_soft >= this.server_playerCap_hard) - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("Server's soft-cap is either the same as or larger than the server's hard-cap. Running server in player-limit mode."), NamedTextColor.YELLOW); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text("Server's soft-cap is either the same as or larger than the server's hard-cap. Running server in player-limit mode."), NamedTextColor.YELLOW); this.redis_host = this.getNode(this.data,"redis.host",String.class); if(this.redis_host.equals("")) throw new IllegalStateException("Please configure your Redis settings."); diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/YAML.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/YAML.java index b6a5fdbe3..ef2ce6b50 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/YAML.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/YAML.java @@ -1,6 +1,8 @@ package group.aelysium.rustyconnector.plugin.paper.lib.config; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import java.io.File; import java.io.IOException; @@ -14,37 +16,38 @@ public YAML(File configPointer, String template) { @Override public boolean generate() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); - plugin.logger().log("---| Registering "+this.configPointer.getName()+"..."); - plugin.logger().log("-----| Looking for "+this.configPointer.getName()+"..."); + logger.log("---| Registering "+this.configPointer.getName()+"..."); + logger.log("-----| Looking for "+this.configPointer.getName()+"..."); if (!this.configPointer.exists()) { - plugin.logger().log("-------| "+this.configPointer.getName()+" doesn't exist! Setting it up now..."); - plugin.logger().log("-------| Preparing directory..."); + logger.log("-------| "+this.configPointer.getName()+" doesn't exist! Setting it up now..."); + logger.log("-------| Preparing directory..."); File parent = this.configPointer.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } - plugin.logger().log("-------| Preparing template file..."); - InputStream templateStream = plugin.getResourceAsStream(this.template); + logger.log("-------| Preparing template file..."); + InputStream templateStream = api.getResourceAsStream(this.template); if (templateStream == null) { - plugin.logger().error("!!!!! Unable to setup "+this.configPointer.getName()+". This config has no template !!!!!"); + logger.error("!!!!! Unable to setup "+this.configPointer.getName()+". This config has no template !!!!!"); return false; } try { - plugin.logger().log("-------| Cloning template file to new configuration..."); + logger.log("-------| Cloning template file to new configuration..."); Files.copy(templateStream, this.configPointer.toPath()); - plugin.logger().log("-------| Finished setting up "+this.configPointer.getName()); + logger.log("-------| Finished setting up "+this.configPointer.getName()); } catch (IOException e) { - plugin.logger().error("!!!!! Unable to setup "+this.configPointer.getName()+" !!!!!",e); + logger.error("!!!!! Unable to setup "+this.configPointer.getName()+" !!!!!",e); return false; } } else { - plugin.logger().log("-----| Found it!"); + logger.log("-----| Found it!"); } try { diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/database/Redis.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/database/Redis.java index 552ecd773..4102a3c67 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/database/Redis.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/database/Redis.java @@ -9,6 +9,8 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage; import group.aelysium.rustyconnector.core.lib.util.AddressUtil; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import group.aelysium.rustyconnector.plugin.paper.lib.message.handling.PingHandler; import group.aelysium.rustyconnector.plugin.paper.lib.message.handling.ServerRegAllHandler; import group.aelysium.rustyconnector.plugin.paper.lib.message.handling.ServerRegFamilyHandler; @@ -22,21 +24,23 @@ public class Redis extends group.aelysium.rustyconnector.core.lib.database.Redis { @Override public void onMessage(String rawMessage) { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); - CacheableMessage cachedMessage = plugin.getVirtualServer().getMessageCache().cacheMessage(rawMessage, MessageStatus.UNDEFINED); + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + CacheableMessage cachedMessage = api.getVirtualProcessor().getMessageCache().cacheMessage(rawMessage, MessageStatus.UNDEFINED); try { - RedisMessage message = RedisMessage.create(rawMessage, MessageOrigin.SERVER, plugin.getVirtualServer().getAddress()); + RedisMessage message = RedisMessage.create(rawMessage, MessageOrigin.SERVER, api.getVirtualProcessor().getAddress()); try { - if (!(plugin.getVirtualServer().validatePrivateKey(message.getKey()))) + if (!(api.getVirtualProcessor().validatePrivateKey(message.getKey()))) throw new AuthenticationException("This message has an invalid private key!"); cachedMessage.sentenceMessage(MessageStatus.ACCEPTED); Redis.processParameters(message, cachedMessage); } catch (AuthenticationException e) { - plugin.logger().error("Incoming message from: " + message.getAddress().toString() + " contains an invalid private key! Throwing away..."); - plugin.logger().log("To view the thrown away message use: /rc message get " + cachedMessage.getSnowflake()); + logger.error("Incoming message from: " + message.getAddress().toString() + " contains an invalid private key! Throwing away..."); + logger.log("To view the thrown away message use: /rc message get " + cachedMessage.getSnowflake()); } } catch (Exception e) { cachedMessage.sentenceMessage(MessageStatus.TRASHED); @@ -50,6 +54,8 @@ public void onMessage(String rawMessage) { } private static void processParameters(RedisMessage message, CacheableMessage cachedMessage) { + PluginLogger logger = PaperRustyConnector.getAPI().getLogger(); + Gson gson = new Gson(); JsonObject object = gson.fromJson(message.toString(), JsonObject.class); @@ -74,8 +80,8 @@ private static void processParameters(RedisMessage message, CacheableMessage cac } catch (Exception e) { cachedMessage.sentenceMessage(MessageStatus.PARSING_ERROR); - PaperRustyConnector.getInstance().logger().error("Incoming message " + message.getType().toString() + " from " + message.getAddress() + " is not formatted properly. Throwing away...", e); - PaperRustyConnector.getInstance().logger().log("To view the thrown away message use: /rc message get " + cachedMessage.getSnowflake()); + logger.error("Incoming message " + message.getType().toString() + " from " + message.getAddress() + " is not formatted properly. Throwing away...", e); + logger.log("To view the thrown away message use: /rc message get " + cachedMessage.getSnowflake()); } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerJoin.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerJoin.java index 8062c99d5..a9b1140af 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerJoin.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerJoin.java @@ -1,6 +1,7 @@ package group.aelysium.rustyconnector.plugin.paper.lib.events; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang; import group.aelysium.rustyconnector.plugin.paper.lib.tpa.TPARequest; import org.bukkit.event.EventHandler; @@ -11,9 +12,9 @@ public class OnPlayerJoin implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PaperAPI api = PaperRustyConnector.getAPI(); - TPARequest tpaRequest = plugin.getVirtualServer().getTPAQueue().findClient(event.getPlayer().getPlayerProfile().getName()); + TPARequest tpaRequest = api.getVirtualProcessor().getTPAQueue().findClient(event.getPlayer().getPlayerProfile().getName()); if(tpaRequest == null) return; try { tpaRequest.resolveClient(); @@ -23,10 +24,10 @@ public void onPlayerJoin(PlayerJoinEvent event) { } catch (NullPointerException e) { event.getPlayer().sendMessage(PaperLang.TPA_FAILED_TELEPORT.build(tpaRequest.getTarget().getPlayerProfile().getName())); } - } catch (NullPointerException e) { + } catch (Exception e) { event.getPlayer().sendMessage(PaperLang.TPA_FAILED_TELEPORT.build(tpaRequest.getTarget().getPlayerProfile().getName())); } - plugin.getVirtualServer().getTPAQueue().removeAllPlayersRequests(event.getPlayer()); + api.getVirtualProcessor().getTPAQueue().removeAllPlayersRequests(event.getPlayer()); } } \ No newline at end of file diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java index b357e7849..c38e28de7 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java @@ -1,6 +1,8 @@ package group.aelysium.rustyconnector.plugin.paper.lib.events; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; @@ -9,7 +11,10 @@ public class OnPlayerLeave implements Listener { @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - PaperRustyConnector.getInstance().getVirtualServer().getTPAQueue().removeAllPlayersRequests(event.getPlayer()); - PaperRustyConnector.getInstance().logger().log("Deleted player entries!"); + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + api.getVirtualProcessor().getTPAQueue().removeAllPlayersRequests(event.getPlayer()); + logger.log("Deleted player entries!"); } } \ No newline at end of file diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/PingHandler.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/PingHandler.java index 83e664c23..2d95ad3b1 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/PingHandler.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/PingHandler.java @@ -3,6 +3,8 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; public class PingHandler implements MessageHandler { private final RedisMessage message; @@ -13,8 +15,8 @@ public PingHandler(RedisMessage message) { @Override public void execute() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PaperAPI api = PaperRustyConnector.getAPI(); - plugin.getVirtualServer().pong(); + api.getVirtualProcessor().pong(); } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegAllHandler.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegAllHandler.java index 34bcddc6d..02f6f6184 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegAllHandler.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegAllHandler.java @@ -4,6 +4,8 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import java.util.Objects; @@ -16,10 +18,11 @@ public ServerRegAllHandler(RedisMessage message) { @Override public void execute() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); - PaperRustyConnector.getInstance().logger().log("Server has been requested to register itself..."); - plugin.registerToProxy(); - PaperRustyConnector.getInstance().logger().log("Server has submitted its registration request."); + logger.log("Server has been requested to register itself..."); + api.getVirtualProcessor().registerToProxy(); + logger.log("Server has submitted its registration request."); } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegFamilyHandler.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegFamilyHandler.java index afaa7c662..2effe0d31 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegFamilyHandler.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/ServerRegFamilyHandler.java @@ -4,6 +4,8 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.PluginLogger; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import java.util.Objects; @@ -16,12 +18,13 @@ public ServerRegFamilyHandler(RedisMessage message) { @Override public void execute() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PaperAPI api = PaperRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); - if(Objects.equals(message.getParameter("family"), plugin.getVirtualServer().getFamily())) { - PaperRustyConnector.getInstance().logger().log("Server has been requested to register itself..."); - plugin.registerToProxy(); - PaperRustyConnector.getInstance().logger().log("Server has submitted its registration request."); + if(Objects.equals(message.getParameter("family"), api.getVirtualProcessor().getFamily())) { + logger.log("Server has been requested to register itself..."); + api.getVirtualProcessor().registerToProxy(); + logger.log("Server has submitted its registration request."); } } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/TPAQueuePlayerHandler.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/TPAQueuePlayerHandler.java index 268b8fc9d..8ae58d2bd 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/TPAQueuePlayerHandler.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/message/handling/TPAQueuePlayerHandler.java @@ -3,6 +3,7 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang; import group.aelysium.rustyconnector.plugin.paper.lib.tpa.TPARequest; import org.bukkit.entity.Player; @@ -16,17 +17,17 @@ public TPAQueuePlayerHandler(RedisMessage message) { @Override public void execute() { - PaperRustyConnector plugin = PaperRustyConnector.getInstance(); + PaperAPI api = PaperRustyConnector.getAPI(); String targetUsername = message.getParameter("target-username"); - Player target = plugin.getServer().getPlayer(targetUsername); + Player target = api.getServer().getPlayer(targetUsername); if(target == null) return; if(!target.isOnline()) return; String sourceUsername = message.getParameter("source-username"); - TPARequest tpaRequest = plugin.getVirtualServer().getTPAQueue().newRequest(sourceUsername, target); + TPARequest tpaRequest = api.getVirtualProcessor().getTPAQueue().newRequest(sourceUsername, target); // Attempt to resolve the tpa right away! If the player isn't on the server, this should fail silently. try { @@ -34,7 +35,7 @@ public void execute() { try { tpaRequest.teleport(); - } catch (NullPointerException e) { + } catch (Exception e) { tpaRequest.getClient().sendMessage(PaperLang.TPA_FAILED_TELEPORT.build(tpaRequest.getTarget().getPlayerProfile().getName())); } } catch (NullPointerException ignore) {} diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPARequest.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPARequest.java index 03423c315..ff27b25e4 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPARequest.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPARequest.java @@ -1,9 +1,8 @@ package group.aelysium.rustyconnector.plugin.paper.lib.tpa; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; -import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; public class TPARequest { private String clientUsername; @@ -37,19 +36,20 @@ public Player getTarget() { * @throws NullPointerException If the player with `clientUsername` is not online. */ public void resolveClient() { - Player client = PaperRustyConnector.getInstance().getServer().getPlayer(this.clientUsername); + PaperAPI api = PaperRustyConnector.getAPI(); + Player client = api.getServer().getPlayer(this.clientUsername); if(client == null) throw new NullPointerException("Attempted to resolve clientUsername `"+this.clientUsername+"` while player wasn't online."); if(!client.isOnline()) throw new NullPointerException("Attempted to resolve clientUsername `"+this.clientUsername+"` while player wasn't online."); this.client = client; } - public void teleport() { + public void teleport() throws RuntimeException { if(this.client == null) throw new NullPointerException("Attempted to resolve a tpa request while the client isn't online!"); if(!this.client.isOnline()) throw new NullPointerException("Attempted to resolve a tpa request while the client isn't online!"); if(!this.target.isOnline()) throw new NullPointerException("Attempted to resolve a tpa request while the target isn't online!"); - new TeleportRunnable(this.client, this.target).runTaskLater(PaperRustyConnector.getInstance(), 0); + this.client.teleportAsync(this.target.getLocation()).completeExceptionally(new RuntimeException("Failed to teleport "+this.client.getName()+" to "+this.target.getName())); } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TeleportRunnable.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TeleportRunnable.java deleted file mode 100644 index 74afefe8d..000000000 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TeleportRunnable.java +++ /dev/null @@ -1,22 +0,0 @@ -package group.aelysium.rustyconnector.plugin.paper.lib.tpa; - -import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -public class TeleportRunnable extends BukkitRunnable { - - private final Player client; - private final Player target; - - public TeleportRunnable(Player client, Player target) { - this.client = client; - this.target = target; - } - - @Override - public void run() { - this.client.teleport(this.target.getLocation()); - this.client.sendMessage(PaperLang.TPA_COMPLETE); - } -} \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index f9b5146bf..8ae1bbf52 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,5 +2,8 @@ name: rustyconnector-paper version: '0.4.1' main: group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector api-version: 1.16 +website: https://github.com/Aelysium-Group/rusty-connector authors: [ Sivin ] -commands: {} \ No newline at end of file +commands: {} + +folia-supported: true \ No newline at end of file diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/PluginLogger.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/PluginLogger.java index 54aac2f18..15a451f3d 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/PluginLogger.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/PluginLogger.java @@ -1,11 +1,12 @@ package group.aelysium.rustyconnector.plugin.velocity; import group.aelysium.rustyconnector.core.lib.lang_messaging.*; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.config.LoggerConfig; import net.kyori.adventure.text.Component; import org.slf4j.Logger; -public class PluginLogger implements group.aelysium.rustyconnector.core.lib.lang_messaging.Logger { +public class PluginLogger implements group.aelysium.rustyconnector.core.central.PluginLogger { private final LoggerGate gate = new LoggerGate(); private final Logger logger; @@ -58,13 +59,14 @@ public void error(String message, Throwable e) { } public void send(Component message) { - VelocityRustyConnector.getInstance().getVelocityServer().getConsoleCommandSource().sendMessage(message); + VelocityAPI api = VelocityRustyConnector.getAPI(); + api.getServer().getConsoleCommandSource().sendMessage(message); } public static void init(LoggerConfig config) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger pluginLogger = VelocityRustyConnector.getAPI().getLogger(); - LoggerGate gate = plugin.logger().getGate(); + LoggerGate gate = pluginLogger.getGate(); gate.registerNode( GateKey.SAVE_TRASH_MESSAGES, diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java index 064bd520f..d4016c122 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java @@ -6,91 +6,49 @@ import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.ProxyServer; +import group.aelysium.rustyconnector.core.lib.exception.DuplicateLifecycleException; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityLifecycle; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.bstats.Metrics; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.Proxy; -import group.aelysium.rustyconnector.core.RustyConnector; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import org.slf4j.Logger; -import java.io.File; -import java.io.InputStream; import java.nio.file.Path; -public class VelocityRustyConnector implements RustyConnector { - private final Metrics.Factory metricsFactory; - private static RustyConnector instance; - private Proxy proxy; - private final ProxyServer server; - private final PluginLogger logger; - private final File dataFolder; +public class VelocityRustyConnector implements PluginRuntime { + private static VelocityLifecycle lifecycle; + private static VelocityAPI api; - /** - * Set the proxy for Velocity. Once this is set it cannot be changed. - * @param proxy The proxy to set. - */ - public void setVirtualServer(Proxy proxy) throws IllegalStateException { - if(this.proxy != null) throw new IllegalStateException("This has already been set! You can't set this twice!"); - this.proxy = proxy; - } - public void unsetVirtualServer() { - this.proxy = null; + public static VelocityAPI getAPI() { + return api; } - public static VelocityRustyConnector getInstance() { return (VelocityRustyConnector) instance; } - public Proxy getVirtualServer() { return this.proxy; } - public ProxyServer getVelocityServer() { return this.server; } + public static VelocityLifecycle getLifecycle() { + return lifecycle; + } @Inject public VelocityRustyConnector(ProxyServer server, Logger logger, @DataDirectory Path dataFolder, Metrics.Factory metricsFactory) { - this.server = server; - this.logger = new PluginLogger(logger); - this.dataFolder = dataFolder.toFile(); - this.metricsFactory = metricsFactory; + api = new VelocityAPI(this, server, logger, dataFolder); + lifecycle = new VelocityLifecycle(); + try { + metricsFactory.make(this, 17972); + } catch (Exception e) { + VelocityRustyConnector.getAPI().getLogger().log("Failed to register to bstats!"); + } } @Subscribe - public void onLoad(ProxyInitializeEvent event) { - this.init(); + public void onLoad(ProxyInitializeEvent event) throws DuplicateLifecycleException { + if(!lifecycle.start()) lifecycle.stop(); } @Subscribe public void onUnload(ProxyShutdownEvent event) { try { - this.uninit(); + lifecycle.stop(); } catch (Exception e) { - this.logger().log("RustyConnector: " + e.getMessage()); + VelocityRustyConnector.getAPI().getLogger().log("RustyConnector: " + e.getMessage()); } } - - public void init() { - instance = this; - - metricsFactory.make(this, 17972); - - if(!Engine.start()) uninit(); - } - - public void uninit() { - Engine.stop(); - } - - @Override - public void reload() { - this.uninit(); - this.init(); - } - - @Override - public PluginLogger logger() { - return this.logger; - } - - @Override - public File getDataFolder() { - return this.dataFolder; - } - - @Override - public InputStream getResourceAsStream(String filename) { - return getClass().getClassLoader().getResourceAsStream(filename); - } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java new file mode 100644 index 000000000..9f60bf9e4 --- /dev/null +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java @@ -0,0 +1,100 @@ +package group.aelysium.rustyconnector.plugin.velocity.central; + +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import com.velocitypowered.api.proxy.server.ServerInfo; +import com.velocitypowered.api.scheduler.Scheduler; +import group.aelysium.rustyconnector.core.central.PluginAPI; +import group.aelysium.rustyconnector.core.central.PluginRuntime; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; +import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.lib.config.DefaultConfig; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.VirtualProxyProcessor; +import org.slf4j.Logger; + +import java.io.InputStream; +import java.io.SyncFailedException; +import java.lang.reflect.InvocationTargetException; +import java.nio.file.Path; + +public class VelocityAPI extends PluginAPI { + private final VelocityRustyConnector plugin; + private final ProxyServer server; + private VirtualProxyProcessor virtualProcessor = null; + private final Path dataFolder; + private final PluginLogger pluginLogger; + + public VelocityAPI(VelocityRustyConnector plugin, ProxyServer server, Logger logger, @DataDirectory Path dataFolder) { + this.plugin = plugin; + this.server = server; + this.pluginLogger = new PluginLogger(logger); + this.dataFolder = dataFolder; + } + + @Override + public InputStream getResourceAsStream(String filename) { + return getClass().getClassLoader().getResourceAsStream(filename); + } + + @Override + public Scheduler getScheduler() { + return getServer().getScheduler(); + } + + @Override + public PluginLogger getLogger() { + return this.pluginLogger; + } + + @Override + public String getDataFolder() { + return String.valueOf(this.dataFolder); + } + + @Override + public VirtualProxyProcessor getVirtualProcessor() { + return this.virtualProcessor; + } + + /** + * Get the velocity server + */ + public ProxyServer getServer() { + return this.server; + } + + /** + * Registers a server with this proxy.` A server with this name should not already exist. + * + * @param serverInfo the server to register + * @return the newly registered server + */ + public RegisteredServer registerServer(ServerInfo serverInfo) { + return getServer().registerServer(serverInfo); + } + + /** + * Unregisters this server from the proxy. + * + * @param serverInfo the server to unregister + */ + public void unregisterServer(ServerInfo serverInfo) { + getServer().unregisterServer(serverInfo); + } + + /** + * Attempt to access the plugin instance directly. + * @return The plugin instance. + * @throws SyncFailedException If the plugin is currently running. + */ + public VelocityRustyConnector accessPlugin() throws SyncFailedException { + if(VelocityRustyConnector.getLifecycle().isRunning()) throw new SyncFailedException("You can't get the plugin instance while the plugin is running!"); + return this.plugin; + } + + public void configureProcessor(DefaultConfig config) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { + if(this.virtualProcessor != null) throw new IllegalAccessException("Attempted to configure the processor while it's already running!"); + this.virtualProcessor = VirtualProxyProcessor.init(config); + } +} diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java similarity index 51% rename from velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java rename to velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java index 03acb27cf..fe90d289b 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/Engine.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java @@ -1,10 +1,14 @@ -package group.aelysium.rustyconnector.plugin.velocity; +package group.aelysium.rustyconnector.plugin.velocity.central; import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.event.EventManager; +import group.aelysium.rustyconnector.core.central.PluginLifecycle; import group.aelysium.rustyconnector.core.lib.config.MigrationDirections; +import group.aelysium.rustyconnector.core.lib.exception.DuplicateLifecycleException; import group.aelysium.rustyconnector.core.lib.exception.NoOutputException; import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; +import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; import group.aelysium.rustyconnector.plugin.velocity.commands.CommandRusty; import group.aelysium.rustyconnector.plugin.velocity.commands.CommandTPA; import group.aelysium.rustyconnector.plugin.velocity.lib.config.DefaultConfig; @@ -16,30 +20,33 @@ import group.aelysium.rustyconnector.plugin.velocity.lib.events.OnPlayerDisconnect; import group.aelysium.rustyconnector.plugin.velocity.lib.events.OnPlayerKicked; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.Proxy; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import java.io.File; -public class Engine { - public static boolean start() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); +public class VelocityLifecycle extends PluginLifecycle { + + public boolean start() throws DuplicateLifecycleException { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + if(this.isRunning()) throw new DuplicateLifecycleException("RustyConnector-Velocity is already running! You can't start it a second time!"); MigrationDirections.init(); - if(!initConfigs(plugin)) return false; - if(!initCommands(plugin)) return false; - if(!initEvents(plugin)) return false; + if(!loadConfigs()) return false; + if(!loadCommands()) return false; + if(!loadEvents()) return false; - VelocityLang.WORDMARK_RUSTY_CONNECTOR.send(plugin.logger()); + VelocityLang.WORDMARK_RUSTY_CONNECTOR.send(logger); DefaultConfig defaultConfig = DefaultConfig.getConfig(); if(defaultConfig.isBootCommands_enabled()) { - plugin.logger().log("Issuing boot commands..."); + logger.log("Issuing boot commands..."); defaultConfig.getBootCommands_commands().forEach(command -> { - plugin.logger().log(">>> "+command); - plugin.getVirtualServer().dispatchCommand(command); + logger.log(">>> "+command); + api.getVirtualProcessor().dispatchCommand(command); }); } @@ -47,59 +54,66 @@ public static boolean start() { DefaultConfig.empty(); FamilyConfig.empty(); + this.isRunning = true; return true; } - public static void stop() { + public void stop() { try { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); WhitelistConfig.empty(); DefaultConfig.empty(); FamilyConfig.empty(); LoggerConfig.empty(); - if(plugin.getVirtualServer() != null) { - plugin.getVirtualServer().killHeartbeats(); - plugin.getVirtualServer().killRedis(); - plugin.unsetVirtualServer(); + if(api.getVirtualProcessor() != null) { + api.getVirtualProcessor().killHeartbeats(); + api.getVirtualProcessor().killRedis(); } - plugin.getVelocityServer().getCommandManager().unregister("rc"); + api.getServer().getCommandManager().unregister("rc"); + + this.isRunning = false; - plugin.getVelocityServer().getEventManager().unregisterListener(plugin, new OnPlayerChooseInitialServer()); - plugin.getVelocityServer().getEventManager().unregisterListener(plugin, new OnPlayerChangeServer()); - plugin.getVelocityServer().getEventManager().unregisterListener(plugin, new OnPlayerKicked()); - plugin.getVelocityServer().getEventManager().unregisterListener(plugin, new OnPlayerDisconnect()); + api.getServer().getEventManager().unregisterListener(api.accessPlugin(), new OnPlayerChooseInitialServer()); + api.getServer().getEventManager().unregisterListener(api.accessPlugin(), new OnPlayerChangeServer()); + api.getServer().getEventManager().unregisterListener(api.accessPlugin(), new OnPlayerKicked()); + api.getServer().getEventManager().unregisterListener(api.accessPlugin(), new OnPlayerDisconnect()); } catch (Exception ignore) {} } - private static boolean initConfigs(VelocityRustyConnector plugin) { + protected boolean loadConfigs() { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); try { - DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(plugin.getDataFolder(), "config.yml"), "velocity_config_template.yml"); + DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(String.valueOf(api.getDataFolder()), "config.yml"), "velocity_config_template.yml"); if(!defaultConfig.generate()) { throw new IllegalStateException("Unable to load or create config.yml!"); } defaultConfig.register(); - LoggerConfig loggerConfig = LoggerConfig.newConfig(new File(plugin.getDataFolder(), "logger.yml"), "velocity_logger_template.yml"); + LoggerConfig loggerConfig = LoggerConfig.newConfig(new File(String.valueOf(api.getDataFolder()), "logger.yml"), "velocity_logger_template.yml"); if(!loggerConfig.generate()) { throw new IllegalStateException("Unable to load or create logger.yml!"); } loggerConfig.register(); PluginLogger.init(loggerConfig); - plugin.setVirtualServer(Proxy.init(defaultConfig)); + api.configureProcessor(defaultConfig); return true; } catch (NoOutputException ignore) { return false; } catch (Exception e) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text(e.getMessage()), NamedTextColor.RED); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text(e.getMessage()), NamedTextColor.RED); return false; } } - private static boolean initCommands(VelocityRustyConnector plugin) { - CommandManager commandManager = plugin.getVelocityServer().getCommandManager(); + protected boolean loadCommands() { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + CommandManager commandManager = api.getServer().getCommandManager(); try { commandManager.register( commandManager.metaBuilder("rustyconnector") @@ -119,22 +133,25 @@ private static boolean initCommands(VelocityRustyConnector plugin) { return true; } catch (Exception e) { - VelocityLang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text(e.getMessage()), NamedTextColor.RED); + VelocityLang.BOXED_MESSAGE_COLORED.send(logger, Component.text(e.getMessage()), NamedTextColor.RED); return false; } } - private static boolean initEvents(VelocityRustyConnector plugin) { - EventManager manager = plugin.getVelocityServer().getEventManager(); + protected boolean loadEvents() { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + + EventManager manager = api.getServer().getEventManager(); try { - manager.register(plugin, new OnPlayerChooseInitialServer()); - manager.register(plugin, new OnPlayerChangeServer()); - manager.register(plugin, new OnPlayerKicked()); - manager.register(plugin, new OnPlayerDisconnect()); + manager.register(api.accessPlugin(), new OnPlayerChooseInitialServer()); + manager.register(api.accessPlugin(), new OnPlayerChangeServer()); + manager.register(api.accessPlugin(), new OnPlayerKicked()); + manager.register(api.accessPlugin(), new OnPlayerDisconnect()); return true; } catch (Exception e) { - VelocityLang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text(e.getMessage()), NamedTextColor.RED); + VelocityLang.BOXED_MESSAGE_COLORED.send(logger, Component.text(e.getMessage()), NamedTextColor.RED); return false; } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandRusty.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandRusty.java index 3b53e7af5..265be6f95 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandRusty.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandRusty.java @@ -15,53 +15,57 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage; import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.config.DefaultConfig; import group.aelysium.rustyconnector.plugin.velocity.lib.config.LoggerConfig; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.module.ServerFamily; import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.VirtualProxyProcessor; import java.io.File; import java.util.List; public final class CommandRusty { public static BrigadierCommand create() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + VirtualProxyProcessor virtualProcessor = api.getVirtualProcessor(); LiteralCommandNode rusty = LiteralArgumentBuilder .literal("rc") .requires(source -> source instanceof ConsoleCommandSource) .executes(context -> { - VelocityLang.RC_ROOT_USAGE.send(plugin.logger()); + VelocityLang.RC_ROOT_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) .then(LiteralArgumentBuilder.literal("message") .executes(context -> { - VelocityLang.RC_MESSAGE_ROOT_USAGE.send(plugin.logger()); + VelocityLang.RC_MESSAGE_ROOT_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) .then(LiteralArgumentBuilder.literal("list") .executes(context -> { new Thread(() -> { try { - if(plugin.getVirtualServer().getMessageCache().getSize() > 10) { - int numberOfPages = Math.floorDiv(plugin.getVirtualServer().getMessageCache().getSize(),10) + 1; + if(virtualProcessor.getMessageCache().getSize() > 10) { + int numberOfPages = Math.floorDiv(virtualProcessor.getMessageCache().getSize(),10) + 1; - List messagesPage = plugin.getVirtualServer().getMessageCache().getMessagesPage(1); + List messagesPage = virtualProcessor.getMessageCache().getMessagesPage(1); - VelocityLang.RC_MESSAGE_PAGE.send(plugin.logger(),messagesPage,1,numberOfPages); + VelocityLang.RC_MESSAGE_PAGE.send(logger,messagesPage,1,numberOfPages); return; } - List messages = plugin.getVirtualServer().getMessageCache().getMessages(); + List messages = virtualProcessor.getMessageCache().getMessages(); - VelocityLang.RC_MESSAGE_PAGE.send(plugin.logger(),messages,1,1); + VelocityLang.RC_MESSAGE_PAGE.send(logger,messages,1,1); } catch (Exception e) { - VelocityLang.RC_MESSAGE_ERROR.send(plugin.logger(),"There was an issue getting those messages!"); + VelocityLang.RC_MESSAGE_ERROR.send(logger,"There was an issue getting those messages!"); } }).start(); @@ -73,13 +77,13 @@ public static BrigadierCommand create() { try { int pageNumber = context.getArgument("page-number", Integer.class); - List messages = plugin.getVirtualServer().getMessageCache().getMessagesPage(pageNumber); + List messages = virtualProcessor.getMessageCache().getMessagesPage(pageNumber); - int numberOfPages = Math.floorDiv(plugin.getVirtualServer().getMessageCache().getSize(),10) + 1; + int numberOfPages = Math.floorDiv(virtualProcessor.getMessageCache().getSize(),10) + 1; - VelocityLang.RC_MESSAGE_PAGE.send(plugin.logger(),messages,pageNumber,numberOfPages); + VelocityLang.RC_MESSAGE_PAGE.send(logger,messages,pageNumber,numberOfPages); } catch (Exception e) { - VelocityLang.RC_MESSAGE_ERROR.send(plugin.logger(),"There was an issue getting that page!"); + VelocityLang.RC_MESSAGE_ERROR.send(logger,"There was an issue getting that page!"); } }).start(); @@ -89,7 +93,7 @@ public static BrigadierCommand create() { ) .then(LiteralArgumentBuilder.literal("get") .executes(context -> { - VelocityLang.RC_MESSAGE_GET_USAGE.send(plugin.logger()); + VelocityLang.RC_MESSAGE_GET_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) @@ -97,13 +101,13 @@ public static BrigadierCommand create() { .executes(context -> { try { Long snowflake = context.getArgument("snowflake", Long.class); - MessageCache messageCache = VelocityRustyConnector.getInstance().getVirtualServer().getMessageCache(); + MessageCache messageCache = virtualProcessor.getMessageCache(); CacheableMessage message = messageCache.getMessage(snowflake); - VelocityLang.RC_MESSAGE_GET_MESSAGE.send(plugin.logger(),message.getSnowflake(),message.getDate(),message.getContents()); + VelocityLang.RC_MESSAGE_GET_MESSAGE.send(logger,message.getSnowflake(),message.getDate(),message.getContents()); } catch (Exception e) { - VelocityLang.RC_MESSAGE_ERROR.send(plugin.logger(),"There's no saved message with that ID!"); + VelocityLang.RC_MESSAGE_ERROR.send(logger,"There's no saved message with that ID!"); } return Command.SINGLE_SUCCESS; @@ -114,9 +118,9 @@ public static BrigadierCommand create() { .then(LiteralArgumentBuilder.literal("family") .executes(context -> { try { - VelocityLang.RC_FAMILY.send(plugin.logger()); + VelocityLang.RC_FAMILY.send(logger); } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"Something prevented us from getting the families!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from getting the families!"); } return Command.SINGLE_SUCCESS; @@ -125,14 +129,14 @@ public static BrigadierCommand create() { .executes(context -> { try { String familyName = context.getArgument("familyName", String.class); - ServerFamily family = VelocityRustyConnector.getInstance().getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); - VelocityLang.RC_FAMILY_INFO.send(plugin.logger(), family); + VelocityLang.RC_FAMILY_INFO.send(logger, family); } catch (NullPointerException e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"A family with that name doesn't exist!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"Something prevented us from getting that family!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from getting that family!"); } return Command.SINGLE_SUCCESS; }) @@ -140,16 +144,16 @@ public static BrigadierCommand create() { .executes(context -> { try { String familyName = context.getArgument("familyName", String.class); - ServerFamily family = VelocityRustyConnector.getInstance().getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); family.getLoadBalancer().resetIndex(); - VelocityLang.RC_FAMILY_INFO.send(plugin.logger(), family); + VelocityLang.RC_FAMILY_INFO.send(logger, family); } catch (NullPointerException e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"A family with that name doesn't exist!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"Something prevented us from doing that!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!"); } return Command.SINGLE_SUCCESS; }) @@ -158,16 +162,16 @@ public static BrigadierCommand create() { .executes(context -> { try { String familyName = context.getArgument("familyName", String.class); - ServerFamily family = VelocityRustyConnector.getInstance().getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); family.getLoadBalancer().completeSort(); - VelocityLang.RC_FAMILY_INFO.send(plugin.logger(), family); + VelocityLang.RC_FAMILY_INFO.send(logger, family); } catch (NullPointerException e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"A family with that name doesn't exist!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"Something prevented us from doing that!"+e.getMessage()); + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from doing that!"+e.getMessage()); } return 1; }) @@ -177,9 +181,9 @@ public static BrigadierCommand create() { .then(LiteralArgumentBuilder.literal("register") .executes(context -> { try { - VelocityLang.RC_REGISTER_USAGE.send(plugin.logger()); + VelocityLang.RC_REGISTER_USAGE.send(logger); } catch (Exception e) { - VelocityLang.RC_REGISTER_ERROR.send(plugin.logger(), "Something prevented us from sending a request for registration!"); + VelocityLang.RC_REGISTER_ERROR.send(logger, "Something prevented us from sending a request for registration!"); } return 1; @@ -187,30 +191,30 @@ public static BrigadierCommand create() { .then(LiteralArgumentBuilder.literal("all") .executes(context -> { try { - plugin.getVirtualServer().registerAllServers(); + virtualProcessor.registerAllServers(); return 1; } catch (Exception e) { - VelocityLang.RC_REGISTER_ERROR.send(plugin.logger(), e.getMessage()); + VelocityLang.RC_REGISTER_ERROR.send(logger, e.getMessage()); } return 0; }) ) .then(LiteralArgumentBuilder.literal("family") .executes(context -> { - VelocityLang.RC_REGISTER_USAGE.send(plugin.logger()); + VelocityLang.RC_REGISTER_USAGE.send(logger); return 1; }).then(RequiredArgumentBuilder.argument("familyName", StringArgumentType.string()) .executes(context -> { try { String familyName = context.getArgument("familyName", String.class); - ServerFamily family = VelocityRustyConnector.getInstance().getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); - VelocityRustyConnector.getInstance().getVirtualServer().registerAllServers(familyName); + virtualProcessor.registerAllServers(familyName); } catch (NullPointerException e) { - VelocityLang.RC_REGISTER_ERROR.send(plugin.logger(),"A family with that name doesn't exist!"); + VelocityLang.RC_REGISTER_ERROR.send(logger,"A family with that name doesn't exist!"); } catch (Exception e) { - VelocityLang.RC_REGISTER_ERROR.send(plugin.logger(),"Something prevented us from reloading that family!"); + VelocityLang.RC_REGISTER_ERROR.send(logger,"Something prevented us from reloading that family!"); } return 1; }) @@ -219,58 +223,58 @@ public static BrigadierCommand create() { ) .then(LiteralArgumentBuilder.literal("reload") .executes(context -> { - VelocityLang.RC_RELOAD_USAGE.send(plugin.logger()); + VelocityLang.RC_RELOAD_USAGE.send(logger); return 1; }) .then(LiteralArgumentBuilder.literal("proxy") .executes(context -> { - plugin.logger().log("Reloading the proxy..."); + logger.log("Reloading the proxy..."); try { - DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(plugin.getDataFolder(), "config.yml"), "velocity_config_template.yml"); + DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(api.getDataFolder(), "config.yml"), "velocity_config_template.yml"); if(!defaultConfig.generate()) { throw new IllegalStateException("Unable to load or create config.yml!"); } defaultConfig.register(); - plugin.getVirtualServer().reload(defaultConfig); - plugin.logger().log("Done reloading!"); + virtualProcessor.reload(defaultConfig); + logger.log("Done reloading!"); - VelocityLang.RC_ROOT_USAGE.send(plugin.logger()); + VelocityLang.RC_ROOT_USAGE.send(logger); return 1; } catch (Exception e) { - VelocityRustyConnector.getInstance().logger().error(e.getMessage(),e); + logger.error(e.getMessage(),e); } return 0; }) ) .then(LiteralArgumentBuilder.literal("family") .executes(context -> { - VelocityLang.RC_RELOAD_USAGE.send(plugin.logger()); + VelocityLang.RC_RELOAD_USAGE.send(logger); return 1; }).then(RequiredArgumentBuilder.argument("familyName", StringArgumentType.string()) .executes(context -> { try { String familyName = context.getArgument("familyName", String.class); - plugin.logger().log("Reloading the family: "+familyName+"..."); - ServerFamily oldFamily = VelocityRustyConnector.getInstance().getVirtualServer().getFamilyManager().find(familyName); + logger.log("Reloading the family: "+familyName+"..."); + ServerFamily oldFamily = virtualProcessor.getFamilyManager().find(familyName); if(oldFamily == null) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"A family with that name doesn't exist!"); + VelocityLang.RC_FAMILY_ERROR.send(logger,"A family with that name doesn't exist!"); return 1; } - ServerFamily newFamily = ServerFamily.init(plugin.getVirtualServer(), familyName); + ServerFamily newFamily = ServerFamily.init(virtualProcessor, familyName); oldFamily.unregisterServers(); - plugin.getVirtualServer().getFamilyManager().remove(oldFamily); - plugin.getVirtualServer().getFamilyManager().add(newFamily); + virtualProcessor.getFamilyManager().remove(oldFamily); + virtualProcessor.getFamilyManager().add(newFamily); - plugin.logger().log("Done reloading!"); + logger.log("Done reloading!"); - VelocityLang.RC_FAMILY_INFO.send(plugin.logger(), newFamily); + VelocityLang.RC_FAMILY_INFO.send(logger, newFamily); return 1; } catch (Exception e) { - VelocityLang.RC_FAMILY_ERROR.send(plugin.logger(),"Something prevented us from reloading that family!\n"+e.getMessage()); + VelocityLang.RC_FAMILY_ERROR.send(logger,"Something prevented us from reloading that family!\n"+e.getMessage()); } return 0; }) @@ -279,37 +283,37 @@ public static BrigadierCommand create() { .then(LiteralArgumentBuilder.literal("logger") .executes(context -> { try { - plugin.logger().log("Reloading plugin logger..."); - LoggerConfig loggerConfig = LoggerConfig.newConfig(new File(plugin.getDataFolder(), "logger.yml"), "velocity_logger_template.yml"); + logger.log("Reloading plugin logger..."); + LoggerConfig loggerConfig = LoggerConfig.newConfig(new File(api.getDataFolder(), "logger.yml"), "velocity_logger_template.yml"); if (!loggerConfig.generate()) { throw new IllegalStateException("Unable to load or create logger.yml!"); } loggerConfig.register(); PluginLogger.init(loggerConfig); - plugin.logger().log("Done reloading!"); + logger.log("Done reloading!"); return 1; } catch (Exception e) { - VelocityRustyConnector.getInstance().logger().error(e.getMessage(),e); + logger.error(e.getMessage(),e); } return 0; }) ) .then(LiteralArgumentBuilder.literal("whitelists") .executes(context -> { - plugin.logger().log("Reloading whitelists..."); + logger.log("Reloading whitelists..."); try { - DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(plugin.getDataFolder(), "config.yml"), "velocity_config_template.yml"); + DefaultConfig defaultConfig = DefaultConfig.newConfig(new File(api.getDataFolder(), "config.yml"), "velocity_config_template.yml"); if(!defaultConfig.generate()) { throw new IllegalStateException("Unable to load or create config.yml!"); } defaultConfig.register(); - plugin.getVirtualServer().reloadWhitelists(defaultConfig); - plugin.logger().log("Done reloading!"); + virtualProcessor.reloadWhitelists(defaultConfig); + logger.log("Done reloading!"); return 1; } catch (Exception e) { - VelocityRustyConnector.getInstance().logger().error(e.getMessage(),e); + logger.error(e.getMessage(),e); } return 0; }) @@ -317,12 +321,12 @@ public static BrigadierCommand create() { ) .then(LiteralArgumentBuilder.literal("send") .executes(context -> { - VelocityLang.RC_SEND_USAGE.send(plugin.logger()); + VelocityLang.RC_SEND_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("username", StringArgumentType.string()) .executes(context -> { - VelocityLang.RC_SEND_USAGE.send(plugin.logger()); + VelocityLang.RC_SEND_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("familyName", StringArgumentType.greedyString()) @@ -330,15 +334,15 @@ public static BrigadierCommand create() { String familyName = context.getArgument("familyName", String.class); String username = context.getArgument("username", String.class); - Player player = plugin.getVelocityServer().getPlayer(username).orElse(null); + Player player = api.getServer().getPlayer(username).orElse(null); if(player == null) { - plugin.logger().send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); + logger.send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); return Command.SINGLE_SUCCESS; } - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) { - plugin.logger().send(VelocityLang.RC_SEND_NO_FAMILY.build(familyName)); + logger.send(VelocityLang.RC_SEND_NO_FAMILY.build(familyName)); return Command.SINGLE_SUCCESS; } @@ -350,12 +354,12 @@ public static BrigadierCommand create() { ) .then(LiteralArgumentBuilder.literal("server") .executes(context -> { - VelocityLang.RC_SEND_USAGE.send(plugin.logger()); + VelocityLang.RC_SEND_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("username", StringArgumentType.string()) .executes(context -> { - VelocityLang.RC_SEND_USAGE.send(plugin.logger()); + VelocityLang.RC_SEND_USAGE.send(logger); return Command.SINGLE_SUCCESS; }) .then(RequiredArgumentBuilder.argument("serverName", StringArgumentType.greedyString()) @@ -363,21 +367,21 @@ public static BrigadierCommand create() { String serverName = context.getArgument("serverName", String.class); String username = context.getArgument("username", String.class); - Player player = plugin.getVelocityServer().getPlayer(username).orElse(null); + Player player = api.getServer().getPlayer(username).orElse(null); if(player == null) { - plugin.logger().send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); + logger.send(VelocityLang.RC_SEND_NO_PLAYER.build(username)); return Command.SINGLE_SUCCESS; } - RegisteredServer registeredServer = plugin.getVelocityServer().getServer(serverName).orElse(null); + RegisteredServer registeredServer = api.getServer().getServer(serverName).orElse(null); if(registeredServer == null) { - plugin.logger().send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); + logger.send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); return Command.SINGLE_SUCCESS; } - PaperServer server = plugin.getVirtualServer().findServer(registeredServer.getServerInfo()); + PlayerServer server = virtualProcessor.findServer(registeredServer.getServerInfo()); if(server == null) { - plugin.logger().send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); + logger.send(VelocityLang.RC_SEND_NO_SERVER.build(serverName)); return Command.SINGLE_SUCCESS; } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java index e8d81c911..ca3f73dbe 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java @@ -7,16 +7,19 @@ import com.mojang.brigadier.tree.LiteralCommandNode; import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.command.VelocityBrigadierMessage; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.module.Permission; import group.aelysium.rustyconnector.plugin.velocity.lib.module.ServerFamily; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.VirtualProxyProcessor; import group.aelysium.rustyconnector.plugin.velocity.lib.tpa.TPARequest; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -32,13 +35,13 @@ public final class CommandTPA { * @return `true` is /tpa is allowed. `false` otherwise. */ public static boolean tpaEnabled(Player sender) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VirtualProxyProcessor virtualProcessor = VelocityRustyConnector.getAPI().getVirtualProcessor(); try { ServerInfo serverInfo = sender.getCurrentServer().orElseThrow().getServerInfo(); - PaperServer targetServer = plugin.getVirtualServer().findServer(serverInfo); + PlayerServer targetServer = virtualProcessor.findServer(serverInfo); String familyName = targetServer.getFamilyName(); - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) return false; return family.getTPAHandler().getSettings().isEnabled(); @@ -47,14 +50,16 @@ public static boolean tpaEnabled(Player sender) { } public static BrigadierCommand create() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + VirtualProxyProcessor virtualProcessor = api.getVirtualProcessor(); LiteralCommandNode tpa = LiteralArgumentBuilder .literal("tpa") .requires(source -> source instanceof Player) .executes(context -> { if(!(context.getSource() instanceof Player player)) { - plugin.logger().log("/tpa must be sent as a player!"); + logger.log("/tpa must be sent as a player!"); return Command.SINGLE_SUCCESS; } @@ -74,7 +79,7 @@ public static BrigadierCommand create() { .then(LiteralArgumentBuilder.literal("deny") .executes(context -> { if(!(context.getSource() instanceof Player)) { - plugin.logger().log("/tpa must be sent as a player!"); + logger.log("/tpa must be sent as a player!"); return Command.SINGLE_SUCCESS; } @@ -94,8 +99,8 @@ public static BrigadierCommand create() { try { ServerInfo sendingServer = ((Player) context.getSource()).getCurrentServer().orElseThrow().getServerInfo(); - String familyName = plugin.getVirtualServer().findServer(sendingServer).getFamilyName(); - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + String familyName = virtualProcessor.findServer(sendingServer).getFamilyName(); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); List requests = family.getTPAHandler().findRequestsForTarget(player); if(requests.size() <= 0) { @@ -113,7 +118,7 @@ public static BrigadierCommand create() { }) .executes(context -> { if(!(context.getSource() instanceof Player player)) { - plugin.logger().log("/tpa must be sent as a player!"); + logger.log("/tpa must be sent as a player!"); return Command.SINGLE_SUCCESS; } @@ -129,13 +134,13 @@ public static BrigadierCommand create() { String username = context.getArgument("username", String.class); try { - Player senderPlayer = plugin.getVelocityServer().getPlayer(username).orElseThrow(); + Player senderPlayer = api.getServer().getPlayer(username).orElseThrow(); ServerInfo targetServerInfo = ((Player) context.getSource()).getCurrentServer().orElseThrow().getServerInfo(); - PaperServer targetServer = plugin.getVirtualServer().findServer(targetServerInfo); + PlayerServer targetServer = virtualProcessor.findServer(targetServerInfo); String familyName = targetServer.getFamilyName(); try { - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); TPARequest request = family.getTPAHandler().findRequest(senderPlayer, (Player) context.getSource()); @@ -148,7 +153,7 @@ public static BrigadierCommand create() { family.getTPAHandler().remove(request); return Command.SINGLE_SUCCESS; } catch (NullPointerException e) { - plugin.logger().send(Component.text("Player attempted to use /tpa deny from a family that doesn't exist! (How?)", NamedTextColor.RED)); + logger.send(Component.text("Player attempted to use /tpa deny from a family that doesn't exist! (How?)", NamedTextColor.RED)); context.getSource().sendMessage(VelocityLang.TPA_FAILURE.build(username)); } } catch (NoSuchElementException e) { @@ -164,7 +169,7 @@ public static BrigadierCommand create() { .then(LiteralArgumentBuilder.literal("accept") .executes(context -> { if(!(context.getSource() instanceof Player player)) { - plugin.logger().log("/tpa must be sent as a player!"); + logger.log("/tpa must be sent as a player!"); return Command.SINGLE_SUCCESS; } @@ -188,8 +193,8 @@ public static BrigadierCommand create() { try { ServerInfo sendingServer = ((Player) context.getSource()).getCurrentServer().orElseThrow().getServerInfo(); - String familyName = plugin.getVirtualServer().findServer(sendingServer).getFamilyName(); - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + String familyName = virtualProcessor.findServer(sendingServer).getFamilyName(); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); List requests = family.getTPAHandler().findRequestsForTarget(player); if(requests.size() <= 0) { @@ -207,20 +212,20 @@ public static BrigadierCommand create() { }) .executes(context -> { if(!(context.getSource() instanceof Player)) { - plugin.logger().log("/tpa must be sent as a player!"); + logger.log("/tpa must be sent as a player!"); return Command.SINGLE_SUCCESS; } String username = context.getArgument("username", String.class); try { - Player senderPlayer = plugin.getVelocityServer().getPlayer(username).orElseThrow(); + Player senderPlayer = api.getServer().getPlayer(username).orElseThrow(); ServerInfo targetServerInfo = ((Player) context.getSource()).getCurrentServer().orElseThrow().getServerInfo(); - PaperServer targetServer = plugin.getVirtualServer().findServer(targetServerInfo); + PlayerServer targetServer = virtualProcessor.findServer(targetServerInfo); String familyName = targetServer.getFamilyName(); try { - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); TPARequest request = family.getTPAHandler().findRequest(senderPlayer, (Player) context.getSource()); @@ -233,7 +238,7 @@ public static BrigadierCommand create() { family.getTPAHandler().remove(request); return Command.SINGLE_SUCCESS; } catch (NullPointerException e) { - plugin.logger().send(Component.text("Player attempted to use /tpa accept from a family that doesn't exist! (How?)", NamedTextColor.RED)); + logger.send(Component.text("Player attempted to use /tpa accept from a family that doesn't exist! (How?)", NamedTextColor.RED)); context.getSource().sendMessage(VelocityLang.TPA_FAILURE.build(username)); } } catch (NoSuchElementException e) { @@ -253,8 +258,8 @@ public static BrigadierCommand create() { try { ServerInfo sendingServer = ((Player) context.getSource()).getCurrentServer().orElseThrow().getServerInfo(); - String familyName = plugin.getVirtualServer().findServer(sendingServer).getFamilyName(); - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + String familyName = virtualProcessor.findServer(sendingServer).getFamilyName(); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); family.getAllPlayers(100).forEach(player -> builder.suggest(player.getUsername())); @@ -266,7 +271,7 @@ public static BrigadierCommand create() { }) .executes(context -> { if(!(context.getSource() instanceof Player player)) { - plugin.logger().log("/tpa must be sent as a player!"); + logger.log("/tpa must be sent as a player!"); return Command.SINGLE_SUCCESS; } @@ -282,7 +287,7 @@ public static BrigadierCommand create() { String username = context.getArgument("username", String.class); try { - Player targetPlayer = plugin.getVelocityServer().getPlayer(username).orElseThrow(); + Player targetPlayer = api.getServer().getPlayer(username).orElseThrow(); if(player.equals(targetPlayer)) { player.sendMessage(VelocityLang.TPA_FAILURE_SELF_TP); @@ -291,10 +296,10 @@ public static BrigadierCommand create() { ServerInfo sendersServerInfo = ((Player) context.getSource()).getCurrentServer().orElseThrow().getServerInfo(); - PaperServer sendersServer = plugin.getVirtualServer().findServer(sendersServerInfo); + PlayerServer sendersServer = virtualProcessor.findServer(sendersServerInfo); String familyName = sendersServer.getFamilyName(); try { - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = virtualProcessor.getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); if(!family.getTPAHandler().getSettings().isEnabled()) throw new RuntimeException(); @@ -308,7 +313,7 @@ public static BrigadierCommand create() { return Command.SINGLE_SUCCESS; } catch (NullPointerException e) { - plugin.logger().send(Component.text("Player attempted to use /tpa from a family that doesn't exist! (How?)", NamedTextColor.RED)); + logger.send(Component.text("Player attempted to use /tpa from a family that doesn't exist! (How?)", NamedTextColor.RED)); context.getSource().sendMessage(VelocityLang.TPA_FAILURE.build(username)); } } catch (NoSuchElementException e) { diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/Clock.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/Clock.java index 9ac1e106b..161f922a2 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/Clock.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/Clock.java @@ -1,6 +1,7 @@ package group.aelysium.rustyconnector.plugin.velocity.lib; import group.aelysium.rustyconnector.core.lib.Callable; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; import java.util.Timer; @@ -15,13 +16,13 @@ public Clock(long delay) { } public void start(Callable callback) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); this.timer.schedule( new TimerTask() { public void run() { try { callback.execute(); } catch (Exception e) { - plugin.logger().log(e.getMessage()); + logger.log(e.getMessage()); } } }, 0, this.delay*1000); diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/DefaultConfig.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/DefaultConfig.java index 697613503..b0b213a9b 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/DefaultConfig.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/DefaultConfig.java @@ -2,6 +2,7 @@ import group.aelysium.rustyconnector.core.lib.exception.NoOutputException; import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; import net.kyori.adventure.text.Component; @@ -15,7 +16,6 @@ public class DefaultConfig extends YAML { private static DefaultConfig config; private String private_key = ""; - private String public_key = ""; private String root_family = "lobby"; private List families = new ArrayList<>(); @@ -160,7 +160,7 @@ public Boolean getMessageTunnel_familyServerSorting_enabled() { @SuppressWarnings("unchecked") public void register() throws IllegalStateException, NoOutputException { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); try { this.processVersion(); @@ -172,10 +172,9 @@ public void register() throws IllegalStateException, NoOutputException { this.private_key = this.getNode(this.data,"private-key",String.class); if(this.private_key.equals("")) throw new Exception("You must provide a private key!"); } catch (Exception e) { - VelocityLang.PRIVATE_KEY.send(plugin.logger()); + VelocityLang.PRIVATE_KEY.send(logger); throw new NoOutputException(e); } - this.public_key = ""; this.root_family = this.getNode(this.data,"root-family",String.class); try { @@ -218,13 +217,13 @@ public void register() throws IllegalStateException, NoOutputException { this.messageTunnel_messageCacheSize = this.getNode(this.data,"message-tunnel.message-cache-size",Integer.class); if(this.messageTunnel_messageCacheSize > 500) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("Message cache size is to large! " + this.messageTunnel_messageCacheSize + " > 500. Message cache size set to 500."), NamedTextColor.YELLOW); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text("Message cache size is to large! " + this.messageTunnel_messageCacheSize + " > 500. Message cache size set to 500."), NamedTextColor.YELLOW); this.messageTunnel_messageCacheSize = 500; } this.messageTunnel_messageMaxLength = this.getNode(this.data,"message-tunnel.message-max-length",Integer.class); if(this.messageTunnel_messageMaxLength < 384) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("Max message length is to small to be effective! " + this.messageTunnel_messageMaxLength + " < 384. Max message length set to 384."), NamedTextColor.YELLOW); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text("Max message length is to small to be effective! " + this.messageTunnel_messageMaxLength + " < 384. Max message length set to 384."), NamedTextColor.YELLOW); this.messageTunnel_messageMaxLength = 384; } @@ -254,7 +253,7 @@ public void register() throws IllegalStateException, NoOutputException { this.hearts_serverLifecycle_enabled = this.getNode(this.data,"hearts.server-lifecycle.enabled",Boolean.class); this.hearts_serverLifecycle_interval = this.getNode(this.data,"hearts.server-lifecycle.interval",Integer.class); if(this.hearts_serverLifecycle_interval < 10) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("Server lifecycle interval is set dangerously fast: " + this.hearts_serverLifecycle_interval + "ms. Setting to default of 30ms."), NamedTextColor.YELLOW); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text("Server lifecycle interval is set dangerously fast: " + this.hearts_serverLifecycle_interval + "ms. Setting to default of 30ms."), NamedTextColor.YELLOW); this.messageTunnel_messageMaxLength = 30; } this.hearts_serverLifecycle_unregisterOnIgnore = this.getNode(this.data,"hearts.server-lifecycle.unregister-on-ignore",Boolean.class); @@ -262,7 +261,7 @@ public void register() throws IllegalStateException, NoOutputException { this.messageTunnel_familyServerSorting_enabled = this.getNode(this.data,"hearts.family-server-sorting.enabled",Boolean.class); this.messageTunnel_familyServerSorting_interval = this.getNode(this.data,"hearts.family-server-sorting.interval",Integer.class); if(this.messageTunnel_familyServerSorting_interval < 7) { - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("Server sorting interval is set dangerously fast: " + this.messageTunnel_familyServerSorting_interval + "ms. Setting to default of 20ms."), NamedTextColor.YELLOW); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text("Server sorting interval is set dangerously fast: " + this.messageTunnel_familyServerSorting_interval + "ms. Setting to default of 20ms."), NamedTextColor.YELLOW); this.messageTunnel_familyServerSorting_interval = 20; } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/WhitelistConfig.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/WhitelistConfig.java index 366ab8408..d9e94fff5 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/WhitelistConfig.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/WhitelistConfig.java @@ -1,6 +1,8 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.config; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -75,7 +77,7 @@ public static void empty() { @SuppressWarnings("unchecked") public void register() throws IllegalStateException { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); this.use_players = this.getNode(this.data,"use-players",Boolean.class); try { @@ -88,7 +90,7 @@ public void register() throws IllegalStateException { this.use_country = this.getNode(this.data,"use-country",Boolean.class); if(this.use_country) - Lang.BOXED_MESSAGE_COLORED.send(plugin.logger(), Component.text("RustyConnector does not currently support country codes in whitelists. Setting `use-country` to false."), NamedTextColor.YELLOW); + Lang.BOXED_MESSAGE_COLORED.send(logger, Component.text("RustyConnector does not currently support country codes in whitelists. Setting `use-country` to false."), NamedTextColor.YELLOW); this.use_country = false; this.countries = new ArrayList<>(); diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/YAML.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/YAML.java index 519ac6b76..0b598de32 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/YAML.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/config/YAML.java @@ -1,6 +1,8 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.config; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import java.io.File; import java.io.IOException; @@ -14,22 +16,23 @@ public YAML(File configPointer, String template) { @Override public boolean generate() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); if (!this.configPointer.exists()) { File parent = this.configPointer.getParentFile(); if (!parent.exists()) parent.mkdirs(); - InputStream templateStream = plugin.getResourceAsStream(this.template); + InputStream templateStream = api.getResourceAsStream(this.template); if (templateStream == null) { - plugin.logger().error("!!!!! Unable to setup "+this.configPointer.getName()+". This config has no template !!!!!"); + logger.error("!!!!! Unable to setup "+this.configPointer.getName()+". This config has no template !!!!!"); return false; } try { Files.copy(templateStream, this.configPointer.toPath()); } catch (IOException e) { - plugin.logger().error("!!!!! Unable to setup "+this.configPointer.getName()+" !!!!!",e); + logger.error("!!!!! Unable to setup "+this.configPointer.getName()+" !!!!!",e); return false; } } @@ -37,10 +40,10 @@ public boolean generate() { try { this.data = this.loadYAML(this.configPointer); if(this.data == null) return false; - plugin.logger().log("Finished registering "+this.configPointer.getName()); + logger.log("Finished registering "+this.configPointer.getName()); return true; } catch (Exception e) { - plugin.logger().log("Failed to register: "+this.configPointer.getName()); + logger.log("Failed to register: "+this.configPointer.getName()); return false; } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/database/Redis.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/database/Redis.java index 3175fa216..92fc0d008 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/database/Redis.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/database/Redis.java @@ -2,6 +2,7 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.data_messaging.MessageOrigin; import group.aelysium.rustyconnector.core.lib.data_messaging.MessageStatus; import group.aelysium.rustyconnector.core.lib.data_messaging.cache.CacheableMessage; @@ -10,7 +11,10 @@ import group.aelysium.rustyconnector.core.lib.exception.NoOutputException; import group.aelysium.rustyconnector.core.lib.util.AddressUtil; import group.aelysium.rustyconnector.core.lib.lang_messaging.GateKey; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.VirtualProxyProcessor; import group.aelysium.rustyconnector.plugin.velocity.lib.message.handling.*; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessageType; @@ -24,8 +28,10 @@ public class Redis extends group.aelysium.rustyconnector.core.lib.database.Redis @Override public void onMessage(String rawMessage) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); - MessageCache messageCache = plugin.getVirtualServer().getMessageCache(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + VirtualProxyProcessor virtualProcessor = api.getVirtualProcessor(); + MessageCache messageCache = virtualProcessor.getMessageCache(); // If the proxy doesn't have a message cache (maybe it's in the middle of a reload. // Send a temporary, worthless, message cache so that the system can still "cache" messages into the worthless cache if needed. @@ -35,9 +41,9 @@ public void onMessage(String rawMessage) { try { RedisMessage message = RedisMessage.create(rawMessage, MessageOrigin.PROXY, null); try { - plugin.getVirtualServer().validateMessage(message); + virtualProcessor.validateMessage(message); - if (!(plugin.getVirtualServer().validatePrivateKey(message.getKey()))) + if (!(virtualProcessor.validatePrivateKey(message.getKey()))) throw new AuthenticationException("This message has an invalid private key!"); cachedMessage.sentenceMessage(MessageStatus.ACCEPTED); @@ -45,33 +51,33 @@ public void onMessage(String rawMessage) { } catch (AuthenticationException e) { cachedMessage.sentenceMessage(MessageStatus.AUTH_DENIAL, e.getMessage()); - plugin.logger().error("An incoming message from: "+message.getAddress().toString()+" had an invalid private-key!"); - plugin.logger().log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); + logger.error("An incoming message from: "+message.getAddress().toString()+" had an invalid private-key!"); + logger.log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); } catch (BlockedMessageException e) { cachedMessage.sentenceMessage(MessageStatus.AUTH_DENIAL, e.getMessage()); - if(!plugin.logger().getGate().check(GateKey.MESSAGE_TUNNEL_FAILED_MESSAGE)) return; + if(!logger.getGate().check(GateKey.MESSAGE_TUNNEL_FAILED_MESSAGE)) return; - plugin.logger().error("An incoming message from: "+message.getAddress().toString()+" was blocked by the message tunnel!"); - plugin.logger().log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); + logger.error("An incoming message from: "+message.getAddress().toString()+" was blocked by the message tunnel!"); + logger.log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); } catch (NoOutputException e) { cachedMessage.sentenceMessage(MessageStatus.AUTH_DENIAL, e.getMessage()); } } catch (Exception e) { - if(plugin.logger().getGate().check(GateKey.SAVE_TRASH_MESSAGES)) + if(logger.getGate().check(GateKey.SAVE_TRASH_MESSAGES)) cachedMessage.sentenceMessage(MessageStatus.TRASHED, e.getMessage()); else - plugin.getVirtualServer().getMessageCache().removeMessage(cachedMessage.getSnowflake()); + virtualProcessor.getMessageCache().removeMessage(cachedMessage.getSnowflake()); - if(!plugin.logger().getGate().check(GateKey.MESSAGE_PARSER_TRASH)) return; + if(!logger.getGate().check(GateKey.MESSAGE_PARSER_TRASH)) return; - plugin.logger().error("An incoming message was thrown away!"); - plugin.logger().log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); + logger.error("An incoming message was thrown away!"); + logger.log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); } } private static void processParameters(RedisMessage message, CacheableMessage cachedMessage) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); Gson gson = new Gson(); JsonObject object = gson.fromJson(message.toString(), JsonObject.class); @@ -110,17 +116,17 @@ private static void processParameters(RedisMessage message, CacheableMessage cac } catch (NullPointerException e) { cachedMessage.sentenceMessage(MessageStatus.PARSING_ERROR); - if(!plugin.logger().getGate().check(GateKey.MESSAGE_PARSER_TRASH)) return; + if(!logger.getGate().check(GateKey.MESSAGE_PARSER_TRASH)) return; - plugin.logger().error("There was an issue handling the message. Throwing away...", e); - plugin.logger().log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); + logger.error("There was an issue handling the message. Throwing away...", e); + logger.log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); } catch (Exception e) { cachedMessage.sentenceMessage(MessageStatus.EXECUTING_ERROR, e.getMessage()); - if(!plugin.logger().getGate().check(GateKey.MESSAGE_PARSER_TRASH)) return; + if(!logger.getGate().check(GateKey.MESSAGE_PARSER_TRASH)) return; - plugin.logger().error("There was an issue handling the message. Throwing away...", e); - plugin.logger().log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); + logger.error("There was an issue handling the message. Throwing away...", e); + logger.log("To view the thrown away message use: /rc message get "+cachedMessage.getSnowflake()); } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChangeServer.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChangeServer.java index 9c845d035..80819e678 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChangeServer.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChangeServer.java @@ -4,8 +4,11 @@ import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.player.ServerConnectedEvent; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.VirtualProxyProcessor; public class OnPlayerChangeServer { /** @@ -14,25 +17,28 @@ public class OnPlayerChangeServer { @Subscribe(order = PostOrder.FIRST) public EventTask onPlayerChangeServer(ServerConnectedEvent event) { return EventTask.async(() -> { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + VirtualProxyProcessor virtualProcessor = api.getVirtualProcessor(); + try { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); - PaperServer newServer = plugin.getVirtualServer().findServer(event.getServer().getServerInfo()); + PlayerServer newServer = virtualProcessor.findServer(event.getServer().getServerInfo()); if(newServer == null) - plugin.logger().log("The server that this player is joining doesn't seem to exist!"); + logger.log("The server that this player is joining doesn't seem to exist!"); else newServer.playerJoined(); if(event.getPreviousServer().isPresent()) { - PaperServer oldServer = plugin.getVirtualServer().findServer(event.getPreviousServer().get().getServerInfo()); + PlayerServer oldServer = virtualProcessor.findServer(event.getPreviousServer().get().getServerInfo()); if(oldServer == null) - plugin.logger().log("The server that this player is leaving doesn't seem to exist!"); + logger.log("The server that this player is leaving doesn't seem to exist!"); else oldServer.playerLeft(); } } catch (Exception e) { - VelocityRustyConnector.getInstance().logger().log(e.getMessage()); + logger.log(e.getMessage()); } }); } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChooseInitialServer.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChooseInitialServer.java index 0370e5472..96a16a9e9 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChooseInitialServer.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerChooseInitialServer.java @@ -5,7 +5,9 @@ import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.proxy.Player; +import group.aelysium.rustyconnector.core.central.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; import group.aelysium.rustyconnector.plugin.velocity.lib.module.ServerFamily; import group.aelysium.rustyconnector.plugin.velocity.lib.module.Whitelist; @@ -17,22 +19,23 @@ public class OnPlayerChooseInitialServer { */ @Subscribe(order = PostOrder.LAST) public EventTask onPlayerChooseInitialServer(PlayerChooseInitialServerEvent event) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); Player player = event.getPlayer(); return EventTask.async(() -> { try { // Check if there's a whitelist, run it if there is. - Whitelist whitelist = plugin.getVirtualServer().getProxyWhitelist(); + Whitelist whitelist = api.getVirtualProcessor().getProxyWhitelist(); if(whitelist != null) { if (!whitelist.validate(player)) { - plugin.logger().log("Player isn't whitelisted on the proxy whitelist! Kicking..."); + logger.log("Player isn't whitelisted on the proxy whitelist! Kicking..."); player.disconnect(Component.text(whitelist.getMessage())); return; } } - ServerFamily rootFamily = plugin.getVirtualServer().getRootFamily(); + ServerFamily rootFamily = api.getVirtualProcessor().getRootFamily(); rootFamily.connect(player, event); } catch (Exception e) { diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerDisconnect.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerDisconnect.java index cc43b7fe7..2c2cd3a3e 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerDisconnect.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerDisconnect.java @@ -6,7 +6,8 @@ import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.proxy.Player; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; public class OnPlayerDisconnect { /** @@ -15,7 +16,7 @@ public class OnPlayerDisconnect { */ @Subscribe(order = PostOrder.LAST) public EventTask onPlayerDisconnect(DisconnectEvent event) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); return EventTask.async(() -> { try { @@ -23,7 +24,7 @@ public EventTask onPlayerDisconnect(DisconnectEvent event) { if(player == null) return; if(player.getCurrentServer().isPresent()) { - PaperServer server = plugin.getVirtualServer().findServer(player.getCurrentServer().get().getServerInfo()); + PlayerServer server = api.getVirtualProcessor().findServer(player.getCurrentServer().get().getServerInfo()); server.playerLeft(); } } catch (Exception e) { diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerKicked.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerKicked.java index d5477a8ea..32f7cc173 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerKicked.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/events/OnPlayerKicked.java @@ -6,7 +6,8 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.proxy.Player; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import net.kyori.adventure.text.Component; public class OnPlayerKicked { @@ -15,13 +16,13 @@ public class OnPlayerKicked { */ @Subscribe(order = PostOrder.FIRST) public EventTask onPlayerKicked(KickedFromServerEvent event) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); Player player = event.getPlayer(); return EventTask.async(() -> { try { if(player.getCurrentServer().isPresent()) { - PaperServer server = plugin.getVirtualServer().findServer(player.getCurrentServer().orElseThrow().getServerInfo()); + PlayerServer server = api.getVirtualProcessor().findServer(player.getCurrentServer().orElseThrow().getServerInfo()); if (server == null) return; server.playerLeft(); } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java index e09941f2f..d4fc8b3e1 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java @@ -6,9 +6,10 @@ import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; import group.aelysium.rustyconnector.core.lib.util.AddressUtil; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.config.LoggerConfig; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import group.aelysium.rustyconnector.plugin.velocity.lib.module.ServerFamily; import net.kyori.adventure.text.Component; @@ -199,9 +200,9 @@ public interface VelocityLang extends Lang { ); Message RC_FAMILY = () -> { - + VelocityAPI api = VelocityRustyConnector.getAPI(); Component families = text(""); - for (ServerFamily family : VelocityRustyConnector.getInstance().getVirtualServer().getFamilyManager().dump()) { + for (ServerFamily family : api.getVirtualProcessor().getFamilyManager().dump()) { families = families.append(text("[ "+family.getName()+" ] ")); } @@ -257,7 +258,7 @@ public interface VelocityLang extends Lang { if(family.getRegisteredServers() == null) servers = text("There are no registered servers.", DARK_GRAY); else if(family.getRegisteredServers().size() == 0) servers = text("There are no registered servers.", DARK_GRAY); - else for (PaperServer server : family.getRegisteredServers()) { + else for (PlayerServer server : family.getRegisteredServers()) { if(family.getLoadBalancer().getIndex() == i) servers = servers.append( text(" ---| "+(i + 1)+". ["+server.getRegisteredServer().getServerInfo().getName()+"]" + diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/LeastConnection.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/LeastConnection.java index 66c3e00da..a815276d5 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/LeastConnection.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/LeastConnection.java @@ -3,16 +3,15 @@ import group.aelysium.rustyconnector.core.lib.util.QuickSort; import group.aelysium.rustyconnector.core.lib.util.SingleSort; import group.aelysium.rustyconnector.core.lib.util.WeightedQuickSort; -import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; public class LeastConnection extends PaperServerLoadBalancer { @Override public void iterate() { try { - PaperServer thisItem = this.items.get(this.index); - PaperServer theNextItem = this.items.get(this.index + 1); + PlayerServer thisItem = this.items.get(this.index); + PlayerServer theNextItem = this.items.get(this.index + 1); if(thisItem.getPlayerCount() >= theNextItem.getPlayerCount()) this.index++; } catch (IndexOutOfBoundsException ignore) {} @@ -21,7 +20,7 @@ public void iterate() { @Override public void completeSort() { this.index = 0; - if(this.isWeighted()) WeightedQuickSort.sort(this.items, VelocityRustyConnector.getInstance().logger()); + if(this.isWeighted()) WeightedQuickSort.sort(this.items); else QuickSort.sort(this.items); } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/PaperServerLoadBalancer.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/PaperServerLoadBalancer.java index 9121d4925..5522a015e 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/PaperServerLoadBalancer.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/load_balancing/PaperServerLoadBalancer.java @@ -1,17 +1,17 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing; import group.aelysium.rustyconnector.core.lib.LoadBalancer; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import java.util.ArrayList; import java.util.List; -public class PaperServerLoadBalancer implements LoadBalancer { +public class PaperServerLoadBalancer implements LoadBalancer { private boolean weighted = false; private boolean persistence = false; private int attempts = 5; protected int index = 0; - protected List items = new ArrayList<>(); + protected List items = new ArrayList<>(); @Override public boolean isPersistent() { @@ -30,8 +30,8 @@ public boolean isWeighted() { } @Override - public PaperServer getCurrent() { - PaperServer item; + public PlayerServer getCurrent() { + PlayerServer item; if(this.index >= this.size()) { item = this.items.get(this.index); this.index = 0; @@ -66,12 +66,12 @@ public void completeSort() {} public void singleSort() {} @Override - public void add(PaperServer item) { + public void add(PlayerServer item) { this.items.add(item); } @Override - public void remove(PaperServer item) { + public void remove(PlayerServer item) { this.items.remove(item); } @@ -81,7 +81,7 @@ public int size() { } @Override - public List dump() { + public List dump() { return this.items; } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/managers/ServerManager.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/managers/ServerManager.java index 999c598e2..5f656d7ad 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/managers/ServerManager.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/managers/ServerManager.java @@ -1,14 +1,14 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.managers; import group.aelysium.rustyconnector.core.lib.model.NodeManager; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import java.util.HashMap; import java.util.List; import java.util.Map; -public class ServerManager implements NodeManager { - private final Map registeredServers = new HashMap<>(); +public class ServerManager implements NodeManager { + private final Map registeredServers = new HashMap<>(); /** @@ -17,7 +17,7 @@ public class ServerManager implements NodeManager { * @return A server. */ @Override - public PaperServer find(String name) { + public PlayerServer find(String name) { return this.registeredServers.get(name); } @@ -26,7 +26,7 @@ public PaperServer find(String name) { * @param server The server to add to this manager. */ @Override - public void add(PaperServer server) { + public void add(PlayerServer server) { this.registeredServers.put(server.getRegisteredServer().getServerInfo().getName(), server); } @@ -35,12 +35,12 @@ public void add(PaperServer server) { * @param server The server to remove from this manager. */ @Override - public void remove(PaperServer server) { + public void remove(PlayerServer server) { this.registeredServers.remove(server.getRegisteredServer().getServerInfo().getName()); } @Override - public List dump() { + public List dump() { return this.registeredServers.values().stream().toList(); } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/PongHandler.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/PongHandler.java index ea5dac3e6..42a9068a2 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/PongHandler.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/PongHandler.java @@ -1,12 +1,15 @@ package group.aelysium.rustyconnector.plugin.velocity.lib.message.handling; import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.core.central.PluginLogger; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.core.lib.lang_messaging.GateKey; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import java.net.InetSocketAddress; @@ -19,7 +22,8 @@ public PongHandler(RedisMessage message) { @Override public void execute() throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); InetSocketAddress address = message.getAddress(); @@ -29,16 +33,16 @@ public void execute() throws Exception { ); try { - PaperServer server = plugin.getVirtualServer().findServer(serverInfo); + PlayerServer server = api.getVirtualProcessor().findServer(serverInfo); if(server == null) return; - plugin.getVirtualServer().reviveServer(serverInfo); + api.getVirtualProcessor().reviveServer(serverInfo); server.setPlayerCount(Integer.parseInt(message.getParameter("player-count"))); - if(plugin.logger().getGate().check(GateKey.PONG)) - VelocityLang.PONG.send(plugin.logger(), serverInfo); + if(logger.getGate().check(GateKey.PONG)) + VelocityLang.PONG.send(logger, serverInfo); } catch (Exception e) { - if(plugin.logger().getGate().check(GateKey.PONG)) - VelocityLang.PONG_CANCELED.send(plugin.logger(), serverInfo); + if(logger.getGate().check(GateKey.PONG)) + VelocityLang.PONG_CANCELED.send(logger, serverInfo); throw new Exception(e.getMessage()); } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/SendPlayerHandler.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/SendPlayerHandler.java index 88cbdc8e2..c18f3474b 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/SendPlayerHandler.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/SendPlayerHandler.java @@ -4,6 +4,7 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; import group.aelysium.rustyconnector.plugin.velocity.lib.module.ServerFamily; import net.kyori.adventure.text.Component; @@ -20,16 +21,16 @@ public SendPlayerHandler(RedisMessage message) { @Override public void execute() throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); String familyName = message.getParameter("family"); UUID uuid = UUID.fromString(message.getParameter("uuid")); - Player player = VelocityRustyConnector.getInstance().getVelocityServer().getPlayer(uuid).stream().findFirst().orElse(null); + Player player = api.getServer().getPlayer(uuid).stream().findFirst().orElse(null); if(player == null) return; try { - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + ServerFamily family = api.getVirtualProcessor().getFamilyManager().find(familyName); if (family == null) throw new InvalidAlgorithmParameterException("A family with the name `"+familyName+"` doesn't exist!"); family.connect(player); diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerRegHandler.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerRegHandler.java index 74d49535a..eb8f3981f 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerRegHandler.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerRegHandler.java @@ -3,7 +3,7 @@ import com.velocitypowered.api.proxy.server.ServerInfo; import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; -import group.aelysium.rustyconnector.plugin.velocity.lib.module.PaperServer; +import group.aelysium.rustyconnector.plugin.velocity.lib.module.PlayerServer; import java.net.InetSocketAddress; @@ -27,7 +27,7 @@ public void execute() throws Exception { address ); - PaperServer server = new PaperServer( + PlayerServer server = new PlayerServer( serverInfo, Integer.parseInt(message.getParameter("soft-cap")), Integer.parseInt(message.getParameter("hard-cap")), diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerUnRegHandler.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerUnRegHandler.java index 7798abc41..c4513e322 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerUnRegHandler.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/message/handling/ServerUnRegHandler.java @@ -4,6 +4,7 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.MessageHandler; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import java.net.InetSocketAddress; @@ -16,7 +17,7 @@ public ServerUnRegHandler(RedisMessage message) { @Override public void execute() throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); String familyName = message.getParameter("family"); @@ -27,6 +28,6 @@ public void execute() throws Exception { address ); - plugin.getVirtualServer().unregisterServer(serverInfo, familyName, true); + api.getVirtualProcessor().unregisterServer(serverInfo, familyName, true); } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/PaperServer.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/PlayerServer.java similarity index 90% rename from velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/PaperServer.java rename to velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/PlayerServer.java index 645964590..d78cea385 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/PaperServer.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/PlayerServer.java @@ -6,18 +6,19 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.core.central.PluginLogger; import group.aelysium.rustyconnector.core.lib.database.Redis; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessageType; -import group.aelysium.rustyconnector.core.lib.model.Server; import group.aelysium.rustyconnector.core.lib.lang_messaging.GateKey; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; import java.security.InvalidAlgorithmParameterException; -public class PaperServer implements Server { +public class PlayerServer implements group.aelysium.rustyconnector.core.lib.model.PlayerServer { private RegisteredServer registeredServer = null; private final ServerInfo serverInfo; private String familyName; @@ -26,7 +27,7 @@ public class PaperServer implements Server { private int softPlayerCap; private int hardPlayerCap; - public PaperServer(ServerInfo serverInfo, int softPlayerCap, int hardPlayerCap, int weight) { + public PlayerServer(ServerInfo serverInfo, int softPlayerCap, int hardPlayerCap, int weight) { this.serverInfo = serverInfo; this.weight = Math.max(weight, 0); @@ -60,9 +61,9 @@ public RegisteredServer getRegisteredServer() { * @throws InvalidAlgorithmParameterException Of the family doesn't exist. */ public void register(String familyName) throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); - this.registeredServer = plugin.getVirtualServer().registerServer(this, familyName); + this.registeredServer = api.getVirtualProcessor().registerServer(this, familyName); this.familyName = familyName; } @@ -146,9 +147,9 @@ public int getHardPlayerCap() { */ public ServerFamily getFamily() throws IllegalStateException, NullPointerException { if(this.registeredServer == null) throw new IllegalStateException("This server must be registered before you can find its family!"); - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(this.familyName); + ServerFamily family = api.getVirtualProcessor().getFamilyManager().find(this.familyName); if(family == null) throw new NullPointerException("There is no family with that name!"); return family; @@ -159,7 +160,7 @@ public ServerFamily getFamily() throws Illega * @param redis The redis connection to use. */ public void ping(Redis redis, String privateKey) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); RedisMessage message = new RedisMessage( privateKey, @@ -169,8 +170,8 @@ public void ping(Redis redis, String privateKey) { message.dispatchMessage(redis); - if(plugin.logger().getGate().check(GateKey.PING)) - VelocityLang.PING.send(plugin.logger(),this.serverInfo); + if(logger.getGate().check(GateKey.PING)) + VelocityLang.PING.send(logger,this.serverInfo); } /** diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java index 4329023ec..f0ba97bd7 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java @@ -3,9 +3,12 @@ import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.core.central.PluginLogger; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.Callable; import group.aelysium.rustyconnector.core.lib.load_balancing.AlgorithmType; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.config.FamilyConfig; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.LeastConnection; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; @@ -59,8 +62,9 @@ public TPAHandler getTPAHandler() { * @return The whitelist or `null` if there isn't one. */ public Whitelist getWhitelist() { + VelocityAPI api = VelocityRustyConnector.getAPI(); if(this.name == null) return null; - return VelocityRustyConnector.getInstance().getVirtualServer().getWhitelistManager().find(this.whitelist); + return api.getVirtualProcessor().getWhitelistManager().find(this.whitelist); } public long serverCount() { return this.loadBalancer.size(); } @@ -101,7 +105,7 @@ public void connect(Player player) { } Callable notPersistent = () -> { - PaperServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority + PlayerServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority try { if(!server.validatePlayer(player)) throw new RuntimeException("The server you're trying to connect to is full!"); @@ -123,7 +127,7 @@ public void connect(Player player) { for (int attempt = 1; attempt <= attemptsLeft; attempt++) { boolean isFinal = (attempt == attemptsLeft); - PaperServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority + PlayerServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority try { if(!server.validatePlayer(player)) @@ -167,7 +171,7 @@ public void connect(Player player, PlayerChooseInitialServerEvent event) { Callable notPersistent = () -> { - PaperServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority + PlayerServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority try { if(!server.validatePlayer(player)) throw new RuntimeException("The server you're trying to connect to is full!"); @@ -189,7 +193,7 @@ public void connect(Player player, PlayerChooseInitialServerEvent event) { for (int attempt = 1; attempt <= attemptsLeft; attempt++) { boolean isFinal = (attempt == attemptsLeft); - PaperServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority + PlayerServer server = this.loadBalancer.getCurrent(); // Get the server that is currently listed as highest priority try { if(!server.validatePlayer(player)) @@ -219,7 +223,7 @@ public void connect(Player player, PlayerChooseInitialServerEvent event) { public List getAllPlayers(int max) { List players = new ArrayList<>(); - for (PaperServer server : this.getRegisteredServers()) { + for (PlayerServer server : this.getRegisteredServers()) { if(players.size() > max) break; players.addAll(server.getRegisteredServer().getPlayersConnected()); @@ -228,7 +232,7 @@ public List getAllPlayers(int max) { return players; } - public List getRegisteredServers() { + public List getRegisteredServers() { return this.loadBalancer.dump(); } @@ -240,7 +244,7 @@ public String getName() { * Add a server to the family. * @param server The server to add. */ - public void addServer(PaperServer server) { + public void addServer(PlayerServer server) { this.loadBalancer.add(server); } @@ -248,7 +252,7 @@ public void addServer(PaperServer server) { * Remove a server from this family. * @param server The server to remove. */ - public void removeServer(PaperServer server) { + public void removeServer(PlayerServer server) { this.loadBalancer.remove(server); } @@ -257,7 +261,7 @@ public void removeServer(PaperServer server) { * @param serverInfo The info matching the server to get. * @return A found server or `null` if there's no match. */ - public PaperServer getServer(@NotNull ServerInfo serverInfo) { + public PlayerServer getServer(@NotNull ServerInfo serverInfo) { return this.getRegisteredServers().stream() .filter(server -> Objects.equals(server.getServerInfo(), serverInfo) ).findFirst().orElse(null); @@ -267,10 +271,10 @@ public PaperServer getServer(@NotNull ServerInfo serverInfo) { * Unregisters all servers from this family. */ public void unregisterServers() throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); - for (PaperServer server : this.loadBalancer.dump()) { + VelocityAPI api = VelocityRustyConnector.getAPI(); + for (PlayerServer server : this.loadBalancer.dump()) { if(server == null) continue; - plugin.getVirtualServer().unregisterServer(server.getServerInfo(),this.name, false); + api.getVirtualProcessor().unregisterServer(server.getServerInfo(),this.name, false); } } @@ -279,13 +283,14 @@ public void unregisterServers() throws Exception { * By the time this runs, the configuration file should be able to guarantee that all values are present. * @return A list of all server families. */ - public static ServerFamily init(Proxy proxy, String familyName) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); - plugin.logger().log("Registering family: "+familyName); + public static ServerFamily init(VirtualProxyProcessor virtualProxyProcessor, String familyName) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + logger.log("Registering family: "+familyName); FamilyConfig familyConfig = FamilyConfig.newConfig( familyName, - new File(plugin.getDataFolder(), "families/"+familyName+".yml"), + new File(String.valueOf(api.getDataFolder()), "families/"+familyName+".yml"), "velocity_family_template.yml" ); if(!familyConfig.generate()) { @@ -297,11 +302,11 @@ public static ServerFamily init(Proxy proxy, if(familyConfig.isWhitelist_enabled()) { whitelist = Whitelist.init(familyConfig.getWhitelist_name()); - proxy.getWhitelistManager().add(whitelist); + virtualProxyProcessor.getWhitelistManager().add(whitelist); - plugin.logger().log(familyName+" whitelist registered!"); + logger.log(familyName+" whitelist registered!"); } else { - plugin.logger().log(familyName + " doesn't have a whitelist."); + logger.log(familyName + " doesn't have a whitelist."); } switch (Enum.valueOf(AlgorithmType.class, familyConfig.getLoadBalancing_algorithm())) { @@ -335,16 +340,17 @@ public static ServerFamily init(Proxy proxy, * Reloads the whitelist associated with this server. */ public void reloadWhitelist() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); Whitelist currentWhitelist = this.getWhitelist(); if(!(currentWhitelist == null)) { - plugin.getVirtualServer().getWhitelistManager().remove(currentWhitelist); + api.getVirtualProcessor().getWhitelistManager().remove(currentWhitelist); } FamilyConfig familyConfig = FamilyConfig.newConfig( this.name, - new File(plugin.getDataFolder(), "families/"+this.name+".yml"), + new File(String.valueOf(api.getDataFolder()), "families/"+this.name+".yml"), "velocity_family_template.yml" ); if(!familyConfig.generate()) { @@ -357,13 +363,13 @@ public void reloadWhitelist() { newWhitelist = Whitelist.init(familyConfig.getWhitelist_name()); this.whitelist = familyConfig.getWhitelist_name(); - plugin.getVirtualServer().getWhitelistManager().add(newWhitelist); + api.getVirtualProcessor().getWhitelistManager().add(newWhitelist); - plugin.logger().log("Finished reloading whitelist for "+this.name); + logger.log("Finished reloading whitelist for "+this.name); return; } this.whitelist = null; - plugin.logger().log("There is no whitelist for "+this.name); + logger.log("There is no whitelist for "+this.name); } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Proxy.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java similarity index 72% rename from velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Proxy.java rename to velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java index 810c95a67..dbea5a8e5 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Proxy.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java @@ -6,6 +6,7 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.Callable; import group.aelysium.rustyconnector.core.lib.data_messaging.firewall.MessageTunnel; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; @@ -13,7 +14,10 @@ import group.aelysium.rustyconnector.core.lib.data_messaging.cache.MessageCache; import group.aelysium.rustyconnector.core.lib.exception.BlockedMessageException; import group.aelysium.rustyconnector.core.lib.lang_messaging.GateKey; +import group.aelysium.rustyconnector.core.lib.model.VirtualProcessor; +import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.Clock; import group.aelysium.rustyconnector.plugin.velocity.lib.config.DefaultConfig; import group.aelysium.rustyconnector.plugin.velocity.lib.database.Redis; @@ -28,12 +32,12 @@ import java.util.HashMap; import java.util.Map; -public class Proxy { +public class VirtualProxyProcessor implements VirtualProcessor { private MessageCache messageCache; private Redis redis; private final Map lifeMatrix = new HashMap<>(); - private final FamilyManager familyManager; - private final WhitelistManager whitelistManager; + private final FamilyManager familyManager = new FamilyManager(); + private final WhitelistManager whitelistManager = new WhitelistManager(); private final String privateKey; private String rootFamily; private String proxyWhitelist; @@ -42,6 +46,10 @@ public class Proxy { private Clock tpaRequestCleaner; private MessageTunnel messageTunnel; + public VirtualProxyProcessor(String privateKey) { + this.privateKey = privateKey; + } + public ServerFamily getRootFamily() { return this.familyManager.find(this.rootFamily); } @@ -81,13 +89,6 @@ private void setMessageTunnel(MessageTunnel messageTunnel) throws IllegalStateEx this.messageTunnel = messageTunnel; } - private Proxy(String privateKey) { - this.privateKey = privateKey; - - this.familyManager = new FamilyManager(); - this.whitelistManager = new WhitelistManager(); - } - public MessageCache getMessageCache() { return this.messageCache; } @@ -105,29 +106,29 @@ private void startServerLifecycleHeart(long heartbeat, boolean shouldUnregister) this.serverLifecycleHeart = new Clock(heartbeat); this.serverLifecycleHeart.start((Callable) () -> { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); - if(plugin.logger().getGate().check(GateKey.PING)) - plugin.logger().log("Sending out pings and killing dead servers..."); + if(logger.getGate().check(GateKey.PING)) + logger.log("Sending out pings and killing dead servers..."); try { for (Map.Entry entry : lifeMatrix.entrySet()) { ServerInfo serverInfo = entry.getKey(); - PaperServer server = this.findServer(serverInfo); + PlayerServer server = this.findServer(serverInfo); if(server == null) { - plugin.logger().log(serverInfo.getName() + " couldn't be found! Ignoring..."); + logger.log(serverInfo.getName() + " couldn't be found! Ignoring..."); continue; } if(!entry.getValue()) { if(shouldUnregister) { this.unregisterServer(serverInfo, server.getFamilyName(), true); - if (plugin.logger().getGate().check(GateKey.PING)) - plugin.logger().log(server.getServerInfo().getName() + " never responded to ping! Killing it..."); + if (logger.getGate().check(GateKey.PING)) + logger.log(server.getServerInfo().getName() + " never responded to ping! Killing it..."); } else { - if (plugin.logger().getGate().check(GateKey.PING)) - plugin.logger().log(server.getServerInfo().getName() + " never responded to ping!"); + if (logger.getGate().check(GateKey.PING)) + logger.log(server.getServerInfo().getName() + " never responded to ping!"); } continue; } @@ -138,29 +139,30 @@ private void startServerLifecycleHeart(long heartbeat, boolean shouldUnregister) } return true; } catch (Exception error) { - plugin.logger().log(error.getMessage()); + logger.log(error.getMessage()); } return false; }); } private void startFamilyServerSorting(long heartbeat) { + VelocityAPI api = VelocityRustyConnector.getAPI(); this.familyServerSorting = new Clock(heartbeat); this.familyServerSorting.start((Callable) () -> { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); try { - if(plugin.logger().getGate().check(GateKey.FAMILY_BALANCING)) - plugin.logger().log("Balancing families..."); + if(logger.getGate().check(GateKey.FAMILY_BALANCING)) + logger.log("Balancing families..."); - for (ServerFamily family : plugin.getVirtualServer().getFamilyManager().dump()) { + for (ServerFamily family : api.getVirtualProcessor().getFamilyManager().dump()) { family.getLoadBalancer().completeSort(); - if(plugin.logger().getGate().check(GateKey.FAMILY_BALANCING)) - VelocityLang.FAMILY_BALANCING.send(plugin.logger(), family); + if(logger.getGate().check(GateKey.FAMILY_BALANCING)) + VelocityLang.FAMILY_BALANCING.send(logger, family); } - if(plugin.logger().getGate().check(GateKey.FAMILY_BALANCING)) - plugin.logger().log("Finished balancing families."); + if(logger.getGate().check(GateKey.FAMILY_BALANCING)) + logger.log("Finished balancing families."); } catch (Exception e) { return false; } @@ -169,12 +171,11 @@ private void startFamilyServerSorting(long heartbeat) { } private void startTPARequestCleaner(long heartbeat) { + VelocityAPI api = VelocityRustyConnector.getAPI(); this.tpaRequestCleaner = new Clock(heartbeat); this.tpaRequestCleaner.start((Callable) () -> { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); - - for(ServerFamily family : plugin.getVirtualServer().getFamilyManager().dump()) { + for(ServerFamily family : api.getVirtualProcessor().getFamilyManager().dump()) { if(!family.getTPAHandler().getSettings().isEnabled()) continue; family.getTPAHandler().clearExpired(); } @@ -214,9 +215,9 @@ public void reviveServer(ServerInfo serverInfo) { this.lifeMatrix.put(serverInfo, true); } - public PaperServer findServer(ServerInfo serverInfo) { + public PlayerServer findServer(ServerInfo serverInfo) { for(ServerFamily family : this.getFamilyManager().dump()) { - PaperServer server = family.getServer(serverInfo); + PlayerServer server = family.getServer(serverInfo); if(server == null) continue; return server; @@ -278,10 +279,10 @@ public boolean validatePrivateKey(String key) { * Can be usefull if you've just restarted your proxy and need to quickly get all your servers back online. */ public void registerAllServers() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); - if(VelocityRustyConnector.getInstance().logger().getGate().check(GateKey.CALL_FOR_REGISTRATION)) - VelocityLang.CALL_FOR_REGISTRATION.send(plugin.logger()); + if(logger.getGate().check(GateKey.CALL_FOR_REGISTRATION)) + VelocityLang.CALL_FOR_REGISTRATION.send(logger); RedisMessage message = new RedisMessage( this.privateKey, @@ -298,10 +299,10 @@ public void registerAllServers() { * @param familyName The name of the family to target. */ public void registerAllServers(String familyName) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); - if(VelocityRustyConnector.getInstance().logger().getGate().check(GateKey.CALL_FOR_REGISTRATION)) - VelocityLang.CALL_FOR_FAMILY_REGISTRATION.send(plugin.logger(), familyName); + if(logger.getGate().check(GateKey.CALL_FOR_REGISTRATION)) + VelocityLang.CALL_FOR_FAMILY_REGISTRATION.send(logger, familyName); RedisMessage message = new RedisMessage( this.privateKey, @@ -322,11 +323,11 @@ public void registerAllServers(String familyName) { * @throws NullPointerException If the server doesn't exist in the family. */ public void tpaSendPlayer(Player source, Player target, ServerInfo targetServerInfo) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); ServerInfo senderServerInfo = source.getCurrentServer().orElseThrow().getServerInfo(); - PaperServer targetServer = plugin.getVirtualServer().findServer(targetServerInfo); + PlayerServer targetServer = api.getVirtualProcessor().findServer(targetServerInfo); if(targetServer == null) throw new NullPointerException(); Callable queuePlayer = () -> { @@ -360,31 +361,32 @@ public void tpaSendPlayer(Player source, Player target, ServerInfo targetServerI * @param familyName The family to register the server into. * @return A RegisteredServer node. */ - public RegisteredServer registerServer(PaperServer server, String familyName) throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + public RegisteredServer registerServer(PlayerServer server, String familyName) throws Exception { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); try { - if(VelocityRustyConnector.getInstance().logger().getGate().check(GateKey.REGISTRATION_REQUEST)) - VelocityLang.REGISTRATION_REQUEST.send(plugin.logger(), server.getServerInfo(), familyName); + if(logger.getGate().check(GateKey.REGISTRATION_REQUEST)) + VelocityLang.REGISTRATION_REQUEST.send(logger, server.getServerInfo(), familyName); - if(plugin.getVirtualServer().contains(server.getServerInfo())) throw new DuplicateRequestException("Server ["+server.getServerInfo().getName()+"]("+server.getServerInfo().getAddress()+":"+server.getServerInfo().getAddress().getPort()+") can't be registered twice!"); + if(api.getVirtualProcessor().contains(server.getServerInfo())) throw new DuplicateRequestException("Server ["+server.getServerInfo().getName()+"]("+server.getServerInfo().getAddress()+":"+server.getServerInfo().getAddress().getPort()+") can't be registered twice!"); ServerFamily family = this.familyManager.find(familyName); if(family == null) throw new InvalidAlgorithmParameterException("A family with the name `"+familyName+"` doesn't exist!"); - RegisteredServer registeredServer = plugin.getVelocityServer().registerServer(server.getServerInfo()); + RegisteredServer registeredServer = api.registerServer(server.getServerInfo()); if(registeredServer == null) throw new NullPointerException("Unable to register the server to the proxy."); family.addServer(server); this.lifeMatrix.put(server.getServerInfo(),true); - if(VelocityRustyConnector.getInstance().logger().getGate().check(GateKey.REGISTRATION_REQUEST)) - VelocityLang.REGISTERED.send(plugin.logger(), server.getServerInfo(), familyName); + if(logger.getGate().check(GateKey.REGISTRATION_REQUEST)) + VelocityLang.REGISTERED.send(logger, server.getServerInfo(), familyName); return registeredServer; } catch (Exception error) { - if(plugin.logger().getGate().check(GateKey.REGISTRATION_REQUEST)) - VelocityLang.REGISTRATION_CANCELED.send(plugin.logger(), server.getServerInfo(), familyName); + if(logger.getGate().check(GateKey.REGISTRATION_REQUEST)) + VelocityLang.REGISTRATION_CANCELED.send(logger, server.getServerInfo(), familyName); throw new Exception(error.getMessage()); } } @@ -396,26 +398,27 @@ public RegisteredServer registerServer(PaperServer server, String familyName) th * @param removeFromFamily Should the server be removed from it's associated family? */ public void unregisterServer(ServerInfo serverInfo, String familyName, Boolean removeFromFamily) throws Exception { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); try { - PaperServer server = this.findServer(serverInfo); + PlayerServer server = this.findServer(serverInfo); if(server == null) throw new NullPointerException("Server ["+serverInfo.getName()+"]("+serverInfo.getAddress()+":"+serverInfo.getAddress().getPort()+") doesn't exist! It can't be unregistered!"); - if(plugin.logger().getGate().check(GateKey.UNREGISTRATION_REQUEST)) - VelocityLang.UNREGISTRATION_REQUEST.send(plugin.logger(), serverInfo, familyName); + if(logger.getGate().check(GateKey.UNREGISTRATION_REQUEST)) + VelocityLang.UNREGISTRATION_REQUEST.send(logger, serverInfo, familyName); ServerFamily family = server.getFamily(); this.lifeMatrix.remove(serverInfo); - plugin.getVelocityServer().unregisterServer(server.getServerInfo()); + api.unregisterServer(server.getServerInfo()); if(removeFromFamily) family.removeServer(server); - if(plugin.logger().getGate().check(GateKey.UNREGISTRATION_REQUEST)) - VelocityLang.UNREGISTERED.send(plugin.logger(), serverInfo, familyName); + if(logger.getGate().check(GateKey.UNREGISTRATION_REQUEST)) + VelocityLang.UNREGISTERED.send(logger, serverInfo, familyName); } catch (Exception e) { - if(plugin.logger().getGate().check(GateKey.UNREGISTRATION_REQUEST)) - VelocityLang.UNREGISTRATION_CANCELED.send(plugin.logger(), serverInfo, familyName); + if(logger.getGate().check(GateKey.UNREGISTRATION_REQUEST)) + VelocityLang.UNREGISTRATION_CANCELED.send(logger, serverInfo, familyName); throw new Exception(e.getMessage()); } } @@ -425,7 +428,8 @@ public void unregisterServer(ServerInfo serverInfo, String familyName, Boolean r * @param command The command to dispatch. */ public void dispatchCommand(String command) { - VelocityRustyConnector.getInstance().getVelocityServer().getCommandManager() + VelocityAPI api = VelocityRustyConnector.getAPI(); + api.getServer().getCommandManager() .executeAsync((ConsoleCommandSource) permission -> null, command); } @@ -434,19 +438,19 @@ public void dispatchCommand(String command) { * By the time this runs, the configuration file should be able to guarantee that all values are present. * @param config The configuration file. */ - public static Proxy init(DefaultConfig config) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException { - Proxy proxy = new Proxy(config.getPrivate_key()); - - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + public static VirtualProxyProcessor init(DefaultConfig config) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException { + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); + VirtualProxyProcessor virtualProxyProcessor = new VirtualProxyProcessor(config.getPrivate_key()); // Setup families for (String familyName: config.getFamilies()) - proxy.getFamilyManager().add(ServerFamily.init(proxy, familyName)); + virtualProxyProcessor.getFamilyManager().add(ServerFamily.init(virtualProxyProcessor, familyName)); - plugin.logger().log("Finished setting up families"); + logger.log("Finished setting up families"); - proxy.setRootFamily(config.getRoot_family()); - plugin.logger().log("Finished setting up root family"); + virtualProxyProcessor.setRootFamily(config.getRoot_family()); + logger.log("Finished setting up root family"); // Setup Redis Redis redis = new Redis(); @@ -456,34 +460,34 @@ public static Proxy init(DefaultConfig config) throws IllegalAccessException, In config.getRedis_password(), config.getRedis_dataChannel() ); - redis.connect(plugin); + redis.connect(api); - proxy.setRedis(redis); - plugin.logger().log("Finished setting up redis"); + virtualProxyProcessor.setRedis(redis); + logger.log("Finished setting up redis"); - if(config.isHearts_serverLifecycle_enabled()) proxy.startServerLifecycleHeart(config.getHearts_serverLifecycle_interval(),config.shouldHearts_serverLifecycle_unregisterOnIgnore()); - if(config.getMessageTunnel_familyServerSorting_enabled()) proxy.startFamilyServerSorting(config.getMessageTunnel_familyServerSorting_interval()); - proxy.startTPARequestCleaner(10); - plugin.logger().log("Finished setting up heartbeats"); + if(config.isHearts_serverLifecycle_enabled()) virtualProxyProcessor.startServerLifecycleHeart(config.getHearts_serverLifecycle_interval(),config.shouldHearts_serverLifecycle_unregisterOnIgnore()); + if(config.getMessageTunnel_familyServerSorting_enabled()) virtualProxyProcessor.startFamilyServerSorting(config.getMessageTunnel_familyServerSorting_interval()); + virtualProxyProcessor.startTPARequestCleaner(10); + logger.log("Finished setting up heartbeats"); // Setup network whitelist if(config.isWhitelist_enabled()) { - proxy.setWhitelist(config.getWhitelist_name()); + virtualProxyProcessor.setWhitelist(config.getWhitelist_name()); - proxy.whitelistManager.add(Whitelist.init(config.getWhitelist_name())); + virtualProxyProcessor.whitelistManager.add(Whitelist.init(config.getWhitelist_name())); } - plugin.logger().log("Finished setting up network whitelist"); + logger.log("Finished setting up network whitelist"); // Setup message tunnel - proxy.setMessageCache(config.getMessageTunnel_messageCacheSize()); - plugin.logger().log("Set message cache size to be: "+config.getMessageTunnel_messageCacheSize()); + virtualProxyProcessor.setMessageCache(config.getMessageTunnel_messageCacheSize()); + logger.log("Set message cache size to be: "+config.getMessageTunnel_messageCacheSize()); MessageTunnel messageTunnel = new MessageTunnel( config.isMessageTunnel_denylist_enabled(), config.isMessageTunnel_whitelist_enabled(), config.getMessageTunnel_messageMaxLength() ); - proxy.setMessageTunnel(messageTunnel); + virtualProxyProcessor.setMessageTunnel(messageTunnel); if(config.isMessageTunnel_whitelist_enabled()) config.getMessageTunnel_whitelist_addresses().forEach(entry -> { @@ -503,9 +507,9 @@ public static Proxy init(DefaultConfig config) throws IllegalAccessException, In messageTunnel.blacklistAddress(address); }); - plugin.logger().log("Finished setting up message tunnel"); + logger.log("Finished setting up message tunnel"); - return proxy; + return virtualProxyProcessor; } /** @@ -514,23 +518,23 @@ public static Proxy init(DefaultConfig config) throws IllegalAccessException, In * @param config The configuration file. */ public void reload(DefaultConfig config) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); - plugin.logger().log("Reloading config.yml"); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); + logger.log("Reloading config.yml"); // Heartbeats this.killHeartbeats(); if(config.isHearts_serverLifecycle_enabled()) this.startServerLifecycleHeart(config.getHearts_serverLifecycle_interval(),config.shouldHearts_serverLifecycle_unregisterOnIgnore()); if(config.getMessageTunnel_familyServerSorting_enabled()) this.startFamilyServerSorting(config.getMessageTunnel_familyServerSorting_interval()); - plugin.logger().log("Restarted heartbeats"); + logger.log("Restarted heartbeats"); this.reloadWhitelists(config); - plugin.logger().log("Reloaded all whitelists"); + logger.log("Reloaded all whitelists"); // Setup message tunnel this.messageCache.empty(); this.messageCache = null; this.setMessageCache(config.getMessageTunnel_messageCacheSize()); - plugin.logger().log("Message cache size set to: "+config.getMessageTunnel_messageCacheSize()); + logger.log("Message cache size set to: "+config.getMessageTunnel_messageCacheSize()); this.messageTunnel = null; MessageTunnel messageTunnel = new MessageTunnel( @@ -557,7 +561,7 @@ public void reload(DefaultConfig config) { messageTunnel.blacklistAddress(address); }); - plugin.logger().log("Message tunnel reloaded"); + logger.log("Message tunnel reloaded"); } /** @@ -566,7 +570,7 @@ public void reload(DefaultConfig config) { * @param config The default config to read. */ public void reloadWhitelists(DefaultConfig config) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + PluginLogger logger = VelocityRustyConnector.getAPI().getLogger(); this.proxyWhitelist = null; this.whitelistManager.clear(); @@ -576,15 +580,15 @@ public void reloadWhitelists(DefaultConfig config) { this.setWhitelist(config.getWhitelist_name()); this.whitelistManager.add(Whitelist.init(config.getWhitelist_name())); - plugin.logger().log("Proxy whitelist is enabled"); + logger.log("Proxy whitelist is enabled"); } else { - plugin.logger().log("There is no proxy whitelist"); + logger.log("There is no proxy whitelist"); } // Reload server whitelists for (ServerFamily family : this.familyManager.dump()) { family.reloadWhitelist(); } - plugin.logger().log("Reloaded all family whitelists"); + logger.log("Reloaded all family whitelists"); } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Whitelist.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Whitelist.java index 8e11d552f..4be79320f 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Whitelist.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/Whitelist.java @@ -2,8 +2,11 @@ import com.google.gson.Gson; import com.velocitypowered.api.proxy.Player; -import group.aelysium.rustyconnector.plugin.velocity.lib.managers.WhitelistPlayerManager; +import group.aelysium.rustyconnector.core.central.PluginLogger; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; +import group.aelysium.rustyconnector.plugin.velocity.lib.managers.WhitelistPlayerManager; import group.aelysium.rustyconnector.plugin.velocity.lib.config.WhitelistConfig; import java.io.File; @@ -108,11 +111,12 @@ public boolean validateCountry(String ipAddress) { * @return A whitelist. */ public static Whitelist init(String whitelistName) { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); + PluginLogger logger = api.getLogger(); WhitelistConfig whitelistConfig = WhitelistConfig.newConfig( whitelistName, - new File(plugin.getDataFolder(), "whitelists/"+whitelistName+".yml"), + new File(String.valueOf(api.getDataFolder()), "whitelists/"+whitelistName+".yml"), "velocity_whitelist_template.yml" ); if(!whitelistConfig.generate()) { @@ -143,7 +147,7 @@ public static Whitelist init(String whitelistName) { countries.forEach(whitelist::registerCountry); }; - plugin.logger().log("Loaded whitelist: "+whitelistName); + logger.log("Loaded whitelist: "+whitelistName); return whitelist; } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/tpa/TPARequest.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/tpa/TPARequest.java index 0e489d29e..2869b608f 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/tpa/TPARequest.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/tpa/TPARequest.java @@ -2,12 +2,13 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.ServerInfo; +import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; +import group.aelysium.rustyconnector.plugin.velocity.central.VelocityAPI; import group.aelysium.rustyconnector.plugin.velocity.lib.lang_messaging.VelocityLang; import group.aelysium.rustyconnector.plugin.velocity.lib.load_balancing.PaperServerLoadBalancer; import group.aelysium.rustyconnector.plugin.velocity.lib.module.ServerFamily; -import java.time.Instant; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -58,7 +59,7 @@ public void deny() { } public void accept() { - VelocityRustyConnector plugin = VelocityRustyConnector.getInstance(); + VelocityAPI api = VelocityRustyConnector.getAPI(); this.getSender().sendMessage(VelocityLang.TPA_REQUEST_ACCEPTED_SENDER.build(this.getTarget().getUsername())); this.getTarget().sendMessage(VelocityLang.TPA_REQUEST_ACCEPTED_TARGET.build(this.getSender().getUsername())); @@ -67,11 +68,11 @@ public void accept() { this.updateStatus(TPARequestStatus.ACCEPTED); ServerInfo serverInfo = this.getTarget().getCurrentServer().orElseThrow().getServerInfo(); - String familyName = plugin.getVirtualServer().findServer(serverInfo).getFamilyName(); - ServerFamily family = plugin.getVirtualServer().getFamilyManager().find(familyName); + String familyName = api.getVirtualProcessor().findServer(serverInfo).getFamilyName(); + ServerFamily family = api.getVirtualProcessor().getFamilyManager().find(familyName); if(family == null) throw new NullPointerException(); - plugin.getVirtualServer().tpaSendPlayer(this.getSender(), this.getTarget(), serverInfo); + api.getVirtualProcessor().tpaSendPlayer(this.getSender(), this.getTarget(), serverInfo); } catch (Exception e) { this.getSender().sendMessage(VelocityLang.TPA_FAILURE.build(this.getTarget().getUsername())); this.getTarget().sendMessage(VelocityLang.TPA_FAILURE_TARGET.build(this.getSender().getUsername())); From f9e25580f7a3cd19c68614c19e2a1ed1e128d258 Mon Sep 17 00:00:00 2001 From: Nathan Martin Date: Sun, 2 Apr 2023 23:51:46 -0400 Subject: [PATCH 3/6] Adjust a few files --- .../core/central/PluginRuntime.java | 2 +- .../plugin/paper/PaperRustyConnector.java | 15 ++++----------- .../plugin/paper/central/PaperAPI.java | 2 -- .../plugin/paper/central/PaperLifecycle.java | 3 +-- .../plugin/velocity/VelocityRustyConnector.java | 4 +--- .../plugin/velocity/central/VelocityAPI.java | 1 - .../velocity/central/VelocityLifecycle.java | 1 - 7 files changed, 7 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java index 1b552258c..9544f1d6c 100644 --- a/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java +++ b/core/src/main/java/group/aelysium/rustyconnector/core/central/PluginRuntime.java @@ -2,7 +2,7 @@ import group.aelysium.rustyconnector.core.lib.database.Redis; -public interface PluginRuntime> { +public interface PluginRuntime { Redis redis = null; static PluginAPI getAPI() { diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java index 36904ee96..f98555b98 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/PaperRustyConnector.java @@ -1,17 +1,13 @@ package group.aelysium.rustyconnector.plugin.paper; import group.aelysium.rustyconnector.core.central.PluginRuntime; -import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; import group.aelysium.rustyconnector.plugin.paper.central.PaperLifecycle; import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; -import group.aelysium.rustyconnector.plugin.paper.lib.VirtualServerProcessor; import group.aelysium.rustyconnector.plugin.paper.lib.bstats.Metrics; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -public final class PaperRustyConnector extends JavaPlugin implements Listener, PluginRuntime { +public final class PaperRustyConnector extends JavaPlugin implements Listener, PluginRuntime { private static PaperLifecycle lifecycle; private static PaperAPI api; @@ -26,9 +22,10 @@ public static PaperLifecycle getLifecycle() { public void onEnable() { try { api = new PaperAPI(this, this.getSLF4JLogger()); + lifecycle = new PaperLifecycle(); if (!lifecycle.start()) { - this.killPlugin(); + this.getPluginLoader().disablePlugin(this); return; } @@ -39,7 +36,7 @@ public void onEnable() { } } catch (Exception e) { e.printStackTrace(); - this.killPlugin(); + this.getPluginLoader().disablePlugin(this); } } @@ -52,8 +49,4 @@ public void onDisable() { getAPI().getLogger().log("RustyConnector: " + e.getMessage()); } } - - private void killPlugin() { - this.getPluginLoader().disablePlugin(this); - } } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java index 9b288d67d..0ed4420fd 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperAPI.java @@ -1,7 +1,5 @@ package group.aelysium.rustyconnector.plugin.paper.central; -import cloud.commandframework.Command; -import cloud.commandframework.CommandManager; import cloud.commandframework.execution.CommandExecutionCoordinator; import cloud.commandframework.paper.PaperCommandManager; import group.aelysium.rustyconnector.core.central.PluginAPI; diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java index f0fc0da1a..d123c7752 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java @@ -16,9 +16,8 @@ import java.io.File; public class PaperLifecycle extends PluginLifecycle { - public boolean start() throws DuplicateLifecycleException { - if(this.isRunning()) throw new DuplicateLifecycleException("RustyConnector-Velocity is already running! You can't start it a second time!"); + if(this.isRunning()) throw new DuplicateLifecycleException("RustyConnector-Paper is already running! You can't start it a second time!"); MigrationDirections.init(); diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java index d4016c122..2af57b8cc 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/VelocityRustyConnector.java @@ -15,14 +15,12 @@ import java.nio.file.Path; -public class VelocityRustyConnector implements PluginRuntime { +public class VelocityRustyConnector implements PluginRuntime { private static VelocityLifecycle lifecycle; private static VelocityAPI api; - public static VelocityAPI getAPI() { return api; } - public static VelocityLifecycle getLifecycle() { return lifecycle; } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java index 9f60bf9e4..e61f4ec0b 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java @@ -6,7 +6,6 @@ import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.scheduler.Scheduler; import group.aelysium.rustyconnector.core.central.PluginAPI; -import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.plugin.velocity.PluginLogger; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; import group.aelysium.rustyconnector.plugin.velocity.lib.config.DefaultConfig; diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java index fe90d289b..8a3c27fe9 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityLifecycle.java @@ -26,7 +26,6 @@ import java.io.File; public class VelocityLifecycle extends PluginLifecycle { - public boolean start() throws DuplicateLifecycleException { VelocityAPI api = VelocityRustyConnector.getAPI(); PluginLogger logger = api.getLogger(); From 0b66a2100d0645783d8a0abb56b24ae02ae296a3 Mon Sep 17 00:00:00 2001 From: Nathan Martin Date: Mon, 10 Apr 2023 20:33:49 -0400 Subject: [PATCH 4/6] Remove garbage logs and fix API call --- .../plugin/paper/lib/events/OnPlayerLeave.java | 1 - .../plugin/velocity/central/VelocityAPI.java | 10 +++++----- .../plugin/velocity/lib/module/ServerFamily.java | 1 - .../velocity/lib/module/VirtualProxyProcessor.java | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java index c38e28de7..54b76ac83 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java @@ -15,6 +15,5 @@ public void onPlayerLeave(PlayerQuitEvent event) { PluginLogger logger = api.getLogger(); api.getVirtualProcessor().getTPAQueue().removeAllPlayersRequests(event.getPlayer()); - logger.log("Deleted player entries!"); } } \ No newline at end of file diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java index e61f4ec0b..5f4bff815 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/central/VelocityAPI.java @@ -56,6 +56,11 @@ public VirtualProxyProcessor getVirtualProcessor() { return this.virtualProcessor; } + public void configureProcessor(DefaultConfig config) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { + if(this.virtualProcessor != null) throw new IllegalAccessException("Attempted to configure the processor while it's already running!"); + this.virtualProcessor = VirtualProxyProcessor.init(config); + } + /** * Get the velocity server */ @@ -91,9 +96,4 @@ public VelocityRustyConnector accessPlugin() throws SyncFailedException { if(VelocityRustyConnector.getLifecycle().isRunning()) throw new SyncFailedException("You can't get the plugin instance while the plugin is running!"); return this.plugin; } - - public void configureProcessor(DefaultConfig config) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { - if(this.virtualProcessor != null) throw new IllegalAccessException("Attempted to configure the processor while it's already running!"); - this.virtualProcessor = VirtualProxyProcessor.init(config); - } } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java index f0ba97bd7..2a5a0f8a1 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java @@ -49,7 +49,6 @@ public boolean isWeighted() { } public LB getLoadBalancer() { - System.out.print(this.loadBalancer); return this.loadBalancer; } diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java index dbea5a8e5..fc2abd914 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java @@ -6,7 +6,6 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; -import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.Callable; import group.aelysium.rustyconnector.core.lib.data_messaging.firewall.MessageTunnel; import group.aelysium.rustyconnector.core.lib.data_messaging.RedisMessage; @@ -155,7 +154,7 @@ private void startFamilyServerSorting(long heartbeat) { if(logger.getGate().check(GateKey.FAMILY_BALANCING)) logger.log("Balancing families..."); - for (ServerFamily family : api.getVirtualProcessor().getFamilyManager().dump()) { + for (ServerFamily family : this.getFamilyManager().dump()) { family.getLoadBalancer().completeSort(); if(logger.getGate().check(GateKey.FAMILY_BALANCING)) VelocityLang.FAMILY_BALANCING.send(logger, family); From 46c067f29571f9c84df96d2abf06fa1554cef311 Mon Sep 17 00:00:00 2001 From: Nathan Martin Date: Mon, 10 Apr 2023 20:35:29 -0400 Subject: [PATCH 5/6] Remove worthless import --- .../rustyconnector/plugin/velocity/lib/module/ServerFamily.java | 1 - 1 file changed, 1 deletion(-) diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java index 2a5a0f8a1..d2a44e4f7 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/ServerFamily.java @@ -4,7 +4,6 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.ServerInfo; import group.aelysium.rustyconnector.core.central.PluginLogger; -import group.aelysium.rustyconnector.core.central.PluginRuntime; import group.aelysium.rustyconnector.core.lib.Callable; import group.aelysium.rustyconnector.core.lib.load_balancing.AlgorithmType; import group.aelysium.rustyconnector.plugin.velocity.VelocityRustyConnector; From 48c4bd1695e8b534febbd97311ae36df4232f393 Mon Sep 17 00:00:00 2001 From: Nathan Martin Date: Mon, 17 Apr 2023 13:32:16 -0400 Subject: [PATCH 6/6] Update /tpa for Folia --- .../plugin/paper/central/PaperLifecycle.java | 6 +++++- .../plugin/paper/lib/config/DefaultConfig.java | 1 - .../plugin/paper/lib/events/OnPlayerLeave.java | 2 -- .../plugin/paper/lib/lang_messaging/PaperLang.java | 12 ++++++++++++ .../plugin/paper/lib/tpa/TPAQueue.java | 11 +++++++---- .../plugin/velocity/commands/CommandTPA.java | 4 ++-- .../velocity/lib/lang_messaging/VelocityLang.java | 1 - .../velocity/lib/module/VirtualProxyProcessor.java | 4 +--- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java index d123c7752..5f2a2a220 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/central/PaperLifecycle.java @@ -10,6 +10,7 @@ import group.aelysium.rustyconnector.plugin.paper.lib.config.DefaultConfig; import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerJoin; import group.aelysium.rustyconnector.plugin.paper.lib.events.OnPlayerLeave; +import group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging.PaperLang; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -17,7 +18,10 @@ public class PaperLifecycle extends PluginLifecycle { public boolean start() throws DuplicateLifecycleException { - if(this.isRunning()) throw new DuplicateLifecycleException("RustyConnector-Paper is already running! You can't start it a second time!"); + PaperAPI api = PaperRustyConnector.getAPI(); + if(this.isRunning()) throw new DuplicateLifecycleException( + PaperLang.RCNAME_PAPER_FOLIA.build(api.isFolia()).toString() + + " is already running! You can't start it a second time!"); MigrationDirections.init(); diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java index ace9cb4dc..f4c1e2c16 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/config/DefaultConfig.java @@ -3,7 +3,6 @@ import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; import group.aelysium.rustyconnector.plugin.paper.PluginLogger; -import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java index 54b76ac83..0e014a593 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/events/OnPlayerLeave.java @@ -1,7 +1,6 @@ package group.aelysium.rustyconnector.plugin.paper.lib.events; import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; -import group.aelysium.rustyconnector.plugin.paper.PluginLogger; import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -12,7 +11,6 @@ public class OnPlayerLeave implements Listener { @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { PaperAPI api = PaperRustyConnector.getAPI(); - PluginLogger logger = api.getLogger(); api.getVirtualProcessor().getTPAQueue().removeAllPlayersRequests(event.getPlayer()); } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/lang_messaging/PaperLang.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/lang_messaging/PaperLang.java index d64dc19d1..0b23e226f 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/lang_messaging/PaperLang.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/lang_messaging/PaperLang.java @@ -1,6 +1,8 @@ package group.aelysium.rustyconnector.plugin.paper.lib.lang_messaging; import group.aelysium.rustyconnector.core.lib.lang_messaging.Lang; +import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; +import group.aelysium.rustyconnector.plugin.paper.central.PaperAPI; import net.kyori.adventure.text.Component; import java.util.Date; @@ -64,4 +66,14 @@ public interface PaperLang extends Lang { ); Component TPA_COMPLETE = text("Teleport completed!",GREEN); + + ParameterizedMessage1 RCNAME_PAPER_FOLIA = isFolia -> { + if(isFolia) return text("RustyConnector-Folia"); + return text("RustyConnector-Paper"); + }; + + ParameterizedMessage1 RCNAME_PAPER_FOLIA_LOWER = isFolia -> { + if(isFolia) return text("rustyconnector-folia"); + return text("rustyconnector-paper"); + }; } diff --git a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPAQueue.java b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPAQueue.java index da7faff7a..327b7e949 100644 --- a/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPAQueue.java +++ b/paper/src/main/java/group/aelysium/rustyconnector/plugin/paper/lib/tpa/TPAQueue.java @@ -1,5 +1,6 @@ package group.aelysium.rustyconnector.plugin.paper.lib.tpa; +import group.aelysium.rustyconnector.plugin.paper.PaperRustyConnector; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -29,10 +30,12 @@ public TPARequest findTarget(Player target) { * @param player The player to search for. */ public void removeAllPlayersRequests(Player player) { - this.requests.stream().filter(tpaRequest -> - Objects.equals(tpaRequest.getTarget(), player) - || Objects.equals(tpaRequest.getClientUsername(), player.getPlayerProfile().getName()) - ).forEach(this.requests::remove); + if(PaperRustyConnector.getAPI().isFolia()) { + this.requests.removeIf(tpaRequest -> + Objects.equals(tpaRequest.getTarget(), player) + || Objects.equals(tpaRequest.getClientUsername(), player.getPlayerProfile().getName()) + ); + } } public void remove(TPARequest tpaRequest) { diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java index ca3f73dbe..2c252fc7b 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/commands/CommandTPA.java @@ -108,7 +108,7 @@ public static BrigadierCommand create() { return builder.buildFuture(); } - family.getTPAHandler().findRequestsForTarget(player).forEach(targetRequest -> builder.suggest(targetRequest.getTarget().getUsername())); + family.getTPAHandler().findRequestsForTarget(player).forEach(targetRequest -> builder.suggest(targetRequest.getSender().getUsername())); return builder.buildFuture(); } catch (Exception ignored) {} @@ -202,7 +202,7 @@ public static BrigadierCommand create() { return builder.buildFuture(); } - family.getTPAHandler().findRequestsForTarget(player).forEach(targetRequest -> builder.suggest(targetRequest.getTarget().getUsername())); + family.getTPAHandler().findRequestsForTarget(player).forEach(targetRequest -> builder.suggest(targetRequest.getSender().getUsername())); return builder.buildFuture(); } catch (Exception ignored) {} diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java index d4fc8b3e1..a056b1f19 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/lang_messaging/VelocityLang.java @@ -252,7 +252,6 @@ public interface VelocityLang extends Lang { ); ParameterizedMessage1> RC_FAMILY_INFO = (family) -> { - Component servers = text(""); int i = 0; diff --git a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java index fc2abd914..fdcdfcd1c 100644 --- a/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java +++ b/velocity/src/main/java/group/aelysium/rustyconnector/plugin/velocity/lib/module/VirtualProxyProcessor.java @@ -145,7 +145,6 @@ private void startServerLifecycleHeart(long heartbeat, boolean shouldUnregister) } private void startFamilyServerSorting(long heartbeat) { - VelocityAPI api = VelocityRustyConnector.getAPI(); this.familyServerSorting = new Clock(heartbeat); this.familyServerSorting.start((Callable) () -> { @@ -170,11 +169,10 @@ private void startFamilyServerSorting(long heartbeat) { } private void startTPARequestCleaner(long heartbeat) { - VelocityAPI api = VelocityRustyConnector.getAPI(); this.tpaRequestCleaner = new Clock(heartbeat); this.tpaRequestCleaner.start((Callable) () -> { - for(ServerFamily family : api.getVirtualProcessor().getFamilyManager().dump()) { + for(ServerFamily family : this.getFamilyManager().dump()) { if(!family.getTPAHandler().getSettings().isEnabled()) continue; family.getTPAHandler().clearExpired(); }