diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index 5fa98b5..bcc70f3 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -3,6 +3,7 @@ package pw.kaboom.extras; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -30,8 +31,6 @@ import org.bukkit.block.Container; import org.bukkit.block.CreatureSpawner; import org.bukkit.block.Sign; -import org.bukkit.command.CommandSender; - import org.bukkit.entity.Player; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -324,34 +323,35 @@ class Events implements Listener { void onEntitySpawn(EntitySpawnEvent event) { Entity entity = event.getEntity(); Entity[] chunkEntities = event.getLocation().getChunk().getEntities(); - int onChunk = 0; + List worldEntities = event.getLocation().getWorld().getLivingEntities(); + int count = 0; if (entity.getType() == EntityType.ENDER_DRAGON) { - for (Entity chunkEntity : chunkEntities) { - if (onChunk < 5) { - if (chunkEntity.getType() == EntityType.ENDER_DRAGON) { - onChunk++; - continue; + for (LivingEntity worldEntity : worldEntities) { + if (count < 25) { + if (worldEntity.getType() == EntityType.ENDER_DRAGON) { + count++; } + continue; } break; } - if (onChunk == 5) { + if (count == 25) { event.setCancelled(true); } } else if (entity.getType() != EntityType.PLAYER) { for (Entity chunkEntity : chunkEntities) { - if (onChunk < 50) { + if (count < 50) { if (chunkEntity.getType() != EntityType.PLAYER) { - onChunk++; - continue; + count++; } + continue; } break; } - if (onChunk == 50) { + if (count == 50) { event.setCancelled(true); } } @@ -552,7 +552,7 @@ class Events implements Listener { @EventHandler void onPreCreatureSpawn(PreCreatureSpawnEvent event) { - Entity[] chunkEntities = event.getSpawnLocation().getChunk().getEntities(); +/* Entity[] chunkEntities = event.getSpawnLocation().getChunk().getEntities(); int onChunk = 0; if (event.getType() == EntityType.ENDER_DRAGON) { @@ -583,7 +583,7 @@ class Events implements Listener { if (onChunk == 50) { event.setCancelled(true); } - } + }*/ } @EventHandler