[FEATURE] CommandRemover

This commit is contained in:
Gravit 2019-03-28 17:26:47 +07:00
parent 24aefd47f1
commit 1ed588e1c0
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 42 additions and 2 deletions

View file

@ -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<String, Command> 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<String, Command> e : commandsList.entrySet())
{
LaunchServer.server.commandHandler.registerCommand(e.getKey(), e.getValue());
}
}
}

View file

@ -31,6 +31,7 @@ public static String getComponentName(Class<Component> clazz) {
public static void registerComponents() {
if (!registredComp) {
registerComponent("authLimiter", AuthLimiterComponent.class);
registerComponent("commandRemover", CommandRemoverComponent.class);
registredComp = true;
}
}

View file

@ -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