Interface SuggestionProvider
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface for providing custom suggestions for an argument.
Implement this to provide dynamic suggestions based on the command context.
Example Usage
// Custom player name suggestions
SuggestionProvider playerSuggestions = (context, builder) -> {
for (TalePlayer player : getOnlinePlayers()) {
builder.suggest(player.getDisplayName());
}
return builder.buildFuture();
};
Command.literal("tp")
.then(Command.argument("player", StringArgumentType.word())
.suggests(playerSuggestions))
.build();
-
Method Summary
Modifier and TypeMethodDescriptionstatic SuggestionProviderempty()Returns a suggestion provider that always returns empty suggestions.getSuggestions(CommandContext context, SuggestionsBuilder builder) Provides suggestions for the argument.static SuggestionProviderReturns a suggestion provider from a dynamic collection.static SuggestionProviderReturns a suggestion provider from a list of static suggestions.
-
Method Details
-
getSuggestions
Provides suggestions for the argument.- Parameters:
context- the current command contextbuilder- the suggestions builder- Returns:
- a future that completes with suggestions
-
empty
Returns a suggestion provider that always returns empty suggestions.- Returns:
- an empty suggestion provider
-
of
Returns a suggestion provider from a list of static suggestions.- Parameters:
suggestions- the suggestions to provide- Returns:
- a static suggestion provider
-
of
Returns a suggestion provider from a dynamic collection.- Parameters:
suggestions- supplier for suggestions- Returns:
- a dynamic suggestion provider
-