Refactor code to enable golem spawning. #180

This commit is contained in:
tastybento 2024-01-09 17:47:24 +09:00
parent 843aa89f6c
commit 9ffe0c740a
1 changed files with 9 additions and 8 deletions

View File

@ -180,7 +180,7 @@ public class EntityLimitListener implements Listener {
if (island.isSpawn() || !res.hit()) { if (island.isSpawn() || !res.hit()) {
// Allowed // Allowed
if (async) { if (async) {
Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> l.getWorld().spawn(l, e.getClass(), entity -> preSpawn(entity, reason, l))); Bukkit.getScheduler().runTask(BentoBox.getInstance(), () -> preSpawn(e.getType(), reason, l));
} // else do nothing } // else do nothing
} else { } else {
if (async) { if (async) {
@ -195,21 +195,23 @@ public class EntityLimitListener implements Listener {
return true; return true;
} }
private void preSpawn(Entity entity, SpawnReason reason, Location l) { private void preSpawn(EntityType entityType, SpawnReason reason, Location l) {
justSpawned.add(entity.getUniqueId());
// Check for entities that need cleanup // Check for entities that need cleanup
switch (reason) { switch (reason) {
case BUILD_IRONGOLEM -> detectIronGolem(l); case BUILD_IRONGOLEM -> detectIronGolem(l);
case BUILD_SNOWMAN -> detectSnowman(l); case BUILD_SNOWMAN -> detectSnowman(l);
case BUILD_WITHER -> { case BUILD_WITHER -> {
detectWither(l); detectWither(l);
}
default -> throw new IllegalArgumentException("Unexpected value: " + reason);
}
Entity entity = l.getWorld().spawnEntity(l, entityType);
justSpawned.add(entity.getUniqueId());
if (reason == SpawnReason.BUILD_WITHER) {
// Create explosion // Create explosion
l.getWorld().createExplosion(l, 7F, true, true, entity); l.getWorld().createExplosion(l, 7F, true, true, entity);
} }
default -> {
// Do nothing
}
}
} }
private void detectIronGolem(Location l) { private void detectIronGolem(Location l) {
@ -246,7 +248,6 @@ public class EntityLimitListener implements Listener {
} }
} }
} }
} }
private void detectSnowman(Location l) { private void detectSnowman(Location l) {