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
|
|
|
|
|
2023-08-16 09:58:07 +02:00
|
|
|
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
|
2023-09-22 19:59:56 +02:00
|
|
|
index 644a0fdea6576647539b96528717dbaeab498d93..221e64a66ff12a8de5c75992fc26a54a03b317e7 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
|
2023-08-16 09:58:07 +02:00
|
|
|
@@ -169,4 +169,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
|
2023-12-05 20:54:55 +01:00
|
|
|
index 870a1d6679fa062d90bcfa1a21a8af0cf67f2950..d03d5629e3605626bba6ea806990443bfb151c61 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
|
2023-12-05 20:54:55 +01:00
|
|
|
@@ -2401,8 +2401,38 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
2021-06-12 05:37:02 +02:00
|
|
|
});
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-16 09:58:07 +02:00
|
|
|
+ // Paper start - PlayerUseUnknownEntityEvent
|
2021-06-11 14:02:28 +02:00
|
|
|
+ else {
|
2021-06-12 05:37:02 +02:00
|
|
|
+ packet.dispatch(new net.minecraft.network.protocol.game.ServerboundInteractPacket.Handler() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onInteraction(net.minecraft.world.InteractionHand hand) {
|
2023-08-16 09:58:07 +02:00
|
|
|
+ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, hand, null);
|
2021-06-12 05:37:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onInteraction(net.minecraft.world.InteractionHand hand, net.minecraft.world.phys.Vec3 pos) {
|
2023-08-16 09:58:07 +02:00
|
|
|
+ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, hand, pos);
|
2021-06-12 05:37:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onAttack() {
|
2023-08-16 09:58:07 +02:00
|
|
|
+ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, net.minecraft.world.InteractionHand.MAIN_HAND, null);
|
2021-06-12 05:37:02 +02:00
|
|
|
+ }
|
|
|
|
+ });
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2023-03-23 22:57:03 +01:00
|
|
|
+
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2023-08-16 09:58:07 +02:00
|
|
|
+ private void callPlayerUseUnknownEntityEvent(ServerboundInteractPacket packet, InteractionHand hand, @Nullable net.minecraft.world.phys.Vec3 vector) {
|
2021-06-12 05:37:02 +02:00
|
|
|
+ this.cserver.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent(
|
|
|
|
+ this.getCraftPlayer(),
|
|
|
|
+ packet.getEntityId(),
|
2023-08-16 09:58:07 +02:00
|
|
|
+ packet.isAttack(),
|
|
|
|
+ hand == InteractionHand.MAIN_HAND ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND,
|
|
|
|
+ vector != null ? new org.bukkit.util.Vector(vector.x, vector.y, vector.z) : null)
|
|
|
|
+ );
|
2023-03-23 22:57:03 +01:00
|
|
|
}
|
2023-08-16 09:58:07 +02:00
|
|
|
+ // Paper end - PlayerUseUnknownEntityEvent
|
2023-03-23 22:57:03 +01:00
|
|
|
|
2021-06-12 05:37:02 +02:00
|
|
|
@Override
|
|
|
|
public void handleClientCommand(ServerboundClientCommandPacket packet) {
|