Remove and replace subcommands.

This commit is contained in:
Olof Larsson 2014-11-12 11:36:04 +01:00
parent 6e096e1a92
commit d986f2ba31

View File

@ -53,7 +53,14 @@ public class MassiveCommand
this.addSubCommand(subCommand, this.subCommands.size()); this.addSubCommand(subCommand, this.subCommands.size());
} }
public void addSubCommand(MassiveCommand subCommand, MassiveCommand after) public void addSubCommand(MassiveCommand subCommand, int index)
{
subCommand.commandChain.addAll(this.commandChain);
subCommand.commandChain.add(this);
this.subCommands.add(index, subCommand);
}
public void addSubCommandAfter(MassiveCommand subCommand, MassiveCommand after)
{ {
int index = this.subCommands.indexOf(after); int index = this.subCommands.indexOf(after);
if (index == -1) if (index == -1)
@ -67,11 +74,19 @@ public class MassiveCommand
this.addSubCommand(subCommand, index); this.addSubCommand(subCommand, index);
} }
public void addSubCommand(MassiveCommand subCommand, int index) public int removeSubCommand(MassiveCommand subCommand)
{ {
subCommand.commandChain.addAll(this.commandChain); int index = this.subCommands.indexOf(subCommand);
subCommand.commandChain.add(this); this.subCommands.remove(index);
this.subCommands.add(index, subCommand); return index;
}
public int replaceSubCommand(MassiveCommand subCommand, MassiveCommand replaced)
{
int index = this.removeSubCommand(replaced);
if (index < 0) return index;
this.addSubCommand(subCommand, index);
return index;
} }
// FIELD: aliases // FIELD: aliases