fix: tweak spawner restrictions

This commit is contained in:
amyavi 2024-11-01 11:28:04 -03:00
parent 70f7134de9
commit 85fe8525d8
No known key found for this signature in database

View file

@ -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();
boolean didChange = false;
if (!spawnedType.isAlive() || spawnedType.equals(EntityType.ARMOR_STAND)) {
spawner.setSpawnedType(EntityType.PIG);
spawner.update();
didChange = true;
}
if (spawner.getMinSpawnDelay() <= 5000) {
spawner.setMinSpawnDelay(5000);
spawner.update();
if (spawner.getMaxSpawnDelay() < 2000) {
spawner.setMaxSpawnDelay(2000);
didChange = true;
}
if (spawner.getMaxSpawnDelay() <= 10000) {
spawner.setMaxSpawnDelay(10000);
spawner.update();
if (spawner.getMinSpawnDelay() < 1000) {
spawner.setMinSpawnDelay(1000);
didChange = true;
}
if (spawner.getDelay() <= 5000) {
if (spawner.getDelay() < 5000) {
spawner.setDelay(5000);
spawner.update();
didChange = true;
}
if (spawner.getSpawnCount() > 10) {
spawner.setSpawnCount(10);
spawner.update();
didChange = true;
}
if (spawner.getSpawnRange() > 10) {
spawner.setSpawnRange(10);
spawner.update();
didChange = true;
}
if (didChange) {
spawner.update();
return true;
}
return false;
}
@EventHandler
@ -196,15 +205,6 @@ public final class EntitySpawn implements Listener {
applyEntityChanges(entity);
}
@EventHandler
void onItemSpawn(final ItemSpawnEvent event) {
try {
event.getEntity().getItemStack().getItemMeta();
} catch (Exception exception) {
event.setCancelled(true);
}
}
@EventHandler
void onLightningStrike(final LightningStrikeEvent event) {
final LightningStrike lightning = event.getLightning();
@ -230,9 +230,10 @@ public final class EntitySpawn implements Listener {
@EventHandler
void onPreSpawnerSpawn(final PreSpawnerSpawnEvent event) {
try {
limitSpawner((CreatureSpawner) event.getSpawnerLocation().getBlock().getState());
} catch (Exception exception) {
final CreatureSpawner spawner = (CreatureSpawner)event.getSpawnerLocation().getBlock()
.getState();
if (limitSpawner(spawner)) {
event.setCancelled(true);
}
}