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
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundInteractPacket.java
2021-06-12 05:37:02 +02:00
index 1b316ecf2d8725b9c91a4869e6c2362c1443160d..70d309ddb215c62805b6ee13be50d8f93cdc38ba 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
2021-06-12 05:37:02 +02:00
@@ -10,8 +10,8 @@ import net.minecraft.world.entity.Entity;
2021-06-12 05:07:57 +02:00
import net.minecraft.world.phys.Vec3;
2021-06-11 14:02:28 +02:00
public class ServerboundInteractPacket implements Packet<ServerGamePacketListener> {
2021-06-12 05:07:57 +02:00
- private final int entityId;
2021-06-12 05:37:02 +02:00
- private final ServerboundInteractPacket.Action action;
2021-06-12 05:07:57 +02:00
+ private final int entityId; public final int getEntityId() { return this.entityId; } // Paper - add accessor
2021-06-12 05:37:02 +02:00
+ private final ServerboundInteractPacket.Action action; public final ServerboundInteractPacket.ActionType getActionType() { return this.action.getType(); } // Paper - add accessor
2021-06-12 05:07:57 +02:00
private final boolean usingSecondaryAction;
static final ServerboundInteractPacket.Action ATTACK_ACTION = new ServerboundInteractPacket.Action() {
2021-06-12 05:37:02 +02:00
@Override
@@ -88,7 +88,7 @@ public class ServerboundInteractPacket implements Packet<ServerGamePacketListene
void write(FriendlyByteBuf buf);
}
- static enum ActionType {
+ public static enum ActionType { // Paper - package-private -> public
INTERACT(ServerboundInteractPacket.InteractionAction::new),
ATTACK((friendlyByteBuf) -> {
return ServerboundInteractPacket.ATTACK_ACTION;
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
2021-06-13 07:13:07 +02:00
index dfab012166354af6233ee1fdab1b0fba6fcbe940..fa6d414387950d522243370714d5425f09e351e8 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
2021-06-13 07:13:07 +02:00
@@ -2203,8 +2203,37 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-12 05:37:02 +02:00
});
2021-06-11 14:02:28 +02:00
}
}
+ // Paper start - fire event
+ 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) {
+ 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);
+ }
+ });
2021-06-11 14:02:28 +02:00
+ }
2021-06-12 05:37:02 +02:00
+
+ }
2021-06-11 14:02:28 +02:00
2021-06-12 05:37:02 +02:00
+ 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
+ ));
2021-06-11 14:02:28 +02:00
}
2021-06-12 05:37:02 +02:00
+ // Paper end
2021-06-11 14:02:28 +02:00
2021-06-12 05:37:02 +02:00
@Override
public void handleClientCommand(ServerboundClientCommandPacket packet) {