Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-09 21:10:05 +01:00
Added allFlags setting to Command to prevent it from restricting allowed flags
Dieser Commit ist enthalten in:
Ursprung
73dbbbac9a
Commit
5e8f50699d
@ -34,28 +34,36 @@ public @interface Command {
|
||||
* A list of aliases for the command. The first alias is the most
|
||||
* important -- it is the main name of the command. (The method name
|
||||
* is never used for anything).
|
||||
*
|
||||
* @return Aliases for a command
|
||||
*/
|
||||
String[] aliases();
|
||||
|
||||
/**
|
||||
* Usage instruction. Example text for usage could be
|
||||
* <code>[-h] [name] [message]</code>.
|
||||
* <code>[-h harps] [name] [message]</code>.
|
||||
*
|
||||
* @return Usage instructions for a command
|
||||
*/
|
||||
String usage() default "";
|
||||
|
||||
/**
|
||||
* A short description for the command.
|
||||
* @return A short description for the command.
|
||||
*/
|
||||
String desc();
|
||||
|
||||
/**
|
||||
* The minimum number of arguments. This should be 0 or above.
|
||||
*
|
||||
* @return the minimum number of arguments
|
||||
*/
|
||||
int min() default 0;
|
||||
|
||||
/**
|
||||
* The maximum number of arguments. Use -1 for an unlimited number
|
||||
* of arguments.
|
||||
*
|
||||
* @return the maximum number of arguments
|
||||
*/
|
||||
int max() default -1;
|
||||
|
||||
@ -65,11 +73,20 @@ public @interface Command {
|
||||
* each character being a flag. Use A-Z and a-z as possible flags.
|
||||
* Appending a flag with a : makes the flag character before a value flag,
|
||||
* meaning that if it is given it must have a value
|
||||
*
|
||||
* @return Flags matching a-zA-Z
|
||||
*/
|
||||
String flags() default "";
|
||||
|
||||
/**
|
||||
* A long description for the command.
|
||||
* @return A long description for the command.
|
||||
*/
|
||||
String help() default "";
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Whether any flag can be provided to the command, even if it is not in {@link #flags()}
|
||||
*/
|
||||
boolean anyFlags() default false;
|
||||
}
|
||||
|
@ -140,8 +140,7 @@ public abstract class CommandsManager<T> {
|
||||
if (getInjector() == null) {
|
||||
return registerMethods(cls, parent, null);
|
||||
} else {
|
||||
Object obj = null;
|
||||
obj = getInjector().getInstance(cls);
|
||||
Object obj = getInjector().getInstance(cls);
|
||||
return registerMethods(cls, parent, obj);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
@ -159,6 +158,8 @@ public abstract class CommandsManager<T> {
|
||||
*
|
||||
* @param cls
|
||||
* @param parent
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
|
||||
Map<String, Method> map;
|
||||
@ -217,7 +218,7 @@ public abstract class CommandsManager<T> {
|
||||
|
||||
final CharSequence arguments = getArguments(cmd);
|
||||
for (String alias : cmd.aliases()) {
|
||||
final String helpMessage = "/"+alias+" "+arguments+"\n\n"+help;
|
||||
final String helpMessage = "/" + alias + " " + arguments + "\n\n" + help;
|
||||
final String key = alias.replaceAll("/", "");
|
||||
String previous = helpMessages.put(key, helpMessage);
|
||||
|
||||
@ -242,6 +243,11 @@ public abstract class CommandsManager<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cls.getSuperclass() != null) {
|
||||
registerMethods(cls.getSuperclass(), parent, obj);
|
||||
}
|
||||
|
||||
return registered;
|
||||
}
|
||||
|
||||
@ -488,11 +494,13 @@ public abstract class CommandsManager<T> {
|
||||
throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd));
|
||||
}
|
||||
|
||||
if (!cmd.anyFlags()) {
|
||||
for (char flag : context.getFlags()) {
|
||||
if (!newFlags.contains(flag)) {
|
||||
throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, level, cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
methodArgs[0] = context;
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren