mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 17:57:38 +00:00
Added @NestedCommand(executeBody=true/false) annotation.
Setting this annotation to true will execute the method body of the tagged method if the argument count is 0.
This commit is contained in:
parent
e75b0ab34c
commit
94a549214d
@ -456,7 +456,18 @@ public abstract class CommandsManager<T> {
|
|||||||
|
|
||||||
int argsCount = args.length - 1 - level;
|
int argsCount = args.length - 1 - level;
|
||||||
|
|
||||||
if (method.isAnnotationPresent(NestedCommand.class)) {
|
// checks if we need to execute the body of the nested command method (false)
|
||||||
|
// or display the help what commands are available (true)
|
||||||
|
// this is all for an args count of 0 if it is > 0 and a NestedCommand Annotation is present
|
||||||
|
// it will always handle the methods that NestedCommand points to
|
||||||
|
// e.g.:
|
||||||
|
// - /cmd - @NestedCommand(executeBody = true) will go into the else loop and execute code in that method
|
||||||
|
// - /cmd <arg1> <arg2> - @NestedCommand(executeBody = true) will always go to the nested command class
|
||||||
|
// - /cmd <arg1> - @NestedCommand(executeBody = false) will always go to the nested command class not matter the args
|
||||||
|
boolean executeNested = method.isAnnotationPresent(NestedCommand.class)
|
||||||
|
&& (argsCount > 0 || !method.getAnnotation(NestedCommand.class).executeBody());
|
||||||
|
|
||||||
|
if (executeNested) {
|
||||||
if (argsCount == 0) {
|
if (argsCount == 0) {
|
||||||
throw new MissingNestedCommandException("Sub-command required.",
|
throw new MissingNestedCommandException("Sub-command required.",
|
||||||
getNestedUsage(args, level, method, player));
|
getNestedUsage(args, level, method, player));
|
||||||
|
@ -38,4 +38,9 @@ public @interface NestedCommand {
|
|||||||
* A list of classes with the child commands.
|
* A list of classes with the child commands.
|
||||||
*/
|
*/
|
||||||
Class<?>[] value();
|
Class<?>[] value();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set to true it will execute the body of the tagged method.
|
||||||
|
*/
|
||||||
|
boolean executeBody() default false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user