Newly placed spawners will now spawn the correct amounts.

This commit is contained in:
Brianna 2019-06-27 15:06:35 -04:00
parent 70fbf7a3e5
commit 3801d8ecbd
1 changed files with 13 additions and 10 deletions

View File

@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.spawner;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.utils.Reflection;
import com.songoda.ultimatestacker.utils.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.CreatureSpawner;
@ -27,16 +28,18 @@ public class SpawnerStack {
public void setAmount(int amount) {
this.amount = amount;
int count = 4 * amount;
int maxNearby = amount > 6 ? amount + 3 : 6;
CreatureSpawner creatureSpawner = (CreatureSpawner)location.getBlock().getState();
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) {
creatureSpawner.setMaxNearbyEntities(maxNearby);
creatureSpawner.setSpawnCount(count);
} else {
Reflection.updateSpawner(creatureSpawner, count, maxNearby);
}
creatureSpawner.update();
Bukkit.getScheduler().runTaskLater(UltimateStacker.getInstance(), () -> {
int count = 4 * amount;
int maxNearby = amount > 6 ? amount + 3 : 6;
CreatureSpawner creatureSpawner = (CreatureSpawner) location.getBlock().getState();
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) {
creatureSpawner.setMaxNearbyEntities(maxNearby);
creatureSpawner.setSpawnCount(count);
} else {
Reflection.updateSpawner(creatureSpawner, count, maxNearby);
}
creatureSpawner.update();
}, 1L);
}
@Override