Class ItemUtils

java.lang.Object
valorless.valorlessutils.items.ItemUtils

public class ItemUtils extends Object
Utility class for interacting with ItemMeta fields introduced in Minecraft 1.20.5+.

These helper methods allow for easy access to new item metadata, such as:

  • Item name (internal vs. display name)
  • Item rarity
  • Custom max stack size
  • Item model (resource key)

Note: These methods rely on APIs only available in 1.20.5 and above. Always check the server version before calling these methods to avoid errors on older servers.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    GetCustomName(org.bukkit.inventory.ItemStack item)
    Gets the custom display name.
    static org.bukkit.NamespacedKey
    GetItemModel(org.bukkit.inventory.ItemStack item)
    Gets the namespaced key of the item's model.
    static String
    GetItemName(org.bukkit.inventory.ItemStack item)
    Gets the internal item name.
    static Integer
    GetMaxStackSize(org.bukkit.inventory.ItemStack item)
    Gets the maximum stack size defined on the item.
    static String
    GetRarity(org.bukkit.inventory.ItemStack item)
    Gets the rarity of the item as a string.
    static Boolean
    HasCustomName(org.bukkit.inventory.ItemStack item)
    Checks if the item has a custom display name.
    static Boolean
    HasItemName(org.bukkit.inventory.ItemStack item)
    Checks if the item has an internal item name.
    static Boolean
    HasMaxStackSize(org.bukkit.inventory.ItemStack item)
    Checks if the item has a custom max stack size.
    static Boolean
    HasRarity(org.bukkit.inventory.ItemStack item)
    Checks if the item has a rarity value.
    static void
    SetCustomName(org.bukkit.inventory.ItemStack item, String name)
    Sets the custom display name.
    static void
    SetItemModel(org.bukkit.inventory.ItemStack item, String value)
    Sets the item model using a string in the format "namespace:key".
    static void
    SetItemModel(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey value)
    Sets the item model using a NamespacedKey.
    static void
    SetItemName(org.bukkit.inventory.ItemStack item, String name)
    Sets the internal item name.
    static void
    SetMaxStackSize(org.bukkit.inventory.ItemStack item, Integer value)
    Sets a custom maximum stack size for the item.
    static void
    SetRarity(org.bukkit.inventory.ItemStack item, String rarity)
    Sets the rarity of the item.

    Methods inherited from class java.lang.Object

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

    • ItemUtils

      public ItemUtils()
  • Method Details

    • HasItemName

      public static Boolean HasItemName(org.bukkit.inventory.ItemStack item)
      Checks if the item has an internal item name.
      Parameters:
      item - The ItemStack to check
      Returns:
      True if the item has an internal name, false otherwise
    • GetItemName

      public static String GetItemName(org.bukkit.inventory.ItemStack item)
      Gets the internal item name.
      Parameters:
      item - The ItemStack to get the name from
      Returns:
      The item name string
    • SetItemName

      public static void SetItemName(org.bukkit.inventory.ItemStack item, String name)
      Sets the internal item name.
      Parameters:
      item - The ItemStack to modify
      name - The name to set
    • HasCustomName

      public static Boolean HasCustomName(org.bukkit.inventory.ItemStack item)
      Checks if the item has a custom display name.
      Parameters:
      item - The ItemStack to check
      Returns:
      True if the item has a display name, false otherwise
    • GetCustomName

      public static String GetCustomName(org.bukkit.inventory.ItemStack item)
      Gets the custom display name.
      Parameters:
      item - The ItemStack to get the display name from
      Returns:
      The display name string
    • SetCustomName

      public static void SetCustomName(org.bukkit.inventory.ItemStack item, String name)
      Sets the custom display name.
      Parameters:
      item - The ItemStack to modify
      name - The display name to set
    • HasRarity

      public static Boolean HasRarity(org.bukkit.inventory.ItemStack item)
      Checks if the item has a rarity value.
      Parameters:
      item - The ItemStack to check
      Returns:
      True if the item has a rarity, false otherwise
    • GetRarity

      public static String GetRarity(org.bukkit.inventory.ItemStack item)
      Gets the rarity of the item as a string.
      Parameters:
      item - The ItemStack to get rarity from
      Returns:
      The rarity as a string (e.g., "COMMON", "RARE", "EPIC")
    • SetRarity

      public static void SetRarity(org.bukkit.inventory.ItemStack item, String rarity)
      Sets the rarity of the item.
      Parameters:
      item - The ItemStack to modify
      rarity - The rarity as a string (must match ItemRarity name)
    • HasMaxStackSize

      public static Boolean HasMaxStackSize(org.bukkit.inventory.ItemStack item)
      Checks if the item has a custom max stack size.
      Parameters:
      item - The ItemStack to check
      Returns:
      True if a custom max stack size is set, false otherwise
    • GetMaxStackSize

      public static Integer GetMaxStackSize(org.bukkit.inventory.ItemStack item)
      Gets the maximum stack size defined on the item.
      Parameters:
      item - The ItemStack to get the value from
      Returns:
      The maximum stack size
    • SetMaxStackSize

      public static void SetMaxStackSize(org.bukkit.inventory.ItemStack item, Integer value)
      Sets a custom maximum stack size for the item.
      Parameters:
      item - The ItemStack to modify
      value - The maximum stack size value
    • GetItemModel

      public static org.bukkit.NamespacedKey GetItemModel(org.bukkit.inventory.ItemStack item)
      Gets the namespaced key of the item's model.
      Parameters:
      item - The ItemStack to query
      Returns:
      The NamespacedKey representing the item model
    • SetItemModel

      public static void SetItemModel(org.bukkit.inventory.ItemStack item, org.bukkit.NamespacedKey value)
      Sets the item model using a NamespacedKey.
      Parameters:
      item - The ItemStack to modify
      value - The NamespacedKey of the model
    • SetItemModel

      public static void SetItemModel(org.bukkit.inventory.ItemStack item, String value)
      Sets the item model using a string in the format "namespace:key".
      Parameters:
      item - The ItemStack to modify
      value - The string representing the model key