CommandAPI 9.6.0
An API for the command UI introduced in Minecraft 1.13
com.mojang.brigadier.suggestion.Suggestions Class Reference

A collection of Suggestions. More...

Public Member Functions

 Suggestions (final StringRange range, final List< Suggestion > suggestions)
 
StringRange getRange ()
 Returns the range the suggestions span. More...
 
List< SuggestiongetList ()
 Returns all suggestions as a list. More...
 
boolean isEmpty ()
 Checks if no suggestions are stored in this object. More...
 
boolean equals (final Object o)
 
int hashCode ()
 
String toString ()
 

Static Public Member Functions

static CompletableFuture< Suggestionsempty ()
 Returns a future that instantly completes with an empty Suggestions instance. More...
 
static Suggestions merge (final String command, final Collection< Suggestions > input)
 Merges multiple Suggestions instances for a single command. More...
 
static Suggestions create (final String command, final Collection< Suggestion > suggestions)
 Creates a Suggestions instance from a command and a list of possible Suggestions. More...
 

Detailed Description

A collection of Suggestions.

Member Function Documentation

◆ create()

static Suggestions com.mojang.brigadier.suggestion.Suggestions.create ( final String  command,
final Collection< Suggestion suggestions 
)
static

Creates a Suggestions instance from a command and a list of possible Suggestions.

The Suggestions instance will span the entire range, from the minimal index to maximum index found in the suggestions.

It will also automatically call Suggestion#expand for every possible suggestion, using the command and the computed general range.

After all of that it sorts the results and returns them.


Some examples:

Suggestion foo = new Suggestion(StringRange.between(0, 2), "foo");
Suggestion bar = new Suggestion(StringRange.at(2), "bar");

Suggestions suggestions = Suggestions.create("1234567", List.of(foo, bar));
for (Suggestion suggestion : suggestions.getList()) {
    System.out.println(suggestion.apply("abcdefgh"));
}

Prints:

(ordered alphabetically)
12barcdefgh (range expanded from 0 to 2, so it replaced "ab")
foocdefgh (range was already 0 to 2, so nothing really changed)
Parameters
commandthe command to get them for
suggestionsa list with possible suggestions
Returns
a Suggestions instance for the given command with the passed suggestions

◆ empty()

static CompletableFuture< Suggestions > com.mojang.brigadier.suggestion.Suggestions.empty ( )
static

Returns a future that instantly completes with an empty Suggestions instance.

Returns
a future that instantly completes with an empty Suggestions instance

◆ getList()

List< Suggestion > com.mojang.brigadier.suggestion.Suggestions.getList ( )

Returns all suggestions as a list.

Returns
all suggestions as a list

◆ getRange()

StringRange com.mojang.brigadier.suggestion.Suggestions.getRange ( )

Returns the range the suggestions span.

Returns
the range the suggestions span

◆ isEmpty()

boolean com.mojang.brigadier.suggestion.Suggestions.isEmpty ( )

Checks if no suggestions are stored in this object.

Returns
true if no suggestions are stored in this object

◆ merge()

static Suggestions com.mojang.brigadier.suggestion.Suggestions.merge ( final String  command,
final Collection< Suggestions input 
)
static

Merges multiple Suggestions instances for a single command.

Just combines the input into one collection and then calls create with the result.

Parameters
commandthe command
inputthe suggestions instances
Returns
returns a merged Suggestions instance