From 0b9e598efbc38ecb84bfed53975eb770a589e0de Mon Sep 17 00:00:00 2001 From: mingjun97 Date: Wed, 18 May 2022 18:36:08 -0700 Subject: [PATCH] Display version when enabled --- .../com/mojo/consoleplus/ConsolePlus.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/gc-plugin/src/main/java/com/mojo/consoleplus/ConsolePlus.java b/gc-plugin/src/main/java/com/mojo/consoleplus/ConsolePlus.java index 4fd0d64..4a665c0 100644 --- a/gc-plugin/src/main/java/com/mojo/consoleplus/ConsolePlus.java +++ b/gc-plugin/src/main/java/com/mojo/consoleplus/ConsolePlus.java @@ -4,11 +4,16 @@ import emu.grasscutter.Grasscutter; import emu.grasscutter.command.CommandMap; import emu.grasscutter.plugin.Plugin; +import java.io.BufferedReader; import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import com.google.gson.Gson; import com.mojo.consoleplus.command.PluginCommand; import io.javalin.http.staticfiles.Location; +import emu.grasscutter.plugin.PluginConfig; import static emu.grasscutter.Configuration.PLUGIN; import static emu.grasscutter.Configuration.HTTP_POLICIES; @@ -16,12 +21,24 @@ import com.mojo.consoleplus.config.MojoConfig; public class ConsolePlus extends Plugin{ public static MojoConfig config = MojoConfig.loadConfig(); + public static String versionTag; @Override public void onLoad() { - Grasscutter.getLogger().info("[MojoConsole] loaded!"); + try (InputStream in = getClass().getResourceAsStream("/plugin.json"); + BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { + Gson gson = new Gson(); + PluginConfig pluginConfig = gson.fromJson(reader, PluginConfig.class); + this.getLogger().info("[MojoConsole] loaded!"); + versionTag = pluginConfig.version; + } + catch (Exception e) { + e.printStackTrace(); + } + // Use resource } + @Override public void onEnable() { String folder_name = PLUGIN("mojoconsole/"); @@ -40,14 +57,14 @@ public class ConsolePlus extends Plugin{ } Grasscutter.getHttpServer().addRouter(RequestHandler.class); CommandMap.getInstance().registerCommand("mojoconsole", new PluginCommand()); - Grasscutter.getLogger().info("[MojoConsole] enabled"); + this.getLogger().info("[MojoConsole] enabled. Version: " + versionTag); } @Override public void onDisable() { CommandMap.getInstance().unregisterCommand("mojoconsole"); - Grasscutter.getLogger().info("[MojoConsole] Mojoconsole Disabled"); + this.getLogger().info("[MojoConsole] Mojoconsole Disabled"); } }