diff --git a/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java b/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java index 72594630b..1d6283d37 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/CommandsManager.java @@ -456,7 +456,18 @@ public abstract class CommandsManager { 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 - @NestedCommand(executeBody = true) will always go to the nested command class + // - /cmd - @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) { throw new MissingNestedCommandException("Sub-command required.", getNestedUsage(args, level, method, player)); diff --git a/src/main/java/com/sk89q/minecraft/util/commands/NestedCommand.java b/src/main/java/com/sk89q/minecraft/util/commands/NestedCommand.java index c87f0deba..142577bb1 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/NestedCommand.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/NestedCommand.java @@ -38,4 +38,9 @@ public @interface NestedCommand { * A list of classes with the child commands. */ Class[] value(); + + /** + * If set to true it will execute the body of the tagged method. + */ + boolean executeBody() default false; }