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.protected static <S,T> Collection <Tooltip<S>> generate(Function<S, T> tooltipGenerator, BiFunction<S, T, Tooltip<S>> tooltipWrapper, Collection<S> suggestions) Internal base method for the other generation types, for processing collectionsprotected static <S,T> Collection <Tooltip<S>> generate(Function<S, T> tooltipGenerator, BiFunction<S, T, Tooltip<S>> tooltipWrapper, S... suggestions) Internal base method for the other generation types, for processing arraysstatic <S> Collection<Tooltip<S>> generateMessages(Function<S, com.mojang.brigadier.Message> tooltipGenerator, Collection<S> suggestions) static <S> Collection<Tooltip<S>> generateMessages(Function<S, com.mojang.brigadier.Message> tooltipGenerator, S... suggestions) static <S> Collection<Tooltip<S>> generateStrings(Function<S, String> tooltipGenerator, Collection<S> suggestions) static <S> Collection<Tooltip<S>> generateStrings(Function<S, String> tooltipGenerator, S... suggestions) Gets the suggestion for this objectcom.mojang.brigadier.MessageGets the formatted tooltip for this objectstatic 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) static <S> Tooltip<S> none(S object) Constructs aTooltip<S>with a suggestion and no tooltipstatic <S> Collection<Tooltip<S>> none(S... suggestions) static <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
-
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
-
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
-
none
-
generateStrings
@SafeVarargs public static <S> Collection<Tooltip<S>> generateStrings(Function<S, String> tooltipGenerator, S... suggestions) Constructs a collection ofobjects 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
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 ofobjects 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
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 ofobjects 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
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 ofobjects 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
objects from the provided suggestions, with the generated formatted tooltips
-
generate
@SafeVarargs protected static <S,T> Collection<Tooltip<S>> generate(Function<S, T> tooltipGenerator, BiFunction<S, T, Tooltip<S>> tooltipWrapper, S... suggestions) Internal base method for the other generation types, for processing arrays- Type Parameters:
S- the object that the argument suggestions useT- the type of the tooltip- Parameters:
tooltipGenerator- tooltip generation functiontooltipWrapper- function which wraps suggestion and tooltip into aobjectsuggestions- array of suggestions to provide to the user- Returns:
- a collection of
objects from the provided suggestion, wrapped using the above functions
-
generate
protected static <S,T> Collection<Tooltip<S>> generate(Function<S, T> tooltipGenerator, BiFunction<S, T, Tooltip<S>> tooltipWrapper, Collection<S> suggestions) Internal base method for the other generation types, for processing collections- Type Parameters:
S- the object that the argument suggestions useT- the type of the tooltip- Parameters:
tooltipGenerator- tooltip generation functiontooltipWrapper- function which wraps suggestion and tooltip into aobjectsuggestions- collection of suggestions to provide to the user- Returns:
- a collection of
objects from the provided suggestion, wrapped using the above functions
-
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 see the various othermessageFromXXXmethods.- Parameters:
string- unformatted string tooltip- Returns:
- wrapped tooltip as a
LiteralMessage
-