Class AdventureUtil

java.lang.Object
me.deecaad.core.utils.AdventureUtil

public final class AdventureUtil extends Object
Utility class for working with Adventure components on items.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable List<net.kyori.adventure.text.Component>
    getLore(@NotNull org.bukkit.inventory.ItemStack item)
     
    static @Nullable List<net.kyori.adventure.text.Component>
    getLore(@NotNull org.bukkit.inventory.meta.ItemMeta meta)
     
    static @NotNull net.kyori.adventure.text.Component
    getName(@NotNull org.bukkit.inventory.ItemStack item)
    Returns the display name of the item in adventure format.
    static void
    setLore(@NotNull org.bukkit.inventory.ItemStack item, @NotNull List<net.kyori.adventure.text.Component> lines)
    Sets the lore of the item.
    static void
    setLore(@NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull List<net.kyori.adventure.text.Component> lines)
    Sets the lore of the item.
    static void
    setLoreUnparsed(@NotNull org.bukkit.inventory.ItemStack item, @NotNull List<?> unparsedText)
    Sets the lore of the item.
    static void
    setLoreUnparsed(@NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull List<?> unparsedText)
    Sets the lore of the item meta.
    static void
    setName(@NotNull org.bukkit.inventory.ItemStack item, @NotNull net.kyori.adventure.text.Component name)
    Sets the display name of the item.
    static void
    setName(@NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull net.kyori.adventure.text.Component name)
    Sets the display name of the item's meta.
    static void
    setNameUnparsed(@NotNull org.bukkit.inventory.ItemStack item, @NotNull String name)
    Sets the display name of the item.
    static void
    setNameUnparsed(@NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull String name)
    Sets the display name of the item's meta.
    static void
    updatePlaceholders(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack itemStack)
    Replaces any PlaceholderAPI placeholders present in the display name and lore of the item.

    Methods inherited from class java.lang.Object

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

    • getName

      @NotNull public static @NotNull net.kyori.adventure.text.Component getName(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Returns the display name of the item in adventure format.
      Parameters:
      item - The item get the name from.
      Returns:
      The name component.
    • setNameUnparsed

      public static void setNameUnparsed(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull String name)
      Sets the display name of the item. Parsed using MiniMessage.
      Parameters:
      item - The item to set the name.
      name - The value of the name.
    • setNameUnparsed

      public static void setNameUnparsed(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull @NotNull String name)
      Sets the display name of the item's meta. Parsed using MiniMessage.
      Parameters:
      meta - The meta to set the name.
      name - The value of the name.
    • setName

      public static void setName(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull net.kyori.adventure.text.Component name)
      Sets the display name of the item.
      Parameters:
      item - The item to set the name.
      name - The value of the name.
    • setName

      public static void setName(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull @NotNull net.kyori.adventure.text.Component name)
      Sets the display name of the item's meta.
      Parameters:
      meta - The meta to set the name.
      name - The value of the name.
    • getLore

      @Nullable public static @Nullable List<net.kyori.adventure.text.Component> getLore(@NotNull @NotNull org.bukkit.inventory.ItemStack item)
    • getLore

      @Nullable public static @Nullable List<net.kyori.adventure.text.Component> getLore(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta)
    • setLoreUnparsed

      public static void setLoreUnparsed(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull List<?> unparsedText)
      Sets the lore of the item.

      The list should be a list of strings (or any list where Object.toString() is acceptable). The strings are then parsed using MiniMessage, then set as the lore. This is quite slow, so consider parsing the list with MiniMessage first then setting it using setLore(ItemStack, List).

      Parameters:
      item - The item to set the lore.
      unparsedText - The list of strings.
    • setLoreUnparsed

      public static void setLoreUnparsed(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull @NotNull List<?> unparsedText)
      Sets the lore of the item meta.

      The list should be a list of strings (or any list where Object.toString() is acceptable). The strings are then parsed using MiniMessage, then set as the lore. This is quite slow, so consider parsing the list with MiniMessage first then setting it using setLore(ItemStack, List).

      Parameters:
      meta - The item meta to set the lore.
      unparsedText - The list of strings.
    • setLore

      public static void setLore(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull List<net.kyori.adventure.text.Component> lines)
      Sets the lore of the item.
      Parameters:
      item - The item to set the lore.
      lines - The list of adventure components for lore.
    • setLore

      public static void setLore(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta, @NotNull @NotNull List<net.kyori.adventure.text.Component> lines)
      Sets the lore of the item.
      Parameters:
      meta - The item to set the lore.
      lines - The list of adventure components for lore.
    • updatePlaceholders

      public static void updatePlaceholders(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack itemStack)
      Replaces any PlaceholderAPI placeholders present in the display name and lore of the item. If PlaceholderAPI is not installed, this method is skipped.
      Parameters:
      player - The player holding the item.
      itemStack - The item to apply the placeholders to.