Fix double click clickedItem always being air

This commit is contained in:
TheMode 2021-08-14 18:21:01 +02:00
parent 4560f2e630
commit 8cf58fa397
3 changed files with 10 additions and 5 deletions

View File

@ -421,10 +421,14 @@ public class Inventory extends AbstractInventory implements Viewable {
@Override
public boolean doubleClick(@NotNull Player player, int slot) {
final PlayerInventory playerInventory = player.getInventory();
final ItemStack cursor = getCursorItem(player);
final boolean isInWindow = isClickInWindow(slot);
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = slot != -999 ?
(isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)) :
ItemStack.AIR;
final ItemStack cursor = getCursorItem(player);
final InventoryClickResult clickResult = clickProcessor.doubleClick(isInWindow ? this : playerInventory,
this, player, slot, cursor);
this, player, slot, clicked, cursor);
if (clickResult.isCancel()) {
updateAll(player);
return false;

View File

@ -363,7 +363,8 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl
@Override
public boolean doubleClick(@NotNull Player player, int slot) {
final ItemStack cursor = getCursorItem();
final InventoryClickResult clickResult = clickProcessor.doubleClick(this, this, player, slot, cursor);
final ItemStack clicked = getItemStack(slot, OFFSET);
final InventoryClickResult clickResult = clickProcessor.doubleClick(this, this, player, slot, clicked, cursor);
if (clickResult.isCancel()) {
update();
return false;

View File

@ -265,8 +265,8 @@ public final class InventoryClickProcessor {
}
public @NotNull InventoryClickResult doubleClick(@NotNull AbstractInventory clickedInventory, @NotNull AbstractInventory inventory, @NotNull Player player, int slot,
@NotNull final ItemStack cursor) {
InventoryClickResult clickResult = startCondition(player, inventory, slot, ClickType.START_DOUBLE_CLICK, ItemStack.AIR, cursor);
@NotNull ItemStack clicked, @NotNull ItemStack cursor) {
InventoryClickResult clickResult = startCondition(player, inventory, slot, ClickType.START_DOUBLE_CLICK, clicked, cursor);
if (clickResult.isCancel()) return clickResult;
if (cursor.isAir()) return clickResult.cancelled();