Skip to content

Commit 4afec01

Browse files
Fix inventory background items being cloneable
1 parent 9605d1f commit 4afec01

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

invui-core/src/main/java/xyz/xenondevs/invui/gui/AbstractGui.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ public void handleClick(int slotNumber, Player player, ClickType clickType, Inve
108108
protected void handleInvSlotElementClick(SlotElement.InventorySlotElement element, InventoryClickEvent event) {
109109
// these actions are ignored as they don't modify the inventory
110110
InventoryAction action = event.getAction();
111-
if (action != InventoryAction.CLONE_STACK
112-
&& action != InventoryAction.DROP_ALL_CURSOR
113-
&& action != InventoryAction.DROP_ONE_CURSOR
114-
) {
111+
if (action != InventoryAction.DROP_ALL_CURSOR && action != InventoryAction.DROP_ONE_CURSOR) {
115112
event.setCancelled(true);
116113

117114
Inventory inventory = element.getInventory();
@@ -152,6 +149,9 @@ protected void handleInvSlotElementClick(SlotElement.InventorySlotElement elemen
152149
case "DOUBLE_CLICK":
153150
handleInvDoubleClick(event, player, cursor);
154151
break;
152+
case "MIDDLE":
153+
handleInvMiddleClick(event, inventory, slot);
154+
break;
155155
default:
156156
InvUI.getInstance().getLogger().warning("Unknown click type: " + event.getClick().name());
157157
break;
@@ -384,6 +384,21 @@ protected void handleInvDoubleClick(InventoryClickEvent event, Player player, It
384384
((AbstractWindow) window).handleCursorCollect(event);
385385
}
386386

387+
/**
388+
* Handles a middle click on an {@link SlotElement.InventorySlotElement}.
389+
*
390+
* @param event The {@link InventoryClickEvent} that was triggered
391+
* @param inventory The {@link Inventory} that was clicked
392+
* @param slot The slot that was clicked
393+
*/
394+
@SuppressWarnings("deprecation")
395+
protected void handleInvMiddleClick(InventoryClickEvent event, Inventory inventory, int slot) {
396+
ItemStack cursor = inventory.getItem(slot);
397+
if (cursor != null)
398+
cursor.setAmount(cursor.getMaxStackSize());
399+
event.setCursor(cursor);
400+
}
401+
387402
/**
388403
* Handles an item drag on a single slot of this {@link AbstractGui}.
389404
*

0 commit comments

Comments
 (0)