3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-14 20:10:05 +01:00
Paper/patches/api/0032-EntityPathfindEvent.patch

98 Zeilen
2.9 KiB
Diff

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..8624e0a528985c9b118f5e8a0f33d3286af2fc36
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityPathfindEvent.java
@@ -0,0 +1,84 @@
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;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+/**
+ * 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.
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class EntityPathfindEvent extends EntityEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final @Nullable Entity targetEntity;
+ private final Location location;
2024-02-01 10:15:57 +01:00
+ private boolean cancelled;
2021-06-11 14:02:28 +02:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public EntityPathfindEvent(final Entity entity, final Location location, final @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.
+ */
+ @Override
2021-06-11 14:02:28 +02:00
+ 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
+ */
+ public @Nullable 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.
+ */
+ 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(final boolean cancel) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = cancel;
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
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}