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,9 +32,12 @@ public class CommandHandler
|
|||||||
if (lifecycleRegistered)
|
if (lifecycleRegistered)
|
||||||
{
|
{
|
||||||
lifecycleReloadRequired = true;
|
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());
|
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)
|
public void unregisterCommand(PlexCommand command)
|
||||||
{
|
{
|
||||||
@@ -41,9 +45,19 @@ public class CommandHandler
|
|||||||
if (removed && lifecycleRegistered)
|
if (removed && lifecycleRegistered)
|
||||||
{
|
{
|
||||||
lifecycleReloadRequired = true;
|
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());
|
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()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -151,6 +152,10 @@ public class ModuleManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void enableModules()
|
public void enableModules()
|
||||||
|
{
|
||||||
|
CommandHandler handler = plugin.getCommandHandler();
|
||||||
|
boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true);
|
||||||
|
try
|
||||||
{
|
{
|
||||||
this.modules.forEach(module ->
|
this.modules.forEach(module ->
|
||||||
{
|
{
|
||||||
@@ -158,8 +163,20 @@ public class ModuleManager
|
|||||||
module.enable();
|
module.enable();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
handler.setSuppressLifecycleWarnings(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void disableModules()
|
public void disableModules()
|
||||||
|
{
|
||||||
|
CommandHandler handler = plugin.getCommandHandler();
|
||||||
|
boolean previous = handler != null && handler.setSuppressLifecycleWarnings(true);
|
||||||
|
try
|
||||||
{
|
{
|
||||||
this.modules.forEach(module ->
|
this.modules.forEach(module ->
|
||||||
{
|
{
|
||||||
@@ -172,6 +189,14 @@ public class ModuleManager
|
|||||||
module.disable();
|
module.disable();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (handler != null)
|
||||||
|
{
|
||||||
|
handler.setSuppressLifecycleWarnings(previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void unloadModules()
|
public void unloadModules()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user