Launcher/LaunchServer/src/main/java/pro/gravit/launchserver/components/CommandRemoverComponent.java

40 lines
1.1 KiB
Java
Raw Normal View History

package pro.gravit.launchserver.components;
2019-03-28 13:26:47 +03:00
2019-06-03 10:58:10 +03:00
import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.command.Command;
2019-10-19 19:46:04 +03:00
import java.util.HashMap;
import java.util.Map;
2019-03-28 13:26:47 +03:00
public class CommandRemoverComponent extends Component implements AutoCloseable {
2019-10-19 19:43:25 +03:00
public final String[] removeList = new String[]{};
public final transient Map<String, Command> commandsList = new HashMap<>();
private transient LaunchServer server = null;
2019-04-03 16:27:40 +03:00
2019-03-28 13:26:47 +03:00
@Override
public void preInit(LaunchServer launchServer) {
2019-10-19 19:46:04 +03:00
server = launchServer;
2019-03-28 13:26:47 +03:00
}
@Override
public void init(LaunchServer launchServer) {
}
@Override
public void postInit(LaunchServer launchServer) {
2019-04-03 16:27:40 +03:00
for (String cmd : removeList) {
2019-03-28 13:26:47 +03:00
Command removedCmd = launchServer.commandHandler.unregisterCommand(cmd);
2019-04-03 16:27:40 +03:00
if (removedCmd != null)
commandsList.put(cmd, removedCmd);
2019-03-28 13:26:47 +03:00
}
}
@Override
2019-04-20 01:14:02 +03:00
public void close() {
2019-04-03 16:27:40 +03:00
for (Map.Entry<String, Command> e : commandsList.entrySet()) {
server.commandHandler.registerCommand(e.getKey(), e.getValue());
2019-03-28 13:26:47 +03:00
}
}
}