UltimateStacker/src/main/java/com/songoda/ultimatestacker/spawner/SpawnerStack.java

55 lines
1.6 KiB
Java
Raw Normal View History

2018-11-06 04:33:10 +01:00
package com.songoda.ultimatestacker.spawner;
2018-11-06 05:41:58 +01:00
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.utils.Reflection;
import com.songoda.ultimatestacker.utils.ServerVersion;
2018-11-06 04:33:10 +01:00
import org.bukkit.Location;
import org.bukkit.block.CreatureSpawner;
public class SpawnerStack {
private final Location location;
2019-01-23 19:01:31 +01:00
private int amount = 1;
2018-11-06 04:33:10 +01:00
public SpawnerStack(Location location, int amount) {
this.location = location;
setAmount(amount);
}
public Location getLocation() {
return location.clone();
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
2018-11-30 04:08:34 +01:00
int count = 4 * amount;
int maxNearby = amount > 6 ? amount + 3 : 6;
2018-11-06 04:33:10 +01:00
CreatureSpawner creatureSpawner = (CreatureSpawner)location.getBlock().getState();
2018-11-30 04:08:34 +01:00
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) {
creatureSpawner.setMaxNearbyEntities(maxNearby);
creatureSpawner.setSpawnCount(count);
} else {
Reflection.updateSpawner(creatureSpawner, count, maxNearby);
}
2018-11-06 04:33:10 +01:00
creatureSpawner.update();
}
@Override
public String toString() {
return "SpawnerStack:{"
+ "Amount:\"" + amount + "\","
+ "Location:{"
+ "World:\"" + location.getWorld().getName() + "\","
+ "X:" + location.getBlockX() + ","
+ "Y:" + location.getBlockY() + ","
+ "Z:" + location.getBlockZ()
+ "}"
+ "}";
}
}