Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 18:40: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
|
* 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;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ import com.sk89q.util.StringUtil;
|
|||||||
/**
|
/**
|
||||||
* <p>Manager for handling commands. This allows you to easily process commands,
|
* <p>Manager for handling commands. This allows you to easily process commands,
|
||||||
* including nested commands, by correctly annotating methods of a class.</p>
|
* including nested commands, by correctly annotating methods of a class.</p>
|
||||||
*
|
*
|
||||||
* <p>To use this, it is merely a matter of registering classes containing
|
* <p>To use this, it is merely a matter of registering classes containing
|
||||||
* the commands (as methods with the proper annotations) with the
|
* the commands (as methods with the proper annotations) with the
|
||||||
* manager. When you want to process a command, use one of the
|
* manager. When you want to process a command, use one of the
|
||||||
@ -47,16 +47,16 @@ import com.sk89q.util.StringUtil;
|
|||||||
* <p>Methods of a class to be registered can be static, but if an injector
|
* <p>Methods of a class to be registered can be static, but if an injector
|
||||||
* is registered with the class, the instances of the command classes
|
* is registered with the class, the instances of the command classes
|
||||||
* will be created automatically and methods will be called non-statically.</p>
|
* will be created automatically and methods will be called non-statically.</p>
|
||||||
*
|
*
|
||||||
* <p>To mark a method as a command, use {@link Command}. For nested commands,
|
* <p>To mark a method as a command, use {@link Command}. For nested commands,
|
||||||
* see {@link NestedCommand}. To handle permissions, use
|
* see {@link NestedCommand}. To handle permissions, use
|
||||||
* {@link CommandPermissions}.</p>
|
* {@link CommandPermissions}.</p>
|
||||||
*
|
*
|
||||||
* <p>This uses Java reflection extensively, but to reduce the overhead of
|
* <p>This uses Java reflection extensively, but to reduce the overhead of
|
||||||
* reflection, command lookups are completely cached on registration. This
|
* reflection, command lookups are completely cached on registration. This
|
||||||
* allows for fast command handling. Method invocation still has to be done
|
* allows for fast command handling. Method invocation still has to be done
|
||||||
* with reflection, but this is quite fast in that of itself.</p>
|
* with reflection, but this is quite fast in that of itself.</p>
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
* @param <T> command sender class
|
* @param <T> command sender class
|
||||||
*/
|
*/
|
||||||
@ -104,7 +104,7 @@ public abstract class CommandsManager<T> {
|
|||||||
* class will be registered to be called statically. Otherwise, new
|
* class will be registered to be called statically. Otherwise, new
|
||||||
* instances will be created of the command classes and methods will
|
* instances will be created of the command classes and methods will
|
||||||
* not be called statically.
|
* not be called statically.
|
||||||
*
|
*
|
||||||
* @param cls
|
* @param cls
|
||||||
*/
|
*/
|
||||||
public void register(Class<?> cls) {
|
public void register(Class<?> cls) {
|
||||||
@ -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) {
|
||||||
@ -156,9 +155,11 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the methods of a class.
|
* Register the methods of a class.
|
||||||
*
|
*
|
||||||
* @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;
|
||||||
@ -213,11 +214,11 @@ public abstract class CommandsManager<T> {
|
|||||||
String help = cmd.help();
|
String help = cmd.help();
|
||||||
if (help.length() == 0) {
|
if (help.length() == 0) {
|
||||||
help = desc;
|
help = desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,13 +243,18 @@ public abstract class CommandsManager<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cls.getSuperclass() != null) {
|
||||||
|
registerMethods(cls.getSuperclass(), parent, obj);
|
||||||
|
}
|
||||||
|
|
||||||
return registered;
|
return registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see whether there is a command named such at the root level.
|
* Checks to see whether there is a command named such at the root level.
|
||||||
* This will check aliases as well.
|
* This will check aliases as well.
|
||||||
*
|
*
|
||||||
* @param command
|
* @param command
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -258,7 +264,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of command descriptions. This is only for root commands.
|
* Get a list of command descriptions. This is only for root commands.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getCommands() {
|
public Map<String, String> getCommands() {
|
||||||
@ -271,7 +277,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a map from command name to help message. This is only for root commands.
|
* Get a map from command name to help message. This is only for root commands.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getHelpMessages() {
|
public Map<String, String> getHelpMessages() {
|
||||||
@ -280,7 +286,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the usage string for a command.
|
* Get the usage string for a command.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* @param level
|
* @param level
|
||||||
* @param cmd
|
* @param cmd
|
||||||
@ -328,7 +334,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the usage string for a nested command.
|
* Get the usage string for a nested command.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* @param level
|
* @param level
|
||||||
* @param method
|
* @param method
|
||||||
@ -384,12 +390,12 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Attempt to execute a command. This version takes a separate command
|
* Attempt to execute a command. This version takes a separate command
|
||||||
* name (for the root command) and then a list of following arguments.
|
* name (for the root command) and then a list of following arguments.
|
||||||
*
|
*
|
||||||
* @param cmd command to run
|
* @param cmd command to run
|
||||||
* @param args arguments
|
* @param args arguments
|
||||||
* @param player command source
|
* @param player command source
|
||||||
* @param methodArgs method arguments
|
* @param methodArgs method arguments
|
||||||
* @throws CommandException
|
* @throws CommandException
|
||||||
*/
|
*/
|
||||||
public void execute(String cmd, String[] args, T player,
|
public void execute(String cmd, String[] args, T player,
|
||||||
Object... methodArgs) throws CommandException {
|
Object... methodArgs) throws CommandException {
|
||||||
@ -405,11 +411,11 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to execute a command.
|
* Attempt to execute a command.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* @param player
|
* @param player
|
||||||
* @param methodArgs
|
* @param methodArgs
|
||||||
* @throws CommandException
|
* @throws CommandException
|
||||||
*/
|
*/
|
||||||
public void execute(String[] args, T player,
|
public void execute(String[] args, T player,
|
||||||
Object... methodArgs) throws CommandException {
|
Object... methodArgs) throws CommandException {
|
||||||
@ -421,13 +427,13 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to execute a command.
|
* Attempt to execute a command.
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param args
|
* @param args
|
||||||
* @param player
|
* @param player
|
||||||
* @param methodArgs
|
* @param methodArgs
|
||||||
* @param level
|
* @param level
|
||||||
* @throws CommandException
|
* @throws CommandException
|
||||||
*/
|
*/
|
||||||
public void executeMethod(Method parent, String[] args,
|
public void executeMethod(Method parent, String[] args,
|
||||||
T player, Object[] methodArgs, int level) throws CommandException {
|
T player, Object[] methodArgs, int level) throws CommandException {
|
||||||
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +535,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether a player has access to a command.
|
* Returns whether a player has access to a command.
|
||||||
*
|
*
|
||||||
* @param method
|
* @param method
|
||||||
* @param player
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
@ -549,7 +557,7 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether a player permission..
|
* Returns whether a player permission..
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param perm
|
* @param perm
|
||||||
* @return
|
* @return
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren