Class ItemUtils

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

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

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
     
    static final boolean
     
    static final boolean
     
    static final boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable org.bukkit.Material
    asBlock(org.bukkit.Material type)
    Gets a block material corresponding to given item material, which might be the given material.
    static org.bukkit.Material
    asItem(org.bukkit.Material type)
    Deprecated, for removal: This API element is subject to removal in a future version.
    This just returns itself and has no use
    static @Nullable org.bukkit.inventory.ItemStack
    asItemStack(@Nullable Object object)
    Convert an ItemType/Slot to ItemStack Will also accept an ItemStack that will return itself
    static <T extends org.bukkit.inventory.meta.ItemMeta>
    org.bukkit.inventory.ItemStack
    changeItemMeta(@NotNull Class<T> metaClass, @NotNull org.bukkit.inventory.ItemStack itemStack, @NotNull Consumer<T> metaChanger)
    Applies a provided Consumer to the meta of the provided ItemStack and returns the updated ItemStack (with updated ItemMeta).
    static int
    getDamage(ItemType itemType)
    Gets damage/durability of an item, or 0 if it does not have damage.
    static int
    getDamage(org.bukkit.inventory.ItemStack itemStack)
    Gets damage/durability of an item, or 0 if it does not have damage.
    static int
    getDamage(org.bukkit.inventory.meta.ItemMeta itemMeta)
    Gets damage/durability of an itemmeta, or 0 if it does not have damage.
    static int
    Gets the max damage/durability of an item
    static int
    getMaxDamage(org.bukkit.inventory.ItemStack itemStack)
    Gets the max damage/durability of an item
    static org.bukkit.Material
    getTreeSapling(org.bukkit.TreeType treeType)
     
    static boolean
    isAir(org.bukkit.Material type)
     
    static boolean
    isFence(org.bukkit.block.Block block)
    Whether the block is a fence or a wall.
    static boolean
    isGlass(org.bukkit.Material material)
     
    static boolean
    itemStacksEqual(@Nullable org.bukkit.inventory.ItemStack itemStack1, @Nullable org.bukkit.inventory.ItemStack itemStack2)
    Tests whether two item stacks are of the same type, i.e.
    static void
    setDamage(ItemType itemType, int damage)
    Sets damage/durability of an item if possible.
    static void
    setDamage(org.bukkit.inventory.ItemStack itemStack, int damage)
    Sets damage/durability of an item if possible.
    static void
    setHeadOwner(ItemType skull, org.bukkit.OfflinePlayer player)
    Sets the owner of a player head.
    static void
    setItemMeta(Object object, @NotNull org.bukkit.inventory.meta.ItemMeta itemMeta)
    Updates the provided object's (Slot, ItemType, ItemStack) ItemMeta by setting it to the provided ItemStack.
    static void
    setMaxDamage(org.bukkit.inventory.ItemStack itemStack, int maxDamage)
    Set the max damage/durability of an item

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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
    • REQUIRES_TEXTURE_LOOKUP

      public static final boolean REQUIRES_TEXTURE_LOOKUP
  • Constructor Details

    • ItemUtils

      public ItemUtils()
  • Method Details

    • getDamage

      public static int getDamage(org.bukkit.inventory.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(org.bukkit.inventory.meta.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(org.bukkit.inventory.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(org.bukkit.inventory.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(org.bukkit.inventory.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.
    • getDamage

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

      public static int getMaxDamage(ItemType itemType)
      Gets the max damage/durability of an item

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

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

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

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

      @Nullable public static @Nullable org.bukkit.Material asBlock(org.bukkit.Material type)
      Gets a block material corresponding to given item material, which might be the given material. If no block material is found, null is returned.
      Parameters:
      type - Material.
      Returns:
      Block version of material or null.
    • asItem

      @Deprecated(since="2.8.4", forRemoval=true) public static org.bukkit.Material asItem(org.bukkit.Material type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This just returns itself and has no use
      Gets an item material corresponding to given block material, which might be the given material.
      Parameters:
      type - Material.
      Returns:
      Item version of material or null.
    • asItemStack

      @Nullable public static @Nullable org.bukkit.inventory.ItemStack asItemStack(@Nullable @Nullable Object object)
      Convert an ItemType/Slot to ItemStack Will also accept an ItemStack that will return itself
      Parameters:
      object - Object to convert
      Returns:
      ItemStack from slot/itemtype
    • itemStacksEqual

      public static boolean itemStacksEqual(@Nullable @Nullable org.bukkit.inventory.ItemStack itemStack1, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack2)
      Tests whether two item stacks are of the same type, i.e. it ignores the amounts.
      Parameters:
      itemStack1 -
      itemStack2 -
      Returns:
      Whether the item stacks are of the same type
    • isAir

      public static boolean isAir(org.bukkit.Material type)
    • getTreeSapling

      public static org.bukkit.Material getTreeSapling(org.bukkit.TreeType treeType)
    • isFence

      public static boolean isFence(org.bukkit.block.Block block)
      Whether the block is a fence or a wall.
      Parameters:
      block - the block to check.
      Returns:
      whether the block is a fence/wall.
    • isGlass

      public static boolean isGlass(org.bukkit.Material material)
      Parameters:
      material - The material to check
      Returns:
      whether the material is a full glass block
    • changeItemMeta

      public static <T extends org.bukkit.inventory.meta.ItemMeta> org.bukkit.inventory.ItemStack changeItemMeta(@NotNull @NotNull Class<T> metaClass, @NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, @NotNull @NotNull Consumer<T> metaChanger)
      Applies a provided Consumer to the meta of the provided ItemStack and returns the updated ItemStack (with updated ItemMeta).
      Type Parameters:
      T -
      Parameters:
      itemStack - the item whose meta is to be changed using the provided Consumer
      metaChanger - a consumer to update the meta of the provided ItemStack
      Returns:
      the updated item
    • setItemMeta

      public static void setItemMeta(Object object, @NotNull @NotNull org.bukkit.inventory.meta.ItemMeta itemMeta)
      Updates the provided object's (Slot, ItemType, ItemStack) ItemMeta by setting it to the provided ItemStack.
      Parameters:
      object - the object to update
      itemMeta - the ItemMeta to change to
      See Also: