Paper/patches/api/0032-EntityPathfindEvent.patch

101 lines
2.9 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 21:15:34 -0400
Subject: [PATCH] EntityPathfindEvent
Fires when an Entity decides to start moving to a location.
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityPathfindEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityPathfindEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..8267e8f1f0ade29a284831069e1268ee4b29e109
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityPathfindEvent.java
2024-02-01 10:15:57 +01:00
@@ -0,0 +1,87 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
2021-06-11 14:02:28 +02:00
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Fired when an Entity decides to start moving towards a location.
2024-02-01 10:15:57 +01:00
+ * <p>
2021-06-11 14:02:28 +02:00
+ * This event does not fire for the entities actual movement. Only when it
+ * is choosing to start moving to a location.
+ */
+public class EntityPathfindEvent extends EntityEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-06-11 14:02:28 +02:00
+ @Nullable private final Entity targetEntity;
2024-02-01 10:15:57 +01:00
+ @NotNull private final Location location;
+ private boolean cancelled;
2021-06-11 14:02:28 +02:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public EntityPathfindEvent(@NotNull Entity entity, @NotNull Location location, @Nullable Entity targetEntity) {
2021-06-11 14:02:28 +02:00
+ super(entity);
+ this.targetEntity = targetEntity;
2024-02-01 10:15:57 +01:00
+ this.location = location;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * The Entity that is pathfinding.
2024-02-01 10:15:57 +01:00
+ *
2021-06-11 14:02:28 +02:00
+ * @return The Entity that is pathfinding.
+ */
+ @NotNull
+ public Entity getEntity() {
2024-02-01 10:15:57 +01:00
+ return this.entity;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * If the Entity is trying to pathfind to an entity, this is the entity in relation.
2024-02-01 10:15:57 +01:00
+ * <br>
+ * Otherwise this will return {@code null}.
2021-06-11 14:02:28 +02:00
+ *
2024-02-01 10:15:57 +01:00
+ * @return The entity target or {@code null}
2021-06-11 14:02:28 +02:00
+ */
+ @Nullable
+ public Entity getTargetEntity() {
2024-02-01 10:15:57 +01:00
+ return this.targetEntity;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * The Location of where the entity is about to move to.
2024-02-01 10:15:57 +01:00
+ * <br>
2021-06-11 14:02:28 +02:00
+ * Note that if the target happened to of been an entity
2024-02-01 10:15:57 +01:00
+ *
2021-06-11 14:02:28 +02:00
+ * @return Location of where the entity is trying to pathfind to.
+ */
+ @NotNull
+ public Location getLoc() {
+ return this.location.clone();
2021-06-11 14:02:28 +02:00
+ }
+
2024-02-01 10:15:57 +01:00
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled;
2021-06-11 14:02:28 +02:00
+ }
+
2024-02-01 10:15:57 +01:00
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
2021-06-11 14:02:28 +02:00
+ }
+
2024-02-01 10:15:57 +01:00
+ @NotNull
2021-06-11 14:02:28 +02:00
+ @Override
2024-02-01 10:15:57 +01:00
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
2024-02-01 10:15:57 +01:00
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}