From 85fe8525d8fc2dc1cc6d1d94cfeb5fe24ab15075 Mon Sep 17 00:00:00 2001 From: amyavi <144570677+amyavi@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:28:04 -0300 Subject: [PATCH] fix: tweak spawner restrictions --- .../extras/modules/entity/EntitySpawn.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) 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 c2d0d0b..0df8558 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -130,37 +130,46 @@ public final class EntitySpawn implements Listener { } } - private void limitSpawner(final CreatureSpawner spawner) { + private boolean limitSpawner(final CreatureSpawner spawner) { final EntityType spawnedType = spawner.getSpawnedType(); + boolean didChange = false; + if (!spawnedType.isAlive() || spawnedType.equals(EntityType.ARMOR_STAND)) { spawner.setSpawnedType(EntityType.PIG); - spawner.update(); + didChange = true; } - if (spawner.getMinSpawnDelay() <= 5000) { - spawner.setMinSpawnDelay(5000); - spawner.update(); + if (spawner.getMaxSpawnDelay() < 2000) { + spawner.setMaxSpawnDelay(2000); + didChange = true; } - if (spawner.getMaxSpawnDelay() <= 10000) { - spawner.setMaxSpawnDelay(10000); - spawner.update(); + if (spawner.getMinSpawnDelay() < 1000) { + spawner.setMinSpawnDelay(1000); + didChange = true; } - if (spawner.getDelay() <= 5000) { + if (spawner.getDelay() < 5000) { spawner.setDelay(5000); - spawner.update(); + didChange = true; } if (spawner.getSpawnCount() > 10) { spawner.setSpawnCount(10); - spawner.update(); + didChange = true; } if (spawner.getSpawnRange() > 10) { spawner.setSpawnRange(10); - spawner.update(); + didChange = true; } + + if (didChange) { + spawner.update(); + return true; + } + + return false; } @EventHandler @@ -196,15 +205,6 @@ public final class EntitySpawn implements Listener { applyEntityChanges(entity); } - @EventHandler - void onItemSpawn(final ItemSpawnEvent event) { - try { - event.getEntity().getItemStack().getItemMeta(); - } catch (Exception exception) { - event.setCancelled(true); - } - } - @EventHandler void onLightningStrike(final LightningStrikeEvent event) { final LightningStrike lightning = event.getLightning(); @@ -230,9 +230,10 @@ public final class EntitySpawn implements Listener { @EventHandler void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) { - try { - limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState()); - } catch (Exception exception) { + final CreatureSpawner spawner = (CreatureSpawner)event.getSpawnerLocation().getBlock() + .getState(); + + if (limitSpawner(spawner)) { event.setCancelled(true); } }