CommandsAPI - Implemented CommandsManager to manage registering of commands by both BSB and its addons

This commit is contained in:
Florian CUNY 2017-12-11 21:55:05 +01:00
parent 7effb541ba
commit 2c8a36ed54
2 changed files with 45 additions and 4 deletions

View File

@ -23,8 +23,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.subCommands = new LinkedHashMap<>();
this.setup();
plugin.getNMSHandler().getServerCommandMap().register(label, this);
}
public CompositeCommand(String label, String description, String... aliases) {
@ -35,8 +33,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.subCommands = new LinkedHashMap<>();
this.setup();
plugin.getNMSHandler().getServerCommandMap().register(label, this);
}
public abstract void setup();

View File

@ -0,0 +1,45 @@
package us.tastybento.bskyblock.managers;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.BSModule;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public final class CommandsManager {
private Map<BSModule, List<Command>> commands = new LinkedHashMap<>();
public void registerCommand(BSModule module, Command command) {
List<Command> cmds = new ArrayList<>();
if (commands.containsKey(module)) {
cmds = commands.get(module);
}
cmds.add(command);
commands.put(module, cmds);
BSkyBlock.getPlugin().getNMSHandler().getServerCommandMap().register(command.getLabel(), command);
}
public void unregisterCommand(Command command) {
}
public List<Command> getCommands(BSModule module) {
return commands.get(module);
}
public Command getCommand(String label) {
for (List<Command> cmds : commands.values()) {
for (Command cmd : cmds) {
if (cmd.getLabel().equalsIgnoreCase(label)) return cmd;
}
}
return null;
}
}