mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-08 03:21:32 +01:00
Spawners won't auto stack in disabled worlds anymore.
This commit is contained in:
parent
9e38374cb1
commit
7891479a78
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -44,16 +44,13 @@ public class StackingTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Gather disabled worlds.
|
||||
List<String> 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<Entity> entities = new ArrayList<>(world.getEntities());
|
||||
@ -80,6 +77,11 @@ public class StackingTask extends BukkitRunnable {
|
||||
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) {
|
||||
// Make sure we have the correct entity type and that it is valid.
|
||||
if (!entity.isValid()
|
||||
|
Loading…
Reference in New Issue
Block a user