mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] CommandRemover
This commit is contained in:
parent
24aefd47f1
commit
1ed588e1c0
3 changed files with 42 additions and 2 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue