diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/SpawnerListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/SpawnerListeners.java index 56ca2d2..ccc5772 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/SpawnerListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/SpawnerListeners.java @@ -12,22 +12,24 @@ import org.bukkit.event.entity.SpawnerSpawnEvent; public class SpawnerListeners implements Listener { - private final UltimateStacker instance; + private final UltimateStacker plugin; - public SpawnerListeners(UltimateStacker instance) { - this.instance = instance; + public SpawnerListeners(UltimateStacker plugin) { + this.plugin = plugin; } @EventHandler public void onSpawn(SpawnerSpawnEvent event) { - if (!Setting.STACK_ENTITIES.getBoolean() || !instance.spawnersEnabled()) return; - SpawnerStackManager spawnerStackManager = instance.getSpawnerStackManager(); + if (!Setting.STACK_ENTITIES.getBoolean() + || !plugin.spawnersEnabled() + || plugin.getStackingTask().isWorldDisabled(event.getLocation().getWorld())) return; + SpawnerStackManager spawnerStackManager = plugin.getSpawnerStackManager(); if (!spawnerStackManager.isSpawner(event.getSpawner().getLocation())) return; SpawnerStack spawnerStack = spawnerStackManager.getSpawner(event.getSpawner().getLocation()); - EntityStack stack = instance.getEntityStackManager().addStack(event.getEntity().getUniqueId(), spawnerStack.calculateSpawnCount()); + EntityStack stack = plugin.getEntityStackManager().addStack(event.getEntity().getUniqueId(), spawnerStack.calculateSpawnCount()); - instance.getStackingTask().attemptSplit(stack, (LivingEntity)event.getEntity()); + plugin.getStackingTask().attemptSplit(stack, (LivingEntity) event.getEntity()); } } diff --git a/src/main/java/com/songoda/ultimatestacker/spawner/SpawnerStack.java b/src/main/java/com/songoda/ultimatestacker/spawner/SpawnerStack.java index dae4a8f..8851b7a 100644 --- a/src/main/java/com/songoda/ultimatestacker/spawner/SpawnerStack.java +++ b/src/main/java/com/songoda/ultimatestacker/spawner/SpawnerStack.java @@ -29,11 +29,13 @@ public class SpawnerStack { } public void setAmount(int amount) { + UltimateStacker plugin = UltimateStacker.getInstance(); this.amount = amount; - Bukkit.getScheduler().runTaskLater(UltimateStacker.getInstance(), () -> { + Bukkit.getScheduler().runTaskLater(plugin, () -> { if (!(location.getBlock().getState() instanceof CreatureSpawner)) return; - int count = Setting.STACK_ENTITIES.getBoolean() ? 1 : calculateSpawnCount(); + int count = Setting.STACK_ENTITIES.getBoolean() + && !plugin.getStackingTask().isWorldDisabled(location.getWorld()) ? 1 : calculateSpawnCount(); int maxNearby = amount > 6 ? amount + 3 : 6; CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState(); if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) { diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index 2e6247d..3ec83fe 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -44,16 +44,13 @@ public class StackingTask extends BukkitRunnable { @Override public void run() { - // Gather disabled worlds. - List disabledWorlds = Setting.DISABLED_WORLDS.getStringList(); - // Should entities be stacked? if (!Setting.STACK_ENTITIES.getBoolean()) return; // Loop through each world. for (World world : Bukkit.getWorlds()) { // If world is disabled then continue to the next world. - if (disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr))) continue; + if (isWorldDisabled(world)) continue; // Get the loaded entities from the current world and reverse them. List entities = new ArrayList<>(world.getEntities()); @@ -80,6 +77,11 @@ public class StackingTask extends BukkitRunnable { processed.clear(); } + public boolean isWorldDisabled(World world) { + List disabledWorlds = Setting.DISABLED_WORLDS.getStringList(); + return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr)); + } + private boolean isEntityStackable(Entity entity, Location location) { // Make sure we have the correct entity type and that it is valid. if (!entity.isValid()