From e72a876037330dbef4fd924a5013c42600021e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 21 Sep 2020 19:51:17 +0200 Subject: [PATCH] Allow argument descriptions to be set using the `@Argument` annotation --- .../commands/annotations/AnnotationParser.java | 7 ++++++- .../intellectualsites/commands/annotations/Argument.java | 7 +++++++ .../java/com/intellectualsites/commands/BukkitTest.java | 7 ++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/AnnotationParser.java b/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/AnnotationParser.java index cf078759..a5ee8413 100644 --- a/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/AnnotationParser.java +++ b/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/AnnotationParser.java @@ -170,12 +170,14 @@ public final class AnnotationParser { this.createMeta(method.getAnnotations())); final Collection arguments = this.getArguments(method); final Map> commandArguments = Maps.newHashMap(); + final Map, String> argumentDescriptions = Maps.newHashMap(); /* Go through all annotated parameters and build up the argument tree */ for (final ArgumentParameterPair argumentPair : arguments) { final CommandArgument argument = this.buildArgument(method, tokens.get(argumentPair.getArgument().value()), argumentPair); commandArguments.put(argument.getName(), argument); + argumentDescriptions.put(argument, argumentPair.getArgument().description()); } boolean commandNameFound = false; /* Build the command tree */ @@ -194,7 +196,10 @@ public final class AnnotationParser { entry.getKey(), method.getName() )); } - builder = builder.argument(argument); + + final String description = argumentDescriptions.getOrDefault(argument, ""); + + builder = builder.argument(argument, description); } } /* Try to find the command sender type */ diff --git a/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/Argument.java b/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/Argument.java index 2256e4d7..42834339 100644 --- a/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/Argument.java +++ b/cloud-annotations/src/main/java/com/intellectualsites/commands/annotations/Argument.java @@ -56,4 +56,11 @@ public @interface Argument { */ String defaultValue() default ""; + /** + * The argument description + * + * @return Argument description + */ + String description() default ""; + } diff --git a/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java b/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java index a6c0bfb7..630a27ae 100644 --- a/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java +++ b/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java @@ -198,9 +198,10 @@ public final class BukkitTest extends JavaPlugin { @Description("Test cloud command using @CommandMethod") @CommandMethod(value = "annotation|a [number]", permission = "some.permission.node") private void annotatedCommand(@Nonnull final Player player, - @Argument("input") @Completions("one,two,duck") @Nonnull final String input, - @Argument(value = "number", defaultValue = "5") @Range(min = "10", max = "100") - final int number) { + @Argument(value = "input", description = "Some string") @Completions("one,two,duck") + @Nonnull final String input, + @Argument(value = "number", defaultValue = "5", description = "A number") + @Range(min = "10", max = "100") final int number) { player.sendMessage(ChatColor.GOLD + "Your input was: " + ChatColor.AQUA + input + ChatColor.GREEN + " (" + number + ")"); }