Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +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
|
* 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
|
* important -- it is the main name of the command. (The method name
|
||||||
* is never used for anything).
|
* is never used for anything).
|
||||||
|
*
|
||||||
|
* @return Aliases for a command
|
||||||
*/
|
*/
|
||||||
String[] aliases();
|
String[] aliases();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Usage instruction. Example text for usage could be
|
* 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 "";
|
String usage() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A short description for the command.
|
* @return A short description for the command.
|
||||||
*/
|
*/
|
||||||
String desc();
|
String desc();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum number of arguments. This should be 0 or above.
|
* The minimum number of arguments. This should be 0 or above.
|
||||||
|
*
|
||||||
|
* @return the minimum number of arguments
|
||||||
*/
|
*/
|
||||||
int min() default 0;
|
int min() default 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The maximum number of arguments. Use -1 for an unlimited number
|
* The maximum number of arguments. Use -1 for an unlimited number
|
||||||
* of arguments.
|
* of arguments.
|
||||||
|
*
|
||||||
|
* @return the maximum number of arguments
|
||||||
*/
|
*/
|
||||||
int max() default -1;
|
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.
|
* 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,
|
* Appending a flag with a : makes the flag character before a value flag,
|
||||||
* meaning that if it is given it must have a value
|
* meaning that if it is given it must have a value
|
||||||
|
*
|
||||||
|
* @return Flags matching a-zA-Z
|
||||||
*/
|
*/
|
||||||
String flags() default "";
|
String flags() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A long description for the command.
|
* @return A long description for the command.
|
||||||
*/
|
*/
|
||||||
String help() default "";
|
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) {
|
if (getInjector() == null) {
|
||||||
return registerMethods(cls, parent, null);
|
return registerMethods(cls, parent, null);
|
||||||
} else {
|
} else {
|
||||||
Object obj = null;
|
Object obj = getInjector().getInstance(cls);
|
||||||
obj = getInjector().getInstance(cls);
|
|
||||||
return registerMethods(cls, parent, obj);
|
return registerMethods(cls, parent, obj);
|
||||||
}
|
}
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
@ -159,6 +158,8 @@ public abstract class CommandsManager<T> {
|
|||||||
*
|
*
|
||||||
* @param cls
|
* @param cls
|
||||||
* @param parent
|
* @param parent
|
||||||
|
* @param obj
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
|
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
|
||||||
Map<String, Method> map;
|
Map<String, Method> map;
|
||||||
@ -217,7 +218,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
final CharSequence arguments = getArguments(cmd);
|
final CharSequence arguments = getArguments(cmd);
|
||||||
for (String alias : cmd.aliases()) {
|
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("/", "");
|
final String key = alias.replaceAll("/", "");
|
||||||
String previous = helpMessages.put(key, helpMessage);
|
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;
|
return registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,9 +494,11 @@ public abstract class CommandsManager<T> {
|
|||||||
throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd));
|
throw new CommandUsageException("Too many arguments.", getUsage(args, level, cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (char flag : context.getFlags()) {
|
if (!cmd.anyFlags()) {
|
||||||
if (!newFlags.contains(flag)) {
|
for (char flag : context.getFlags()) {
|
||||||
throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, level, cmd));
|
if (!newFlags.contains(flag)) {
|
||||||
|
throw new CommandUsageException("Unknown flag: " + flag, getUsage(args, level, cmd));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren