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.

@FunctionalInterface public interface SuggestionProvider
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 Details

    • getSuggestions

      CompletableFuture<Suggestions> getSuggestions(CommandContext context, SuggestionsBuilder builder)
      Provides suggestions for the argument.
      Parameters:
      context - the current command context
      builder - the suggestions builder
      Returns:
      a future that completes with suggestions
    • empty

      static SuggestionProvider empty()
      Returns a suggestion provider that always returns empty suggestions.
      Returns:
      an empty suggestion provider
    • of

      static SuggestionProvider of(String... suggestions)
      Returns a suggestion provider from a list of static suggestions.
      Parameters:
      suggestions - the suggestions to provide
      Returns:
      a static suggestion provider
    • of

      static SuggestionProvider of(Iterable<String> suggestions)
      Returns a suggestion provider from a dynamic collection.
      Parameters:
      suggestions - supplier for suggestions
      Returns:
      a dynamic suggestion provider