Package net.glowstone.util
Class InventoryUtil
java.lang.Object
net.glowstone.util.InventoryUtil
-
Field Summary
Modifier and TypeFieldDescriptionstatic final ImmutableItemStack
static final org.bukkit.inventory.ItemStack[]
static final Collection<org.bukkit.inventory.ItemStack>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Field Details
-
NO_ITEMS
public static final org.bukkit.inventory.ItemStack[] NO_ITEMS -
NO_ITEMS_COLLECTION
-
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 instanceinventory
- the inventoryignoreEmpty
- 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 dispenserholding
- 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 itemitem
- the item to consume
-