Replace a bit of code duplication and misc cleanup

This commit is contained in:
Aikar
2017-07-03 00:02:43 -05:00
parent d9652ba9eb
commit b128908a77
7 changed files with 58 additions and 65 deletions
@@ -78,13 +78,13 @@ public class BungeeCommandManager extends CommandManager {
public void registerCommand(BaseCommand command) {
command.onRegister(this);
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
String key = entry.getKey().toLowerCase();
BungeeRootCommand value = (BungeeRootCommand) entry.getValue();
if (!value.isRegistered) {
this.plugin.getProxy().getPluginManager().registerCommand(this.plugin, value);
String commandName = entry.getKey().toLowerCase();
BungeeRootCommand bungeeCommand = (BungeeRootCommand) entry.getValue();
if (!bungeeCommand.isRegistered) {
this.plugin.getProxy().getPluginManager().registerCommand(this.plugin, bungeeCommand);
}
value.isRegistered = true;
registeredCommands.put(key, value);
bungeeCommand.isRegistered = true;
registeredCommands.put(commandName, bungeeCommand);
}
}
@@ -37,7 +37,6 @@ public class BungeeRootCommand extends Command implements RootCommand, TabExecut
private BaseCommand defCommand;
private Map<String, BaseCommand> subCommands = new HashMap<>();
private List<BaseCommand> children = new ArrayList<>();
private String permission;
boolean isRegistered = false;
BungeeRootCommand(BungeeCommandManager manager, String name) {
@@ -46,28 +45,18 @@ public class BungeeRootCommand extends Command implements RootCommand, TabExecut
this.name = name;
}
@Override
public String getCommandName() {
return name;
}
@Override
public void addChild(BaseCommand command) {
if (this.defCommand == null || !command.subCommands.get("__default").isEmpty()) {
this.defCommand = command;
this.permission = command.permission;
//this.setPermissionMessage(command.permissionMessage);
//this.setDescription(command.getDescription());
//this.setUsage(command.getUsage());
}
command.subCommands.keySet().forEach(key -> {
if (key.equals(BaseCommand.DEFAULT) || key.equals(BaseCommand.UNKNOWN)) {
return;
}
BaseCommand regged = this.subCommands.get(key);
if (regged != null) {
this.manager.log(LogLevel.ERROR, "ACF Error: " + command.getName() + " registered subcommand " + key + " for root command " + getName() + " - but it is already defined in " + regged.getName());
this.manager.log(LogLevel.ERROR, "2 subcommands of the same prefix may not be spread over 2 different classes. Ignoring this.");
return;
}
this.subCommands.put(key, command);
});
this.children.add(command);
this.addChildShared(this.children, this.subCommands, command);
}
@Override