Class InventoryUtil

java.lang.Object
net.glowstone.util.InventoryUtil

public class InventoryUtil extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ImmutableItemStack
     
    static final org.bukkit.inventory.ItemStack[]
     
    static final Collection<org.bukkit.inventory.ItemStack>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    consumeHeldItem(@NotNull org.bukkit.entity.HumanEntity player, @NotNull org.bukkit.inventory.ItemStack item)
    Consumes 1 copy of the given item, which must be held by the given player, unless that player is in Creative mode.
    static @NotNull org.bukkit.inventory.ItemStack
    Creates an empty ItemStack (Material.AIR * 0).
    static @NotNull org.bukkit.inventory.ItemStack
    damageItem(GlowPlayer player, @NotNull org.bukkit.inventory.ItemStack holding)
    Inflicts damage to an item.
    static int
    getRandomSlot(@NotNull Random random, @NotNull org.bukkit.inventory.Inventory inventory, boolean ignoreEmpty)
    Get a random slot index in an Inventory.
    static boolean
    isEmpty(org.bukkit.inventory.ItemStack stack)
    Checks whether the given ItemStack is empty.
    static @NotNull org.bukkit.inventory.ItemStack
    itemOrEmpty(org.bukkit.inventory.ItemStack stack)
    Converts the ItemStack to an empty ItemStack if the given ItemStack is null.

    Methods inherited from class java.lang.Object

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

    • NO_ITEMS

      public static final org.bukkit.inventory.ItemStack[] NO_ITEMS
    • NO_ITEMS_COLLECTION

      public static final Collection<org.bukkit.inventory.ItemStack> NO_ITEMS_COLLECTION
    • EMPTY_STACK

      public static final ImmutableItemStack EMPTY_STACK
  • Constructor Details

    • InventoryUtil

      public InventoryUtil()
  • Method Details

    • isEmpty

      public static boolean isEmpty(@Nullable org.bukkit.inventory.ItemStack stack)
      Checks whether the given ItemStack is empty.
      Parameters:
      stack - the ItemStack to check
      Returns:
      whether the given ItemStack is empty
    • itemOrEmpty

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack itemOrEmpty(@Nullable org.bukkit.inventory.ItemStack stack)
      Converts the ItemStack to an empty ItemStack if the given ItemStack is null.
      Parameters:
      stack - the ItemStack to check and convert, if applicable
      Returns:
      the converted ItemStack if applicable, the original ItemStack otherwise
    • createEmptyStack

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack createEmptyStack()
      Creates an empty ItemStack (Material.AIR * 0).
      Returns:
      an empty ItemStack
    • getRandomSlot

      public static int getRandomSlot(@NotNull @NotNull Random random, @NotNull @NotNull org.bukkit.inventory.Inventory inventory, boolean ignoreEmpty)
      Get a random slot index in an Inventory.
      Parameters:
      random - a Random instance
      inventory - the inventory
      ignoreEmpty - whether to skip empty items in the inventory
      Returns:
      the index of a random slot in the inventory, -1 if no possible slot was found
    • damageItem

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack damageItem(@Nullable GlowPlayer player, @NotNull @NotNull org.bukkit.inventory.ItemStack holding)
      Inflicts damage to an item. Unbreaking enchantment is applied if present.
      Parameters:
      player - the player holding the item, or null if held by a dispenser
      holding - the item
      Returns:
      the updated item stack
    • consumeHeldItem

      public static void consumeHeldItem(@NotNull @NotNull org.bukkit.entity.HumanEntity player, @NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Consumes 1 copy of the given item, which must be held by the given player, unless that player is in Creative mode.
      Parameters:
      player - the player holding the item
      item - the item to consume