mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-05 06:51:22 +01:00
Fix Inventory never being null when clicking inside an inventory (when the click happens on a player inventory slot)
This commit is contained in:
parent
25176e9b9d
commit
c2f302ad0e
@ -397,7 +397,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
|
||||
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
|
||||
|
||||
final InventoryClickResult clickResult = clickProcessor.leftClick(this, player, slot, clicked, cursor);
|
||||
final InventoryClickResult clickResult = clickProcessor.leftClick(isInWindow ? this : null, player, slot, clicked, cursor);
|
||||
|
||||
if (clickResult.doRefresh()) {
|
||||
updateFromClick(clickResult, player);
|
||||
@ -411,7 +411,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
callClickEvent(player, this, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.LEFT_CLICK, clicked, cursor);
|
||||
|
||||
return !clickResult.isCancel();
|
||||
}
|
||||
@ -424,7 +424,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
|
||||
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
|
||||
|
||||
final InventoryClickResult clickResult = clickProcessor.rightClick(this, player, slot, clicked, cursor);
|
||||
final InventoryClickResult clickResult = clickProcessor.rightClick(isInWindow ? this : null, player, slot, clicked, cursor);
|
||||
|
||||
if (clickResult.doRefresh()) {
|
||||
updateFromClick(clickResult, player);
|
||||
@ -438,7 +438,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
callClickEvent(player, this, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.RIGHT_CLICK, clicked, cursor);
|
||||
|
||||
return !clickResult.isCancel();
|
||||
}
|
||||
@ -470,7 +470,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
clickResult = clickProcessor.shiftClick(this, player, slot, clicked, cursor,
|
||||
clickResult = clickProcessor.shiftClick(null, player, slot, clicked, cursor,
|
||||
// Window loop
|
||||
new InventoryClickLoopHandler(0, getSize(), 1,
|
||||
i -> i,
|
||||
@ -508,7 +508,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
|
||||
final ItemStack heldItem = playerInventory.getItemStack(key);
|
||||
|
||||
final InventoryClickResult clickResult = clickProcessor.changeHeld(this, player, slot, key, clicked, heldItem);
|
||||
final InventoryClickResult clickResult = clickProcessor.changeHeld(isInWindow ? this : null, player, slot, key, clicked, heldItem);
|
||||
|
||||
if (clickResult.doRefresh()) {
|
||||
updateFromClick(clickResult, player);
|
||||
@ -522,7 +522,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
playerInventory.setItemStack(key, clickResult.getCursor());
|
||||
|
||||
if (!clickResult.isCancel())
|
||||
callClickEvent(player, this, slot, ClickType.CHANGE_HELD, clicked, getCursorItem(player));
|
||||
callClickEvent(player, isInWindow ? this : null, slot, ClickType.CHANGE_HELD, clicked, getCursorItem(player));
|
||||
|
||||
// Weird synchronization issue when omitted
|
||||
updateFromClick(clickResult, player);
|
||||
@ -546,7 +546,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
ItemStack.getAirItem() : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot));
|
||||
final ItemStack cursor = getCursorItem(player);
|
||||
|
||||
final InventoryClickResult clickResult = clickProcessor.drop(this, player,
|
||||
final InventoryClickResult clickResult = clickProcessor.drop(isInWindow ? this : null, player,
|
||||
mode, slot, button, clicked, cursor);
|
||||
|
||||
if (clickResult.doRefresh()) {
|
||||
@ -577,7 +577,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
ItemStack.getAirItem();
|
||||
final ItemStack cursor = getCursorItem(player);
|
||||
|
||||
final InventoryClickResult clickResult = clickProcessor.dragging(this, player,
|
||||
final InventoryClickResult clickResult = clickProcessor.dragging(isInWindow ? this : null, player,
|
||||
slot, button,
|
||||
clicked, cursor,
|
||||
|
||||
@ -609,8 +609,9 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
public boolean doubleClick(@NotNull Player player, int slot) {
|
||||
final PlayerInventory playerInventory = player.getInventory();
|
||||
final ItemStack cursor = getCursorItem(player);
|
||||
final boolean isInWindow = isClickInWindow(slot);
|
||||
|
||||
final InventoryClickResult clickResult = clickProcessor.doubleClick(this, player, slot, cursor,
|
||||
final InventoryClickResult clickResult = clickProcessor.doubleClick(isInWindow ? this : null, player, slot, cursor,
|
||||
// Start by looping through the opened inventory
|
||||
new InventoryClickLoopHandler(0, getSize(), 1,
|
||||
i -> i,
|
||||
|
Loading…
Reference in New Issue
Block a user