From c1139ca04c3a9a1d6b29949e125451be9ab426cc Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 13 May 2023 17:08:55 -0400 Subject: [PATCH] Add temporary backwards compatability for `ServerHelper` --- .../java/emu/grasscutter/Grasscutter.java | 22 ++++++++------ .../java/emu/grasscutter/plugin/Plugin.java | 15 ++++++---- .../grasscutter/plugin/api/ServerHelper.java | 2 +- .../grasscutter/plugin/api/ServerHook.java | 30 +++++++++++++++++++ 4 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/main/java/emu/grasscutter/plugin/api/ServerHook.java diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index fbba334b4..de97bb11e 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -1,8 +1,5 @@ package emu.grasscutter; -import static emu.grasscutter.config.Configuration.SERVER; -import static emu.grasscutter.utils.Language.translate; - import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import emu.grasscutter.auth.AuthenticationSystem; @@ -15,6 +12,7 @@ import emu.grasscutter.data.ResourceLoader; import emu.grasscutter.database.DatabaseManager; import emu.grasscutter.plugin.PluginManager; import emu.grasscutter.plugin.api.ServerHelper; +import emu.grasscutter.plugin.api.ServerHook; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.http.HttpServer; import emu.grasscutter.server.http.dispatch.DispatchHandler; @@ -27,12 +25,6 @@ import emu.grasscutter.server.http.handlers.GenericHandler; import emu.grasscutter.server.http.handlers.LogHandler; import emu.grasscutter.tools.Tools; import emu.grasscutter.utils.*; -import java.io.File; -import java.io.FileWriter; -import java.io.IOError; -import java.io.IOException; -import java.util.Calendar; -import javax.annotation.Nullable; import lombok.Getter; import lombok.Setter; import org.jline.reader.EndOfFileException; @@ -44,6 +36,16 @@ import org.jline.terminal.TerminalBuilder; import org.reflections.Reflections; import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; +import java.io.File; +import java.io.FileWriter; +import java.io.IOError; +import java.io.IOException; +import java.util.Calendar; + +import static emu.grasscutter.config.Configuration.SERVER; +import static emu.grasscutter.utils.Language.translate; + public final class Grasscutter { public static final File configFile = new File("./config.json"); public static final Reflections reflector = new Reflections("emu.grasscutter"); @@ -122,6 +124,8 @@ public final class Grasscutter { gameServer = new GameServer(); // Create a server hook instance with both servers. new ServerHelper(gameServer, httpServer); + // noinspection removal + new ServerHook(gameServer, httpServer); // Create plugin manager instance. pluginManager = new PluginManager(); diff --git a/src/main/java/emu/grasscutter/plugin/Plugin.java b/src/main/java/emu/grasscutter/plugin/Plugin.java index e8a1fe053..41e6e05a7 100644 --- a/src/main/java/emu/grasscutter/plugin/Plugin.java +++ b/src/main/java/emu/grasscutter/plugin/Plugin.java @@ -2,17 +2,20 @@ package emu.grasscutter.plugin; import emu.grasscutter.Grasscutter; import emu.grasscutter.plugin.api.ServerHelper; +import emu.grasscutter.plugin.api.ServerHook; import emu.grasscutter.server.game.GameServer; import emu.grasscutter.utils.FileUtils; -import java.io.File; -import java.io.InputStream; -import java.net.URLClassLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.InputStream; +import java.net.URLClassLoader; + /** The base class for all plugins to extend. */ +@SuppressWarnings("removal") public abstract class Plugin { - private final ServerHelper server = ServerHelper.getInstance(); + private final ServerHelper server = ServerHook.getInstance(); private PluginIdentifier identifier; private URLClassLoader classLoader; @@ -100,8 +103,8 @@ public abstract class Plugin { * * @return A server hook singleton. */ - public final ServerHelper getHandle() { - return this.server; + public final ServerHook getHandle() { + return (ServerHook) this.server; } /** diff --git a/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java b/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java index d4069f448..4fc8256bc 100644 --- a/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java +++ b/src/main/java/emu/grasscutter/plugin/api/ServerHelper.java @@ -15,7 +15,7 @@ import java.util.List; import java.util.stream.Stream; /** Hooks into the {@link GameServer} class, adding convenient ways to do certain things. */ -public final class ServerHelper { +public class ServerHelper { private static ServerHelper instance; private final GameServer gameServer; private final HttpServer httpServer; diff --git a/src/main/java/emu/grasscutter/plugin/api/ServerHook.java b/src/main/java/emu/grasscutter/plugin/api/ServerHook.java new file mode 100644 index 000000000..e34c2bd5f --- /dev/null +++ b/src/main/java/emu/grasscutter/plugin/api/ServerHook.java @@ -0,0 +1,30 @@ +package emu.grasscutter.plugin.api; + +import emu.grasscutter.server.game.GameServer; +import emu.grasscutter.server.http.HttpServer; + +@Deprecated(since = "2.0.0", forRemoval = true) +public final class ServerHook extends ServerHelper { + private static ServerHook instance; + + /** + * Hooks into a server. + * + * @param gameServer The game server to hook into. + * @param httpServer The HTTP server to hook into. + */ + public ServerHook(GameServer gameServer, HttpServer httpServer) { + super(gameServer, httpServer); + + instance = this; + } + + /** + * Gets the server hook instance. + * + * @return A {@link ServerHook} singleton. + */ + public static ServerHook getInstance() { + return instance; + } +}