Package dev.jorel.commandapi
Class Tooltip<S>
java.lang.Object
dev.jorel.commandapi.Tooltip<S>
- Type Parameters:
S- the object that the argument suggestions use
This class represents a suggestion for an argument with a hover tooltip text
for that suggestion. This class is parameterized over some object S that
represents the safe cast type for argument suggestions. This class is to be
used with safe suggestion overrides, via the
SafeOverrideableArgument.safeOverrideSuggestionsT method.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <S> Tooltip<S>[]Constructs aTooltip<S>[] from an array ofTooltip<S>via varargs.static <S> Function<Tooltip<S>,StringTooltip> Constructs a function that maps the currentTooltip<S>into a StringTooltip, using a standard mapping function which is defined for a given argument.static <S> Collection<Tooltip<S>>generateAdvenureComponents(Function<S, net.kyori.adventure.text.Component> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and a function which generates a tooltip formatted as an adventureComponentfor each suggestionstatic <S> Collection<Tooltip<S>>generateAdvenureComponents(Function<S, net.kyori.adventure.text.Component> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a tooltip formatted as an adventureComponentfor each suggestionstatic <S> Collection<Tooltip<S>>generateBaseComponents(Function<S, net.md_5.bungee.api.chat.BaseComponent[]> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and a function which generates a tooltip formatted as an array ofBaseComponents for each suggestionstatic <S> Collection<Tooltip<S>>generateBaseComponents(Function<S, net.md_5.bungee.api.chat.BaseComponent[]> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a tooltip formatted as an array ofBaseComponents for each suggestionstatic <S> Collection<Tooltip<S>>generateMessages(Function<S, com.mojang.brigadier.Message> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from an collection of suggestions, and a function which generates a formatted tooltip for each suggestionstatic <S> Collection<Tooltip<S>>generateMessages(Function<S, com.mojang.brigadier.Message> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a formatted tooltip for each suggestionstatic <S> Collection<Tooltip<S>>generateStrings(Function<S, String> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and a function which generates a string tooltip for each suggestionstatic <S> Collection<Tooltip<S>>generateStrings(Function<S, String> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a string tooltip for each suggestionGets the suggestion for this objectcom.mojang.brigadier.MessageGets the formatted tooltip for this objectstatic com.mojang.brigadier.MessagemessageFromAdventureComponent(net.kyori.adventure.text.Component component) Converts a formatted adventure text component to a native minecraft text component which can be used natively by brigadier.static com.mojang.brigadier.MessagemessageFromBaseComponents(net.md_5.bungee.api.chat.BaseComponent... components) Converts a formatted bungee text component to a native minecraft text component which can be used natively by brigadier.static com.mojang.brigadier.MessagemessageFromString(String string) Converts an unformatted string to an unformatted tooltip by wrapping as with aLiteralMessage.static <S> Collection<Tooltip<S>>none(Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and no tooltipsstatic <S> Tooltip<S>none(S object) Constructs aTooltip<S>with a suggestion and no tooltipstatic <S> Collection<Tooltip<S>>none(S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and no tooltipsstatic <S> Tooltip<S>Deprecated, for removal: This API element is subject to removal in a future version.static <S> Tooltip<S>ofAdventureComponent(S object, net.kyori.adventure.text.Component tooltip) Constructs aTooltip<S>with a suggestion and a formatted tooltipstatic <S> Tooltip<S>ofBaseComponents(S object, net.md_5.bungee.api.chat.BaseComponent... tooltip) Constructs aTooltip<S>with a suggestion and a formatted tooltipstatic <S> Tooltip<S>ofMessage(S object, com.mojang.brigadier.Message tooltip) Constructs aTooltip<S>with a suggestion and a tooltipstatic <S> Tooltip<S>Constructs aTooltip<S>with a suggestion and a tooltip
-
Constructor Details
-
Tooltip
-
-
Method Details
-
getSuggestion
Gets the suggestion for this object- Returns:
- the suggestion for this object
-
getTooltip
public com.mojang.brigadier.Message getTooltip()Gets the formatted tooltip for this object- Returns:
- the formatted tooltip for this object
-
of
Deprecated, for removal: This API element is subject to removal in a future version.Please useofString(Object, String)insteadConstructs aTooltip<S>with a suggestion and a tooltip- Type Parameters:
S- the object that the argument suggestions use- Parameters:
object- the suggestion to provide to the usertooltip- the tooltip to show to the user when they hover over the suggestion- Returns:
- a
Tooltip<S>representing this suggestion and tooltip
-
ofString
Constructs aTooltip<S>with a suggestion and a tooltip- Type Parameters:
S- the object that the argument suggestions use- Parameters:
object- the suggestion to provide to the usertooltip- the tooltip to show to the user when they hover over the suggestion- Returns:
- a
Tooltip<S>representing this suggestion and tooltip
-
ofMessage
Constructs aTooltip<S>with a suggestion and a tooltip- Type Parameters:
S- the object that the argument suggestions use- Parameters:
object- the suggestion to provide to the usertooltip- the tooltip to show to the user when they hover over the suggestion- Returns:
- a
Tooltip<S>representing this suggestion and tooltip
-
ofBaseComponents
public static <S> Tooltip<S> ofBaseComponents(S object, net.md_5.bungee.api.chat.BaseComponent... tooltip) Constructs aTooltip<S>with a suggestion and a formatted tooltip- Type Parameters:
S- the object that the argument suggestions use- Parameters:
object- the suggestion to provide to the usertooltip- the formatted tooltip to show to the user when they hover over the suggestion- Returns:
- a
Tooltip<S>representing this suggestion and tooltip
-
ofAdventureComponent
public static <S> Tooltip<S> ofAdventureComponent(S object, net.kyori.adventure.text.Component tooltip) Constructs aTooltip<S>with a suggestion and a formatted tooltip- Type Parameters:
S- the object that the argument suggestions use- Parameters:
object- the suggestion to provide to the usertooltip- the formatted tooltip to show to the user when they hover over the suggestion- Returns:
- a
Tooltip<S>representing this suggestion and tooltip
-
none
Constructs aTooltip<S>with a suggestion and no tooltip- Type Parameters:
S- the object that the argument suggestions use- Parameters:
object- the suggestion to provide to the user- Returns:
- a
Tooltip<S>representing this suggestion
-
none
Constructs a collection ofTooltip<S>objects from an array of suggestions, and no tooltips- Type Parameters:
S- the object that the argument suggestions use- Parameters:
suggestions- array of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the suggestions, with no tooltips
-
none
Constructs a collection ofTooltip<S>objects from a collection of suggestions, and no tooltips- Type Parameters:
S- the object that the argument suggestions use- Parameters:
suggestions- collection of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the suggestions, with no tooltips
-
generateStrings
@SafeVarargs public static <S> Collection<Tooltip<S>> generateStrings(Function<S, String> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a string tooltip for each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a string tooltip for the suggestionsuggestions- array of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated string tooltips
-
generateStrings
public static <S> Collection<Tooltip<S>> generateStrings(Function<S, String> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and a function which generates a string tooltip for each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a string tooltip for the suggestionsuggestions- collection of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated string tooltips
-
generateMessages
@SafeVarargs public static <S> Collection<Tooltip<S>> generateMessages(Function<S, com.mojang.brigadier.Message> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a formatted tooltip for each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a formatted tooltip for the suggestionsuggestions- array of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated formatted tooltips
-
generateMessages
public static <S> Collection<Tooltip<S>> generateMessages(Function<S, com.mojang.brigadier.Message> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from an collection of suggestions, and a function which generates a formatted tooltip for each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a formatted tooltip for the suggestionsuggestions- collection of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated formatted tooltips
-
generateBaseComponents
@SafeVarargs public static <S> Collection<Tooltip<S>> generateBaseComponents(Function<S, net.md_5.bungee.api.chat.BaseComponent[]> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a tooltip formatted as an array ofBaseComponents for each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a formatted tooltip for the suggestion, an array ofBaseComponentssuggestions- array of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated formatted tooltips
-
generateBaseComponents
public static <S> Collection<Tooltip<S>> generateBaseComponents(Function<S, net.md_5.bungee.api.chat.BaseComponent[]> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and a function which generates a tooltip formatted as an array ofBaseComponents for each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a formatted tooltip for the suggestion, an array ofBaseComponentssuggestions- collection of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated formatted tooltips
-
generateAdvenureComponents
@SafeVarargs public static <S> Collection<Tooltip<S>> generateAdvenureComponents(Function<S, net.kyori.adventure.text.Component> tooltipGenerator, S... suggestions) Constructs a collection ofTooltip<S>objects from an array of suggestions, and a function which generates a tooltip formatted as an adventureComponentfor each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a formatted tooltip for the suggestion, an adventureComponentsuggestions- array of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated formatted tooltips
-
generateAdvenureComponents
public static <S> Collection<Tooltip<S>> generateAdvenureComponents(Function<S, net.kyori.adventure.text.Component> tooltipGenerator, Collection<S> suggestions) Constructs a collection ofTooltip<S>objects from a collection of suggestions, and a function which generates a tooltip formatted as an adventureComponentfor each suggestion- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltipGenerator- function which returns a formatted tooltip for the suggestion, an adventureComponentsuggestions- collection of suggestions to provide to the user- Returns:
- a collection of
Tooltip<S>objects from the provided suggestions, with the generated formatted tooltips
-
arrayOf
Constructs aTooltip<S>[] from an array ofTooltip<S>via varargs. This method takes advantage of Java's varargs to construct a generic array parameterised over S for the purpose of type safety for the safeOverrideSuggestionsT method, because Java doesn't allow you to create generic arrays.- Type Parameters:
S- the object that the argument suggestions use- Parameters:
tooltips- an array ofTooltip<S>to be converted intoTooltip<S>[]- Returns:
- a
Tooltip<S>[] from the providedTooltip<S>
-
build
Constructs a function that maps the currentTooltip<S>into a StringTooltip, using a standard mapping function which is defined for a given argument. This method is used internally by the CommandAPI.- Type Parameters:
S- the object that the argument suggestions use- Parameters:
mapper- a mapping function that converts an S instance into a String- Returns:
- the mapping function from this tooltip into a StringTooltip
-
messageFromString
Converts an unformatted string to an unformatted tooltip by wrapping as with aLiteralMessage. If formatting is required, please seemessageFromBaseComponents(BaseComponent...), or consider using the more modern adventure text api.- Parameters:
string- unformatted string tooltip- Returns:
- wrapped tooltip as a
LiteralMessage
-
messageFromBaseComponents
public static com.mojang.brigadier.Message messageFromBaseComponents(net.md_5.bungee.api.chat.BaseComponent... components) Converts a formatted bungee text component to a native minecraft text component which can be used natively by brigadier. This supports all forms of formatting including entity selectors, scores, click & hover events, translations, keybinds and more. Note: the bungee component api is deprecated, and the adventure text component api should be used instead- Parameters:
components- array of bungee text components- Returns:
- native minecraft message object which can be used natively by brigadier.
-
messageFromAdventureComponent
public static com.mojang.brigadier.Message messageFromAdventureComponent(net.kyori.adventure.text.Component component) Converts a formatted adventure text component to a native minecraft text component which can be used natively by brigadier. This supports all forms of formatting including entity selectors, scores, click & hover events, translations, keybinds and more.- Parameters:
component- adventure text component- Returns:
- native minecraft message object which can be used natively by brigadier.
-
ofString(Object, String)instead