Skip to content

Commit a453d2d

Browse files
tastybentoclaude
andcommitted
Reduce complexity of findEntities() by extracting helper methods
Extracts isAcidSusceptible() and addToBurnList() from findEntities() to reduce cognitive complexity and improve readability. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent eebc4cb commit a453d2d

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

src/main/java/world/bentobox/acidisland/world/AcidTask.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,35 @@ public AcidTask(AcidIsland addon) {
5757
void findEntities() {
5858
Map<Entity, Long> burnList = new WeakHashMap<>();
5959
for (Entity e : getEntityStream()) {
60-
if (e instanceof Item || (!IMMUNE.contains(e.getType()) && !(e instanceof WaterMob))) {
60+
if (isAcidSusceptible(e)) {
6161
int x = e.getLocation().getBlockX() >> 4;
6262
int z = e.getLocation().getBlockZ() >> 4;
63-
if (e.getWorld().isChunkLoaded(x,z)) {
64-
if (e.getLocation().getBlock().getType().equals(Material.WATER)) {
65-
if ((e instanceof Monster || e instanceof MagmaCube) && addon.getSettings().getAcidDamageMonster() > 0D) {
66-
burnList.put(e, (long)addon.getSettings().getAcidDamageMonster());
67-
68-
} else if ((e instanceof Animals) && addon.getSettings().getAcidDamageAnimal() > 0D
69-
&& (!e.getType().equals(EntityType.CHICKEN) || addon.getSettings().isAcidDamageChickens())) {
70-
burnList.put(e, (long)addon.getSettings().getAcidDamageAnimal());
71-
} else if (addon.getSettings().getAcidDestroyItemTime() > 0 && e instanceof Item) {
72-
burnList.put(e, System.currentTimeMillis());
73-
}
74-
}
63+
if (e.getWorld().isChunkLoaded(x, z)
64+
&& e.getLocation().getBlock().getType().equals(Material.WATER)) {
65+
addToBurnList(e, burnList);
7566
}
7667
}
7768
}
7869
// Remove any entities not on the burn list
7970
itemsInWater.keySet().removeIf(i -> !burnList.containsKey(i));
80-
8171
if (!burnList.isEmpty()) {
82-
Bukkit.getScheduler().runTask(addon.getPlugin(), () ->
8372
// Burn everything
84-
burnList.forEach(this::applyDamage));
73+
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> burnList.forEach(this::applyDamage));
74+
}
75+
}
76+
77+
private boolean isAcidSusceptible(Entity e) {
78+
return e instanceof Item || (!IMMUNE.contains(e.getType()) && !(e instanceof WaterMob));
79+
}
80+
81+
private void addToBurnList(Entity e, Map<Entity, Long> burnList) {
82+
if ((e instanceof Monster || e instanceof MagmaCube) && addon.getSettings().getAcidDamageMonster() > 0D) {
83+
burnList.put(e, (long) addon.getSettings().getAcidDamageMonster());
84+
} else if (e instanceof Animals && addon.getSettings().getAcidDamageAnimal() > 0D
85+
&& (!e.getType().equals(EntityType.CHICKEN) || addon.getSettings().isAcidDamageChickens())) {
86+
burnList.put(e, (long) addon.getSettings().getAcidDamageAnimal());
87+
} else if (addon.getSettings().getAcidDestroyItemTime() > 0 && e instanceof Item) {
88+
burnList.put(e, System.currentTimeMillis());
8589
}
8690
}
8791

0 commit comments

Comments
 (0)