From eb77c8e47ac51ddf15f3e49c2c7302afffd001fb Mon Sep 17 00:00:00 2001 From: mathias Date: Thu, 20 Dec 2018 02:48:50 +0200 Subject: [PATCH] Add enderdragon limiter to PreCreatureSpawnEvent --- src/main/java/pw/kaboom/extras/Events.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/Events.java b/src/main/java/pw/kaboom/extras/Events.java index bcc70f3..6d8c91a 100644 --- a/src/main/java/pw/kaboom/extras/Events.java +++ b/src/main/java/pw/kaboom/extras/Events.java @@ -552,38 +552,39 @@ class Events implements Listener { @EventHandler void onPreCreatureSpawn(PreCreatureSpawnEvent event) { -/* Entity[] chunkEntities = event.getSpawnLocation().getChunk().getEntities(); - int onChunk = 0; + Entity[] chunkEntities = event.getSpawnLocation().getChunk().getEntities(); + List worldEntities = event.getSpawnLocation().getWorld().getLivingEntities(); + int count = 0; if (event.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 (event.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); } - }*/ + } } @EventHandler