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 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
|
||||||
{
|
{
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user