3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/server/0083-Add-PlayerUseUnknownEntityEvent.patch

73 Zeilen
3.5 KiB
Diff

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
2023-09-22 19:31:02 +02:00
index 47130f72d8ad96565ba2357dd6cd6c32779e14c3..7b830d1fcb83cbf24e7a12e9bc5aff0d1c9d1a44 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
@@ -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-09-22 00:26:51 +02:00
index 98266c0349d21fc1ebf0d34a3d898825d477d6e5..a4e010b9195d0afeb4724dc64c85964a843eb59a 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-09-22 00:26:51 +02:00
@@ -2385,8 +2385,38 @@ 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) {
+ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, hand, null);
+ }
+
+ @Override
+ public void onInteraction(net.minecraft.world.InteractionHand hand, net.minecraft.world.phys.Vec3 pos) {
+ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, hand, pos);
+ }
+
+ @Override
+ public void onAttack() {
+ ServerGamePacketListenerImpl.this.callPlayerUseUnknownEntityEvent(packet, net.minecraft.world.InteractionHand.MAIN_HAND, null);
+ }
+ });
2021-06-11 14:02:28 +02:00
+ }
2023-03-23 22:57:03 +01:00
+
+ }
2021-06-11 14:02:28 +02:00
+ private void callPlayerUseUnknownEntityEvent(ServerboundInteractPacket packet, InteractionHand hand, @Nullable net.minecraft.world.phys.Vec3 vector) {
+ this.cserver.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerUseUnknownEntityEvent(
+ this.getCraftPlayer(),
+ packet.getEntityId(),
+ 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
}
+ // Paper end - PlayerUseUnknownEntityEvent
2023-03-23 22:57:03 +01:00
@Override
public void handleClientCommand(ServerboundClientCommandPacket packet) {