Break out some sub routines within the command system.
This commit is contained in:
parent
22cef1d9da
commit
ed58b3185a
@ -96,6 +96,21 @@ public class MassiveCommand
|
||||
public List<MassiveCommand> getSubCommands() { return this.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)
|
||||
{
|
||||
this.addSubCommand(subCommand, this.subCommands.size());
|
||||
@ -295,18 +310,13 @@ public class MassiveCommand
|
||||
// Is there a matching sub command?
|
||||
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);
|
||||
commandChain.add(this);
|
||||
subCommand.execute(sender, args, commandChain);
|
||||
return;
|
||||
}
|
||||
}
|
||||
args.remove(0);
|
||||
commandChain.add(this);
|
||||
subCommand.execute(sender, args, commandChain);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,29 +56,33 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
|
||||
@Override
|
||||
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())
|
||||
{
|
||||
argList = Txt.tokenizeArguments(Txt.implode(args, " "));
|
||||
ret = Txt.tokenizeArguments(Txt.implode(args, " "));
|
||||
}
|
||||
else
|
||||
{
|
||||
argList = new ArrayList<String>(Arrays.asList(args));
|
||||
ret = new ArrayList<String>(Arrays.asList(args));
|
||||
}
|
||||
|
||||
if (this.massiveCommand.isUsingSmartQuotesRemoval())
|
||||
{
|
||||
List<String> oldArgList = argList;
|
||||
argList = new ArrayList<String>();
|
||||
List<String> oldArgList = ret;
|
||||
ret = new ArrayList<String>();
|
||||
for (String arg : oldArgList)
|
||||
{
|
||||
argList.add(Txt.removeSmartQuotes(arg));
|
||||
ret.add(Txt.removeSmartQuotes(arg));
|
||||
}
|
||||
}
|
||||
|
||||
this.massiveCommand.execute(sender, argList);
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user