Check entity count on chunk load

This commit is contained in:
mathias 2019-08-01 18:39:06 +03:00
parent aadc92ce7a
commit 3d1581d5b4

View file

@ -25,6 +25,8 @@ import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.ItemStack;
import com.destroystokyo.paper.event.block.TNTPrimeEvent;
@ -34,6 +36,17 @@ import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
class EntitySpawn implements Listener {
@EventHandler
void onChunkLoad(ChunkLoadEvent event) {
final int count = event.getChunk().getEntities().length;
if (count > 50) {
for (int i = 51; i <= count; i++) {
event.getChunk().getEntities()[i].remove();
}
}
}
@EventHandler
void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == SpawnReason.CUSTOM ||