Command registration lifecycle fix

This commit is contained in:
2026-05-21 18:34:53 -04:00
parent 9802d23832
commit 2b9f7c7de7
2 changed files with 52 additions and 13 deletions
@@ -16,6 +16,7 @@ public class CommandHandler
private final List<PlexCommand> commands = new ArrayList<>();
private boolean lifecycleRegistered;
private boolean lifecycleReloadRequired;
private boolean suppressLifecycleWarnings;
public CommandHandler(Plex plugin)
{
@@ -31,9 +32,12 @@ public class CommandHandler
if (lifecycleRegistered)
{
lifecycleReloadRequired = true;
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());
}
}
}
public void unregisterCommand(PlexCommand command)
{
@@ -41,9 +45,19 @@ public class CommandHandler
if (removed && lifecycleRegistered)
{
lifecycleReloadRequired = true;
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()
{
@@ -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;
@@ -151,6 +152,10 @@ public class ModuleManager
}
public void enableModules()
{
CommandHandler handler = plugin.getCommandHandler();
boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true);
try
{
this.modules.forEach(module ->
{
@@ -158,8 +163,20 @@ public class ModuleManager
module.enable();
});
}
finally
{
if (handler != null)
{
handler.setSuppressLifecycleWarnings(previous);
}
}
}
public void disableModules()
{
CommandHandler handler = plugin.getCommandHandler();
boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true);
try
{
this.modules.forEach(module ->
{
@@ -172,6 +189,14 @@ public class ModuleManager
module.disable();
});
}
finally
{
if (handler != null)
{
handler.setSuppressLifecycleWarnings(previous);
}
}
}
public void unloadModules()
{