Class Tooltip<S>

java.lang.Object
dev.jorel.commandapi.Tooltip<S>
Type Parameters:
S - the object that the argument suggestions use

public class Tooltip<S> extends Object
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
    Modifier
    Constructor
    Description
    protected
    Tooltip(S object, com.mojang.brigadier.Message tooltip)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <S> Tooltip<S>[]
    arrayOf(Tooltip<S>... tooltips)
    Constructs a Tooltip<S>[] from an array of Tooltip<S> via varargs.
    build(Function<S,String> mapper)
    Constructs a function that maps the current Tooltip<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 collections
    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
    static <S> Collection<Tooltip<S>>
    generateMessages(Function<S,com.mojang.brigadier.Message> tooltipGenerator, Collection<S> suggestions)
    Constructs a collection of objects from an collection of suggestions, and a function which generates a formatted tooltip for each suggestion
    static <S> Collection<Tooltip<S>>
    generateMessages(Function<S,com.mojang.brigadier.Message> tooltipGenerator, S... suggestions)
    Constructs a collection of objects from an array of suggestions, and a function which generates a formatted tooltip for each suggestion
    static <S> Collection<Tooltip<S>>
    generateStrings(Function<S,String> tooltipGenerator, Collection<S> suggestions)
    Constructs a collection of objects from a collection of suggestions, and a function which generates a string tooltip for each suggestion
    static <S> Collection<Tooltip<S>>
    generateStrings(Function<S,String> tooltipGenerator, S... suggestions)
    Constructs a collection of objects from an array of suggestions, and a function which generates a string tooltip for each suggestion
    Gets the suggestion for this object
    com.mojang.brigadier.Message
    Gets the formatted tooltip for this object
    static com.mojang.brigadier.Message
    Converts an unformatted string to an unformatted tooltip by wrapping as with a LiteralMessage.
    static <S> Collection<Tooltip<S>>
    none(Collection<S> suggestions)
    Constructs a collection of objects from a collection of suggestions, and no tooltips
    static <S> Tooltip<S>
    none(S object)
    Constructs a Tooltip<S> with a suggestion and no tooltip
    static <S> Collection<Tooltip<S>>
    none(S... suggestions)
    Constructs a collection of objects from an array of suggestions, and no tooltips
    static <S> Tooltip<S>
    ofMessage(S object, com.mojang.brigadier.Message tooltip)
    Constructs a Tooltip<S> with a suggestion and a tooltip
    static <S> Tooltip<S>
    ofString(S object, String tooltip)
    Constructs a Tooltip<S> with a suggestion and a tooltip

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Tooltip

      protected Tooltip(S object, com.mojang.brigadier.Message tooltip)
  • Method Details

    • getSuggestion

      public S 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

      public static <S> Tooltip<S> ofString(S object, String tooltip)
      Constructs a Tooltip<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 user
      tooltip - the tooltip to show to the user when they hover over the suggestion
      Returns:
      a Tooltip<S> representing this suggestion and tooltip
    • ofMessage

      public static <S> Tooltip<S> ofMessage(S object, com.mojang.brigadier.Message tooltip)
      Constructs a Tooltip<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 user
      tooltip - the tooltip to show to the user when they hover over the suggestion
      Returns:
      a Tooltip<S> representing this suggestion and tooltip
    • none

      public static <S> Tooltip<S> none(S object)
      Constructs a Tooltip<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

      @SafeVarargs public static <S> Collection<Tooltip<S>> none(S... suggestions)
      Constructs a collection of 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 objects from the suggestions, with no tooltips
    • none

      public static <S> Collection<Tooltip<S>> none(Collection<S> suggestions)
      Constructs a collection of 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 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 of 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 suggestion
      suggestions - 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 of 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 suggestion
      suggestions - 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 of 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 suggestion
      suggestions - 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 of 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 suggestion
      suggestions - 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 use
      T - the type of the tooltip
      Parameters:
      tooltipGenerator - tooltip generation function
      tooltipWrapper - function which wraps suggestion and tooltip into a object
      suggestions - 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 use
      T - the type of the tooltip
      Parameters:
      tooltipGenerator - tooltip generation function
      tooltipWrapper - function which wraps suggestion and tooltip into a object
      suggestions - collection of suggestions to provide to the user
      Returns:
      a collection of objects from the provided suggestion, wrapped using the above functions
    • arrayOf

      @SafeVarargs public static <S> Tooltip<S>[] arrayOf(Tooltip<S>... tooltips)
      Constructs a Tooltip<S>[] from an array of Tooltip<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 of Tooltip<S> to be converted into Tooltip<S>[]
      Returns:
      a Tooltip<S>[] from the provided Tooltip<S>
    • build

      public static <S> Function<Tooltip<S>,StringTooltip> build(Function<S,String> mapper)
      Constructs a function that maps the current Tooltip<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

      public static com.mojang.brigadier.Message messageFromString(String string)
      Converts an unformatted string to an unformatted tooltip by wrapping as with a LiteralMessage. If formatting is required, please see the various other messageFromXXX methods.
      Parameters:
      string - unformatted string tooltip
      Returns:
      wrapped tooltip as a LiteralMessage