Class InventoryUtils
java.lang.Object
me.mehboss.utils.InventoryUtils
Utility class for handling various inventory-related operations such as:
- Custom click interaction behavior
- Stack merging logic
- Space calculations for inventory storage
- Detecting empty inventory slots
This class is stateless and all methods are static.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcalculateClickedSlot(org.bukkit.event.inventory.InventoryClickEvent event) Wrapper method that reads the cursor and clicked item directly from the event.static voidcalculateClickedSlot(org.bukkit.event.inventory.InventoryClickEvent event, org.bukkit.inventory.ItemStack cursor, org.bukkit.inventory.ItemStack currentItem) Manually computes the behavior of clicking inside an inventory, overriding Bukkit's default logic.static intgetInventorySpace(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item) Computes available space for a specific item in a player's inventory.static intgetInventorySpace(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Computes available space in an inventory for one specific item type.static intgetInventorySpace(org.bukkit.inventory.ItemStack[] contents, org.bukkit.inventory.ItemStack item) Computes total available capacity for an item based on empty slots and partially filled stacks that match.static booleanhasEmptySpaces(org.bukkit.entity.Player p, int count) Checks whether a player has at least a specified number of empty slots.static booleanhasInventorySpace(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item) Checks if a player has room for the given item.static booleanhasInventorySpace(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack) Checks if an inventory has space for one stack of the given item.static booleanhasInventorySpace(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack, int amount) Checks if an inventory has room for a given number of a specific item.static booleanhasInventorySpace(org.bukkit.inventory.ItemStack[] contents, org.bukkit.inventory.ItemStack itemStack) Checks if inventory contents have enough space for the given item.static booleanisAirOrNull(org.bukkit.inventory.ItemStack item) Checks if an item is null or AIR.
-
Constructor Details
-
InventoryUtils
public InventoryUtils()
-
-
Method Details
-
calculateClickedSlot
public static void calculateClickedSlot(org.bukkit.event.inventory.InventoryClickEvent event) Wrapper method that reads the cursor and clicked item directly from the event.- Parameters:
event- The inventory click event.
-
calculateClickedSlot
public static void calculateClickedSlot(org.bukkit.event.inventory.InventoryClickEvent event, org.bukkit.inventory.ItemStack cursor, org.bukkit.inventory.ItemStack currentItem) Manually computes the behavior of clicking inside an inventory, overriding Bukkit's default logic. Supports custom stack behavior for both left and right clicks.Actions supported:
- Left-click stack swapping
- Left-click stack merge
- Right-click single-item placement
- Right-click stack merge
- Parameters:
event- The click event being processed.cursor- The item on the player's cursor.currentItem- The item currently in the clicked slot.
-
isAirOrNull
public static boolean isAirOrNull(org.bukkit.inventory.ItemStack item) Checks if an item is null or AIR.- Parameters:
item- The item to check.- Returns:
- True if null or AIR.
-
hasInventorySpace
public static boolean hasInventorySpace(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack, int amount) Checks if an inventory has room for a given number of a specific item.- Parameters:
inventory- Inventory to check.itemStack- The item type being added.amount- Number of stacks to fit.- Returns:
- True if enough space exists.
-
hasInventorySpace
public static boolean hasInventorySpace(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack itemStack) Checks if an inventory has space for one stack of the given item.- Parameters:
inventory- Inventory to check.itemStack- Item being added.- Returns:
- True if enough space exists.
-
hasInventorySpace
public static boolean hasInventorySpace(org.bukkit.inventory.ItemStack[] contents, org.bukkit.inventory.ItemStack itemStack) Checks if inventory contents have enough space for the given item.- Parameters:
contents- Inventory contents.itemStack- Item being added.- Returns:
- True if space is available.
-
hasInventorySpace
public static boolean hasInventorySpace(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item) Checks if a player has room for the given item.- Parameters:
p- Player whose inventory will be checked.item- Item the player wants to add.- Returns:
- True if enough space exists.
-
getInventorySpace
public static int getInventorySpace(org.bukkit.entity.Player p, org.bukkit.inventory.ItemStack item) Computes available space for a specific item in a player's inventory.- Parameters:
p- Player to check.item- Item type that may be added.- Returns:
- The number of items that can fit.
-
getInventorySpace
public static int getInventorySpace(org.bukkit.inventory.Inventory inventory, org.bukkit.inventory.ItemStack item) Computes available space in an inventory for one specific item type.- Parameters:
inventory- The inventory to scan.item- The item type being checked.- Returns:
- The total number of items that can fit.
-
getInventorySpace
public static int getInventorySpace(org.bukkit.inventory.ItemStack[] contents, org.bukkit.inventory.ItemStack item) Computes total available capacity for an item based on empty slots and partially filled stacks that match.- Parameters:
contents- Inventory contents.item- Item type being evaluated.- Returns:
- Total capacity for the item.
-
hasEmptySpaces
public static boolean hasEmptySpaces(org.bukkit.entity.Player p, int count) Checks whether a player has at least a specified number of empty slots.- Parameters:
p- The player whose inventory to check.count- Minimum number of empty slots needed.- Returns:
- True if at least
countempty slots exist.
-