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

A Suggestion that suggests an integer. More...

+ Inheritance diagram for com.mojang.brigadier.suggestion.IntegerSuggestion:

Public Member Functions

 IntegerSuggestion (final StringRange range, final int value)
 Creates a new IntegerSuggestion that covers a given range and suggests a given int value. More...
 
 IntegerSuggestion (final StringRange range, final int value, final Message tooltip)
 Creates a new IntegerSuggestion that covers a given range and has a given int value and tooltip. More...
 
int getValue ()
 Returns the underlying integer suggestion value. More...
 
boolean equals (final Object o)
 
int hashCode ()
 
String toString ()
 
int compareTo (final Suggestion o)
 Compares the getText() of this suggestion to the getText() of the passed suggestion. More...
 
int compareToIgnoreCase (final Suggestion b)
 Compares the getText() of this suggestion to the getText() of the passed suggestion, ignoring case. More...
 
StringRange getRange ()
 Returns the range in the input string this suggestion is applicable in. More...
 
String getText ()
 Returns the text this suggestion suggests. More...
 
Message getTooltip ()
 Returns the tooltip with some explanatory message for the user. More...
 
String apply (final String input)
 Applies the suggestion to the input. More...
 
Suggestion expand (final String command, final StringRange range)
 Expands this suggestion by changing the range to the passed one and filling everything that lies outside getText() with characters from the passed command. More...
 

Detailed Description

A Suggestion that suggests an integer.

The method compareTo(Suggestion) orders IntegerSuggestions in ascending order, but when compared with other suggestion types orders them based on the textual representation of the integer value.

Constructor & Destructor Documentation

◆ IntegerSuggestion() [1/2]

com.mojang.brigadier.suggestion.IntegerSuggestion.IntegerSuggestion ( final StringRange  range,
final int  value 
)

Creates a new IntegerSuggestion that covers a given range and suggests a given int value.

Parameters
rangethe range it covers in the input
valuethe integer value to suggest

◆ IntegerSuggestion() [2/2]

com.mojang.brigadier.suggestion.IntegerSuggestion.IntegerSuggestion ( final StringRange  range,
final int  value,
final Message  tooltip 
)

Creates a new IntegerSuggestion that covers a given range and has a given int value and tooltip.

Parameters
rangethe range it covers in the input
valuethe integer value to suggest
tooltipa tooltip message to show the user

Member Function Documentation

◆ apply()

String com.mojang.brigadier.suggestion.Suggestion.apply ( final String  input)
inherited

Applies the suggestion to the input.

This method will replace or insert the getText() into the passed input string.


An Example with the text fizz:

  • Input: buzz, range 0-4
    Output: fizz
  • Input: buzz, range 0-0
    Output: fizzbuzz
  • Input: buzz, range 4-4
    Output: buzzfizz
Parameters
inputthe input string to apply it to
Returns
the result of applying the suggestion to the input
Exceptions
StringIndexOutOfBoundsExceptionif the range is not contained in the input string

◆ compareTo()

int com.mojang.brigadier.suggestion.IntegerSuggestion.compareTo ( final Suggestion  o)

Compares the getText() of this suggestion to the getText() of the passed suggestion.

This method is case sensitive, see compareToIgnoreCase(Suggestion) if you need it to the ignore the case.

Parameters
othe suggestion to compare it to
Returns
-1 if this suggestion is less than the other, 0 if they are equal or 1 if this suggestion should appear behind the passed one
See also
compareToIgnoreCase
String::compareTo

Reimplemented from com.mojang.brigadier.suggestion.Suggestion.

◆ compareToIgnoreCase()

int com.mojang.brigadier.suggestion.IntegerSuggestion.compareToIgnoreCase ( final Suggestion  b)

Compares the getText() of this suggestion to the getText() of the passed suggestion, ignoring case.

Parameters
bthe suggestion to compare it to
Returns
-1 if this suggestion is less than the other, 0 if they are equal or 1 if this suggestion should appear behind the passed one
See also
String::compareToIgnoreCase
compareTo

Reimplemented from com.mojang.brigadier.suggestion.Suggestion.

◆ equals()

boolean com.mojang.brigadier.suggestion.IntegerSuggestion.equals ( final Object  o)

◆ expand()

Suggestion com.mojang.brigadier.suggestion.Suggestion.expand ( final String  command,
final StringRange  range 
)
inherited

Expands this suggestion by changing the range to the passed one and filling everything that lies outside getText() with characters from the passed command.


Examples with text = ---- and range = 0 and the text to apply it to as abcdefghi:

  • expand("123", StringRange.at(0):
    ----abcdefghi, as the ranges matched and so nothing was changed
  • expand("123", StringRange.at(1):
    a----1bcdefghi, as the passed range (1) was taken and one character from the command was used to fill up the index 1, as the range of the original suggestion was 0
  • expand("123", StringRange.between(1, 3):
    a----123defghi, as the passed range (1,3) was taken and 3 characters from the command were used to fill up the indices 1, 2 and 3, as the range of the original suggestion was 0. It is then inserted after the first character in the text it is applied to (after the a) and replaces everything that lies in its interval (bc).
Parameters
commandthe command to fill the range up with
rangethe range to widen it to
Returns
the expanded suggestion

◆ getRange()

StringRange com.mojang.brigadier.suggestion.Suggestion.getRange ( )
inherited

Returns the range in the input string this suggestion is applicable in.

Returns
the range in the input it is applicable in

◆ getText()

String com.mojang.brigadier.suggestion.Suggestion.getText ( )
inherited

Returns the text this suggestion suggests.

Returns
the text this suggestion suggests

◆ getTooltip()

Message com.mojang.brigadier.suggestion.Suggestion.getTooltip ( )
inherited

Returns the tooltip with some explanatory message for the user.

Returns
the tooltip with some explanatory message for the user or null if not set

◆ getValue()

int com.mojang.brigadier.suggestion.IntegerSuggestion.getValue ( )

Returns the underlying integer suggestion value.

Returns
the underlying integer suggestion value

◆ hashCode()

int com.mojang.brigadier.suggestion.IntegerSuggestion.hashCode ( )

◆ toString()

String com.mojang.brigadier.suggestion.IntegerSuggestion.toString ( )