Allow argument descriptions to be set using the @Argument annotation
This commit is contained in:
parent
d6ce74f2d9
commit
e72a876037
3 changed files with 17 additions and 4 deletions
|
|
@ -170,12 +170,14 @@ public final class AnnotationParser<C> {
|
||||||
this.createMeta(method.getAnnotations()));
|
this.createMeta(method.getAnnotations()));
|
||||||
final Collection<ArgumentParameterPair> arguments = this.getArguments(method);
|
final Collection<ArgumentParameterPair> arguments = this.getArguments(method);
|
||||||
final Map<String, CommandArgument<C, ?>> commandArguments = Maps.newHashMap();
|
final Map<String, CommandArgument<C, ?>> commandArguments = Maps.newHashMap();
|
||||||
|
final Map<CommandArgument<C, ?>, String> argumentDescriptions = Maps.newHashMap();
|
||||||
/* Go through all annotated parameters and build up the argument tree */
|
/* Go through all annotated parameters and build up the argument tree */
|
||||||
for (final ArgumentParameterPair argumentPair : arguments) {
|
for (final ArgumentParameterPair argumentPair : arguments) {
|
||||||
final CommandArgument<C, ?> argument = this.buildArgument(method,
|
final CommandArgument<C, ?> argument = this.buildArgument(method,
|
||||||
tokens.get(argumentPair.getArgument().value()),
|
tokens.get(argumentPair.getArgument().value()),
|
||||||
argumentPair);
|
argumentPair);
|
||||||
commandArguments.put(argument.getName(), argument);
|
commandArguments.put(argument.getName(), argument);
|
||||||
|
argumentDescriptions.put(argument, argumentPair.getArgument().description());
|
||||||
}
|
}
|
||||||
boolean commandNameFound = false;
|
boolean commandNameFound = false;
|
||||||
/* Build the command tree */
|
/* Build the command tree */
|
||||||
|
|
@ -194,7 +196,10 @@ public final class AnnotationParser<C> {
|
||||||
entry.getKey(), method.getName()
|
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 */
|
/* Try to find the command sender type */
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,11 @@ public @interface Argument {
|
||||||
*/
|
*/
|
||||||
String defaultValue() default "";
|
String defaultValue() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The argument description
|
||||||
|
*
|
||||||
|
* @return Argument description
|
||||||
|
*/
|
||||||
|
String description() default "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -198,9 +198,10 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
@Description("Test cloud command using @CommandMethod")
|
@Description("Test cloud command using @CommandMethod")
|
||||||
@CommandMethod(value = "annotation|a <input> [number]", permission = "some.permission.node")
|
@CommandMethod(value = "annotation|a <input> [number]", permission = "some.permission.node")
|
||||||
private void annotatedCommand(@Nonnull final Player player,
|
private void annotatedCommand(@Nonnull final Player player,
|
||||||
@Argument("input") @Completions("one,two,duck") @Nonnull final String input,
|
@Argument(value = "input", description = "Some string") @Completions("one,two,duck")
|
||||||
@Argument(value = "number", defaultValue = "5") @Range(min = "10", max = "100")
|
@Nonnull final String input,
|
||||||
final int number) {
|
@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 + ")");
|
player.sendMessage(ChatColor.GOLD + "Your input was: " + ChatColor.AQUA + input + ChatColor.GREEN + " (" + number + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue