From 2b9f7c7de73c4f8f8aca565c79ee319a71fc7e4d Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Thu, 21 May 2026 18:34:53 -0400 Subject: [PATCH] Command registration lifecycle fix --- .../dev/plex/handlers/CommandHandler.java | 18 ++++++- .../java/dev/plex/module/ModuleManager.java | 47 ++++++++++++++----- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/dev/plex/handlers/CommandHandler.java b/server/src/main/java/dev/plex/handlers/CommandHandler.java index 472de82..761527e 100644 --- a/server/src/main/java/dev/plex/handlers/CommandHandler.java +++ b/server/src/main/java/dev/plex/handlers/CommandHandler.java @@ -16,6 +16,7 @@ public class CommandHandler private final List commands = new ArrayList<>(); private boolean lifecycleRegistered; private boolean lifecycleReloadRequired; + private boolean suppressLifecycleWarnings; public CommandHandler(Plex plugin) { @@ -31,7 +32,10 @@ public class CommandHandler if (lifecycleRegistered) { lifecycleReloadRequired = true; - PlexLog.warn("Command {0} was registered after the Brigadier command lifecycle event; it will be included on the next command lifecycle rebuild.", command.getName()); + if (!suppressLifecycleWarnings) + { + PlexLog.warn("Command {0} was registered after the Brigadier command lifecycle event; it will be included on the next command lifecycle rebuild.", command.getName()); + } } } @@ -41,10 +45,20 @@ public class CommandHandler if (removed && lifecycleRegistered) { lifecycleReloadRequired = true; - PlexLog.warn("Command {0} was unregistered after the Brigadier command lifecycle event; Paper may keep the active Brigadier node until the next command lifecycle rebuild.", command.getName()); + if (!suppressLifecycleWarnings) + { + PlexLog.warn("Command {0} was unregistered after the Brigadier command lifecycle event; Paper may keep the active Brigadier node until the next command lifecycle rebuild.", command.getName()); + } } } + public boolean setSuppressLifecycleWarnings(boolean suppress) + { + boolean previous = suppressLifecycleWarnings; + suppressLifecycleWarnings = suppress; + return previous; + } + public boolean requiresLifecycleReload() { return lifecycleReloadRequired; diff --git a/server/src/main/java/dev/plex/module/ModuleManager.java b/server/src/main/java/dev/plex/module/ModuleManager.java index 068b19c..a088fe6 100644 --- a/server/src/main/java/dev/plex/module/ModuleManager.java +++ b/server/src/main/java/dev/plex/module/ModuleManager.java @@ -2,6 +2,7 @@ package dev.plex.module; import com.google.common.collect.Lists; import dev.plex.Plex; +import dev.plex.handlers.CommandHandler; import dev.plex.module.exception.ModuleLoadException; import dev.plex.util.PlexLog; @@ -152,25 +153,49 @@ public class ModuleManager public void enableModules() { - this.modules.forEach(module -> + CommandHandler handler = plugin.getCommandHandler(); + boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true); + try { - PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); - module.enable(); - }); + this.modules.forEach(module -> + { + PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); + module.enable(); + }); + } + finally + { + if (handler != null) + { + handler.setSuppressLifecycleWarnings(previous); + } + } } public void disableModules() { - this.modules.forEach(module -> + CommandHandler handler = plugin.getCommandHandler(); + boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true); + try { - PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); - module.getCommands().stream().toList().forEach(plexCommand -> + this.modules.forEach(module -> { - module.unregisterCommand(plexCommand); + PlexLog.log("Disabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion()); + module.getCommands().stream().toList().forEach(plexCommand -> + { + module.unregisterCommand(plexCommand); + }); + module.getListeners().stream().toList().forEach(module::unregisterListener); + module.disable(); }); - module.getListeners().stream().toList().forEach(module::unregisterListener); - module.disable(); - }); + } + finally + { + if (handler != null) + { + handler.setSuppressLifecycleWarnings(previous); + } + } } public void unloadModules()