Paper/patches/server/0090-Add-PlayerUseUnknownEntityEvent.patch

79 lines
4.1 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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>
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
2024-04-24 03:25:14 +02:00
index 1e9c68cd1868d083e6a790d56006dd4aa432010a..8a0ee9564fc36a2badf1357f7e6c47b5f1500f6c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
2024-04-24 03:25:14 +02:00
@@ -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
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-04-24 03:25:14 +02:00
index a944eb2b5dbc2a44c32cf9ea794c9b225de16a70..00043179d939e95734d56d221d79c0996321f875 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-04-24 03:25:14 +02:00
@@ -2486,7 +2486,26 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
});
2021-06-11 14:02:28 +02:00
}
}
+ // Paper start - PlayerUseUnknownEntityEvent
2021-06-11 14:02:28 +02:00
+ else {
+ packet.dispatch(new net.minecraft.network.protocol.game.ServerboundInteractPacket.Handler() {
+ @Override
+ public void onInteraction(net.minecraft.world.InteractionHand hand) {
2024-02-01 10:15:57 +01:00
+ CraftEventFactory.callPlayerUseUnknownEntityEvent(ServerGamePacketListenerImpl.this.player, packet, hand, null);
+ }
+
+ @Override
+ public void onInteraction(net.minecraft.world.InteractionHand hand, net.minecraft.world.phys.Vec3 pos) {
2024-02-01 10:15:57 +01:00
+ CraftEventFactory.callPlayerUseUnknownEntityEvent(ServerGamePacketListenerImpl.this.player, packet, hand, pos);
+ }
2024-02-01 10:15:57 +01:00
+ @Override
+ public void onAttack() {
2024-02-01 10:15:57 +01:00
+ CraftEventFactory.callPlayerUseUnknownEntityEvent(ServerGamePacketListenerImpl.this.player, packet, net.minecraft.world.InteractionHand.MAIN_HAND, null);
+ }
+ });
2021-06-11 14:02:28 +02:00
+ }
2024-02-01 10:15:57 +01:00
+ // Paper end - PlayerUseUnknownEntityEvent
2023-03-23 22:57:03 +01:00
}
@Override
2024-02-01 10:15:57 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-04-24 03:25:14 +02:00
index 387305bb835dca0cee7ab398d5630e3522c6162f..ff95b1f9935311ec156e41bf9aa16005df23eb27 100644
2024-02-01 10:15:57 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-04-24 03:25:14 +02:00
@@ -1851,4 +1851,13 @@ public class CraftEventFactory {
Bukkit.getPluginManager().callEvent(new EntityRemoveEvent(entity.getBukkitEntity(), cause));
2024-02-01 10:15:57 +01:00
}
+ // 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
}