From 891608deca1de45226398baaf4c9baab06ad0a57 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 1 Sep 2021 18:55:16 +1000 Subject: [PATCH] SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load By: DerFrZocker --- paper-api/src/main/java/org/bukkit/Chunk.java | 1 + .../bukkit/event/world/EntitiesLoadEvent.java | 44 +++++++++++++++++++ .../event/world/EntitiesUnloadEvent.java | 44 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/world/EntitiesLoadEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/world/EntitiesUnloadEvent.java diff --git a/paper-api/src/main/java/org/bukkit/Chunk.java b/paper-api/src/main/java/org/bukkit/Chunk.java index beac1439c7..40e9e375a6 100644 --- a/paper-api/src/main/java/org/bukkit/Chunk.java +++ b/paper-api/src/main/java/org/bukkit/Chunk.java @@ -71,6 +71,7 @@ public interface Chunk extends PersistentDataHolder { /** * Get a list of all entities in the chunk. + * This will force load any entities, which are not loaded. * * @return The entities. */ diff --git a/paper-api/src/main/java/org/bukkit/event/world/EntitiesLoadEvent.java b/paper-api/src/main/java/org/bukkit/event/world/EntitiesLoadEvent.java new file mode 100644 index 0000000000..88b13a481e --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/EntitiesLoadEvent.java @@ -0,0 +1,44 @@ +package org.bukkit.event.world; + +import java.util.List; +import org.bukkit.Chunk; +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * Called when entities are loaded. + * + * The provided chunk may or may not be loaded. + */ +public class EntitiesLoadEvent extends ChunkEvent { + + private static final HandlerList handlers = new HandlerList(); + private final List entities; + + public EntitiesLoadEvent(@NotNull Chunk chunk, @NotNull List entities) { + super(chunk); + this.entities = entities; + } + + /** + * Get the entities which are being loaded. + * + * @return unmodifiable list of loaded entities. + */ + @NotNull + public List getEntities() { + return entities; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/world/EntitiesUnloadEvent.java b/paper-api/src/main/java/org/bukkit/event/world/EntitiesUnloadEvent.java new file mode 100644 index 0000000000..1e3f144f1f --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/world/EntitiesUnloadEvent.java @@ -0,0 +1,44 @@ +package org.bukkit.event.world; + +import java.util.List; +import org.bukkit.Chunk; +import org.bukkit.entity.Entity; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +/** + * Called when entities are unloaded. + * + * The provided chunk may or may not be loaded. + */ +public class EntitiesUnloadEvent extends ChunkEvent { + + private static final HandlerList handlers = new HandlerList(); + private final List entities; + + public EntitiesUnloadEvent(@NotNull Chunk chunk, @NotNull List entities) { + super(chunk); + this.entities = entities; + } + + /** + * Get the entities which are being unloaded. + * + * @return unmodifiable list of unloaded entities. + */ + @NotNull + public List getEntities() { + return entities; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +}