From d986f2ba315db1ff127f987fd7708059dc9ae055 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 12 Nov 2014 11:36:04 +0100 Subject: [PATCH] Remove and replace subcommands. --- .../massivecore/cmd/MassiveCommand.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/massivecraft/massivecore/cmd/MassiveCommand.java b/src/main/java/com/massivecraft/massivecore/cmd/MassiveCommand.java index 3dc9c8a1..9de8c897 100644 --- a/src/main/java/com/massivecraft/massivecore/cmd/MassiveCommand.java +++ b/src/main/java/com/massivecraft/massivecore/cmd/MassiveCommand.java @@ -53,7 +53,14 @@ public class MassiveCommand 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); if (index == -1) @@ -67,11 +74,19 @@ public class MassiveCommand this.addSubCommand(subCommand, index); } - public void addSubCommand(MassiveCommand subCommand, int index) + public int removeSubCommand(MassiveCommand subCommand) { - subCommand.commandChain.addAll(this.commandChain); - subCommand.commandChain.add(this); - this.subCommands.add(index, subCommand); + int index = this.subCommands.indexOf(subCommand); + this.subCommands.remove(index); + 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