forked from kaboomserver/extras
fix: tweak spawner restrictions
This commit is contained in:
parent
70f7134de9
commit
85fe8525d8
1 changed files with 25 additions and 24 deletions
|
@ -130,37 +130,46 @@ public final class EntitySpawn implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void limitSpawner(final CreatureSpawner spawner) {
|
private boolean limitSpawner(final CreatureSpawner spawner) {
|
||||||
final EntityType spawnedType = spawner.getSpawnedType();
|
final EntityType spawnedType = spawner.getSpawnedType();
|
||||||
|
boolean didChange = false;
|
||||||
|
|
||||||
if (!spawnedType.isAlive() || spawnedType.equals(EntityType.ARMOR_STAND)) {
|
if (!spawnedType.isAlive() || spawnedType.equals(EntityType.ARMOR_STAND)) {
|
||||||
spawner.setSpawnedType(EntityType.PIG);
|
spawner.setSpawnedType(EntityType.PIG);
|
||||||
spawner.update();
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getMinSpawnDelay() <= 5000) {
|
if (spawner.getMaxSpawnDelay() < 2000) {
|
||||||
spawner.setMinSpawnDelay(5000);
|
spawner.setMaxSpawnDelay(2000);
|
||||||
spawner.update();
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getMaxSpawnDelay() <= 10000) {
|
if (spawner.getMinSpawnDelay() < 1000) {
|
||||||
spawner.setMaxSpawnDelay(10000);
|
spawner.setMinSpawnDelay(1000);
|
||||||
spawner.update();
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getDelay() <= 5000) {
|
if (spawner.getDelay() < 5000) {
|
||||||
spawner.setDelay(5000);
|
spawner.setDelay(5000);
|
||||||
spawner.update();
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getSpawnCount() > 10) {
|
if (spawner.getSpawnCount() > 10) {
|
||||||
spawner.setSpawnCount(10);
|
spawner.setSpawnCount(10);
|
||||||
spawner.update();
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spawner.getSpawnRange() > 10) {
|
if (spawner.getSpawnRange() > 10) {
|
||||||
spawner.setSpawnRange(10);
|
spawner.setSpawnRange(10);
|
||||||
spawner.update();
|
didChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (didChange) {
|
||||||
|
spawner.update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -196,15 +205,6 @@ public final class EntitySpawn implements Listener {
|
||||||
applyEntityChanges(entity);
|
applyEntityChanges(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
void onItemSpawn(final ItemSpawnEvent event) {
|
|
||||||
try {
|
|
||||||
event.getEntity().getItemStack().getItemMeta();
|
|
||||||
} catch (Exception exception) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onLightningStrike(final LightningStrikeEvent event) {
|
void onLightningStrike(final LightningStrikeEvent event) {
|
||||||
final LightningStrike lightning = event.getLightning();
|
final LightningStrike lightning = event.getLightning();
|
||||||
|
@ -230,9 +230,10 @@ public final class EntitySpawn implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) {
|
void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) {
|
||||||
try {
|
final CreatureSpawner spawner = (CreatureSpawner)event.getSpawnerLocation().getBlock()
|
||||||
limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState());
|
.getState();
|
||||||
} catch (Exception exception) {
|
|
||||||
|
if (limitSpawner(spawner)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue