mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 17:57:38 +00:00
Added support for value flags to the command system
This commit is contained in:
parent
b8a310dfdc
commit
d64fd95173
@ -65,4 +65,13 @@ public @interface Command {
|
||||
* each character being a flag. Use A-Z and a-z as possible flags.
|
||||
*/
|
||||
String flags() default "";
|
||||
|
||||
/**
|
||||
* Value flags are special flags, that take a value after the flag.
|
||||
* The semantics are the same as with the flags parameter.
|
||||
* They aren't automatically documented and thus need to be added
|
||||
* to the "usage" parameter separately.
|
||||
*/
|
||||
String valueFlags() default "";
|
||||
|
||||
}
|
||||
|
@ -378,23 +378,24 @@ public abstract class CommandsManager<T> {
|
||||
String[] newArgs = new String[args.length - level];
|
||||
System.arraycopy(args, level, newArgs, 0, args.length - level);
|
||||
|
||||
CommandContext context = new CommandContext(newArgs);
|
||||
final String valueFlags = cmd.valueFlags();
|
||||
final Set<Character> isValueFlag = new HashSet<Character>();
|
||||
|
||||
if (context.argsLength() < cmd.min()) {
|
||||
throw new CommandUsageException("Too few arguments.",
|
||||
getUsage(args, level, cmd));
|
||||
for (int i = 0; i < valueFlags.length(); ++i) {
|
||||
isValueFlag.add(valueFlags.charAt(i));
|
||||
}
|
||||
|
||||
if (cmd.max() != -1 && context.argsLength() > cmd.max()) {
|
||||
throw new CommandUsageException("Too many arguments.",
|
||||
getUsage(args, level, cmd));
|
||||
}
|
||||
CommandContext context = new CommandContext(newArgs, isValueFlag);
|
||||
|
||||
if (context.argsLength() < cmd.min())
|
||||
throw new CommandUsageException("Too few arguments.", getUsage(args, level, cmd));
|
||||
|
||||
if (cmd.max() != -1 && context.argsLength() > cmd.max())
|
||||
throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd));
|
||||
|
||||
for (char flag : context.getFlags()) {
|
||||
if (cmd.flags().indexOf(String.valueOf(flag)) == -1) {
|
||||
throw new CommandUsageException("Unknown flag: " + flag,
|
||||
getUsage(args, level, cmd));
|
||||
}
|
||||
if (cmd.flags().indexOf(String.valueOf(flag)) == -1)
|
||||
throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, level, cmd));
|
||||
}
|
||||
|
||||
methodArgs[0] = context;
|
||||
|
Loading…
Reference in New Issue
Block a user