diff --git a/src/com/massivecraft/massivecore/cmd/ArgSetting.java b/src/com/massivecraft/massivecore/cmd/ArgSetting.java new file mode 100644 index 00000000..f2b3e267 --- /dev/null +++ b/src/com/massivecraft/massivecore/cmd/ArgSetting.java @@ -0,0 +1,104 @@ +package com.massivecraft.massivecore.cmd; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.massivecraft.massivecore.cmd.arg.AR; + +public class ArgSetting +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected AR reader; + public AR getReader() { return reader; } + public ArgSetting setReader(AR reader) { this.reader = reader; return this; } + + protected String name; + public String getName() { return name; } + public ArgSetting setName(String name) { this.name = name; return this; } + + protected String def = null; // "default" is a reserved keyword in Java. + public String getDefault() { return def; } + public ArgSetting setDefault(String def) { this.def = def; return this; } + + // Convenience + public boolean isRequired() { return this.getDefault() == null; } + public boolean isOptional() { return ! this.isRequired(); } + + // Is this arg ALWAYS required from the console? + // That might the case if the arg is a player. and default is oneself. + protected boolean requiredFromConsole = false; + public boolean isRequiredFromConsole() { return requiredFromConsole && this.isRequired(); } + public ArgSetting setRequiredFromConsole(boolean requiredFromConsole) { this.requiredFromConsole = requiredFromConsole; return this; } + + // An optional description of this argument. + // Examples: + // 1. "the faction to show info about" + // 2. "the ticket to pick" + // 3. "the amount of money to pay" + protected String desc = null; + public String getDesc() { return desc; } + public ArgSetting setDesc(String desc) { this.desc = desc; return this; } + + public boolean hasDesc() { return this.getDesc() != null; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + // To minimize confusion and mixing of arguments for the constructor + // description must not be set in the constructor. + + // With default option and required from console. + protected ArgSetting(AR reader, boolean requiredFromConsole, String name, String def) + { + this.setReader(reader); + this.setRequiredFromConsole(requiredFromConsole); + this.setName(name); + this.setDefault(def); + } + + // -------------------------------------------- // + // STATIC FACTORY + // -------------------------------------------- // + + public static ArgSetting of(AR reader, boolean requiredFromConsole, String name, String def) + { + // Null checks + if (reader == null) throw new IllegalArgumentException("reader mustn't be null"); + if (name == null) throw new IllegalArgumentException("name mustn't be null"); + + // Create + return new ArgSetting(reader, requiredFromConsole, name, def); + } + + // -------------------------------------------- // + // CONVENIENCE + // -------------------------------------------- // + + public boolean isRequiredFor(CommandSender sender) + { + if (this.isRequired()) return true; // Required for everyone. + if ( ! this.isRequiredFromConsole()) return false; // If not required for console. Then not anyone. + if (sender == null) return false; // If null we will suppose it is a player. + if ( ! (sender instanceof Player)) return true; // Required for console. + return false; // Not required. + } + + public boolean isOptionalFor(CommandSender sender) + { + return ! this.isRequiredFor(sender); + } + + public String getUseageTemplateDisplayFor(CommandSender sender) + { + if (this.isRequiredFor(sender)) return "<" + this.getName() + ">"; + + String def = this.getDefault(); + def = (def != null ? "=" + def : ""); + return "[" + this.getName() + def + "]"; + } + +} diff --git a/src/com/massivecraft/massivecore/cmd/DeprecatedCommand.java b/src/com/massivecraft/massivecore/cmd/DeprecatedCommand.java index 49aea730..971c2c68 100644 --- a/src/com/massivecraft/massivecore/cmd/DeprecatedCommand.java +++ b/src/com/massivecraft/massivecore/cmd/DeprecatedCommand.java @@ -25,7 +25,7 @@ public class DeprecatedCommand extends MassiveCommand this.setAliases(aliases); // Args - this.setErrorOnToManyArgs(false); + this.setErrorOnTooManyArgs(false); // Visibility this.setVisibilityMode(VisibilityMode.INVISIBLE); diff --git a/src/com/massivecraft/massivecore/cmd/HelpCommand.java b/src/com/massivecraft/massivecore/cmd/HelpCommand.java index 9de504b3..42ec0edb 100644 --- a/src/com/massivecraft/massivecore/cmd/HelpCommand.java +++ b/src/com/massivecraft/massivecore/cmd/HelpCommand.java @@ -21,7 +21,7 @@ public class HelpCommand extends MassiveCommand this.addAliases("?", "h", "help"); // Args - this.addOptionalArg("page", "1"); + this.addArg(ARInteger.get(), "page", "1"); // Other this.setDesc(""); @@ -35,17 +35,17 @@ public class HelpCommand extends MassiveCommand public void perform() throws MassiveException { // Args - Integer pagenumber = this.arg(0, ARInteger.get(), 1); + int pagenumber = (Integer) this.readArg(1); // Get parent command - if (this.getCommandChain().size() == 0) return; - MassiveCommand parentCommand = this.getCommandChain().get(this.getCommandChain().size()-1); + if ( ! this.hasParentCommand()) return; + MassiveCommand parentCommand = this.getParentCommand(); // Create Lines ArrayList lines = new ArrayList(); for (String helpline : parentCommand.getHelp()) { - lines.add(Txt.parse("# "+helpline)); + lines.add(Txt.parse("# " + helpline)); } for (MassiveCommand subCommand : parentCommand.getSubCommands()) @@ -57,7 +57,7 @@ public class HelpCommand extends MassiveCommand } // Send Lines - sendMessage(Txt.getPage(lines, pagenumber, "Help for command \""+parentCommand.getAliases().get(0)+"\"", sender)); + sendMessage(Txt.getPage(lines, pagenumber, "Help for command \"" + parentCommand.getAliases().get(0) + "\"", sender)); } } diff --git a/src/com/massivecraft/massivecore/cmd/MassiveCommand.java b/src/com/massivecraft/massivecore/cmd/MassiveCommand.java index d66a4ca3..7deda285 100644 --- a/src/com/massivecraft/massivecore/cmd/MassiveCommand.java +++ b/src/com/massivecraft/massivecore/cmd/MassiveCommand.java @@ -3,6 +3,7 @@ package com.massivecraft.massivecore.cmd; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -104,6 +105,7 @@ public class MassiveCommand protected List subCommands; public List getSubCommands() { return this.subCommands; } public void setSubCommands(List subCommands) { this.subCommands = subCommands; } + public boolean isParentCommand() { return this.getSubCommands().size() > 0; } public MassiveCommand getSubCommand(String alias) @@ -173,27 +175,144 @@ public class MassiveCommand public void addAliases(Collection aliases) { this.aliases.addAll(aliases); } public void addAliases(String... aliases) { this.addAliases(Arrays.asList(aliases)); } + // FIELD argSettings + // Settings for all args. + protected List argSettings; + public List getArgSettings() { return this.argSettings; } + public void setArgSettings(List argSettings) { this.argSettings = argSettings; } + + // The index is the same as the argument index. + // So argAt(x) should be read by getArgReader(x) + + public ArgSetting getArgSetting(int index) + { + if (this.isUsingConcatFrom() && this.getConcatFromIndex() < index) index = this.getConcatFromIndex(); + return this.getArgSettings().get(index); + } + + public AR getArgReader(int index) + { + ArgSetting setting = this.getArgSetting(index); + return setting.getReader(); + } + + public boolean hasArgSettingForIndex(int index) + { + if (index < 0) return false; + if (this.isUsingConcatFrom() && this.getConcatFromIndex() < index) index = this.getConcatFromIndex(); + if (this.getArgSettings().size() <= index) return false; + return true; + } + + // The actual setting. + public ArgSetting addArg(ArgSetting setting, boolean concatFromHere) + { + // Concat safety. + if (this.isUsingConcatFrom()) + { + throw new IllegalStateException("You can't add args if a prior one concatenates."); + } + + // Req/optional safety. + int prior = this.getArgSettings().size()-1; + if (this.hasArgSettingForIndex(prior) && this.getArgSetting(prior).isOptional() && setting.isRequired()) + { + throw new IllegalArgumentException("You can't add required args, if a prior one is optional."); + } + + // If false no change is made. + // If true change is made. + this.setUsingConcatFrom(concatFromHere); + + this.getArgSettings().add(setting); + return setting; + } + + // The actual setting without concat. + public ArgSetting addArg(ArgSetting setting) + { + return this.addArg(setting, false); + } + + // All + public ArgSetting addArg(AR reader, boolean requiredFromConsole, String name, String def, boolean concatFromHere) + { + return this.addArg(ArgSetting.of(reader, requiredFromConsole, name, def), concatFromHere); + } + + // Without concat. + public ArgSetting addArg(AR reader, boolean requiredFromConsole, String name, String def) + { + return this.addArg(reader, requiredFromConsole, name, def, false); + } + + // Without reqFromConsole. + public ArgSetting addArg(AR reader, String name, String def, boolean concatFromHere) + { + return this.addArg(reader, false, name, def, concatFromHere); + } + + // Without default. + public ArgSetting addArg(AR reader, boolean requiredFromConsole, String name, boolean concatFromHere) + { + return this.addArg(reader, requiredFromConsole, name, null, concatFromHere); + } + + // Without concat & reqFromConsole. + public ArgSetting addArg(AR reader, String name, String def) + { + return this.addArg(reader, false, name, def, false); + } + + // Without concat and default. + public ArgSetting addArg(AR reader, boolean requiredFromConsole, String name) + { + return this.addArg(reader, requiredFromConsole, name, null, false); + } + + // Without reqFromConsole and default. + public ArgSetting addArg(AR reader, String name, boolean concatFromHere) + { + return this.addArg(reader, false, name, null, concatFromHere); + } + + // Without concat, reqFromConsole and default. + public ArgSetting addArg(AR reader, String name) + { + return this.addArg(reader, false, name, null, false); + } + // FIELD: requiredArgs // These args must always be sent - protected List requiredArgs; - public List getRequiredArgs() { return this.requiredArgs; } - public void setRequiredArgs(List requiredArgs) { this.requiredArgs = requiredArgs; } + @Deprecated protected List requiredArgs; + @Deprecated public List getRequiredArgs() { return this.requiredArgs; } + @Deprecated public void setRequiredArgs(List requiredArgs) { this.requiredArgs = requiredArgs; } - public void addRequiredArg(String arg) { this.requiredArgs.add(arg); } + @Deprecated public void addRequiredArg(String arg) { this.requiredArgs.add(arg); } // FIELD: optionalArgs // These args are optional - protected Map optionalArgs; - public Map getOptionalArgs() { return this.optionalArgs; } - public void setOptionalArgs(Map optionalArgs) { this.optionalArgs = optionalArgs; } + @Deprecated protected Map optionalArgs; + @Deprecated public Map getOptionalArgs() { return this.optionalArgs; } + @Deprecated public void setOptionalArgs(Map optionalArgs) { this.optionalArgs = optionalArgs; } - public void addOptionalArg(String arg, String def) { this.optionalArgs.put(arg, def); } + @Deprecated public void addOptionalArg(String arg, String def) { this.optionalArgs.put(arg, def); } // FIELD: errorOnToManyArgs - // Should an error be thrown if "to many" args are sent. + // Should an error be thrown if "too many" args are sent. protected boolean errorOnToManyArgs; - public boolean getErrorOnToManyArgs() { return this.errorOnToManyArgs; } - public void setErrorOnToManyArgs(boolean val) { this.errorOnToManyArgs = val; } + public boolean isGivingErrorOnTooManyArgs() { return this.errorOnToManyArgs; } + public void setErrorOnTooManyArgs(boolean val) { this.errorOnToManyArgs = val; } + @Deprecated public boolean getErrorOnToManyArgs() { return this.isGivingErrorOnTooManyArgs(); } + @Deprecated public void setErrorOnToManyArgs(boolean val) { this.setErrorOnTooManyArgs(val); } + + // FIELD concatFrom + // From which arg should the be concatenated. + protected boolean usingConcatFrom; + public boolean isUsingConcatFrom() { return this.usingConcatFrom; } + public void setUsingConcatFrom(boolean usingConcatFrom) { this.usingConcatFrom = usingConcatFrom; } + + public int getConcatFromIndex() { return this.getArgSettings().size() -1; } // FIELD: usingTokenizer // Should the arguments be parsed considering quotes and backslashes and such? @@ -283,11 +402,65 @@ public class MassiveCommand public List getCommandChain() { return this.commandChain; } public void setCommandChain(List commandChain) { this.commandChain = commandChain; } + public MassiveCommand getParentCommand() + { + List commandChain = this.getCommandChain(); + if (commandChain == null) return null; + if (commandChain.isEmpty()) return null; + return commandChain.get(commandChain.size()-1); + } + + public boolean hasParentCommand() { return this.getParentCommand() != null; } + + // FIELD: nextArg + // The index of the next arg to read. + public int nextArg; + // FIELDS: sender, me, senderIsConsole public CommandSender sender; public Player me; public boolean senderIsConsole; + // -------------------------------------------- // + // BACKWARDS COMPAT + // -------------------------------------------- // + + public boolean isUsingNewArgSystem() + { + return ! this.getArgSettings().isEmpty(); + } + + public int getRequiredArgsAmountFor(CommandSender sender) + { + if ( ! this.isUsingNewArgSystem()) return this.getRequiredArgs().size(); + + int ret = 0; + for (ArgSetting setting : this.getArgSettings()) + { + if (setting.isRequiredFor(sender)) ret++; + } + + return ret; + } + + public int getOptionalArgsAmountFor(CommandSender sender) + { + if ( ! this.isUsingNewArgSystem()) return this.getOptionalArgs().size(); + + int ret = 0; + for (ArgSetting setting : this.getArgSettings()) + { + if (setting.isOptionalFor(sender)) ret++; + } + + return ret; + } + + public int getAllArgsAmountFor(CommandSender sender) + { + return this.getOptionalArgsAmountFor(sender) + this.getRequiredArgsAmountFor(sender); + } + // -------------------------------------------- // // CONSTRUCTORS AND EXECUTOR // -------------------------------------------- // @@ -298,12 +471,16 @@ public class MassiveCommand this.aliases = new ArrayList(); + this.argSettings = new ArrayList(); + this.requiredArgs = new ArrayList(); this.optionalArgs = new LinkedHashMap(); this.requirements = new ArrayList(); this.errorOnToManyArgs = true; + this.usingConcatFrom = false; + this.usingTokenizer = true; this.usingSmartQuotesRemoval = true; @@ -316,6 +493,7 @@ public class MassiveCommand // The commandChain is a list of the parent command chain used to get to this command. public void execute(CommandSender sender, List args, List commandChain) { + args = this.applyConcatFrom(args); this.setArgs(args); this.setCommandChain(commandChain); @@ -335,6 +513,7 @@ public class MassiveCommand try { // Set Sender Variables + this.nextArg = 0; this.sender = sender; this.senderIsConsole = true; this.me = null; @@ -361,6 +540,7 @@ public class MassiveCommand finally { // Unset Sender Variables + this.nextArg = 0; this.sender = null; this.me = null; this.unsetSenderVars(); @@ -381,6 +561,22 @@ public class MassiveCommand execute(sender, args, new ArrayList()); } + public List applyConcatFrom(List args) + { + if ( ! this.isUsingConcatFrom()) return args; + + List ret = new MassiveList(); + final int maxIdx = Math.min(this.getConcatFromIndex(), args.size()); + ret.addAll(args.subList(0, maxIdx)); // The args that should not be concatenated. + + if (args.size() > maxIdx) + { + ret.add(Txt.implode(args.subList(maxIdx, args.size()), " ")); + } + + return ret; + } + // This is where the command action is performed. public void perform() throws MassiveException { @@ -424,60 +620,61 @@ public class MassiveCommand { for (Req req : this.getRequirements()) { - if ( ! req.apply(sender, this)) + if (req.apply(sender, this)) continue; + + if (informSenderIfNot) { - if (informSenderIfNot) - { - this.msg(req.createErrorMessage(sender, this)); - } - return false; + Mixin.messageOne(sender, req.createErrorMessage(sender, this)); } + return false; } return true; } public boolean isArgsValid(List args, CommandSender sender) { - if (args.size() < this.getRequiredArgs().size()) + if (args.size() < this.getRequiredArgsAmountFor(sender)) { if (sender != null) { - msg(Lang.COMMAND_TOO_FEW_ARGS); - sendMessage(this.getUseageTemplate()); + Mixin.msgOne(sender, Lang.COMMAND_TOO_FEW_ARGS); + Mixin.messageOne(sender, this.getUseageTemplate()); } return false; } - if (args.size() > this.getRequiredArgs().size() + this.getOptionalArgs().size() && this.getErrorOnToManyArgs()) + // We don't need to take argConcatFrom into account. Because at this point the args + // are already concatenated and thus cannot be too many. + if (args.size() > this.getAllArgsAmountFor(sender) && this.isGivingErrorOnTooManyArgs()) { if (sender != null) { if (this.isParentCommand()) { - String arg = this.arg(0); + String arg = args.get(0); // Try Levenshtein List matches = this.getSimilarSubcommandAliases(arg, this.getMaxLevenshteinDistanceForArg(arg)); - msg(Lang.COMMAND_NO_SUCH_SUB, this.getUseageTemplate() + " " + arg); + Mixin.msgOne(sender, Lang.COMMAND_NO_SUCH_SUB, this.getUseageTemplate() + " " + arg); if ( ! matches.isEmpty()) { String suggest = Txt.parse(Txt.implodeCommaAnd(matches, ", ", " or ")); - msg(Lang.COMMAND_SUGGEST_SUB, this.getUseageTemplate() + " " + suggest); + Mixin.msgOne(sender, Lang.COMMAND_SUGGEST_SUB, this.getUseageTemplate() + " " + suggest); } else { - msg(Lang.COMMAND_GET_HELP, this.getUseageTemplate()); + Mixin.msgOne(sender, Lang.COMMAND_GET_HELP, this.getUseageTemplate()); } } else { // Get the too many string slice - List theTooMany = args.subList(this.getRequiredArgs().size() + this.optionalArgs.size(), args.size()); - msg(Lang.COMMAND_TOO_MANY_ARGS, Txt.implodeCommaAndDot(theTooMany, Txt.parse("%s"), Txt.parse(", "), Txt.parse(" and "), "")); - msg(Lang.COMMAND_TOO_MANY_ARGS2); - sendMessage(this.getUseageTemplate()); + List theTooMany = args.subList(this.getAllArgsAmountFor(sender), args.size()); + Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_ARGS, Txt.implodeCommaAndDot(theTooMany, Txt.parse("%s"), Txt.parse(", "), Txt.parse(" and "), "")); + Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_ARGS2); + Mixin.messageOne(sender, this.getUseageTemplate()); } } return false; @@ -495,12 +692,14 @@ public class MassiveCommand public List getSimilarAliases(String arg, int maxLevenshteinDistance) { + if (arg == null) return Collections.emptyList(); arg = arg.toLowerCase(); List matches = new ArrayList(); for (String alias : this.getAliases()) { + if (alias == null) continue; String aliaslc = alias.toLowerCase(); int distance = StringUtils.getLevenshteinDistance(arg, aliaslc); if (distance > maxLevenshteinDistance) continue; @@ -511,6 +710,8 @@ public class MassiveCommand public List getSimilarSubcommandAliases(String arg, int maxLevenshteinDistance) { + if (arg == null) return Collections.emptyList(); + // Try Levenshtein List matches = new ArrayList(); @@ -579,26 +780,7 @@ public class MassiveCommand first = false; } - List args = new ArrayList(); - - for (String requiredArg : this.getRequiredArgs()) - { - args.add("<"+requiredArg+">"); - } - - for (Entry optionalArg : this.getOptionalArgs().entrySet()) - { - String val = optionalArg.getValue(); - if (val == null) - { - val = ""; - } - else - { - val = "="+val; - } - args.add("["+optionalArg.getKey()+val+"]"); - } + List args = this.getArgUseagesFor(sender); if (args.size() > 0) { @@ -617,6 +799,41 @@ public class MassiveCommand return ret.toString(); } + protected List getArgUseagesFor(CommandSender sender) + { + List ret = new MassiveList(); + if (this.isUsingNewArgSystem()) + { + for (ArgSetting setting : this.getArgSettings()) + { + ret.add(setting.getUseageTemplateDisplayFor(sender)); + } + } + else + { + for (String requiredArg : this.getRequiredArgs()) + { + ret.add("<" + requiredArg + ">"); + } + + for (Entry optionalArg : this.getOptionalArgs().entrySet()) + { + String val = optionalArg.getValue(); + if (val == null) + { + val = ""; + } + else + { + val = "=" + val; + } + ret.add("[" + optionalArg.getKey() + val + "]"); + } + } + + return ret; + } + public String getUseageTemplate(List commandChain, boolean addDesc, boolean onlyFirstAlias) { return getUseageTemplate(commandChain, addDesc, onlyFirstAlias, null); @@ -637,6 +854,92 @@ public class MassiveCommand return getUseageTemplate(false); } + // -------------------------------------------- // + // TAB + // -------------------------------------------- // + + public List getTabCompletions(List args, CommandSender sender) + { + if (args == null) throw new IllegalArgumentException("args was mull"); + if (sender == null) throw new IllegalArgumentException("sender was null"); + if (args.isEmpty()) throw new IllegalArgumentException("args was empty"); + + if (this.isParentCommand()) + { + return this.getTabCompletionsSub(args, sender); + } + else if ( ! this.isUsingNewArgSystem()) + { + return Collections.emptyList(); + } + else + { + return this.getTabCompletionsArg(args, sender); + } + } + + protected List getTabCompletionsSub(List args, CommandSender sender) + { + // If this isn't the last argument... + if (args.size() != 1) + { + // ...we will ask the subcommand for tab completions. + MassiveCommand cmd = this.getSubCommand(args.get(0)); + if (cmd == null) return Collections.emptyList(); + args.remove(0); + return cmd.getTabCompletions(args, sender); + } + + // ...else check the subcommands. + List ret = new ArrayList(); + String token = args.get(args.size()-1).toLowerCase(); + for (MassiveCommand sub : this.getSubCommands()) + { + if ( ! this.shouldSenderTabCompleteSub(sender, sub)) continue; + ret.addAll(Txt.getStartsWithIgnoreCase(sub.getAliases(), token)); + } + + return addSpaceAtEnd(ret); + } + + protected boolean shouldSenderTabCompleteSub(CommandSender sender, MassiveCommand sub) + { + if ( ! sub.isVisibleTo(sender)) return false; + if ( ! sub.isRequirementsMet(sender, false)) return false; + return true; + } + + protected List getTabCompletionsArg(List args, CommandSender sender) + { + args = this.applyConcatFrom(args); + + int index = args.size() - 1; + if ( ! this.hasArgSettingForIndex(index)) return Collections.emptyList(); + AR reader = this.getArgReader(index); + + List ret = reader.getTabListFiltered(sender, args.get(index)); + + // If the reader allows space after tab and this is not the last possible argument... + if (reader.allowSpaceAfterTab() && this.hasArgSettingForIndex(args.size())) + { + // ...we will sometimes add a space at the end. Depending on list size. + ret = addSpaceAtEnd(ret); + } + + return ret; + } + + protected static List addSpaceAtEnd(List suggestions) + { + if (suggestions.size() != 1) return suggestions; + + // Get the suggestion. + String suggestion = suggestions.get(0); + // Add the space at the end. + suggestion += ' '; + return Collections.singletonList(suggestion); + } + // -------------------------------------------- // // MESSAGE SENDING HELPERS // -------------------------------------------- // @@ -679,27 +982,101 @@ public class MassiveCommand // ARGUMENT READERS // -------------------------------------------- // - // argIsSet + // Util public boolean argIsSet(int idx) { - return ! (this.args.size() < idx+1); + if (idx < 0) return false; + if (idx+1 > this.getArgs().size()) return false; + return true; } - // arg - - public String arg(int idx) + public boolean argIsSet() { + return this.argIsSet(nextArg); + } + + // Implicit index + + public String arg() + { + return this.argAt(nextArg); + } + + public Object readArg() throws MassiveException + { + return this.readArgAt(nextArg); + } + + public Object readArg(Object defaultNotSet) throws MassiveException + { + return this.readArgAt(nextArg, defaultNotSet); + } + + // Index logic + + public String argAt(int idx) + { + nextArg = idx + 1; if ( ! this.argIsSet(idx)) return null; return this.getArgs().get(idx); } + public Object readArgAt(int idx) throws MassiveException + { + if ( ! this.hasArgSettingForIndex(idx)) throw new IllegalArgumentException(idx + " is out of range. ArgSettings size: " + this.getArgSettings().size()); + String str = this.argAt(idx); + return this.readArgFrom(str, this.getArgSettings().get(idx).getReader()); + } + + @SuppressWarnings("unchecked") + public Object readArgAt(int idx, Object defaultNotSet) throws MassiveException + { + if ( ! this.hasArgSettingForIndex(idx)) throw new IllegalArgumentException(idx + " is out of range. ArgSettings size: " + this.getArgSettings().size()); + String str = this.argAt(idx); + return this.readArgFrom(str, (AR)this.getArgSettings().get(idx).getReader(), defaultNotSet); + } + + // Core Logic + + public T readArgFrom(AR argReader) throws MassiveException + { + if (argReader == null) throw new IllegalArgumentException("argReader is null"); + return this.readArgFrom(null, argReader); + } + + public T readArgFrom(String str, AR argReader) throws MassiveException + { + if (argReader == null) throw new IllegalArgumentException("argReader is null"); + return argReader.read(str, this.sender); + } + + public T readArgFrom(String str, AR argReader, T defaultNotSet) throws MassiveException + { + if (str == null) return defaultNotSet; + return this.readArgFrom(str, argReader); + } + + // -------------------------------------------- // + // OLD ARGUMENT READERS + // -------------------------------------------- // + + // arg + + @Deprecated + public String arg(int idx) + { + return this.argAt(idx); + } + + @Deprecated public T arg(int idx, AR argReader) throws MassiveException { String str = this.arg(idx); return this.arg(str, argReader); } + @Deprecated public T arg(int idx, AR argReader, T defaultNotSet) throws MassiveException { String str = this.arg(idx); @@ -708,6 +1085,7 @@ public class MassiveCommand // argConcatFrom + @Deprecated public String argConcatFrom(int idx) { if ( ! this.argIsSet(idx)) return null; @@ -717,12 +1095,14 @@ public class MassiveCommand return Txt.implode(this.getArgs().subList(from, to), " "); } + @Deprecated public T argConcatFrom(int idx, AR argReader) throws MassiveException { String str = this.argConcatFrom(idx); return this.arg(str, argReader); } + @Deprecated public T argConcatFrom(int idx, AR argReader, T defaultNotSet) throws MassiveException { String str = this.argConcatFrom(idx); @@ -731,16 +1111,19 @@ public class MassiveCommand // Core & Other + @Deprecated public T arg(AR argReader) throws MassiveException { return this.arg(null, argReader); } + @Deprecated public T arg(String str, AR argReader) throws MassiveException { return argReader.read(str, this.sender); } + @Deprecated public T arg(String str, AR argReader, T defaultNotSet) throws MassiveException { if (str == null) return defaultNotSet; diff --git a/src/com/massivecraft/massivecore/cmd/MassiveCoreBukkitCommand.java b/src/com/massivecraft/massivecore/cmd/MassiveCoreBukkitCommand.java index bb77c77f..acbe522a 100644 --- a/src/com/massivecraft/massivecore/cmd/MassiveCoreBukkitCommand.java +++ b/src/com/massivecraft/massivecore/cmd/MassiveCoreBukkitCommand.java @@ -1,18 +1,15 @@ package com.massivecraft.massivecore.cmd; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.Set; -import java.util.TreeSet; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.plugin.Plugin; -import com.massivecraft.massivecore.mixin.Mixin; -import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; public class MassiveCoreBukkitCommand extends Command implements PluginIdentifiableCommand @@ -21,7 +18,7 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia // FIELDS // -------------------------------------------- // - private final MassiveCommand massiveCommand; + protected final MassiveCommand massiveCommand; public MassiveCommand getMassiveCommand() { return this.massiveCommand; } // -------------------------------------------- // @@ -46,7 +43,7 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia @Override public Plugin getPlugin() { - return massiveCommand.getRegisteredPlugin(); + return this.getMassiveCommand().getRegisteredPlugin(); } // -------------------------------------------- // @@ -57,26 +54,26 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia public boolean execute(CommandSender sender, String commandLabel, String[] args) { List argList = this.createArgList(args); - this.massiveCommand.execute(sender, argList); + this.getMassiveCommand().execute(sender, argList); return true; } public List createArgList(String[] args) { List ret; - if (this.massiveCommand.isUsingTokenizer()) + if (this.getMassiveCommand().isUsingTokenizer()) { ret = Txt.tokenizeArguments(Txt.implode(args, " ")); } else { - ret = new ArrayList(Arrays.asList(args)); + ret = MUtil.list(args); } - if (this.massiveCommand.isUsingSmartQuotesRemoval()) + if (this.getMassiveCommand().isUsingSmartQuotesRemoval()) { List oldArgList = ret; - ret = new ArrayList(); + ret = new ArrayList(oldArgList.size()); for (String arg : oldArgList) { ret.add(Txt.removeSmartQuotes(arg)); @@ -89,89 +86,58 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia // OVERRIDE: TAB COMPLETE // -------------------------------------------- // + // NOTE: There is some Vanilla bugs, described here. + + // Test 1. These bugs occur when using commands provided by Bukkit plugins. + // Test 2. These bugs do also occur when using BungeeCoord commands. + // BungeeCoord commands are handled MUCH differently than Bukkit commands. + // In fact BungeeCoord commands are not related to Bukkit at all. + // Test 3. These bugs do also occur in plain singleplayer vanilla MineCraft. + + // These notes suggests that this is a client side bug and NOT a server side one. + + // BUG 1. Tab complete to first common prefix then normal. + // Desc: Tab completes to the first common prefix of the available completions + // after that it will tab complete normally. + // Happens when: + // 1. All possible suggestions has the same common prefix. + // 2. The common prefix must be of at least two characters, + // 3. There is more than one suggestion. + // 4. Tab completing from the end of the chat bar. (There is only text to the left) + // 5. The user typed in the beginning of the arg to tab complete. + + // BUG 2. Tab complete to first common prefix then nothing. + // Desc: Tab completes to the first common prefix of the available completions + // after that it will refuse to tab complete anymore. + // Happens when: + // 1. All possible suggestions has the same common prefix. + // 3. There is more than one suggestion. + // 4. Tab completing from the middle of the chat bar. (There text on both sides) + // 5. The user typed in the beginning of the arg to tab complete. + @Override - public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException + public List tabComplete(CommandSender sender, String alias, String[] rawArgs) throws IllegalArgumentException { - Set ret = new TreeSet(String.CASE_INSENSITIVE_ORDER); - String tokenlc = args[args.length - 1].toLowerCase(); + // The JavaDocs for Command says these checks will be made. + // So we should follow that contract. + if (sender == null) throw new IllegalArgumentException("sender must not be null"); + if (rawArgs == null) throw new IllegalArgumentException("args must not be null"); + if (alias == null) throw new IllegalArgumentException("args must not be null"); - // First we need a command to find the subcommands in. - MassiveCommand cmd = this.getSubCommand(args, massiveCommand); - - // So if we found a command, and it has subcommands - // we will suggest the aliases instead of senders. - if (cmd != null && cmd.getSubCommands().size() > 0) - { - // If we compiled in Java 8, I could have used streams :( - for (MassiveCommand sub : cmd.getSubCommands()) - { - if ( ! sub.isVisibleTo(sender)) continue; - for (String subAlias : sub.getAliases()) - { - if ( ! subAlias.toLowerCase().startsWith(tokenlc)) continue; - ret.add(subAlias); - } - } - - // return, so senders is not suggested. - return new ArrayList(ret); - } - - // If subcommands didn't work, we will try with senders. - List superRet = super.tabComplete(sender, alias, args); - if (args.length == 0) return superRet; - - ret.addAll(superRet); - - // Add names of all online senders that match and isn't added yet. - for (String senderName : IdUtil.getOnlineNames()) + List args = new MassiveList(); + // When several spaces are next to each other, empty elements in the array will occur. + // To avoid such whitespace we do the following + // NOTE: The last arg can be empty, and will be in many cases. + for (int i = 0; i < rawArgs.length-1; i++ ) { - if (!senderName.toLowerCase().startsWith(tokenlc)) continue; - if (!Mixin.canSee(sender, senderName)) continue; - ret.add(senderName); + String str = rawArgs[i]; + if (str == null) continue; + if (str.isEmpty()) continue; + args.add(str); } - - return new ArrayList(ret); + // Here we add the last element. + args.add(rawArgs[rawArgs.length-1]); + return this.getMassiveCommand().getTabCompletions(args, sender); } - // -------------------------------------------- // - // PRIVATE: TAB COMPLETE - // -------------------------------------------- // - - private MassiveCommand getSubCommand(String[] args, MassiveCommand cmd) - { - // First we look in the basecommand, then in its subcommands, - // and the next subcommand and so on. - // Until we run out of args or no subcommand is found. - for (int i = 0; i < args.length-1; i++) - { - String arg = args[i]; - // If no subcommand is found we will not look further. - if (cmd == null) break; - - // We have to loop through the subcommands to see if any match the arg. - // if none exists we will get null, thus we break in case of null. - cmd = this.getSubCommand(arg, cmd); - } - - return cmd; - } - - private MassiveCommand getSubCommand(String arg, MassiveCommand cmd) - { - if (cmd == null || arg == null) return null; - - // We will look in all its subcommands - for (MassiveCommand sub : cmd.getSubCommands()) - { - // and in all those look for an alias that matches - for (String subAlias : sub.getAliases()) - { - // If it matched we had success - if (subAlias.equalsIgnoreCase(arg)) return sub; - } - } - return null; - } - } diff --git a/src/com/massivecraft/massivecore/cmd/VersionCommand.java b/src/com/massivecraft/massivecore/cmd/VersionCommand.java index 412a7e24..cc17ef5d 100644 --- a/src/com/massivecraft/massivecore/cmd/VersionCommand.java +++ b/src/com/massivecraft/massivecore/cmd/VersionCommand.java @@ -1,5 +1,6 @@ package com.massivecraft.massivecore.cmd; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -22,19 +23,19 @@ public class VersionCommand extends MassiveCommand // FIELDS // -------------------------------------------- // - private final Plugin plugin; + protected final Plugin plugin; public Plugin getPlugin() { return this.plugin; } // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public VersionCommand(Plugin plugin, String permissionName, Collection aliases) + public VersionCommand(Plugin plugin, String permissionName, String... aliases) { - this(plugin, permissionName, aliases.toArray(new String[0])); + this(plugin, permissionName, Arrays.asList(aliases)); } - public VersionCommand(Plugin plugin, String permissionName, String... aliases) + public VersionCommand(Plugin plugin, String permissionName, Collection aliases) { this.plugin = plugin; diff --git a/src/com/massivecraft/massivecore/cmd/arg/AMain.java b/src/com/massivecraft/massivecore/cmd/arg/AMain.java deleted file mode 100644 index 3f048690..00000000 --- a/src/com/massivecraft/massivecore/cmd/arg/AMain.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.massivecraft.massivecore.cmd.arg; - -import java.util.ArrayList; -import java.util.List; - -public class AMain -{ - // This class is temporarily here for testing. - public static void main(String[] args) - { - try - { - System.out.println("start"); - List input = new ArrayList(); - - input.add("1"); - - for(String str : ARAbstract.prepareForSpaces(input)) - System.out.println("\"" + str + "\""); - System.out.println("end"); - } - catch(Throwable t) - { - t.printStackTrace(); - } - } - -} diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARAbstract.java b/src/com/massivecraft/massivecore/cmd/arg/ARAbstract.java index 779a0614..2bb36bdc 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARAbstract.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARAbstract.java @@ -87,7 +87,8 @@ public abstract class ARAbstract implements AR { // Filter them to start with what the user typed in. Collection raw = this.getTabList(sender, arg); - if (raw == null) return Collections.emptyList(); + if (raw == null || raw.isEmpty()) return Collections.emptyList(); + List ret = Txt.getStartsWithIgnoreCase(raw, arg); // Here we do a lot of things related to spaces. @@ -103,8 +104,7 @@ public abstract class ARAbstract implements AR // PRIVATE: TAB COMPLETE CALCULATIONS // -------------------------------------------- // - // Should be private. But isn't currently for testing purposes. - static List prepareForSpaces(List suggestions) + public static List prepareForSpaces(List suggestions) { List> suggestionParts = getParts(suggestions); @@ -199,32 +199,5 @@ public abstract class ARAbstract implements AR return ret; } - - //TODO: Move this code somewhere else. - // Currently just kept here. - /* - private List addSpaceAtEnd(MassiveCommand command, int argNumber, List suggestions) - { - // This ArgReader must allow space at the end. - if ( ! this.allowSpaceAfterTab()) return suggestions; - // There must be exactly one suggestion. - if (suggestions.size() != 1) return suggestions; - - // The maximum size of args to pass in. - int argsSize = command.getOptionalArgs().size() + command.getRequiredArgs().size(); - // If it accepts infinite arguments, just make it as high as possible. - if (command.getErrorOnToManyArgs()) argsSize = Integer.MAX_VALUE; - argsSize--; // It now becomes one smaller, so the size matches index. - - // So if this was the last arg meaning the user can't to type more in - // We will just stop here. - if (argNumber >= argsSize) return suggestions; - - // Get the suggestion. - String suggestion = suggestions.get(0); - // Add the space at the end. - suggestion += " "; - return new MassiveCoreSingleValueList(suggestion); - }*/ } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARAbstractSelect.java b/src/com/massivecraft/massivecore/cmd/arg/ARAbstractSelect.java index 7240fdea..44574783 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARAbstractSelect.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARAbstractSelect.java @@ -34,12 +34,17 @@ public abstract class ARAbstractSelect extends ARAbstract @Override public T read(String arg, CommandSender sender) throws MassiveException { - T result = this.select(arg, sender); - + T result = this.select(arg, sender); if (result != null) return result; - MassiveException exception = new MassiveException(); - exception.addMsg("No %s matches \"%s\".", this.getTypeName(), arg); + MassiveException exception = createExceptionForInvalidArg(arg, sender); + throw exception; + } + + public MassiveException createExceptionForInvalidArg(String arg, CommandSender sender) + { + MassiveException ret = new MassiveException(); + ret.addMsg("No %s matches \"%s\".", this.getTypeName(), arg); if (this.canList(sender)) { @@ -50,17 +55,19 @@ public abstract class ARAbstractSelect extends ARAbstract if (names.isEmpty()) { - exception.addMsg("Note: There is no %s available.", this.getTypeName()); + ret.addMsg("Note: There is no %s available.", this.getTypeName()); } - else if ( ! matches.isEmpty() && matches.size() < LIST_COUNT_MAX) + else if ( ! matches.isEmpty() && matches.size() <= LIST_COUNT_MAX) { - // For some reason the arguments doesn't get parsed. - String suggest = Txt.parse(Txt.implodeCommaAnd(matches, ", ", " or ")); - exception.addMsg("Did you mean %s?", suggest); + String format = Txt.parse("%s"); + String comma = Txt.parse(", "); + String and = Txt.parse(" or "); + String dot = Txt.parse("?"); + ret.addMsg("Did you mean %s", Txt.implodeCommaAndDot(matches, format, comma, and, dot)); } else if (names.size() > LIST_COUNT_MAX) { - exception.addMsg("More than %d alternatives available.", LIST_COUNT_MAX); + ret.addMsg("More than %d alternatives available.", LIST_COUNT_MAX); } else { @@ -68,11 +75,10 @@ public abstract class ARAbstractSelect extends ARAbstract String comma = Txt.parse(", "); String and = Txt.parse(" or "); String dot = Txt.parse("."); - exception.addMsg("Use %s", Txt.implodeCommaAndDot(names, format, comma, and, dot)); + ret.addMsg("Use %s", Txt.implodeCommaAndDot(names, format, comma, and, dot)); } } - - throw exception; + return ret; } public List getMatchingAltNames(String arg, CommandSender sender, int maxLevenshteinDistance) diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARAll.java b/src/com/massivecraft/massivecore/cmd/arg/ARAll.java index 8de78487..fbbf379c 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARAll.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARAll.java @@ -1,64 +1,117 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.Collection; -import java.util.List; +import java.util.Collections; import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.collections.MassiveList; -public class ARAll extends ARAbstract> +public final class ARAll { // -------------------------------------------- // - // FIELDS + // INSTANCE & CONSTRUCT // -------------------------------------------- // - private ARAllAble innerArgReader; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public ARAll(ARAllAble inner) + @SuppressWarnings("unchecked") + public static AR> get(AR inner) { - if (inner == null) throw new IllegalArgumentException("innerArgReader musn't be null"); - this.innerArgReader = inner; + if (inner instanceof ARCollection) return new ARAllCollection((ARCollection>) inner); + if (inner instanceof ARAllAble) return new ARAllDefault((ARAllAble) inner); + throw new IllegalArgumentException("innerArgReader must be an instance of either ARCollection or ARAllAble"); } // -------------------------------------------- // - // OVERRIDE + // AR ALL DEFAULT // -------------------------------------------- // - @Override - public String getTypeName() + private static class ARAllDefault extends ARWrapper> { - return innerArgReader.getTypeName(); + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected ARAllAble innerArgReader; + @Override public ARAllAble getInnerArgReader() { return this.innerArgReader; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ARAllDefault(ARAllAble inner) + { + if (inner == null) throw new IllegalArgumentException("innerArgReader musn't be null"); + this.innerArgReader = inner; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Collection read(String arg, CommandSender sender) throws MassiveException + { + if ("all".equalsIgnoreCase(arg)) return getInnerArgReader().getAll(sender); + + T innerRet = getInnerArgReader().read(arg, sender); + return Collections.singletonList(innerRet); + } + + @Override + public boolean isValid(String arg, CommandSender sender) + { + return "all".equalsIgnoreCase(arg) || this.getInnerArgReader().isValid(arg, sender); + } + } - @Override - public Collection read(String arg, CommandSender sender) throws MassiveException - { - if ("all".equalsIgnoreCase(arg)) return innerArgReader.getAll(); - - T innerRet = innerArgReader.read(arg, sender); - - List ret = new MassiveList(); - ret.add(innerRet); - - return ret; - } + // -------------------------------------------- // + // AR ALL COLLECTION + // -------------------------------------------- // - @Override - public boolean isValid(String arg, CommandSender sender) + private static class ARAllCollection extends ARWrapper> { - return "all".equalsIgnoreCase(arg) || innerArgReader.isValid(arg, sender); - } + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected ARCollection> innerArgReader; + @Override public ARCollection> getInnerArgReader() { return this.innerArgReader; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public ARAllCollection(ARCollection> inner) + { + if (inner == null) throw new IllegalArgumentException("innerArgReader musn't be null"); + if ( !(inner.getInnerArgReader() instanceof ARAllAble)) throw new IllegalArgumentException("innerArgReaders innerArgReader must implement ARAllAble"); + this.innerArgReader = inner; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // - @Override - public Collection getTabList(CommandSender sender, String arg) - { - return innerArgReader.getTabList(sender, arg); + @Override + public Collection read(String arg, CommandSender sender) throws MassiveException + { + if ("all".equalsIgnoreCase(arg)) + { + @SuppressWarnings("unchecked") + ARAllAble innersInner = (ARAllAble) getInnerArgReader().getInnerArgReader(); + return innersInner.getAll(sender); + } + + return getInnerArgReader().read(arg, sender); + } + + @Override + public boolean isValid(String arg, CommandSender sender) + { + return "all".equalsIgnoreCase(arg) || this.getInnerArgReader().isValid(arg, sender); + } + } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARAllAble.java b/src/com/massivecraft/massivecore/cmd/arg/ARAllAble.java index 5455b963..b9b381a9 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARAllAble.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARAllAble.java @@ -2,7 +2,9 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.Collection; +import org.bukkit.command.CommandSender; + public interface ARAllAble extends AR { - public Collection getAll(); + public Collection getAll(CommandSender sender); } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARBiome.java b/src/com/massivecraft/massivecore/cmd/arg/ARBiome.java index 68f9c561..ba348a84 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARBiome.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARBiome.java @@ -1,13 +1,14 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import org.bukkit.block.Biome; import org.bukkit.command.CommandSender; -public class ARBiome extends ARAbstractSelect +public class ARBiome extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -27,17 +28,11 @@ public class ARBiome extends ARAbstractSelect for (Biome biome : Biome.values()) { - String biomestr = getComparable(biome.name()); - if (biomestr.equals(arg)) - { - return biome; - } + String biomestr = getComparable(biome); + if (biomestr.equals(arg)) return biome; biomestr = String.valueOf(biome.ordinal()); - if (biomestr.equals(arg)) - { - return biome; - } + if (biomestr.equals(arg)) return biome; } return null; @@ -70,10 +65,23 @@ public class ARBiome extends ARAbstractSelect return ret; } + + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(Biome.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // + public static String getComparable(Biome biome) + { + if (biome == null) return null; + return getComparable(biome.name()); + } + public static String getComparable(String string) { if (string == null) return null; diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARChatColor.java b/src/com/massivecraft/massivecore/cmd/arg/ARChatColor.java index 498d1bf9..8580a23c 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARChatColor.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARChatColor.java @@ -1,13 +1,14 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -public class ARChatColor extends ARAbstractSelect +public class ARChatColor extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -27,9 +28,8 @@ public class ARChatColor extends ARAbstractSelect for (ChatColor cc : ChatColor.values()) { - String ccstr = getComparable(cc.name()); - if ( ! ccstr.equals(arg)) continue; - return cc; + String ccstr = getComparable(cc); + if (ccstr.equals(arg)) return cc; } return null; @@ -42,7 +42,7 @@ public class ARChatColor extends ARAbstractSelect for (ChatColor cc : ChatColor.values()) { - ret.add(cc.toString() + getComparable(cc.name())); + ret.add(cc.toString() + getComparable(cc)); } return ret; @@ -55,16 +55,28 @@ public class ARChatColor extends ARAbstractSelect for (ChatColor cc : ChatColor.values()) { - ret.add(getComparable(cc.name())); + ret.add(getComparable(cc)); } return ret; } + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(ChatColor.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // + public static String getComparable(ChatColor color) + { + if (color == null) return null; + return getComparable(color.name()); + } + // "DARK_RED" --> "darkred" // "DARK RED" --> "darkred" public static String getComparable(String string) diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARColl.java b/src/com/massivecraft/massivecore/cmd/arg/ARColl.java index 4bd86635..049f0504 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARColl.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARColl.java @@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.store.Coll; -public class ARColl extends ARAbstractSelect> +public class ARColl extends ARAbstractSelect> implements ARAllAble> { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -36,5 +36,11 @@ public class ARColl extends ARAbstractSelect> { return this.altNames(sender); } + + @Override + public Collection> getAll(CommandSender sender) + { + return Coll.getMap().values(); + } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARCollection.java b/src/com/massivecraft/massivecore/cmd/arg/ARCollection.java new file mode 100644 index 00000000..da81498e --- /dev/null +++ b/src/com/massivecraft/massivecore/cmd/arg/ARCollection.java @@ -0,0 +1,38 @@ +package com.massivecraft.massivecore.cmd.arg; + +import java.util.Collection; +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.massivecore.util.Txt; + +public abstract class ARCollection> extends ARWrapper +{ + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + // Because we accept multiple arguments of the same type. + // The passed arg might be more than one. We only want the latest. + return this.getInnerArgReader().getTabList(sender, getLastArg(arg)); + } + + @Override + public List getTabListFiltered(CommandSender sender, String arg) + { + // Because we accept multiple arguments of the same type. + // The passed arg might be more than one. We only want the latest. + return this.getInnerArgReader().getTabListFiltered(sender, getLastArg(arg)); + } + + public static String getLastArg(String str) + { + String[] innerArgs = Txt.REGEX_WHITESPACE.split(str, -1); + return innerArgs[innerArgs.length - 1]; + } + +} diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARDifficulty.java b/src/com/massivecraft/massivecore/cmd/arg/ARDifficulty.java index a6056744..166fc81c 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARDifficulty.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARDifficulty.java @@ -1,5 +1,6 @@ package com.massivecraft.massivecore.cmd.arg; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -9,7 +10,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.util.MUtil; -public class ARDifficulty extends ARAbstractSelect +public class ARDifficulty extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // CONSTANTS @@ -64,5 +65,11 @@ public class ARDifficulty extends ARAbstractSelect { return this.altNames(sender); } + + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(Difficulty.values()); + } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/AREntityType.java b/src/com/massivecraft/massivecore/cmd/arg/AREntityType.java index f276457d..fbd3f843 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/AREntityType.java +++ b/src/com/massivecraft/massivecore/cmd/arg/AREntityType.java @@ -1,13 +1,14 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; -public class AREntityType extends ARAbstractSelect +public class AREntityType extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -56,6 +57,12 @@ public class AREntityType extends ARAbstractSelect return this.altNames(sender); } + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(EntityType.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/cmd/arg/AREnum.java b/src/com/massivecraft/massivecore/cmd/arg/AREnum.java index 3cca0adb..0f6e7664 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/AREnum.java +++ b/src/com/massivecraft/massivecore/cmd/arg/AREnum.java @@ -1,6 +1,7 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -8,7 +9,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.util.Txt; -public class AREnum extends ARAbstractSelect +public class AREnum extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // FIELD @@ -87,12 +88,19 @@ public class AREnum extends ARAbstractSelect return this.altNames(sender); } + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(getEnumValues(clazz)); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // public static T[] getEnumValues(Class clazz) { + if (clazz == null) throw new IllegalArgumentException("passed clazz param is null"); if ( ! clazz.isEnum()) throw new IllegalArgumentException("passed clazz param must be an enum"); T[] ret = clazz.getEnumConstants(); diff --git a/src/com/massivecraft/massivecore/cmd/arg/AREnvironment.java b/src/com/massivecraft/massivecore/cmd/arg/AREnvironment.java index 2bc067d4..4d6d75a0 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/AREnvironment.java +++ b/src/com/massivecraft/massivecore/cmd/arg/AREnvironment.java @@ -1,5 +1,6 @@ package com.massivecraft.massivecore.cmd.arg; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -10,7 +11,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.util.MUtil; -public class AREnvironment extends ARAbstractSelect +public class AREnvironment extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // CONSTANTS @@ -75,6 +76,12 @@ public class AREnvironment extends ARAbstractSelect return ret; } + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(Environment.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARGameMode.java b/src/com/massivecraft/massivecore/cmd/arg/ARGameMode.java index 30ee7702..8ca87f1d 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARGameMode.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARGameMode.java @@ -1,6 +1,7 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -9,7 +10,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.util.Txt; -public class ARGameMode extends ARAbstractSelect +public class ARGameMode extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -57,6 +58,12 @@ public class ARGameMode extends ARAbstractSelect return this.altNames(sender); } + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(GameMode.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARList.java b/src/com/massivecraft/massivecore/cmd/arg/ARList.java index f2445ca6..b7b7244e 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARList.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARList.java @@ -1,21 +1,22 @@ package com.massivecraft.massivecore.cmd.arg; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; - -public class ARList extends ARAbstract> +import com.massivecraft.massivecore.util.Txt; + +public class ARList extends ARCollection> { // -------------------------------------------- // // FIELDS // -------------------------------------------- // - + protected AR elementArgReader; public AR getElementArgReader() { return this.elementArgReader; } + @Override public AR getInnerArgReader() { return this.getElementArgReader(); } // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -33,40 +34,28 @@ public class ARList extends ARAbstract> // -------------------------------------------- // // OVERRIDE - // -------------------------------------------- // - - @Override - public String getTypeName() - { - return elementArgReader.getTypeName(); - } + // -------------------------------------------- // // NOTE: Must be used with argConcatFrom and setErrorOnTooManyArgs(false). @Override public List read(String arg, CommandSender sender) throws MassiveException { - // Split into inner args - String[] elementArgs = arg.split("\\s+"); + // Split into inner args + String[] elementArgs = Txt.REGEX_WHITESPACE.split(arg); // Create Ret - List ret = new ArrayList(); + List ret = new ArrayList(); // For Each for (String elementArg : elementArgs) - { + { E element = this.getElementArgReader().read(elementArg, sender); - ret.add(element); + ret.add(element); } // Return Ret return ret; } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - return this.getElementArgReader().getTabList(sender, arg); - } - + } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARMaterial.java b/src/com/massivecraft/massivecore/cmd/arg/ARMaterial.java index 06c4dc85..bad1a94f 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARMaterial.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARMaterial.java @@ -1,5 +1,6 @@ package com.massivecraft.massivecore.cmd.arg; +import java.util.Arrays; import java.util.Collection; import java.util.Set; import java.util.TreeSet; @@ -9,7 +10,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; -public class ARMaterial extends ARAbstract +public class ARMaterial extends ARAbstract implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -48,5 +49,11 @@ public class ARMaterial extends ARAbstract return ret; } + + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(Material.values()); + } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARNullable.java b/src/com/massivecraft/massivecore/cmd/arg/ARNullable.java index fcf03e0a..664b9556 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARNullable.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARNullable.java @@ -1,14 +1,19 @@ package com.massivecraft.massivecore.cmd.arg; -import java.util.Collection; - import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveException; -public class ARNullable extends ARAbstract +public class ARNullable extends ARWrapper { + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + protected AR innerArgReader; + @Override public AR getInnerArgReader() { return this.innerArgReader; } + // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // @@ -21,38 +26,19 @@ public class ARNullable extends ARAbstract public ARNullable(AR inner) { if (inner == null) throw new IllegalArgumentException("inner param is null"); - this.inner = inner; + this.innerArgReader = inner; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - protected AR inner; - public AR getInner() { return this.inner; } - + // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // - @Override - public String getTypeName() - { - return this.getInner().getTypeName(); - } - @Override public T read(String arg, CommandSender sender) throws MassiveException { if (MassiveCore.NOTHING_REMOVE.contains(arg)) return null; - return this.getInner().read(arg, sender); - } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - return this.getInner().getTabList(sender, arg); + return this.getInnerArgReader().read(arg, sender); } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARPermission.java b/src/com/massivecraft/massivecore/cmd/arg/ARPermission.java index 688ebc60..bc15d2fe 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARPermission.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARPermission.java @@ -10,7 +10,7 @@ import org.bukkit.permissions.Permission; import com.massivecraft.massivecore.MassiveException; -public class ARPermission extends ARAbstract +public class ARPermission extends ARAbstract implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -28,8 +28,7 @@ public class ARPermission extends ARAbstract { for (Permission permission : Bukkit.getPluginManager().getPermissions()) { - if ( ! permission.getName().equals(arg)) continue; - return permission; + if (permission.getName().equals(arg)) return permission; } throw new MassiveException().addMsg("No permission with the name \"%s\" was found.", arg); @@ -48,4 +47,10 @@ public class ARPermission extends ARAbstract return ret; } + @Override + public Collection getAll(CommandSender sender) + { + return Bukkit.getPluginManager().getPermissions(); + } + } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java index cba3a608..e8910cdf 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectType.java @@ -1,5 +1,6 @@ package com.massivecraft.massivecore.cmd.arg; +import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -9,7 +10,7 @@ import org.bukkit.potion.PotionEffectType; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.collections.MassiveList; -public class ARPotionEffectType extends ARAbstractSelect +public class ARPotionEffectType extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -64,7 +65,13 @@ public class ARPotionEffectType extends ARAbstractSelect { return this.altNames(sender); } - + + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(PotionEffectType.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java index 0c749fc1..85ceb8a8 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARPotionEffectWrap.java @@ -54,22 +54,22 @@ public class ARPotionEffectWrap extends ARAbstract } else if (i == 1) { - Integer amplifier = (Integer)part; + Integer amplifier = (Integer) part; ret.setAmplifier(amplifier); } else if (i == 2) { - Integer duration = (Integer)part; + Integer duration = (Integer) part; ret.setDuration(duration); } else if (i == 3) { - Boolean ambient = (Boolean)part; + Boolean ambient = (Boolean) part; ret.setAmbient(ambient); } else if (i == 4) { - Boolean particles = (Boolean)part; + Boolean particles = (Boolean) part; ret.setParticles(particles); } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java b/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java index bd146030..0e99388a 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSenderEntity.java @@ -11,13 +11,13 @@ import com.massivecraft.massivecore.store.SenderColl; import com.massivecraft.massivecore.store.SenderEntity; import com.massivecraft.massivecore.util.IdUtil; -public class ARSenderEntity> extends ARSenderIdAbstract +public class ARSenderEntity> extends ARSenderIdAbstract implements ARAllAble { // -------------------------------------------- // // FIELDS // -------------------------------------------- // - private final SenderColl coll; + protected final SenderColl coll; // -------------------------------------------- // // CONSTRUCT @@ -67,4 +67,10 @@ public class ARSenderEntity> extends ARSenderIdAbstrac return ret; } + @Override + public Collection getAll(CommandSender sender) + { + return coll.getAll(); + } + } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java b/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java index 7ca66919..f3b36670 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSenderIdAbstract.java @@ -15,8 +15,8 @@ public abstract class ARSenderIdAbstract extends ARAbstract // FIELDS // -------------------------------------------- // - private final SenderIdSource source; - private final boolean online; + protected final SenderIdSource source; + protected final boolean online; // -------------------------------------------- // // CONSTRUCT @@ -53,16 +53,13 @@ public abstract class ARSenderIdAbstract extends ARAbstract @Override public T read(String arg, CommandSender sender) throws MassiveException { - // Create Ret - T ret; - // arg --> senderId String senderId = this.getSenderIdFor(arg); - // All of our subclasses return null if senderId is null - // Thus we don't need to check for that being null, but only check ret + // All of our subclasses return null if senderId is null. + // Thus we don't need to check for that being null, but only check ret. - // Populate Ret - ret = this.getResultForSenderId(senderId); + // Create & populate Ret + T ret = this.getResultForSenderId(senderId); if (ret == null) { diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSet.java b/src/com/massivecraft/massivecore/cmd/arg/ARSet.java index 9f429cd6..c0fa7005 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSet.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSet.java @@ -8,17 +8,19 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.mixin.Mixin; - -public class ARSet extends ARAbstract> +import com.massivecraft.massivecore.util.Txt; + +public class ARSet extends ARCollection> { // -------------------------------------------- // // FIELDS // -------------------------------------------- // - - private final AR elementArgReader; + + protected final AR elementArgReader; public AR getElementArgReader() { return this.elementArgReader; } + @Override public AR getInnerArgReader() { return this.getElementArgReader(); } - private final boolean warnOnDuplicates; + protected final boolean warnOnDuplicates; public boolean getWarnOnDuplicate() { return warnOnDuplicates; } // -------------------------------------------- // @@ -51,7 +53,7 @@ public class ARSet extends ARAbstract> public Set read(String arg, CommandSender sender) throws MassiveException { // Split into inner args - String[] elementArgs = arg.split("\\s+"); + String[] elementArgs = Txt.REGEX_WHITESPACE.split(arg); // Create Ret Set ret = new LinkedHashSet(); diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARSound.java b/src/com/massivecraft/massivecore/cmd/arg/ARSound.java index 82ed3f53..816aafd1 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARSound.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARSound.java @@ -1,5 +1,6 @@ package com.massivecraft.massivecore.cmd.arg; +import java.util.Arrays; import java.util.Collection; import java.util.Set; import java.util.TreeSet; @@ -9,7 +10,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.MassiveException; -public class ARSound extends ARAbstract +public class ARSound extends ARAbstract implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -48,7 +49,13 @@ public class ARSound extends ARAbstract return ret; } - + + @Override + public Collection getAll(CommandSender sender) + { + return Arrays.asList(Sound.values()); + } + // -------------------------------------------- // // UTIL // -------------------------------------------- // diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARWorld.java b/src/com/massivecraft/massivecore/cmd/arg/ARWorld.java index a692b36a..bef7ebe7 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARWorld.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARWorld.java @@ -24,11 +24,9 @@ public class ARWorld extends ARAbstract @Override public World read(String arg, CommandSender sender) throws MassiveException { - World ret; - String worldId = ARWorldId.get().read(arg, sender); - ret = Bukkit.getWorld(worldId); + World ret = Bukkit.getWorld(worldId); if (ret == null) { diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARWorldId.java b/src/com/massivecraft/massivecore/cmd/arg/ARWorldId.java index 00f76775..17aa0fc7 100644 --- a/src/com/massivecraft/massivecore/cmd/arg/ARWorldId.java +++ b/src/com/massivecraft/massivecore/cmd/arg/ARWorldId.java @@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.massivecore.mixin.Mixin; -public class ARWorldId extends ARAbstractSelect +public class ARWorldId extends ARAbstractSelect implements ARAllAble { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -69,5 +69,11 @@ public class ARWorldId extends ARAbstractSelect { return Mixin.getVisibleWorldIds(sender); } + + @Override + public Collection getAll(CommandSender sender) + { + return Mixin.getVisibleWorldIds(sender); + } } diff --git a/src/com/massivecraft/massivecore/cmd/arg/ARWrapper.java b/src/com/massivecraft/massivecore/cmd/arg/ARWrapper.java new file mode 100644 index 00000000..c00218e0 --- /dev/null +++ b/src/com/massivecraft/massivecore/cmd/arg/ARWrapper.java @@ -0,0 +1,43 @@ +package com.massivecraft.massivecore.cmd.arg; + +import java.util.Collection; + +import org.bukkit.command.CommandSender; + +public abstract class ARWrapper extends ARAbstract +{ + // -------------------------------------------- // + // ABSTRACT + // -------------------------------------------- // + + public abstract AR getInnerArgReader(); + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getTypeName() + { + return this.getInnerArgReader().getTypeName(); + } + + @Override + public boolean isValid(String arg, CommandSender sender) + { + return this.getInnerArgReader().isValid(arg, sender); + } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + return this.getInnerArgReader().getTabList(sender, arg); + } + + @Override + public boolean allowSpaceAfterTab() + { + return this.getInnerArgReader().allowSpaceAfterTab(); + } + +} diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferAdd.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferAdd.java index bb3cd25e..e3cf6ea6 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferAdd.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferAdd.java @@ -2,7 +2,9 @@ package com.massivecraft.massivecore.cmd.massivecore; import com.massivecraft.massivecore.MassiveCoreEngineVariable; import com.massivecraft.massivecore.MassiveCorePerm; +import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.MassiveCommand; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreBufferAdd extends MassiveCommand @@ -17,8 +19,7 @@ public class CmdMassiveCoreBufferAdd extends MassiveCommand this.addAliases("a", "add"); // Args - this.addRequiredArg("string"); - this.setErrorOnToManyArgs(false); + this.addArg(ARString.get(), "text", true).setDesc("the text to add to your buffer"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.BUFFER_ADD.node)); @@ -29,9 +30,9 @@ public class CmdMassiveCoreBufferAdd extends MassiveCommand // -------------------------------------------- // @Override - public void perform() + public void perform() throws MassiveException { - String string = this.argConcatFrom(0); + String string = (String) this.readArg(); String buffer = MassiveCoreEngineVariable.getBuffer(sender); buffer += string; diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferSet.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferSet.java index bb3007e9..69d14373 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferSet.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferSet.java @@ -2,7 +2,9 @@ package com.massivecraft.massivecore.cmd.massivecore; import com.massivecraft.massivecore.MassiveCoreEngineVariable; import com.massivecraft.massivecore.MassiveCorePerm; +import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.MassiveCommand; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreBufferSet extends MassiveCommand @@ -17,8 +19,7 @@ public class CmdMassiveCoreBufferSet extends MassiveCommand this.addAliases("s", "set"); // Args - this.addRequiredArg("string"); - this.setErrorOnToManyArgs(false); + this.addArg(ARString.get(), "text", true).setDesc("the text to set your buffer to"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.BUFFER_SET.node)); @@ -29,9 +30,9 @@ public class CmdMassiveCoreBufferSet extends MassiveCommand // -------------------------------------------- // @Override - public void perform() + public void perform() throws MassiveException { - String string = this.argConcatFrom(0); + String string = (String) this.readArg(); MassiveCoreEngineVariable.setBuffer(sender, string); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferWhitespace.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferWhitespace.java index c8cceca2..933b21c4 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferWhitespace.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreBufferWhitespace.java @@ -20,7 +20,7 @@ public class CmdMassiveCoreBufferWhitespace extends MassiveCommand this.addAliases("w", "whitespace"); // Args - this.addOptionalArg("times", "1"); + this.addArg(ARInteger.get(), "times", "1").setDesc("the amount of whitespace to add to your buffer"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.BUFFER_WHITESPACE.node)); @@ -33,7 +33,7 @@ public class CmdMassiveCoreBufferWhitespace extends MassiveCommand @Override public void perform() throws MassiveException { - Integer times = this.arg(0, ARInteger.get(), 1); + int times = (Integer) this.readArg(1); String string = Txt.repeat(" ", times); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreCmdurl.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreCmdurl.java index e97d9543..52c37667 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreCmdurl.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreCmdurl.java @@ -9,7 +9,9 @@ import org.bukkit.entity.Player; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCorePerm; +import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.MassiveCommand; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.mixin.Mixin; @@ -27,7 +29,7 @@ public class CmdMassiveCoreCmdurl extends MassiveCommand this.addAliases("cmdurl"); // Args - this.addRequiredArg("url"); + this.addArg(ARString.get(), "url").setDesc("the url to load"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.CMDURL.node)); @@ -39,10 +41,10 @@ public class CmdMassiveCoreCmdurl extends MassiveCommand // -------------------------------------------- // @Override - public void perform() + public void perform() throws MassiveException { // Args - String urlString = this.arg(0); + String urlString = (String) this.readArg(); final URL url; try diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreHearsound.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreHearsound.java index 85d5cc05..30f4ddbd 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreHearsound.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreHearsound.java @@ -23,8 +23,7 @@ public class CmdMassiveCoreHearsound extends MassiveCommand this.addAliases("hearsound", "hearsounds"); // Args - this.addRequiredArg("sound(s)"); - this.setErrorOnToManyArgs(false); + this.addArg(ARList.get(ARSoundEffect.get()), "sound(s)", true).setDesc("the sounds to hear"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.HEARSOUND.node)); @@ -35,11 +34,12 @@ public class CmdMassiveCoreHearsound extends MassiveCommand // OVERRIDE // -------------------------------------------- // + @SuppressWarnings("unchecked") @Override public void perform() throws MassiveException { // Args - List soundEffects = this.argConcatFrom(0, ARList.get(ARSoundEffect.get())); + List soundEffects = (List) this.readArg(); // Apply SoundEffect.runAll(soundEffects, me); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreId.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreId.java index f659f83e..c83c662c 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreId.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreId.java @@ -29,7 +29,5 @@ public class CmdMassiveCoreId extends MassiveCommand { this.msg("The id of this server is \"%s\".", ConfServer.serverid); } - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // + } diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreCopydb.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreCopydb.java index 0b8e1c4b..92611aa3 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreCopydb.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreCopydb.java @@ -6,7 +6,9 @@ import java.util.Set; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCorePerm; +import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.MassiveCommand; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Db; @@ -25,8 +27,8 @@ public class CmdMassiveCoreStoreCopydb extends MassiveCommand this.addAliases("copydb"); // Args - this.addRequiredArg("from"); - this.addRequiredArg("to"); + this.addArg(ARString.get(), "from").setDesc("the database to copy from"); + this.addArg(ARString.get(), "to").setDesc("the database to copy to"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.STORE_COPYDB.node)); @@ -37,10 +39,10 @@ public class CmdMassiveCoreStoreCopydb extends MassiveCommand // -------------------------------------------- // @Override - public void perform() + public void perform() throws MassiveException { // Args - final String fromAlias = this.arg(0); + final String fromAlias = (String) this.readArg(); final Db fromDb = MStore.getDb(fromAlias); if (fromDb == null) { @@ -48,7 +50,7 @@ public class CmdMassiveCoreStoreCopydb extends MassiveCommand return; } - final String toAlias = this.arg(1); + final String toAlias = (String) this.readArg(); final Db toDb = MStore.getDb(toAlias); if (toDb == null) { diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreListcolls.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreListcolls.java index 458a5b04..22f268c7 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreListcolls.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreListcolls.java @@ -27,7 +27,7 @@ public class CmdMassiveCoreStoreListcolls extends MassiveCommand this.addAliases("listcolls"); // Args - this.addOptionalArg("db", ConfServer.dburi); + this.addArg(ARString.get(), "db", ConfServer.dburi).setDesc("the database to list colls from"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.STORE_LISTCOLLS.node)); @@ -41,7 +41,7 @@ public class CmdMassiveCoreStoreListcolls extends MassiveCommand public void perform() throws MassiveException { // Args - final String dbAlias = this.arg(0, ARString.get(), ConfServer.dburi); + final String dbAlias = (String) this.readArg(ConfServer.dburi); final Db db = MStore.getDb(dbAlias); if (db == null) { diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreStats.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreStats.java index 27ed2dde..a0358f77 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreStats.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreStoreStats.java @@ -24,7 +24,7 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand this.addAliases("stats"); // Args - this.addOptionalArg("coll", Coll.TOTAL); + this.addArg(ARColl.get(), "coll", Coll.TOTAL).setDesc("the coll to show info about"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.STORE_STATS.node)); @@ -37,13 +37,13 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand @Override public void perform() throws MassiveException { - if (!this.argIsSet(0) || this.arg(0).equalsIgnoreCase(Coll.TOTAL)) + if ( ! this.argIsSet(0) || this.argAt(0).equalsIgnoreCase(Coll.TOTAL)) { this.performTotal(); } else { - Coll coll = this.arg(0, ARColl.get()); + Coll coll = (Coll) this.readArg(); this.performColl(coll); } } diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreTest.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreTest.java index e477ae9e..a4081bc3 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreTest.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreTest.java @@ -26,12 +26,12 @@ public class CmdMassiveCoreTest extends MassiveCommand this.addAliases("test"); // Arg - this.addRequiredArg("particleEffect"); - this.addRequiredArg("offsetX"); - this.addRequiredArg("offsetY"); - this.addRequiredArg("offsetZ"); - this.addRequiredArg("speed"); - this.addRequiredArg("amount"); + this.addArg(AREnum.get(ParticleEffect.class), "particleEffect").setDesc("the particle effect type to show"); + this.addArg(ARFloat.get(), "offsetX").setDesc("the maximum offset on x-axis for this particle"); + this.addArg(ARFloat.get(), "offsetY").setDesc("the maximum offset on y-axis for this particle"); + this.addArg(ARFloat.get(), "offsetZ").setDesc("the maximum offset on z-axis for this particle"); + this.addArg(ARFloat.get(), "speed").setDesc("the speed for this particle"); + this.addArg(ARInteger.get(), "amount").setDesc("the amount of particles to show"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.TEST.node)); @@ -49,15 +49,15 @@ public class CmdMassiveCoreTest extends MassiveCommand public void perform() throws MassiveException { // Args - ParticleEffect particleEffect = this.arg(0, AREnum.get(ParticleEffect.class)); + ParticleEffect particleEffect = (ParticleEffect) this.readArg(); Location center = me.getEyeLocation().add(0, 0, 0); - Float offsetX = this.arg(1, ARFloat.get()); - Float offsetY = this.arg(2, ARFloat.get()); - Float offsetZ = this.arg(3, ARFloat.get()); - Float speed = this.arg(4, ARFloat.get()); - Integer amount = this.arg(5, ARInteger.get()); + float offsetX = (Float) this.readArg(); + float offsetY = (Float) this.readArg(); + float offsetZ = (Float) this.readArg(); + float speed = (Float) this.readArg(); + int amount = (Integer) this.readArg(); Player player = me; diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectList.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectList.java index 73438c20..ac3c27ff 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectList.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectList.java @@ -24,7 +24,7 @@ public class CmdMassiveCoreUsysAspectList extends MassiveCommand this.addAliases("l", "list"); // Args - this.addOptionalArg("page", "1"); + this.addArg(ARInteger.get(), "page", "1").setDesc("the page in the aspect list"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_ASPECT_LIST.node)); @@ -38,7 +38,7 @@ public class CmdMassiveCoreUsysAspectList extends MassiveCommand public void perform() throws MassiveException { // Args - Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); + int pageHumanBased = (Integer) this.readArg(1); // Create Lines List lines = new ArrayList(); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectShow.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectShow.java index 016c4bc0..e781fb7e 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectShow.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectShow.java @@ -20,7 +20,7 @@ public class CmdMassiveCoreUsysAspectShow extends MassiveCommand this.addAliases("s", "show"); // Args - this.addRequiredArg("aspect"); + this.addArg(ARAspect.get(), "aspect").setDesc("the aspect to show info about"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_ASPECT_SHOW.node)); @@ -33,7 +33,7 @@ public class CmdMassiveCoreUsysAspectShow extends MassiveCommand @Override public void perform() throws MassiveException { - Aspect aspect = this.arg(0, ARAspect.get()); + Aspect aspect = (Aspect) this.readArg(); msg(Txt.titleize("Aspect: "+aspect.getId())); msg("using multiverse: %s",aspect.getMultiverse().getId()); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectUse.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectUse.java index 0aa77000..6202427a 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectUse.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysAspectUse.java @@ -21,8 +21,8 @@ public class CmdMassiveCoreUsysAspectUse extends MassiveCommand this.addAliases("u", "use"); // Args - this.addRequiredArg("aspect"); - this.addRequiredArg("multiverse"); + this.addArg(ARAspect.get(), "aspect").setDesc("the aspect to modify"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse which the aspect should use"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_ASPECT_USE.node)); @@ -35,8 +35,8 @@ public class CmdMassiveCoreUsysAspectUse extends MassiveCommand @Override public void perform() throws MassiveException { - Aspect aspect = this.arg(0, ARAspect.get()); - Multiverse multiverse = this.arg(1, ARMultiverse.get()); + Aspect aspect = (Aspect) this.readArg(); + Multiverse multiverse = (Multiverse) this.readArg(); aspect.setMultiverse(multiverse); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseDel.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseDel.java index 730243fa..123b128c 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseDel.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseDel.java @@ -20,7 +20,7 @@ public class CmdMassiveCoreUsysMultiverseDel extends MassiveCommand this.addAliases("d", "del"); // Args - this.addRequiredArg("multiverse"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse to delete"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_DEL.node)); @@ -33,7 +33,7 @@ public class CmdMassiveCoreUsysMultiverseDel extends MassiveCommand @Override public void perform() throws MassiveException { - Multiverse multiverse = this.arg(0, ARMultiverse.get()); + Multiverse multiverse = (Multiverse) this.readArg(); String id = multiverse.getId(); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseList.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseList.java index 299e77b3..04500b39 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseList.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseList.java @@ -24,7 +24,7 @@ public class CmdMassiveCoreUsysMultiverseList extends MassiveCommand this.addAliases("l", "list"); // Args - this.addOptionalArg("page", "1"); + this.addArg(ARInteger.get(), "page", "1").setDesc("the page in the multiverse list"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_LIST.node)); @@ -38,7 +38,7 @@ public class CmdMassiveCoreUsysMultiverseList extends MassiveCommand public void perform() throws MassiveException { // Args - Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); + int pageHumanBased = (Integer) this.readArg(1); // Create Lines List lines = new ArrayList(); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseNew.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseNew.java index 73ba2ce5..8d2cd31e 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseNew.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseNew.java @@ -1,8 +1,10 @@ package com.massivecraft.massivecore.cmd.massivecore; import com.massivecraft.massivecore.MassiveCorePerm; +import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MultiverseColl; import com.massivecraft.massivecore.cmd.MassiveCommand; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreUsysMultiverseNew extends MassiveCommand @@ -17,7 +19,7 @@ public class CmdMassiveCoreUsysMultiverseNew extends MassiveCommand this.addAliases("n", "new"); // Args - this.addRequiredArg("multiverse"); + this.addArg(ARString.get(), "multiverse").setDesc("name of multiverse to create"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_NEW.node)); @@ -28,9 +30,9 @@ public class CmdMassiveCoreUsysMultiverseNew extends MassiveCommand // -------------------------------------------- // @Override - public void perform() + public void perform() throws MassiveException { - String id = this.arg(0); + String id = (String) this.readArg(); if (MultiverseColl.get().containsId(id)) { diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseShow.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseShow.java index 28d7c815..a0b00434 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseShow.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysMultiverseShow.java @@ -25,7 +25,7 @@ public class CmdMassiveCoreUsysMultiverseShow extends MassiveCommand this.addAliases("s", "show"); // Args - this.addRequiredArg("multiverse"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse to show info about"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_SHOW.node)); @@ -38,7 +38,7 @@ public class CmdMassiveCoreUsysMultiverseShow extends MassiveCommand @Override public void perform() throws MassiveException { - Multiverse multiverse = this.arg(0, ARMultiverse.get()); + Multiverse multiverse = (Multiverse) this.readArg(); msg(Txt.titleize("Multiverse: "+multiverse.getId())); diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseClear.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseClear.java index e26a87b0..81e768fd 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseClear.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseClear.java @@ -6,6 +6,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.Multiverse; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.arg.ARMultiverse; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreUsysUniverseClear extends MassiveCommand @@ -20,8 +21,8 @@ public class CmdMassiveCoreUsysUniverseClear extends MassiveCommand this.addAliases("c", "clear"); // Args - this.addRequiredArg("universe"); - this.addRequiredArg("multiverse"); + this.addArg(ARString.get(), "universe").setDesc("the universe to clear"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to clear"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_UNIVERSE_CLEAR.node)); @@ -34,9 +35,8 @@ public class CmdMassiveCoreUsysUniverseClear extends MassiveCommand @Override public void perform() throws MassiveException { - Multiverse multiverse = this.arg(1, ARMultiverse.get()); - - String universe = this.arg(0); + String universe = (String) this.readArg(); + Multiverse multiverse = (Multiverse) this.readArg(); if (universe.equals(MassiveCore.DEFAULT)) { diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseDel.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseDel.java index 66fe86d3..e33c658e 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseDel.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseDel.java @@ -6,6 +6,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.Multiverse; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.arg.ARMultiverse; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreUsysUniverseDel extends MassiveCommand @@ -20,8 +21,8 @@ public class CmdMassiveCoreUsysUniverseDel extends MassiveCommand this.addAliases("d", "del"); // Args - this.addRequiredArg("universe"); - this.addRequiredArg("multiverse"); + this.addArg(ARString.get(), "universe").setDesc("the universe to delete"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to delete"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_DEL.node)); @@ -34,9 +35,8 @@ public class CmdMassiveCoreUsysUniverseDel extends MassiveCommand @Override public void perform() throws MassiveException { - Multiverse multiverse = this.arg(1, ARMultiverse.get()); - - String universe = this.arg(0); + String universe = (String) this.readArg(); + Multiverse multiverse = (Multiverse) this.readArg(); if (universe.equals(MassiveCore.DEFAULT)) { diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseNew.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseNew.java index 8484ff75..95ea54cb 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseNew.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysUniverseNew.java @@ -5,6 +5,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.Multiverse; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.arg.ARMultiverse; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreUsysUniverseNew extends MassiveCommand @@ -19,8 +20,8 @@ public class CmdMassiveCoreUsysUniverseNew extends MassiveCommand this.addAliases("n", "new"); // Args - this.addRequiredArg("universe"); - this.addRequiredArg("multiverse"); + this.addArg(ARString.get(), "universe").setDesc("name of universe to create"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to create"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_UNIVERSE_NEW.node)); @@ -33,9 +34,8 @@ public class CmdMassiveCoreUsysUniverseNew extends MassiveCommand @Override public void perform() throws MassiveException { - Multiverse multiverse = this.arg(1, ARMultiverse.get()); - - String universe = this.arg(0); + String universe = (String) this.readArg(); + Multiverse multiverse = (Multiverse) this.readArg(); if (multiverse.containsUniverse(universe)) { diff --git a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysWorld.java b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysWorld.java index 76a723b9..bb65ba2e 100644 --- a/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysWorld.java +++ b/src/com/massivecraft/massivecore/cmd/massivecore/CmdMassiveCoreUsysWorld.java @@ -5,6 +5,7 @@ import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.Multiverse; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.arg.ARMultiverse; +import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; public class CmdMassiveCoreUsysWorld extends MassiveCommand @@ -19,9 +20,9 @@ public class CmdMassiveCoreUsysWorld extends MassiveCommand this.addAliases("w", "world"); // Args - this.addRequiredArg("world"); - this.addRequiredArg("universe"); - this.addRequiredArg("multiverse"); + this.addArg(ARString.get(), "world").setDesc("the world to move"); + this.addArg(ARString.get(), "universe").setDesc("the universe to move the world ro"); + this.addArg(ARMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to move the world to"); // Requirements this.addRequirements(ReqHasPerm.get(MassiveCorePerm.USYS_WORLD.node)); @@ -34,10 +35,9 @@ public class CmdMassiveCoreUsysWorld extends MassiveCommand @Override public void perform() throws MassiveException { - Multiverse multiverse = this.arg(2, ARMultiverse.get()); - - String universe = this.arg(1); - String worldName = this.arg(0); + String worldName = (String) this.readArg(); + String universe = (String) this.readArg(); + Multiverse multiverse = (Multiverse) this.readArg(); if (!multiverse.containsUniverse(universe)) { diff --git a/src/com/massivecraft/massivecore/util/Txt.java b/src/com/massivecraft/massivecore/util/Txt.java index b136bfc7..e4389385 100644 --- a/src/com/massivecraft/massivecore/util/Txt.java +++ b/src/com/massivecraft/massivecore/util/Txt.java @@ -32,6 +32,8 @@ public class Txt public static final Map parseReplacements; public static final Pattern parsePattern; + public static final Pattern REGEX_WHITESPACE = Pattern.compile("\\s+"); + public static final long millisPerSecond = 1000; public static final long millisPerMinute = 60 * millisPerSecond; public static final long millisPerHour = 60 * millisPerMinute;