mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-04 05:26:55 +00:00
Command registration lifecycle fix
This commit is contained in:
@@ -16,6 +16,7 @@ public class CommandHandler
|
|||||||
private final List<PlexCommand> commands = new ArrayList<>();
|
private final List<PlexCommand> commands = new ArrayList<>();
|
||||||
private boolean lifecycleRegistered;
|
private boolean lifecycleRegistered;
|
||||||
private boolean lifecycleReloadRequired;
|
private boolean lifecycleReloadRequired;
|
||||||
|
private boolean suppressLifecycleWarnings;
|
||||||
|
|
||||||
public CommandHandler(Plex plugin)
|
public CommandHandler(Plex plugin)
|
||||||
{
|
{
|
||||||
@@ -31,7 +32,10 @@ public class CommandHandler
|
|||||||
if (lifecycleRegistered)
|
if (lifecycleRegistered)
|
||||||
{
|
{
|
||||||
lifecycleReloadRequired = true;
|
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)
|
if (removed && lifecycleRegistered)
|
||||||
{
|
{
|
||||||
lifecycleReloadRequired = true;
|
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()
|
public boolean requiresLifecycleReload()
|
||||||
{
|
{
|
||||||
return lifecycleReloadRequired;
|
return lifecycleReloadRequired;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dev.plex.module;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.handlers.CommandHandler;
|
||||||
import dev.plex.module.exception.ModuleLoadException;
|
import dev.plex.module.exception.ModuleLoadException;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
|
|
||||||
@@ -152,25 +153,49 @@ public class ModuleManager
|
|||||||
|
|
||||||
public void enableModules()
|
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());
|
this.modules.forEach(module ->
|
||||||
module.enable();
|
{
|
||||||
});
|
PlexLog.log("Enabling module " + module.getPlexModuleFile().getName() + " with version " + module.getPlexModuleFile().getVersion());
|
||||||
|
module.enable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
handler.setSuppressLifecycleWarnings(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableModules()
|
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());
|
this.modules.forEach(module ->
|
||||||
module.getCommands().stream().toList().forEach(plexCommand ->
|
|
||||||
{
|
{
|
||||||
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()
|
public void unloadModules()
|
||||||
|
|||||||
Reference in New Issue
Block a user