Class ItemTooltip

java.lang.Object
net.risingworld.api.ui.ItemTooltip

public final class ItemTooltip extends Object
Represents a custom tooltip for a particular item. An item tooltip consists of four sections, and every section can be modified individually: the name (header of the tooltip), the modifier (shown next to the header), the info text (shown below the header) and the condition (the colored indicator at the bottom). Sections which are not set remain unchanged, so it's possible to only add an additional info line, for example.
Texts may contain formatting tags (like <color=#FF0000>, <b> or <i>) as well as line breaks.

Please note that item tooltips are not persistent: they are lost when the server restarts or when the player reconnects, so a plugin has to set them again (e.g. when a player spawns).
See Also:

Example: Set a custom name and add an info line
1//Create a tooltip and set a new name (for english and german)
2ItemTooltip tooltip = new ItemTooltip();
3tooltip.setName(ItemTooltip.Mode.Replace, new String[]{"en=Excalibur", "de=Excalibur"});
4
5//Add an additional line below the vanilla info text
6tooltip.setInfo(ItemTooltip.Mode.Append, "<color=#FFD700>Legendary sword</color>");
7
8//Assign the tooltip to the item
9item.setCustomTooltip(tooltip);
  • Field Details

    • COLOR_PRISTINE

      public static final int COLOR_PRISTINE
      Condition color which the game uses for pristine items (rgba)
      See Also:
    • COLOR_WORN

      public static final int COLOR_WORN
      Condition color which the game uses for worn items (rgba)
      See Also:
    • COLOR_DAMAGED

      public static final int COLOR_DAMAGED
      Condition color which the game uses for damaged items (rgba)
      See Also:
    • COLOR_BADLY_DAMAGED

      public static final int COLOR_BADLY_DAMAGED
      Condition color which the game uses for badly damaged items (rgba)
      See Also:
    • COLOR_RUINED

      public static final int COLOR_RUINED
      Condition color which the game uses for broken or spoiled items (rgba)
      See Also:
    • MAX_BYTES

      public static final int MAX_BYTES
      Maximum amount of bytes a single tooltip may have
      See Also:
  • Constructor Details

    • ItemTooltip

      public ItemTooltip()
  • Method Details

    • setName

      public ItemTooltip setName(ItemTooltip.Mode mode, String text)
      Sets the name section (header) of the tooltip.
      Parameters:
      mode - determines how the text is combined with the original name.
      text - the text. May be null if the mode does not need a text (e.g. ItemTooltip.Mode.Hide).
      Returns:
      this tooltip instance.
    • setName

      public ItemTooltip setName(ItemTooltip.Mode mode, String[] localizedTexts)
      Sets the name section (header) of the tooltip, with a separate text per language.
      Parameters:
      mode - determines how the text is combined with the original name.
      localizedTexts - the localized texts, e.g {"en=Pickaxe", "de=Spitzhacke"}. An entry without a language prefix is used for all languages.
      Returns:
      this tooltip instance.
    • setModifier

      public ItemTooltip setModifier(ItemTooltip.Mode mode, String text)
      Sets the modifier section of the tooltip (shown next to the header).
      Parameters:
      mode - determines how the text is combined with the original modifier.
      text - the text. May be null if the mode does not need a text.
      Returns:
      this tooltip instance.
    • setModifier

      public ItemTooltip setModifier(ItemTooltip.Mode mode, String[] localizedTexts)
      Sets the modifier section of the tooltip, with a separate text per language.
      Parameters:
      mode - determines how the text is combined with the original modifier.
      localizedTexts - the localized texts, e.g {"en=Rusty", "de=Rostig"}.
      Returns:
      this tooltip instance.
    • setInfo

      public ItemTooltip setInfo(ItemTooltip.Mode mode, String text)
      Sets the info section of the tooltip (shown below the header). Appended or prepended texts are separated by a line break.
      Parameters:
      mode - determines how the text is combined with the original info text.
      text - the text. May be null if the mode does not need a text.
      Returns:
      this tooltip instance.
    • setInfo

      public ItemTooltip setInfo(ItemTooltip.Mode mode, String[] localizedTexts)
      Sets the info section of the tooltip, with a separate text per language.
      Parameters:
      mode - determines how the text is combined with the original info text.
      localizedTexts - the localized texts, e.g {"en=Heavy", "de=Schwer"}.
      Returns:
      this tooltip instance.
    • setCondition

      public ItemTooltip setCondition(String text, int rgba)
      Replaces the condition of the item, i.e the text and the color of the indicator at the bottom of the tooltip.
      Parameters:
      text - the condition text.
      rgba - color of the condition indicator (e.g COLOR_PRISTINE).
      Returns:
      this tooltip instance.
    • setCondition

      public ItemTooltip setCondition(String[] localizedTexts, int rgba)
      Replaces the condition of the item, with a separate text per language.
      Parameters:
      localizedTexts - the localized texts, e.g {"en=Soulbound", "de=Seelengebunden"}.
      rgba - color of the condition indicator (e.g COLOR_PRISTINE).
      Returns:
      this tooltip instance.
    • hideCondition

      public ItemTooltip hideCondition()
      Hides the condition of the item.
      Returns:
      this tooltip instance.
    • resetCondition

      public ItemTooltip resetCondition()
      Resets the condition, i.e the game shows the regular condition of the item again.
      Returns:
      this tooltip instance.
    • isEmpty

      public boolean isEmpty()
      Checks whether or not this tooltip is empty, i.e no section was set.
      Returns:
      true if no section was set, false if at least one section was set.
    • getNameMode

      public ItemTooltip.Mode getNameMode()
      Gets the mode of the name section.
      Returns:
      the mode of the name section, or ItemTooltip.Mode.Keep if the section was not set.
    • getModifierMode

      public ItemTooltip.Mode getModifierMode()
      Gets the mode of the modifier section.
      Returns:
      the mode of the modifier section, or ItemTooltip.Mode.Keep if the section was not set.
    • getInfoMode

      public ItemTooltip.Mode getInfoMode()
      Gets the mode of the info section.
      Returns:
      the mode of the info section, or ItemTooltip.Mode.Keep if the section was not set.
    • getConditionMode

      public ItemTooltip.Mode getConditionMode()
      Gets the mode of the condition section.
      Returns:
      the mode of the condition section, or ItemTooltip.Mode.Keep if the section was not set.
    • getNameTexts

      public String[] getNameTexts()
      Gets the localized texts of the name section.
      Returns:
      the texts (in the format "en=Text"), or null if the section was not set.
    • getModifierTexts

      public String[] getModifierTexts()
      Gets the localized texts of the modifier section.
      Returns:
      the texts (in the format "en=Text"), or null if the section was not set.
    • getInfoTexts

      public String[] getInfoTexts()
      Gets the localized texts of the info section.
      Returns:
      the texts (in the format "en=Text"), or null if the section was not set.
    • getConditionTexts

      public String[] getConditionTexts()
      Gets the localized texts of the condition section.
      Returns:
      the texts (in the format "en=Text"), or null if the section was not set.
    • getConditionColor

      public int getConditionColor()
      Gets the color of the condition indicator.
      Returns:
      the rgba color of the condition indicator.
    • toBytes

      public byte[] toBytes()
      Converts this tooltip into the serialized format which the game uses internally.
      Returns:
      the serialized tooltip, or null if this tooltip is empty.
    • fromBytes

      public static ItemTooltip fromBytes(byte[] data)
      Creates a tooltip out of the serialized format which the game uses internally.
      Parameters:
      data - the serialized tooltip.
      Returns:
      the tooltip, or null if the data was null or invalid.