aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0083-Add-PlayerUseUnknownEntityEvent.patch
blob: 02aa7f79ffa232a3ab2f0f810926bf2f6b8566cd (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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

Adds the PlayerUseUnknownEntityEvent to be used by plugins dealing with
virtual entities/entities that are not actually known to the server.

Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>

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 1e9c68cd1868d083e6a790d56006dd4aa432010a..8a0ee9564fc36a2badf1357f7e6c47b5f1500f6c 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
@@ -176,4 +176,14 @@ public class ServerboundInteractPacket implements Packet<ServerGamePacketListene
             buf.writeEnum(this.hand);
         }
     }
+
+    // Paper start - PlayerUseUnknownEntityEvent
+    public int getEntityId() {
+        return this.entityId;
+    }
+
+    public boolean isAttack() {
+        return this.action.getType() == ActionType.ATTACK;
+    }
+    // Paper end - PlayerUseUnknownEntityEvent
 }
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 7b9e613d68f5765207bc60aa9b82bfc8e9da49bf..6763ac2a23fd961012fb0e450f1a46c4e036fe11 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2489,7 +2489,26 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
                 });
             }
         }
+        // Paper start - PlayerUseUnknownEntityEvent
+        else {
+            packet.dispatch(new net.minecraft.network.protocol.game.ServerboundInteractPacket.Handler() {
+                @Override
+                public void onInteraction(net.minecraft.world.InteractionHand hand) {
+                    CraftEventFactory.callPlayerUseUnknownEntityEvent(ServerGamePacketListenerImpl.this.player, packet, hand, null);
+                }
+
+                @Override
+                public void onInteraction(net.minecraft.world.InteractionHand hand, net.minecraft.world.phys.Vec3 pos) {
+                    CraftEventFactory.callPlayerUseUnknownEntityEvent(ServerGamePacketListenerImpl.this.player, packet, hand, pos);
+                }
 
+                @Override
+                public void onAttack() {
+                    CraftEventFactory.callPlayerUseUnknownEntityEvent(ServerGamePacketListenerImpl.this.player, packet, net.minecraft.world.InteractionHand.MAIN_HAND, null);
+                }
+            });
+        }
+        // Paper end - PlayerUseUnknownEntityEvent
     }
 
     @Override
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 63e20db8ad84b332a4962d5cea83f1064b7c1a3d..bb296f649afd143adad47595479532cfdd778b71 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1901,4 +1901,13 @@ public class CraftEventFactory {
 
         Bukkit.getPluginManager().callEvent(new EntityRemoveEvent(entity.getBukkitEntity(), cause));
     }
+    // Paper start - PlayerUseUnknownEntityEvent
+    public static void callPlayerUseUnknownEntityEvent(net.minecraft.world.entity.player.Player player, net.minecraft.network.protocol.game.ServerboundInteractPacket packet, InteractionHand hand, @Nullable net.minecraft.world.phys.Vec3 vector) {
+        new com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent(
+            (Player) player.getBukkitEntity(), packet.getEntityId(), packet.isAttack(),
+            CraftEquipmentSlot.getHand(hand),
+            vector != null ? CraftVector.toBukkit(vector) : null
+        ).callEvent();
+    }
+    // Paper end - PlayerUseUnknownEntityEvent
 }