SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot 2021-09-01 18:55:16 +10:00
parent 5f7735a971
commit 891608deca
3 changed files with 89 additions and 0 deletions

View File

@ -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.
*/

View File

@ -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<Entity> entities;
public EntitiesLoadEvent(@NotNull Chunk chunk, @NotNull List<Entity> entities) {
super(chunk);
this.entities = entities;
}
/**
* Get the entities which are being loaded.
*
* @return unmodifiable list of loaded entities.
*/
@NotNull
public List<Entity> getEntities() {
return entities;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -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<Entity> entities;
public EntitiesUnloadEvent(@NotNull Chunk chunk, @NotNull List<Entity> entities) {
super(chunk);
this.entities = entities;
}
/**
* Get the entities which are being unloaded.
*
* @return unmodifiable list of unloaded entities.
*/
@NotNull
public List<Entity> getEntities() {
return entities;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
}