testserver/patches/server-remapped/0714-fix-PlayerItemHeldEven...

31 lines
2.1 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: chickeneer <emcchickeneer@gmail.com>
Date: Thu, 22 Apr 2021 19:02:07 -0700
Subject: [PATCH] fix PlayerItemHeldEvent firing twice
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCarriedItemPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCarriedItemPacket.java
index 68026536cfc26f07ca99ee9e76fd74b4ed4a995c..848fb02988b0fb319655f790112274ac2a437d25 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCarriedItemPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundSetCarriedItemPacket.java
@@ -24,6 +24,7 @@ public class ServerboundSetCarriedItemPacket implements Packet<ServerGamePacketL
listener.handleSetCarriedItem(this);
}
+ public int getItemInHandIndex() { return getSlot(); } // Paper - OBFHELPER
public int getSlot() {
return this.slot;
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 67defaf71752ed29fde483e8232aa358ffa53675..5b0eb8744dba5df6f16bafd6d907cd1efd508fe6 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1907,6 +1907,7 @@ public class ServerGamePacketListenerImpl implements ServerGamePacketListener {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
if (this.player.isImmobile()) return; // CraftBukkit
if (packet.getSlot() >= 0 && packet.getSlot() < Inventory.getSelectionSize()) {
+ if (packet.getItemInHandIndex() == this.player.inventory.selected) { return; } // Paper - don't fire itemheldevent when there wasn't a slot change
PlayerItemHeldEvent event = new PlayerItemHeldEvent(this.getPlayer(), this.player.inventory.selected, packet.getSlot());
this.craftServer.getPluginManager().callEvent(event);
if (event.isCancelled()) {