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.
    static <S> Collection<Tooltip<S>>
    generateAdvenureComponents(Function<S,net.kyori.adventure.text.Component> tooltipGenerator, Collection<S> suggestions)
    Constructs a collection of Tooltip<S> objects from a collection of suggestions, and a function which generates a tooltip formatted as an adventure Component for each suggestion
    static <S> Collection<Tooltip<S>>
    generateAdvenureComponents(Function<S,net.kyori.adventure.text.Component> tooltipGenerator, S... suggestions)
    Constructs a collection of Tooltip<S> objects from an array of suggestions, and a function which generates a tooltip formatted as an adventure Component for each suggestion
    static <S> Collection<Tooltip<S>>
    generateBaseComponents(Function<S,net.md_5.bungee.api.chat.BaseComponent[]> tooltipGenerator, Collection<S> suggestions)
    Constructs a collection of Tooltip<S> objects from a collection of suggestions, and a function which generates a tooltip formatted as an array of BaseComponents for each suggestion
    static <S> Collection<Tooltip<S>>
    generateBaseComponents(Function<S,net.md_5.bungee.api.chat.BaseComponent[]> tooltipGenerator, S... suggestions)
    Constructs a collection of Tooltip<S> objects from an array of suggestions, and a function which generates a tooltip formatted as an array of BaseComponents for each suggestion
    static <S> Collection<Tooltip<S>>
    generateMessages(Function<S,com.mojang.brigadier.Message> tooltipGenerator, Collection<S> suggestions)
    Constructs a collection of Tooltip<S> 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 Tooltip<S> 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 Tooltip<S> 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 Tooltip<S> 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
    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.
    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.
    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 Tooltip<S> 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 Tooltip<S> objects from an array of suggestions, and no tooltips
    static <S> Tooltip<S>
    of(S object, String tooltip)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Please use ofString(Object, String) instead
    static <S> Tooltip<S>
    ofAdventureComponent(S object, net.kyori.adventure.text.Component tooltip)
    Constructs a Tooltip<S> with a suggestion and a formatted tooltip
    static <S> Tooltip<S>
    ofBaseComponents(S object, net.md_5.bungee.api.chat.BaseComponent... tooltip)
    Constructs a Tooltip<S> with a suggestion and a formatted tooltip
    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
    • of

      @Deprecated(forRemoval=true) public static <S> Tooltip<S> of(S object, String tooltip)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Please use ofString(Object, String) instead
      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
    • 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
    • ofBaseComponents

      public static <S> Tooltip<S> ofBaseComponents(S object, net.md_5.bungee.api.chat.BaseComponent... tooltip)
      Constructs a Tooltip<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 user
      tooltip - 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 a Tooltip<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 user
      tooltip - the formatted 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 Tooltip<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

      public static <S> Collection<Tooltip<S>> none(Collection<S> suggestions)
      Constructs a collection of Tooltip<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 of Tooltip<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 suggestion
      suggestions - 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 of Tooltip<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 suggestion
      suggestions - 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 of Tooltip<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 suggestion
      suggestions - 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 of Tooltip<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 suggestion
      suggestions - 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 of Tooltip<S> objects from an array of suggestions, and a function which generates a tooltip formatted as an array of BaseComponents 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 of BaseComponents
      suggestions - 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 of Tooltip<S> objects from a collection of suggestions, and a function which generates a tooltip formatted as an array of BaseComponents 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 of BaseComponents
      suggestions - 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 of Tooltip<S> objects from an array of suggestions, and a function which generates a tooltip formatted as an adventure Component 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 adventure Component
      suggestions - 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 of Tooltip<S> objects from a collection of suggestions, and a function which generates a tooltip formatted as an adventure Component 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 adventure Component
      suggestions - 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

      @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 messageFromBaseComponents(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.