aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0087-Add-PlayerUseUnknownEntityEvent.patch
blob: fb434cc940012b6ac2c2646db8b9e681ca7e0039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Sat, 2 Apr 2016 05:09:16 -0400
Subject: [PATCH] Add PlayerUseUnknownEntityEvent


diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
index 8834ed411a7db86b4d2b88183a1315317107d719..c45b5ab6776f3ac79f856c3a6467c510e20db25a 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
@@ -10,8 +10,8 @@ import net.minecraft.world.entity.Entity;
 import net.minecraft.world.phys.Vec3;
 
 public class ServerboundInteractPacket implements Packet<ServerGamePacketListener> {
-    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; 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
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 9f0a5b950a022aa2a3d3d60837fdb9023f041a9b..b86f742c4a7500f0bb241d5c07a077aa1be1c7e5 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2644,8 +2644,37 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
                 });
             }
         }
+        // Paper start - fire event
+        else {
+            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);
+                }
+            });
+        }
+
+    }
 
+    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) {