Fix inventory events not giving the proper inventory/slot

This commit is contained in:
TheMode 2021-08-18 21:08:04 +02:00
parent f26e6ef91f
commit 5cf358ac3c
2 changed files with 11 additions and 9 deletions

View File

@ -267,7 +267,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final boolean isInWindow = isClickInWindow(slot);
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
final InventoryClickResult clickResult = clickProcessor.leftClick(player, this, slot, clicked, cursor);
final InventoryClickResult clickResult = clickProcessor.leftClick(player,
isInWindow ? this : playerInventory, clickSlot, clicked, cursor);
if (clickResult.isCancel()) {
updateAll(player);
return false;
@ -289,7 +290,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final boolean isInWindow = isClickInWindow(slot);
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
final InventoryClickResult clickResult = clickProcessor.rightClick(player, this, slot, clicked, cursor);
final InventoryClickResult clickResult = clickProcessor.rightClick(player,
isInWindow ? this : playerInventory, clickSlot, clicked, cursor);
if (clickResult.isCancel()) {
updateAll(player);
return false;
@ -337,7 +339,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final int clickSlot = isInWindow ? slot : PlayerInventoryUtils.convertSlot(slot, offset);
final ItemStack clicked = isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot);
final ItemStack heldItem = playerInventory.getItemStack(key);
final InventoryClickResult clickResult = clickProcessor.changeHeld(player, this, slot, key, clicked, heldItem);
final InventoryClickResult clickResult = clickProcessor.changeHeld(player,
isInWindow ? this : playerInventory, clickSlot, key, clicked, heldItem);
if (clickResult.isCancel()) {
updateAll(player);
return false;
@ -368,8 +371,8 @@ public class Inventory extends AbstractInventory implements Viewable {
final ItemStack clicked = outsideDrop ?
ItemStack.AIR : (isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot));
final ItemStack cursor = getCursorItem(player);
final InventoryClickResult clickResult = clickProcessor.drop(player, this,
all, slot, button, clicked, cursor);
final InventoryClickResult clickResult = clickProcessor.drop(player,
isInWindow ? this : playerInventory, all, clickSlot, button, clicked, cursor);
if (clickResult.isCancel()) {
updateAll(player);
return false;
@ -395,8 +398,9 @@ public class Inventory extends AbstractInventory implements Viewable {
(isInWindow ? getItemStack(slot) : playerInventory.getItemStack(clickSlot)) :
ItemStack.AIR;
final ItemStack cursor = getCursorItem(player);
final InventoryClickResult clickResult = clickProcessor.dragging(player, this,
slot, button,
final InventoryClickResult clickResult = clickProcessor.dragging(player,
isInWindow ? this : playerInventory,
clickSlot, button,
clicked, cursor,
s -> isClickInWindow(s) ? getItemStack(s) :

View File

@ -6,7 +6,6 @@ import net.minestom.server.listener.manager.PacketListenerManager;
import org.jetbrains.annotations.NotNull;
public abstract class ClientPlayPacket implements ClientPacket {
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
/**
@ -19,5 +18,4 @@ public abstract class ClientPlayPacket implements ClientPacket {
public void process(@NotNull Player player) {
PACKET_LISTENER_MANAGER.processClientPacket(this, player);
}
}