mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 18:35:15 +00:00
Refactor CommandManager to manage command executor lifecycle and add shutdown method
This commit is contained in:
parent
51e102b343
commit
9bf82012b8
2 changed files with 22 additions and 2 deletions
|
|
@ -152,6 +152,8 @@ public class DMCC {
|
|||
serverInstance.shutdown();
|
||||
}
|
||||
|
||||
CommandManager.shutdown();
|
||||
|
||||
// Do NOT clear event handlers here. They are registered once during mod initialization
|
||||
// and should persist across DMCC reloads.
|
||||
// EventManager.clear();
|
||||
|
|
|
|||
|
|
@ -22,12 +22,16 @@ import java.util.concurrent.Executors;
|
|||
public class CommandManager {
|
||||
|
||||
private static final Map<String, Command> COMMANDS = new ConcurrentHashMap<>();
|
||||
private static final ExecutorService COMMAND_EXECUTOR = Executors.newSingleThreadExecutor(ExecutorServiceUtils.newThreadFactory("DMCC-Command"));
|
||||
private static ExecutorService commandExecutor;
|
||||
|
||||
/**
|
||||
* Initialize and register built-in commands based on the current operating mode.
|
||||
*/
|
||||
public static void initialize() {
|
||||
if (commandExecutor == null || commandExecutor.isShutdown()) {
|
||||
commandExecutor = Executors.newSingleThreadExecutor(ExecutorServiceUtils.newThreadFactory("DMCC-Command"));
|
||||
}
|
||||
|
||||
COMMANDS.clear();
|
||||
|
||||
register(new HelpCommand());
|
||||
|
|
@ -38,6 +42,16 @@ public class CommandManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the command executor.
|
||||
*/
|
||||
public static void shutdown() {
|
||||
if (commandExecutor != null) {
|
||||
commandExecutor.shutdown();
|
||||
commandExecutor = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a command.
|
||||
*
|
||||
|
|
@ -63,7 +77,11 @@ public class CommandManager {
|
|||
* @param rawInput The raw command line
|
||||
*/
|
||||
public static void execute(CommandSender sender, String rawInput) {
|
||||
COMMAND_EXECUTOR.submit(() -> {
|
||||
if (commandExecutor == null || commandExecutor.isShutdown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandExecutor.submit(() -> {
|
||||
String line = rawInput == null ? "" : rawInput.trim();
|
||||
if (line.isEmpty()) {
|
||||
sender.reply(I18nManager.getDmccTranslation("terminal.unknown_command", rawInput));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue