From 3d1581d5b4aa502092cee76006a3d52149b706aa Mon Sep 17 00:00:00 2001 From: mathias Date: Thu, 1 Aug 2019 18:39:06 +0300 Subject: [PATCH] Check entity count on chunk load --- .../kaboom/extras/modules/entity/EntitySpawn.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java index c62c93c..0ce65a9 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -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 ||