From f1f57bd8e5dc543fd0f3e375f3f657eb01ed871c Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 11 Jun 2021 20:37:02 -0700 Subject: [PATCH] fix PlayerUseUnknownEntityEvent patch (#5800) --- .../Add-PlayerUseUnknownEntityEvent.patch | 0 .../Add-PlayerUseUnknownEntityEvent.patch | 50 +++++++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) rename patches/{api-unmapped => api}/Add-PlayerUseUnknownEntityEvent.patch (100%) diff --git a/patches/api-unmapped/Add-PlayerUseUnknownEntityEvent.patch b/patches/api/Add-PlayerUseUnknownEntityEvent.patch similarity index 100% rename from patches/api-unmapped/Add-PlayerUseUnknownEntityEvent.patch rename to patches/api/Add-PlayerUseUnknownEntityEvent.patch diff --git a/patches/server/Add-PlayerUseUnknownEntityEvent.patch b/patches/server/Add-PlayerUseUnknownEntityEvent.patch index a97b970a24..0e895b9b16 100644 --- a/patches/server/Add-PlayerUseUnknownEntityEvent.patch +++ b/patches/server/Add-PlayerUseUnknownEntityEvent.patch @@ -13,28 +13,60 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public class ServerboundInteractPacket implements Packet { - private final int entityId; +- private final ServerboundInteractPacket.Action action; + private final int entityId; public final int getEntityId() { return this.entityId; } // Paper - add accessor - private final ServerboundInteractPacket.Action action; ++ private final ServerboundInteractPacket.Action action; public final ServerboundInteractPacket.ActionType getActionType() { return this.action.getType(); } // Paper - add accessor private final boolean usingSecondaryAction; static final ServerboundInteractPacket.Action ATTACK_ACTION = new ServerboundInteractPacket.Action() { + @Override +@@ -0,0 +0,0 @@ public class ServerboundInteractPacket implements Packet public + INTERACT(ServerboundInteractPacket.InteractionAction::new), + ATTACK((friendlyByteBuf) -> { + return ServerboundInteractPacket.ATTACK_ACTION; diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser - } + }); } } + // Paper start - fire event + else { -+ this.craftServer.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent( -+ this.getPlayer(), -+ packet.getEntityId(), -+ packet.getAction() == ServerboundInteractPacket.Action.ATTACK, -+ packet.getHand() == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND -+ )); ++ packet.dispatch(new net.minecraft.network.protocol.game.ServerboundInteractPacket.Handler() { ++ @Override ++ public void onInteraction(net.minecraft.world.InteractionHand hand) { ++ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, hand); ++ } ++ ++ @Override ++ public void onInteraction(net.minecraft.world.InteractionHand hand, net.minecraft.world.phys.Vec3 pos) { ++ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, hand); ++ } ++ ++ @Override ++ public void onAttack() { ++ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, net.minecraft.world.InteractionHand.MAIN_HAND); ++ } ++ }); + } -+ // Paper end ++ ++ } ++ private void callPlayerUseUnknownEntityEvent(ServerboundInteractPacket packet, InteractionHand hand) { ++ this.cserver.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent( ++ this.getCraftPlayer(), ++ packet.getEntityId(), ++ packet.getActionType() == ServerboundInteractPacket.ActionType.ATTACK, ++ hand == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND ++ )); } ++ // Paper end + @Override + public void handleClientCommand(ServerboundClientCommandPacket packet) {