New arg system.

A new command argument system can now be used.
The old one still works but is deprecated.
The new one will support tab-completion for now
and maybe other cool stuff in the future.
This commit is contained in:
Magnus Ulf 2015-04-07 18:53:56 +02:00 committed by Olof Larsson
parent 0642d3a0d5
commit 4291dc35ba
55 changed files with 1068 additions and 447 deletions

View File

@ -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 + "]";
}
}

View File

@ -25,7 +25,7 @@ public class DeprecatedCommand extends MassiveCommand
this.setAliases(aliases);
// Args
this.setErrorOnToManyArgs(false);
this.setErrorOnTooManyArgs(false);
// Visibility
this.setVisibilityMode(VisibilityMode.INVISIBLE);

View File

@ -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<String> lines = new ArrayList<String>();
for (String helpline : parentCommand.getHelp())
{
lines.add(Txt.parse("<a>#<i> "+helpline));
lines.add(Txt.parse("<a>#<i> " + 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));
}
}

View File

@ -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<MassiveCommand> subCommands;
public List<MassiveCommand> getSubCommands() { return this.subCommands; }
public void setSubCommands(List<MassiveCommand> 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<String> aliases) { this.aliases.addAll(aliases); }
public void addAliases(String... aliases) { this.addAliases(Arrays.asList(aliases)); }
// FIELD argSettings
// Settings for all args.
protected List<ArgSetting> argSettings;
public List<ArgSetting> getArgSettings() { return this.argSettings; }
public void setArgSettings(List<ArgSetting> 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<String> requiredArgs;
public List<String> getRequiredArgs() { return this.requiredArgs; }
public void setRequiredArgs(List<String> requiredArgs) { this.requiredArgs = requiredArgs; }
@Deprecated protected List<String> requiredArgs;
@Deprecated public List<String> getRequiredArgs() { return this.requiredArgs; }
@Deprecated public void setRequiredArgs(List<String> 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<String, String> optionalArgs;
public Map<String, String> getOptionalArgs() { return this.optionalArgs; }
public void setOptionalArgs(Map<String, String> optionalArgs) { this.optionalArgs = optionalArgs; }
@Deprecated protected Map<String, String> optionalArgs;
@Deprecated public Map<String, String> getOptionalArgs() { return this.optionalArgs; }
@Deprecated public void setOptionalArgs(Map<String, String> 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<MassiveCommand> getCommandChain() { return this.commandChain; }
public void setCommandChain(List<MassiveCommand> commandChain) { this.commandChain = commandChain; }
public MassiveCommand getParentCommand()
{
List<MassiveCommand> 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<String>();
this.argSettings = new ArrayList<ArgSetting>();
this.requiredArgs = new ArrayList<String>();
this.optionalArgs = new LinkedHashMap<String, String>();
this.requirements = new ArrayList<Req>();
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<String> args, List<MassiveCommand> 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<MassiveCommand>());
}
public List<String> applyConcatFrom(List<String> args)
{
if ( ! this.isUsingConcatFrom()) return args;
List<String> ret = new MassiveList<String>();
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<String> 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<String> 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, "<i>, <c>", " <i>or <c>"));
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<String> theTooMany = args.subList(this.getRequiredArgs().size() + this.optionalArgs.size(), args.size());
msg(Lang.COMMAND_TOO_MANY_ARGS, Txt.implodeCommaAndDot(theTooMany, Txt.parse("<aqua>%s"), Txt.parse("<b>, "), Txt.parse("<b> and "), ""));
msg(Lang.COMMAND_TOO_MANY_ARGS2);
sendMessage(this.getUseageTemplate());
List<String> theTooMany = args.subList(this.getAllArgsAmountFor(sender), args.size());
Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_ARGS, Txt.implodeCommaAndDot(theTooMany, Txt.parse("<aqua>%s"), Txt.parse("<b>, "), Txt.parse("<b> 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<String> getSimilarAliases(String arg, int maxLevenshteinDistance)
{
if (arg == null) return Collections.emptyList();
arg = arg.toLowerCase();
List<String> matches = new ArrayList<String>();
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<String> getSimilarSubcommandAliases(String arg, int maxLevenshteinDistance)
{
if (arg == null) return Collections.emptyList();
// Try Levenshtein
List<String> matches = new ArrayList<String>();
@ -579,26 +780,7 @@ public class MassiveCommand
first = false;
}
List<String> args = new ArrayList<String>();
for (String requiredArg : this.getRequiredArgs())
{
args.add("<"+requiredArg+">");
}
for (Entry<String, String> optionalArg : this.getOptionalArgs().entrySet())
{
String val = optionalArg.getValue();
if (val == null)
{
val = "";
}
else
{
val = "="+val;
}
args.add("["+optionalArg.getKey()+val+"]");
}
List<String> args = this.getArgUseagesFor(sender);
if (args.size() > 0)
{
@ -617,6 +799,41 @@ public class MassiveCommand
return ret.toString();
}
protected List<String> getArgUseagesFor(CommandSender sender)
{
List<String> ret = new MassiveList<String>();
if (this.isUsingNewArgSystem())
{
for (ArgSetting setting : this.getArgSettings())
{
ret.add(setting.getUseageTemplateDisplayFor(sender));
}
}
else
{
for (String requiredArg : this.getRequiredArgs())
{
ret.add("<" + requiredArg + ">");
}
for (Entry<String, String> 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<MassiveCommand> commandChain, boolean addDesc, boolean onlyFirstAlias)
{
return getUseageTemplate(commandChain, addDesc, onlyFirstAlias, null);
@ -637,6 +854,92 @@ public class MassiveCommand
return getUseageTemplate(false);
}
// -------------------------------------------- //
// TAB
// -------------------------------------------- //
public List<String> getTabCompletions(List<String> 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<String> getTabCompletionsSub(List<String> 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<String> ret = new ArrayList<String>();
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<String> getTabCompletionsArg(List<String> 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<String> 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<String> addSpaceAtEnd(List<String> 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<Object>)this.getArgSettings().get(idx).getReader(), defaultNotSet);
}
// Core Logic
public <T> T readArgFrom(AR<T> argReader) throws MassiveException
{
if (argReader == null) throw new IllegalArgumentException("argReader is null");
return this.readArgFrom(null, argReader);
}
public <T> T readArgFrom(String str, AR<T> argReader) throws MassiveException
{
if (argReader == null) throw new IllegalArgumentException("argReader is null");
return argReader.read(str, this.sender);
}
public <T> T readArgFrom(String str, AR<T> 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> T arg(int idx, AR<T> argReader) throws MassiveException
{
String str = this.arg(idx);
return this.arg(str, argReader);
}
@Deprecated
public <T> T arg(int idx, AR<T> 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> T argConcatFrom(int idx, AR<T> argReader) throws MassiveException
{
String str = this.argConcatFrom(idx);
return this.arg(str, argReader);
}
@Deprecated
public <T> T argConcatFrom(int idx, AR<T> argReader, T defaultNotSet) throws MassiveException
{
String str = this.argConcatFrom(idx);
@ -731,16 +1111,19 @@ public class MassiveCommand
// Core & Other
@Deprecated
public <T> T arg(AR<T> argReader) throws MassiveException
{
return this.arg(null, argReader);
}
@Deprecated
public <T> T arg(String str, AR<T> argReader) throws MassiveException
{
return argReader.read(str, this.sender);
}
@Deprecated
public <T> T arg(String str, AR<T> argReader, T defaultNotSet) throws MassiveException
{
if (str == null) return defaultNotSet;

View File

@ -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<String> argList = this.createArgList(args);
this.massiveCommand.execute(sender, argList);
this.getMassiveCommand().execute(sender, argList);
return true;
}
public List<String> createArgList(String[] args)
{
List<String> ret;
if (this.massiveCommand.isUsingTokenizer())
if (this.getMassiveCommand().isUsingTokenizer())
{
ret = Txt.tokenizeArguments(Txt.implode(args, " "));
}
else
{
ret = new ArrayList<String>(Arrays.asList(args));
ret = MUtil.list(args);
}
if (this.massiveCommand.isUsingSmartQuotesRemoval())
if (this.getMassiveCommand().isUsingSmartQuotesRemoval())
{
List<String> oldArgList = ret;
ret = new ArrayList<String>();
ret = new ArrayList<String>(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<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException
public List<String> tabComplete(CommandSender sender, String alias, String[] rawArgs) throws IllegalArgumentException
{
Set<String> ret = new TreeSet<String>(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<String>(ret);
}
// If subcommands didn't work, we will try with senders.
List<String> 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<String> args = new MassiveList<String>();
// 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<String>(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;
}
}

View File

@ -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<String> 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<String> aliases)
{
this.plugin = plugin;

View File

@ -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<String> input = new ArrayList<String>();
input.add("1");
for(String str : ARAbstract.prepareForSpaces(input))
System.out.println("\"" + str + "\"");
System.out.println("end");
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}

View File

@ -87,7 +87,8 @@ public abstract class ARAbstract<T> implements AR<T>
{
// Filter them to start with what the user typed in.
Collection<String> raw = this.getTabList(sender, arg);
if (raw == null) return Collections.emptyList();
if (raw == null || raw.isEmpty()) return Collections.emptyList();
List<String> ret = Txt.getStartsWithIgnoreCase(raw, arg);
// Here we do a lot of things related to spaces.
@ -103,8 +104,7 @@ public abstract class ARAbstract<T> implements AR<T>
// PRIVATE: TAB COMPLETE CALCULATIONS
// -------------------------------------------- //
// Should be private. But isn't currently for testing purposes.
static List<String> prepareForSpaces(List<String> suggestions)
public static List<String> prepareForSpaces(List<String> suggestions)
{
List<List<String>> suggestionParts = getParts(suggestions);
@ -199,32 +199,5 @@ public abstract class ARAbstract<T> implements AR<T>
return ret;
}
//TODO: Move this code somewhere else.
// Currently just kept here.
/*
private List<String> addSpaceAtEnd(MassiveCommand command, int argNumber, List<String> 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<String>(suggestion);
}*/
}

View File

@ -34,12 +34,17 @@ public abstract class ARAbstractSelect<T> extends ARAbstract<T>
@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("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
MassiveException exception = createExceptionForInvalidArg(arg, sender);
throw exception;
}
public MassiveException createExceptionForInvalidArg(String arg, CommandSender sender)
{
MassiveException ret = new MassiveException();
ret.addMsg("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
if (this.canList(sender))
{
@ -50,17 +55,19 @@ public abstract class ARAbstractSelect<T> extends ARAbstract<T>
if (names.isEmpty())
{
exception.addMsg("<i>Note: There is no %s available.", this.getTypeName());
ret.addMsg("<i>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, "<i>, <h>", " <i>or <h>"));
exception.addMsg("<i>Did you mean <h>%s<i>?", suggest);
String format = Txt.parse("<h>%s");
String comma = Txt.parse("<i>, ");
String and = Txt.parse(" <i>or ");
String dot = Txt.parse("<i>?");
ret.addMsg("<i>Did you mean %s", Txt.implodeCommaAndDot(matches, format, comma, and, dot));
}
else if (names.size() > LIST_COUNT_MAX)
{
exception.addMsg("<i>More than %d alternatives available.", LIST_COUNT_MAX);
ret.addMsg("<i>More than %d alternatives available.", LIST_COUNT_MAX);
}
else
{
@ -68,11 +75,10 @@ public abstract class ARAbstractSelect<T> extends ARAbstract<T>
String comma = Txt.parse("<i>, ");
String and = Txt.parse(" <i>or ");
String dot = Txt.parse("<i>.");
exception.addMsg("<i>Use %s", Txt.implodeCommaAndDot(names, format, comma, and, dot));
ret.addMsg("<i>Use %s", Txt.implodeCommaAndDot(names, format, comma, and, dot));
}
}
throw exception;
return ret;
}
public List<String> getMatchingAltNames(String arg, CommandSender sender, int maxLevenshteinDistance)

View File

@ -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<T> extends ARAbstract<Collection<T>>
public final class ARAll
{
// -------------------------------------------- //
// FIELDS
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private ARAllAble<T> innerArgReader;
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARAll(ARAllAble<T> inner)
@SuppressWarnings("unchecked")
public static <T> AR<Collection<T>> get(AR<?> inner)
{
if (inner == null) throw new IllegalArgumentException("innerArgReader musn't be null");
this.innerArgReader = inner;
if (inner instanceof ARCollection) return new ARAllCollection<T>((ARCollection<? extends Collection<T>>) inner);
if (inner instanceof ARAllAble) return new ARAllDefault<T>((ARAllAble<T>) 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<T> extends ARWrapper<Collection<T>>
{
return innerArgReader.getTypeName();
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected ARAllAble<T> innerArgReader;
@Override public ARAllAble<T> getInnerArgReader() { return this.innerArgReader; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARAllDefault(ARAllAble<T> inner)
{
if (inner == null) throw new IllegalArgumentException("innerArgReader musn't be null");
this.innerArgReader = inner;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Collection<T> 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<T> read(String arg, CommandSender sender) throws MassiveException
{
if ("all".equalsIgnoreCase(arg)) return innerArgReader.getAll();
T innerRet = innerArgReader.read(arg, sender);
List<T> ret = new MassiveList<T>();
ret.add(innerRet);
return ret;
}
// -------------------------------------------- //
// AR ALL COLLECTION
// -------------------------------------------- //
@Override
public boolean isValid(String arg, CommandSender sender)
private static class ARAllCollection<T> extends ARWrapper<Collection<T>>
{
return "all".equalsIgnoreCase(arg) || innerArgReader.isValid(arg, sender);
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected ARCollection<? extends Collection<T>> innerArgReader;
@Override public ARCollection<? extends Collection<T>> getInnerArgReader() { return this.innerArgReader; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public ARAllCollection(ARCollection<? extends Collection<T>> 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<String> getTabList(CommandSender sender, String arg)
{
return innerArgReader.getTabList(sender, arg);
@Override
public Collection<T> read(String arg, CommandSender sender) throws MassiveException
{
if ("all".equalsIgnoreCase(arg))
{
@SuppressWarnings("unchecked")
ARAllAble<T> innersInner = (ARAllAble<T>) 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);
}
}
}

View File

@ -2,7 +2,9 @@ package com.massivecraft.massivecore.cmd.arg;
import java.util.Collection;
import org.bukkit.command.CommandSender;
public interface ARAllAble<T> extends AR<T>
{
public Collection<T> getAll();
public Collection<T> getAll(CommandSender sender);
}

View File

@ -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<Biome>
public class ARBiome extends ARAbstractSelect<Biome> implements ARAllAble<Biome>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -27,17 +28,11 @@ public class ARBiome extends ARAbstractSelect<Biome>
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<Biome>
return ret;
}
@Override
public Collection<Biome> 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;

View File

@ -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<ChatColor>
public class ARChatColor extends ARAbstractSelect<ChatColor> implements ARAllAble<ChatColor>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -27,9 +28,8 @@ public class ARChatColor extends ARAbstractSelect<ChatColor>
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<ChatColor>
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<ChatColor>
for (ChatColor cc : ChatColor.values())
{
ret.add(getComparable(cc.name()));
ret.add(getComparable(cc));
}
return ret;
}
@Override
public Collection<ChatColor> 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)

View File

@ -6,7 +6,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.store.Coll;
public class ARColl extends ARAbstractSelect<Coll<?>>
public class ARColl extends ARAbstractSelect<Coll<?>> implements ARAllAble<Coll<?>>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -36,5 +36,11 @@ public class ARColl extends ARAbstractSelect<Coll<?>>
{
return this.altNames(sender);
}
@Override
public Collection<Coll<?>> getAll(CommandSender sender)
{
return Coll.getMap().values();
}
}

View File

@ -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<E extends Collection<?>> extends ARWrapper<E>
{
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Collection<String> 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<String> 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];
}
}

View File

@ -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<Difficulty>
public class ARDifficulty extends ARAbstractSelect<Difficulty> implements ARAllAble<Difficulty>
{
// -------------------------------------------- //
// CONSTANTS
@ -64,5 +65,11 @@ public class ARDifficulty extends ARAbstractSelect<Difficulty>
{
return this.altNames(sender);
}
@Override
public Collection<Difficulty> getAll(CommandSender sender)
{
return Arrays.asList(Difficulty.values());
}
}

View File

@ -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<EntityType>
public class AREntityType extends ARAbstractSelect<EntityType> implements ARAllAble<EntityType>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -56,6 +57,12 @@ public class AREntityType extends ARAbstractSelect<EntityType>
return this.altNames(sender);
}
@Override
public Collection<EntityType> getAll(CommandSender sender)
{
return Arrays.asList(EntityType.values());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //

View File

@ -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<T> extends ARAbstractSelect<T>
public class AREnum<T> extends ARAbstractSelect<T> implements ARAllAble<T>
{
// -------------------------------------------- //
// FIELD
@ -87,12 +88,19 @@ public class AREnum<T> extends ARAbstractSelect<T>
return this.altNames(sender);
}
@Override
public Collection<T> getAll(CommandSender sender)
{
return Arrays.asList(getEnumValues(clazz));
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public static <T> T[] getEnumValues(Class<T> 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();

View File

@ -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<Environment>
public class AREnvironment extends ARAbstractSelect<Environment> implements ARAllAble<Environment>
{
// -------------------------------------------- //
// CONSTANTS
@ -75,6 +76,12 @@ public class AREnvironment extends ARAbstractSelect<Environment>
return ret;
}
@Override
public Collection<Environment> getAll(CommandSender sender)
{
return Arrays.asList(Environment.values());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //

View File

@ -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<GameMode>
public class ARGameMode extends ARAbstractSelect<GameMode> implements ARAllAble<GameMode>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -57,6 +58,12 @@ public class ARGameMode extends ARAbstractSelect<GameMode>
return this.altNames(sender);
}
@Override
public Collection<GameMode> getAll(CommandSender sender)
{
return Arrays.asList(GameMode.values());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //

View File

@ -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<E> extends ARAbstract<List<E>>
import com.massivecraft.massivecore.util.Txt;
public class ARList<E> extends ARCollection<List<E>>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected AR<E> elementArgReader;
public AR<E> getElementArgReader() { return this.elementArgReader; }
@Override public AR<E> getInnerArgReader() { return this.getElementArgReader(); }
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -33,40 +34,28 @@ public class ARList<E> extends ARAbstract<List<E>>
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String getTypeName()
{
return elementArgReader.getTypeName();
}
// -------------------------------------------- //
// NOTE: Must be used with argConcatFrom and setErrorOnTooManyArgs(false).
@Override
public List<E> 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<E> ret = new ArrayList<E>();
List<E> ret = new ArrayList<E>();
// 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<String> getTabList(CommandSender sender, String arg)
{
return this.getElementArgReader().getTabList(sender, arg);
}
}

View File

@ -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<Material>
public class ARMaterial extends ARAbstract<Material> implements ARAllAble<Material>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -48,5 +49,11 @@ public class ARMaterial extends ARAbstract<Material>
return ret;
}
@Override
public Collection<Material> getAll(CommandSender sender)
{
return Arrays.asList(Material.values());
}
}

View File

@ -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<T> extends ARAbstract<T>
public class ARNullable<T> extends ARWrapper<T>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected AR<T> innerArgReader;
@Override public AR<T> getInnerArgReader() { return this.innerArgReader; }
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
@ -21,38 +26,19 @@ public class ARNullable<T> extends ARAbstract<T>
public ARNullable(AR<T> inner)
{
if (inner == null) throw new IllegalArgumentException("inner param is null");
this.inner = inner;
this.innerArgReader = inner;
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected AR<T> inner;
public AR<T> 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<String> getTabList(CommandSender sender, String arg)
{
return this.getInner().getTabList(sender, arg);
return this.getInnerArgReader().read(arg, sender);
}
}

View File

@ -10,7 +10,7 @@ import org.bukkit.permissions.Permission;
import com.massivecraft.massivecore.MassiveException;
public class ARPermission extends ARAbstract<Permission>
public class ARPermission extends ARAbstract<Permission> implements ARAllAble<Permission>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -28,8 +28,7 @@ public class ARPermission extends ARAbstract<Permission>
{
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("<b>No permission with the name \"<h>%s<b>\" was found.", arg);
@ -48,4 +47,10 @@ public class ARPermission extends ARAbstract<Permission>
return ret;
}
@Override
public Collection<Permission> getAll(CommandSender sender)
{
return Bukkit.getPluginManager().getPermissions();
}
}

View File

@ -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<PotionEffectType>
public class ARPotionEffectType extends ARAbstractSelect<PotionEffectType> implements ARAllAble<PotionEffectType>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -64,7 +65,13 @@ public class ARPotionEffectType extends ARAbstractSelect<PotionEffectType>
{
return this.altNames(sender);
}
@Override
public Collection<PotionEffectType> getAll(CommandSender sender)
{
return Arrays.asList(PotionEffectType.values());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //

View File

@ -54,22 +54,22 @@ public class ARPotionEffectWrap extends ARAbstract<PotionEffectWrap>
}
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);
}
}

View File

@ -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<T extends SenderEntity<T>> extends ARSenderIdAbstract<T>
public class ARSenderEntity<T extends SenderEntity<T>> extends ARSenderIdAbstract<T> implements ARAllAble<T>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final SenderColl<T> coll;
protected final SenderColl<T> coll;
// -------------------------------------------- //
// CONSTRUCT
@ -67,4 +67,10 @@ public class ARSenderEntity<T extends SenderEntity<T>> extends ARSenderIdAbstrac
return ret;
}
@Override
public Collection<T> getAll(CommandSender sender)
{
return coll.getAll();
}
}

View File

@ -15,8 +15,8 @@ public abstract class ARSenderIdAbstract<T> extends ARAbstract<T>
// 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<T> extends ARAbstract<T>
@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)
{

View File

@ -8,17 +8,19 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.mixin.Mixin;
public class ARSet<E> extends ARAbstract<Set<E>>
import com.massivecraft.massivecore.util.Txt;
public class ARSet<E> extends ARCollection<Set<E>>
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final AR<E> elementArgReader;
protected final AR<E> elementArgReader;
public AR<E> getElementArgReader() { return this.elementArgReader; }
@Override public AR<E> getInnerArgReader() { return this.getElementArgReader(); }
private final boolean warnOnDuplicates;
protected final boolean warnOnDuplicates;
public boolean getWarnOnDuplicate() { return warnOnDuplicates; }
// -------------------------------------------- //
@ -51,7 +53,7 @@ public class ARSet<E> extends ARAbstract<Set<E>>
public Set<E> 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<E> ret = new LinkedHashSet<E>();

View File

@ -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<Sound>
public class ARSound extends ARAbstract<Sound> implements ARAllAble<Sound>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -48,7 +49,13 @@ public class ARSound extends ARAbstract<Sound>
return ret;
}
@Override
public Collection<Sound> getAll(CommandSender sender)
{
return Arrays.asList(Sound.values());
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //

View File

@ -24,11 +24,9 @@ public class ARWorld extends ARAbstract<World>
@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)
{

View File

@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.mixin.Mixin;
public class ARWorldId extends ARAbstractSelect<String>
public class ARWorldId extends ARAbstractSelect<String> implements ARAllAble<String>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
@ -69,5 +69,11 @@ public class ARWorldId extends ARAbstractSelect<String>
{
return Mixin.getVisibleWorldIds(sender);
}
@Override
public Collection<String> getAll(CommandSender sender)
{
return Mixin.getVisibleWorldIds(sender);
}
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.massivecore.cmd.arg;
import java.util.Collection;
import org.bukkit.command.CommandSender;
public abstract class ARWrapper<T> extends ARAbstract<T>
{
// -------------------------------------------- //
// 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<String> getTabList(CommandSender sender, String arg)
{
return this.getInnerArgReader().getTabList(sender, arg);
}
@Override
public boolean allowSpaceAfterTab()
{
return this.getInnerArgReader().allowSpaceAfterTab();
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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<SoundEffect> soundEffects = this.argConcatFrom(0, ARList.get(ARSoundEffect.get()));
List<SoundEffect> soundEffects = (List<SoundEffect>) this.readArg();
// Apply
SoundEffect.runAll(soundEffects, me);

View File

@ -29,7 +29,5 @@ public class CmdMassiveCoreId extends MassiveCommand
{
this.msg("<i>The id of this server is \"<h>%s<i>\".", ConfServer.serverid);
}
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
}

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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<String> lines = new ArrayList<String>();

View File

@ -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("<k>using multiverse: <v>%s",aspect.getMultiverse().getId());

View File

@ -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);

View File

@ -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();

View File

@ -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<String> lines = new ArrayList<String>();

View File

@ -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))
{

View File

@ -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()));

View File

@ -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))
{

View File

@ -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))
{

View File

@ -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))
{

View File

@ -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))
{

View File

@ -32,6 +32,8 @@ public class Txt
public static final Map<String, String> 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;