Break out some sub routines within the command system.

This commit is contained in:
Olof Larsson 2015-01-05 11:39:12 +01:00
parent 22cef1d9da
commit ed58b3185a
2 changed files with 35 additions and 21 deletions

View File

@ -96,6 +96,21 @@ public class MassiveCommand
public List<MassiveCommand> getSubCommands() { return this.subCommands; } public List<MassiveCommand> getSubCommands() { return this.subCommands; }
public void setSubCommands(List<MassiveCommand> subCommands) { this.subCommands = subCommands; } public void setSubCommands(List<MassiveCommand> subCommands) { this.subCommands = subCommands; }
public MassiveCommand getSubCommand(String alias)
{
for (MassiveCommand subCommand: this.getSubCommands())
{
for (String subAlias : subCommand.getAliases())
{
if (alias.equalsIgnoreCase(subAlias))
{
return subCommand;
}
}
}
return null;
}
public void addSubCommand(MassiveCommand subCommand) public void addSubCommand(MassiveCommand subCommand)
{ {
this.addSubCommand(subCommand, this.subCommands.size()); this.addSubCommand(subCommand, this.subCommands.size());
@ -295,11 +310,8 @@ public class MassiveCommand
// Is there a matching sub command? // Is there a matching sub command?
if (args.size() > 0) if (args.size() > 0)
{ {
for (MassiveCommand subCommand: this.getSubCommands()) MassiveCommand subCommand = this.getSubCommand(args.get(0));
{ if (subCommand != null)
for (String alias : subCommand.getAliases())
{
if (args.get(0).equalsIgnoreCase(alias))
{ {
args.remove(0); args.remove(0);
commandChain.add(this); commandChain.add(this);
@ -307,8 +319,6 @@ public class MassiveCommand
return; return;
} }
} }
}
}
try try
{ {

View File

@ -56,29 +56,33 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
@Override @Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) public boolean execute(CommandSender sender, String commandLabel, String[] args)
{ {
List<String> argList; List<String> argList = this.createArgList(args);
this.massiveCommand.execute(sender, argList);
return true;
}
public List<String> createArgList(String[] args)
{
List<String> ret;
if (this.massiveCommand.isUsingTokenizer()) if (this.massiveCommand.isUsingTokenizer())
{ {
argList = Txt.tokenizeArguments(Txt.implode(args, " ")); ret = Txt.tokenizeArguments(Txt.implode(args, " "));
} }
else else
{ {
argList = new ArrayList<String>(Arrays.asList(args)); ret = new ArrayList<String>(Arrays.asList(args));
} }
if (this.massiveCommand.isUsingSmartQuotesRemoval()) if (this.massiveCommand.isUsingSmartQuotesRemoval())
{ {
List<String> oldArgList = argList; List<String> oldArgList = ret;
argList = new ArrayList<String>(); ret = new ArrayList<String>();
for (String arg : oldArgList) for (String arg : oldArgList)
{ {
argList.add(Txt.removeSmartQuotes(arg)); ret.add(Txt.removeSmartQuotes(arg));
} }
} }
return ret;
this.massiveCommand.execute(sender, argList);
return true;
} }
// -------------------------------------------- // // -------------------------------------------- //