From f3a331981fdf26afbc61b38709a27aa1e2a0a395 Mon Sep 17 00:00:00 2001 From: ImDaBigBoss <67973871+ImDaBigBoss@users.noreply.github.com> Date: Wed, 12 Jan 2022 15:31:28 +0100 Subject: [PATCH] Added extension dump data & make plugins be enabled on reload --- .../api/extension/ExtensionDescription.java | 5 +++- .../geyser/api/extension/ExtensionLoader.java | 3 +++ .../geyser/api/extension/ExtensionLogger.java | 3 +++ .../geyser/api/extension/GeyserExtension.java | 3 +++ .../java/org/geysermc/geyser/GeyserImpl.java | 3 ++- .../org/geysermc/geyser/dump/DumpInfo.java | 24 +++++++++++++++---- .../extension/GeyserExtensionDescription.java | 2 +- .../extension/GeyserExtensionManager.java | 6 ++--- 8 files changed, 39 insertions(+), 10 deletions(-) diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java index d32300e09..4426a4a92 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionDescription.java @@ -27,6 +27,9 @@ package org.geysermc.geyser.api.extension; import java.util.List; +/** + * This is the Geyer extension description + */ public interface ExtensionDescription { /** * Gets the extension's name @@ -47,7 +50,7 @@ public interface ExtensionDescription { * * @return the extension's api version */ - String ApiVersion(); + String apiVersion(); /** * Gets the extension's description diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLoader.java b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLoader.java index 291a34daf..1301493d5 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLoader.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLoader.java @@ -29,6 +29,9 @@ import org.geysermc.geyser.api.extension.exception.InvalidDescriptionException; import org.geysermc.geyser.api.extension.exception.InvalidExtensionException; import java.io.File; +/** + * The extension loader is responsible for loading, unloading, enabling and disabling extensions + */ public interface ExtensionLoader { /** * Loads an extension from a given file diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLogger.java b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLogger.java index 60ee45572..17e108455 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLogger.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/ExtensionLogger.java @@ -25,6 +25,9 @@ package org.geysermc.geyser.api.extension; +/** + * This is the Geyser extension logger + */ public interface ExtensionLogger { /** * Get the logger prefix diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/GeyserExtension.java b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/GeyserExtension.java index a3f911580..210452c3c 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/extension/GeyserExtension.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/extension/GeyserExtension.java @@ -30,6 +30,9 @@ import java.io.*; import java.net.URL; import java.net.URLConnection; +/** + * This class is to be extended by a Geyser extension + */ public class GeyserExtension { private boolean initialized = false; private boolean enabled = false; diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 7e61b3af7..b563892cc 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -460,7 +460,7 @@ public class GeyserImpl implements GeyserApi { ResourcePack.PACKS.clear(); - GeyserExtensionManager.getExtensionManager().disableExtensions(); + GeyserExtensionManager.getInstance().disableExtensions(); bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.done")); } @@ -468,6 +468,7 @@ public class GeyserImpl implements GeyserApi { @Override public void reload() { shutdown(); + GeyserExtensionManager.getInstance().enableExtensions(); bootstrap.onEnable(); } diff --git a/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java b/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java index 2734c7443..316f095c0 100644 --- a/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java +++ b/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java @@ -36,6 +36,8 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import lombok.AllArgsConstructor; import lombok.Getter; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.extension.GeyserExtension; +import org.geysermc.geyser.extension.GeyserExtensionManager; import org.geysermc.geyser.text.AsteriskSerializer; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.network.MinecraftProtocol; @@ -54,10 +56,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import java.util.*; import java.util.stream.Collectors; @Getter @@ -76,6 +75,7 @@ public class DumpInfo { private LogsInfo logsInfo; private final BootstrapDumpInfo bootstrapInfo; private final FlagsInfo flagsInfo; + private final List extensionInfo; public DumpInfo(boolean addLog) { this.versionInfo = new VersionInfo(); @@ -125,6 +125,11 @@ public class DumpInfo { this.bootstrapInfo = GeyserImpl.getInstance().getBootstrap().getDumpInfo(); this.flagsInfo = new FlagsInfo(); + + this.extensionInfo = new ArrayList<>(); + for (GeyserExtension extension : GeyserExtensionManager.getInstance().getExtensions().values()) { + this.extensionInfo.add(new ExtensionInfo(extension.isEnabled(), extension.name(), extension.description().version(), extension.description().main(), extension.description().authors(), extension.description().apiVersion())); + } } @Getter @@ -277,4 +282,15 @@ public class DumpInfo { this.flags = ManagementFactory.getRuntimeMXBean().getInputArguments(); } } + + @Getter + @AllArgsConstructor + public static class ExtensionInfo { + public boolean enabled; + public String name; + public String version; + public String main; + public List authors; + public String apiVersion; + } } diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionDescription.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionDescription.java index e2a09c598..228b88426 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionDescription.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionDescription.java @@ -85,7 +85,7 @@ public class GeyserExtensionDescription implements org.geysermc.geyser.api.exten } @Override - public String ApiVersion() { + public String apiVersion() { return api; } diff --git a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java index edda15ade..db0515906 100644 --- a/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java +++ b/core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionManager.java @@ -53,7 +53,7 @@ public class GeyserExtensionManager { geyserExtensionManager.enableExtensions(); } - public static GeyserExtensionManager getExtensionManager() { + public static GeyserExtensionManager getInstance() { return geyserExtensionManager; } @@ -170,7 +170,7 @@ public class GeyserExtensionManager { try { //Check the format: majorVersion.minorVersion.patch - if (!Pattern.matches("^[0-9]+\\.[0-9]+\\.[0-9]+$", description.ApiVersion())) { + if (!Pattern.matches("^[0-9]+\\.[0-9]+\\.[0-9]+$", description.apiVersion())) { throw new IllegalArgumentException(); } } catch (NullPointerException | IllegalArgumentException e) { @@ -178,7 +178,7 @@ public class GeyserExtensionManager { continue; } - String[] versionArray = description.ApiVersion().split("\\."); + String[] versionArray = description.apiVersion().split("\\."); //Completely different API version if (!Objects.equals(Integer.valueOf(versionArray[0]), Integer.valueOf(apiVersion[0]))) {