aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0035-Add-PlayerUseUnknownEntityEvent.patch
blob: e0d410dc6e9cf6e44b2b9d0a179bfc531f2f07c4 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com>
Date: Sat, 2 Apr 2016 05:08:36 -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/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..dbb635686e9108b9d3df5d373e6972cca07c0621
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java
@@ -0,0 +1,86 @@
+package com.destroystokyo.paper.event.player;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.event.player.PlayerInteractAtEntityEvent;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents an event that is called when a player right-clicks an unknown entity.
+ * Useful for plugins dealing with virtual entities (entities that aren't actually spawned on the server).
+ * <br>
+ * This event may be called multiple times per interaction with different interaction hands
+ * and with or without the clicked position.
+ */
+public class PlayerUseUnknownEntityEvent extends PlayerEvent {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private final int entityId;
+    private final boolean attack;
+    private final @NotNull EquipmentSlot hand;
+    private final @Nullable Vector clickedPosition;
+
+    @ApiStatus.Internal
+    public PlayerUseUnknownEntityEvent(@NotNull Player player, int entityId, boolean attack, @NotNull EquipmentSlot hand, @Nullable Vector clickedPosition) {
+        super(player);
+        this.entityId = entityId;
+        this.attack = attack;
+        this.hand = hand;
+        this.clickedPosition = clickedPosition;
+    }
+
+    /**
+     * Returns the entity id of the unknown entity that was interacted with.
+     *
+     * @return the entity id of the entity that was interacted with
+     */
+    public int getEntityId() {
+        return this.entityId;
+    }
+
+    /**
+     * Returns whether the interaction was an attack.
+     *
+     * @return {@code true} if the player is attacking the entity, {@code false} if the player is interacting with the entity
+     */
+    public boolean isAttack() {
+        return this.attack;
+    }
+
+    /**
+     * Returns the hand used to perform this interaction.
+     *
+     * @return the hand used to interact
+     */
+    public @NotNull EquipmentSlot getHand() {
+        return this.hand;
+    }
+
+    /**
+     * Returns the position relative to the entity that was clicked, or {@code null} if not available.
+     * See {@link PlayerInteractAtEntityEvent} for more details.
+     *
+     * @return the position relative to the entity that was clicked, or {@code null} if not available
+     * @see PlayerInteractAtEntityEvent
+     */
+    public @Nullable Vector getClickedRelativePosition() {
+        return this.clickedPosition != null ? this.clickedPosition.clone() : null;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}