Spawners won't auto stack in disabled worlds anymore.

This commit is contained in:
Brianna 2019-07-31 15:47:01 -04:00
parent 9e38374cb1
commit 7891479a78
3 changed files with 19 additions and 13 deletions

View File

@ -12,22 +12,24 @@ import org.bukkit.event.entity.SpawnerSpawnEvent;
public class SpawnerListeners implements Listener { public class SpawnerListeners implements Listener {
private final UltimateStacker instance; private final UltimateStacker plugin;
public SpawnerListeners(UltimateStacker instance) { public SpawnerListeners(UltimateStacker plugin) {
this.instance = instance; this.plugin = plugin;
} }
@EventHandler @EventHandler
public void onSpawn(SpawnerSpawnEvent event) { public void onSpawn(SpawnerSpawnEvent event) {
if (!Setting.STACK_ENTITIES.getBoolean() || !instance.spawnersEnabled()) return; if (!Setting.STACK_ENTITIES.getBoolean()
SpawnerStackManager spawnerStackManager = instance.getSpawnerStackManager(); || !plugin.spawnersEnabled()
|| plugin.getStackingTask().isWorldDisabled(event.getLocation().getWorld())) return;
SpawnerStackManager spawnerStackManager = plugin.getSpawnerStackManager();
if (!spawnerStackManager.isSpawner(event.getSpawner().getLocation())) return; if (!spawnerStackManager.isSpawner(event.getSpawner().getLocation())) return;
SpawnerStack spawnerStack = spawnerStackManager.getSpawner(event.getSpawner().getLocation()); 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());
} }
} }

View File

@ -29,11 +29,13 @@ public class SpawnerStack {
} }
public void setAmount(int amount) { public void setAmount(int amount) {
UltimateStacker plugin = UltimateStacker.getInstance();
this.amount = amount; this.amount = amount;
Bukkit.getScheduler().runTaskLater(UltimateStacker.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(plugin, () -> {
if (!(location.getBlock().getState() instanceof CreatureSpawner)) return; 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; int maxNearby = amount > 6 ? amount + 3 : 6;
CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState(); CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState();
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) { if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) {

View File

@ -44,16 +44,13 @@ public class StackingTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
// Gather disabled worlds.
List<String> disabledWorlds = Setting.DISABLED_WORLDS.getStringList();
// Should entities be stacked? // Should entities be stacked?
if (!Setting.STACK_ENTITIES.getBoolean()) return; if (!Setting.STACK_ENTITIES.getBoolean()) return;
// Loop through each world. // Loop through each world.
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
// If world is disabled then continue to the next world. // 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. // Get the loaded entities from the current world and reverse them.
List<Entity> entities = new ArrayList<>(world.getEntities()); List<Entity> entities = new ArrayList<>(world.getEntities());
@ -80,6 +77,11 @@ public class StackingTask extends BukkitRunnable {
processed.clear(); processed.clear();
} }
public boolean isWorldDisabled(World world) {
List<String> disabledWorlds = Setting.DISABLED_WORLDS.getStringList();
return disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr));
}
private boolean isEntityStackable(Entity entity, Location location) { private boolean isEntityStackable(Entity entity, Location location) {
// Make sure we have the correct entity type and that it is valid. // Make sure we have the correct entity type and that it is valid.
if (!entity.isValid() if (!entity.isValid()