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

99 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: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>
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
index 0000000000000000000000000000000000000000..a7228e248e3d8eb2e9f011dfe2c7dd9f3f48000f
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerUseUnknownEntityEvent.java
@@ -0,0 +1,82 @@
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;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.util.Vector;
2021-06-11 14:02:28 +02:00
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Represents an event that is called when a player right-clicks an unknown entity.
+ * Useful for plugins dealing with virtual entities (entities that don'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.
+ */
2021-06-11 14:02:28 +02:00
+public class PlayerUseUnknownEntityEvent extends PlayerEvent {
+
+ private static final HandlerList HANDLERS = new HandlerList();
2021-06-11 14:02:28 +02:00
+ private final int entityId;
+ private final boolean attack;
+ private final @NotNull EquipmentSlot hand;
+ private final @Nullable Vector clickedPosition;
2021-06-11 14:02:28 +02:00
+
+ public PlayerUseUnknownEntityEvent(@NotNull Player who, int entityId, boolean attack, @NotNull EquipmentSlot hand, @Nullable Vector clickedPosition) {
2021-06-11 14:02:28 +02:00
+ super(who);
+ this.entityId = entityId;
+ this.attack = attack;
+ this.hand = hand;
+ this.clickedPosition = clickedPosition;
2021-06-11 14:02:28 +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;
+ }
+
+ /**
+ * Returns whether the interaction was an attack.
+ *
+ * @return true if the player is attacking the entity, false if the player is interacting with the entity
+ */
2021-06-11 14:02:28 +02:00
+ public boolean isAttack() {
+ return this.attack;
+ }
+
+ /**
+ * Returns the hand used to perform this interaction.
+ *
+ * @return the hand used to interact
+ */
+ public @NotNull EquipmentSlot getHand() {
2021-06-11 14:02:28 +02:00
+ return this.hand;
+ }
+
+ /**
+ * Returns the position relative to the entity that was clicked, or null if not available.
+ * See {@link org.bukkit.event.player.PlayerInteractAtEntityEvent} for more details.
+ *
+ * @return the position relative to the entity that was clicked, or null if not available
+ * @see org.bukkit.event.player.PlayerInteractAtEntityEvent
+ */
+ public @Nullable Vector getClickedRelativePosition() {
+ return this.clickedPosition != null ? this.clickedPosition.clone() : null;
+ }
+
2021-06-11 14:02:28 +02:00
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLERS;
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLERS;
2021-06-11 14:02:28 +02:00
+ }
+}