Allow for use of @Completions annotation with argument types other than String

This commit is contained in:
jmp 2020-10-26 23:21:25 -07:00 committed by Alexander Söderberg
parent 9a5c674f0d
commit 9c9e13e8b8
3 changed files with 12 additions and 19 deletions

View file

@ -28,6 +28,7 @@ import cloud.commandframework.CommandManager;
import cloud.commandframework.Description;
import cloud.commandframework.annotations.injection.ParameterInjectorRegistry;
import cloud.commandframework.annotations.injection.RawArgs;
import cloud.commandframework.annotations.specifier.Completions;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.flags.CommandFlag;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
@ -427,8 +428,14 @@ public final class AnnotationParser<C> {
} else {
argumentBuilder.asRequired();
}
/* Check whether or not a suggestion provider should be set */
if (!argument.suggestions().isEmpty()) {
/* Check for Completions annotation */
final Completions completions = parameter.getDeclaredAnnotation(Completions.class);
if (completions != null) {
final List<String> suggestions = Arrays.asList(
completions.value().replace(" ", "").split(",")
);
argumentBuilder.withSuggestionsProvider((commandContext, input) -> suggestions);
} else if (!argument.suggestions().isEmpty()) { /* Check whether or not a suggestion provider should be set */
final String suggestionProviderName = argument.suggestions();
final Optional<BiFunction<CommandContext<C>, String, List<String>>> suggestionsFunction =
this.manager.getParserRegistry().getSuggestionProvider(suggestionProviderName);