aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0031-Entity-AddTo-RemoveFrom-World-Events.patch
blob: 5748bb7aaec91f66bd064a99059fd39ffc9cc224 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 28 Mar 2016 20:26:34 -0400
Subject: [PATCH] Entity AddTo/RemoveFrom World Events


diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..990b307801be996a4707d87e420b05ee25286d5b
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityAddToWorldEvent.java
@@ -0,0 +1,43 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.World;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired any time an entity is being added to the world for any reason (including a chunk loading).
+ * <p>
+ * Not to be confused with {@link CreatureSpawnEvent}
+ */
+@NullMarked
+public class EntityAddToWorldEvent extends EntityEvent {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private final World world;
+
+    @ApiStatus.Internal
+    public EntityAddToWorldEvent(final Entity entity, final World world) {
+        super(entity);
+        this.world = world;
+    }
+
+    /**
+     * @return The world that the entity is being added to
+     */
+    public World getWorld() {
+        return this.world;
+    }
+
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..b7776c1e65c8140a1e800df56bda5bec5717b50e
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityRemoveFromWorldEvent.java
@@ -0,0 +1,41 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.World;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired any time an entity is being removed from a world for any reason (including a chunk unloading).
+ * Note: The entity is updated prior to this event being called, as such, the entity's world may not be equal to {@link #getWorld()}.
+ */
+@NullMarked
+public class EntityRemoveFromWorldEvent extends EntityEvent {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private final World world;
+
+    @ApiStatus.Internal
+    public EntityRemoveFromWorldEvent(final Entity entity, final World world) {
+        super(entity);
+        this.world = world;
+    }
+
+    /**
+     * @return The world that the entity is being removed from
+     */
+    public World getWorld() {
+        return this.world;
+    }
+
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
diff --git a/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java b/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java
index e32df91d911bae42c8137c6f952a6ac6a94d27e0..8ed5d1ccc44951089999db360219b556db89b4ba 100644
--- a/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java
+++ b/src/main/java/org/bukkit/event/entity/EntityRemoveEvent.java
@@ -1,5 +1,6 @@
 package org.bukkit.event.entity;
 
+import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;
 import org.bukkit.entity.Entity;
 import org.bukkit.event.HandlerList;
 import org.jetbrains.annotations.ApiStatus;
@@ -11,8 +12,9 @@ import org.jetbrains.annotations.NotNull;
  * This event should only be used for monitoring. The result
  * of modifying the entity during or after this event is unspecified.
  * This event is not called for a {@link org.bukkit.entity.Player}.
+ * @deprecated use {@link EntityRemoveFromWorldEvent} instead
  */
-@ApiStatus.Experimental
+@Deprecated(forRemoval = true)
 public class EntityRemoveEvent extends EntityEvent {
 
     private static final HandlerList handlers = new HandlerList();
@@ -112,5 +114,6 @@ public class EntityRemoveEvent extends EntityEvent {
          * When the chunk an entity is in gets unloaded.
          */
         UNLOAD,
+        DISCARD
     }
 }