improve command reloading

This commit is contained in:
xGinko 2023-09-27 13:40:44 +02:00
parent 945c0c9666
commit ac197a73a1

View File

@ -18,18 +18,16 @@ public interface VillagerOptimizerCommand extends CommandExecutor {
HashSet<VillagerOptimizerCommand> commands = new HashSet<>(); HashSet<VillagerOptimizerCommand> commands = new HashSet<>();
static void reloadCommands() { static void reloadCommands() {
VillagerOptimizer plugin = VillagerOptimizer.getInstance();
CommandMap commandMap = plugin.getServer().getCommandMap();
commands.forEach(command -> plugin.getCommand(command.label()).unregister(commandMap));
commands.clear(); commands.clear();
commands.add(new VillagerOptimizerCmd()); commands.add(new VillagerOptimizerCmd());
commands.add(new OptVillagersRadius()); commands.add(new OptVillagersRadius());
commands.add(new UnOptVillagersRadius()); commands.add(new UnOptVillagersRadius());
VillagerOptimizer plugin = VillagerOptimizer.getInstance(); commands.forEach(command -> plugin.getCommand(command.label()).setExecutor(command));
CommandMap commandMap = plugin.getServer().getCommandMap();
commands.forEach(command -> {
plugin.getCommand(command.label()).unregister(commandMap);
plugin.getCommand(command.label()).setExecutor(command);
});
} }
@Override @Override