diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java new file mode 100644 index 00000000..a6078dbd --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/CommandRemoverComponent.java @@ -0,0 +1,39 @@ +package ru.gravit.launchserver.components; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.utils.command.Command; + +import java.util.HashMap; +import java.util.Map; + +public class CommandRemoverComponent extends Component implements AutoCloseable { + public String[] removeList = new String[]{}; + public transient Map commandsList = new HashMap<>(); + @Override + public void preInit(LaunchServer launchServer) { + + } + + @Override + public void init(LaunchServer launchServer) { + + } + + @Override + public void postInit(LaunchServer launchServer) { + for(String cmd : removeList) + { + Command removedCmd = launchServer.commandHandler.unregisterCommand(cmd); + if(removedCmd != null) + commandsList.put(cmd, removedCmd); + } + } + + @Override + public void close() throws Exception { + for(Map.Entry e : commandsList.entrySet()) + { + LaunchServer.server.commandHandler.registerCommand(e.getKey(), e.getValue()); + } + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java index 4cd718ac..b0ebcd57 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/components/Component.java @@ -31,6 +31,7 @@ public static String getComponentName(Class clazz) { public static void registerComponents() { if (!registredComp) { registerComponent("authLimiter", AuthLimiterComponent.class); + registerComponent("commandRemover", CommandRemoverComponent.class); registredComp = true; } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java index 0e2c5a0d..8d2b2944 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java @@ -76,9 +76,9 @@ public void registerCommand(String name, Command command) { VerifyHelper.putIfAbsent(commands, name.toLowerCase(), Objects.requireNonNull(command, "command"), String.format("Command has been already registered: '%s'", name.toLowerCase())); } - public void unregisterCommand(String name) + public Command unregisterCommand(String name) { - commands.remove(name); + return commands.remove(name); } @Override