Class ItemUtils

java.lang.Object
ch.njol.skript.bukkitutil.ItemUtils

public class ItemUtils extends Object
Miscellaneous static utility methods related to items.
  • Field Details

    • HAS_MAX_DAMAGE

      public static final boolean HAS_MAX_DAMAGE
    • HAS_RESET

      public static final boolean HAS_RESET
    • CAN_CREATE_PLAYER_PROFILE

      public static final boolean CAN_CREATE_PLAYER_PROFILE
  • Constructor Details

    • ItemUtils

      public ItemUtils()
  • Method Details

    • clampedStack

      public static ItemStack clampedStack(ItemStack itemStack)
      Return an ItemStack with a stack size no higher than 99
      Minecraft will not serialize an ItemStack with a size > 99
      Parameters:
      itemStack - ItemStack to check
      Returns:
      ItemStack with size not greater than 99
    • getDamage

      public static int getDamage(ItemStack itemStack)
      Gets damage/durability of an item, or 0 if it does not have damage.
      Parameters:
      itemStack - Item.
      Returns:
      Damage.
    • getDamage

      public static int getDamage(ItemMeta itemMeta)
      Gets damage/durability of an itemmeta, or 0 if it does not have damage.
      Parameters:
      itemMeta - ItemMeta.
      Returns:
      Damage.
    • getMaxDamage

      public static int getMaxDamage(ItemStack itemStack)
      Gets the max damage/durability of an item

      NOTE: Will account for custom damageable items in MC 1.20.5+

      Parameters:
      itemStack - Item to grab durability from
      Returns:
      Max amount of damage this item can take
    • setMaxDamage

      public static void setMaxDamage(ItemStack itemStack, int maxDamage)
      Set the max damage/durability of an item
      Parameters:
      itemStack - ItemStack to set max damage
      maxDamage - Amount of new max damage
    • setDamage

      public static void setDamage(ItemStack itemStack, int damage)
      Sets damage/durability of an item if possible.
      Parameters:
      itemStack - Item to modify.
      damage - New damage. Note that on some Minecraft versions, this might be truncated to short.
    • getMaxStackSize

      public static int getMaxStackSize(ItemStack itemStack)
      Get the max stack size of an ItemStack
      Parameters:
      itemStack - ItemStack to check
      Returns:
      Max stack size of ItemStack
    • setMaxStackSize

      public static void setMaxStackSize(ItemStack itemStack, int maxStackSize)
      Set the max stack size of an ItemStack
      Parameters:
      itemStack - ItemStack to change max stack size
      maxStackSize - Max stack size clamped between 1 and 99
    • setHeadOwner

      public static void setHeadOwner(ItemStack skull, OfflinePlayer player)
      Sets the owner of a player head.
      Parameters:
      skull - player head item to modify
      player - owner of the head
    • removeItemFromList

      public static void removeItemFromList(ItemStack toRemove, Iterable<ItemStack> from)
      Remove an ItemStack from a list of ItemStacks or an Inventory
      Parameters:
      toRemove - ItemStack to remove
      from - List/Inventory to remove from
    • addItemToList

      public static List<ItemStack> addItemToList(ItemStack toAdd, Iterable<ItemStack> to)
      Add an ItemStack to a List/Inventory
      This will break up the ItemStack if it's too large
      Parameters:
      toAdd - ItemStack to add
      to - List/Inventory to add to
      Returns:
      List of ItemStacks that didn't fit (only when adding to an Inventory)
    • addListToList

      public static List<ItemStack> addListToList(Iterable<ItemStack> from, Iterable<ItemStack> to)
      Add a List/Inventory to another List/Inventory
      Parameters:
      from - List/Inventory to add
      to - List/Inventory to add to
      Returns:
      List of ItemStacks that didn't fit (only when adding to an Inventory)