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
@@ -89,13 +89,13 @@ public class SpongeCommandManager extends CommandManager {
command.onRegister(this);
for (Map.Entry<String, RootCommand> entry : command.registeredCommands.entrySet()) {
String key = entry.getKey().toLowerCase();
SpongeRootCommand value = (SpongeRootCommand) entry.getValue();
if (!value.isRegistered) {
Sponge.getCommandManager().register(this.plugin, value, value.name);
String commandName = entry.getKey().toLowerCase();
SpongeRootCommand spongeCommand = (SpongeRootCommand) entry.getValue();
if (!spongeCommand.isRegistered) {
Sponge.getCommandManager().register(this.plugin, spongeCommand, commandName);
}
value.isRegistered = true;
registeredCommands.put(key, value);
spongeCommand.isRegistered = true;
registeredCommands.put(commandName, spongeCommand);
}
}
@@ -56,6 +56,11 @@ public class SpongeRootCommand implements CommandCallable, RootCommand {
this.name = name;
}
@Override
public String getCommandName() {
return name;
}
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if(this.execute(new SpongeCommandIssuer(manager, source), this.name, arguments.split(" "))) {
@@ -112,23 +117,8 @@ public class SpongeRootCommand implements CommandCallable, RootCommand {
public void addChild(BaseCommand command) {
if (this.defCommand == null || !command.subCommands.get("__default").isEmpty()) {
this.defCommand = command;
//this.setDescription(command.getDescription());
//this.setUsage(command.getUsage());
//this.setAliases(command.getAliases());
}
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 " + this.name + " - 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);
addChildShared(this.children, this.subCommands, command);
}
@Override