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:08:36 -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/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java
new file mode 100644
2024-09-30 01:48:34 +02:00
index 0000000000000000000000000000000000000000..9ff2bbf7f99df45cc626cad60bec4d14a8a04e3e
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java
2024-09-30 01:48:34 +02:00
@@ -0,0 +1,85 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.player;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
2024-02-01 10:15:57 +01:00
+import org.bukkit.event.player.PlayerInteractAtEntityEvent;
2021-06-11 14:02:28 +02:00
+import org.bukkit.inventory.EquipmentSlot;
2023-08-16 09:58:07 +02:00
+import org.bukkit.util.Vector;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
2024-09-30 01:48:34 +02:00
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
2023-08-16 09:58:07 +02:00
+/**
+ * Represents an event that is called when a player right-clicks an unknown entity.
2024-04-22 20:08:37 +02:00
+ * Useful for plugins dealing with virtual entities (entities that aren't actually spawned on the server).
2023-08-16 09:58:07 +02:00
+ * <br>
+ * This event may be called multiple times per interaction with different interaction hands
+ * and with or without the clicked position.
+ */
2024-09-30 01:48:34 +02:00
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class PlayerUseUnknownEntityEvent extends PlayerEvent {
+
2024-02-01 10:15:57 +01:00
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-06-11 14:02:28 +02:00
+ private final int entityId;
+ private final boolean attack;
2024-09-30 01:48:34 +02:00
+ private final EquipmentSlot hand;
2023-08-16 09:58:07 +02:00
+ private final @Nullable Vector clickedPosition;
2021-06-11 14:02:28 +02:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
2024-09-30 01:48:34 +02:00
+ public PlayerUseUnknownEntityEvent(final Player player, final int entityId, final boolean attack, final EquipmentSlot hand, final @Nullable Vector clickedPosition) {
2024-02-01 10:15:57 +01:00
+ super(player);
2021-06-11 14:02:28 +02:00
+ this.entityId = entityId;
+ this.attack = attack;
+ this.hand = hand;
2023-08-16 09:58:07 +02:00
+ this.clickedPosition = clickedPosition;
2021-06-11 14:02:28 +02:00
+ }
+
2023-08-16 09:58:07 +02:00
+ /**
+ * Returns the entity id of the unknown entity that was interacted with.
+ *
+ * @return the entity id of the entity that was interacted with
+ */
2021-06-11 14:02:28 +02:00
+ public int getEntityId() {
+ return this.entityId;
+ }
+
2023-08-16 09:58:07 +02:00
+ /**
+ * Returns whether the interaction was an attack.
+ *
2024-02-01 10:15:57 +01:00
+ * @return {@code true} if the player is attacking the entity, {@code false} if the player is interacting with the entity
2023-08-16 09:58:07 +02:00
+ */
2021-06-11 14:02:28 +02:00
+ public boolean isAttack() {
+ return this.attack;
+ }
+
2023-08-16 09:58:07 +02:00
+ /**
+ * Returns the hand used to perform this interaction.
+ *
+ * @return the hand used to interact
+ */
2024-09-30 01:48:34 +02:00
+ public EquipmentSlot getHand() {
2021-06-11 14:02:28 +02:00
+ return this.hand;
+ }
+
2023-08-16 09:58:07 +02:00
+ /**
2024-02-01 10:15:57 +01:00
+ * Returns the position relative to the entity that was clicked, or {@code null} if not available.
+ * See {@link PlayerInteractAtEntityEvent} for more details.
2023-08-16 09:58:07 +02:00
+ *
2024-02-01 10:15:57 +01:00
+ * @return the position relative to the entity that was clicked, or {@code null} if not available
+ * @see PlayerInteractAtEntityEvent
2023-08-16 09:58:07 +02:00
+ */
+ public @Nullable Vector getClickedRelativePosition() {
2023-08-19 04:01:06 +02:00
+ return this.clickedPosition != null ? this.clickedPosition.clone() : null;
2023-08-16 09:58:07 +02:00
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}