mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 02:07:39 +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.
|
* each character being a flag. Use A-Z and a-z as possible flags.
|
||||||
*/
|
*/
|
||||||
String flags() default "";
|
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];
|
String[] newArgs = new String[args.length - level];
|
||||||
System.arraycopy(args, level, newArgs, 0, 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()) {
|
for (int i = 0; i < valueFlags.length(); ++i) {
|
||||||
throw new CommandUsageException("Too few arguments.",
|
isValueFlag.add(valueFlags.charAt(i));
|
||||||
getUsage(args, level, cmd));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.max() != -1 && context.argsLength() > cmd.max()) {
|
CommandContext context = new CommandContext(newArgs, isValueFlag);
|
||||||
throw new CommandUsageException("Too many arguments.",
|
|
||||||
getUsage(args, level, cmd));
|
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()) {
|
for (char flag : context.getFlags()) {
|
||||||
if (cmd.flags().indexOf(String.valueOf(flag)) == -1) {
|
if (cmd.flags().indexOf(String.valueOf(flag)) == -1)
|
||||||
throw new CommandUsageException("Unknown flag: " + flag,
|
throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, level, cmd));
|
||||||
getUsage(args, level, cmd));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
methodArgs[0] = context;
|
methodArgs[0] = context;
|
||||||
|
Loading…
Reference in New Issue
Block a user