mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 04:05:36 +01:00
CommandsAPI - Implemented CommandsManager to manage registering of commands by both BSB and its addons
This commit is contained in:
parent
7effb541ba
commit
2c8a36ed54
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user