Skip to content

Commit

Permalink
Refactor code to enable golem spawning. #180
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 9, 2024
1 parent 843aa89 commit 9ffe0c7
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private boolean processIsland(Cancellable c, LivingEntity e, Location l, SpawnRe
if (island.isSpawn() || !res.hit()) {
// Allowed
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 {
if (async) {
Expand All @@ -195,20 +195,22 @@ private boolean processIsland(Cancellable c, LivingEntity e, Location l, SpawnRe
return true;
}

private void preSpawn(Entity entity, SpawnReason reason, Location l) {
justSpawned.add(entity.getUniqueId());
private void preSpawn(EntityType entityType, SpawnReason reason, Location l) {

// Check for entities that need cleanup
switch (reason) {
case BUILD_IRONGOLEM -> detectIronGolem(l);
case BUILD_SNOWMAN -> detectSnowman(l);
case BUILD_WITHER -> {
detectWither(l);
// Create explosion
l.getWorld().createExplosion(l, 7F, true, true, entity);
}
default -> {
// Do nothing
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
l.getWorld().createExplosion(l, 7F, true, true, entity);
}
}

Expand Down Expand Up @@ -246,7 +248,6 @@ private void detectIronGolem(Location l) {
}
}
}

}

private void detectSnowman(Location l) {
Expand Down

0 comments on commit 9ffe0c7

Please sign in to comment.