Skip to content

Commit

Permalink
Prevent concurrent modification exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jul 17, 2024
1 parent c6ed2a8 commit c1582a8
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package world.bentobox.bentobox.listeners.flags.protection;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.bukkit.Material;
Expand Down Expand Up @@ -91,11 +93,15 @@ private boolean checkBlocks(Event e, Player player, Block block) {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileExplode(EntityExplodeEvent e) {
if (e.getEntity() instanceof Projectile p && p.getShooter() instanceof Player player) {
List<Block> blocksToRemove = new ArrayList<>();

for (Block b : e.blockList()) {
if (!this.checkBlocks(e, player, b)) {
e.blockList().clear();
blocksToRemove.add(b);
}
}

e.blockList().removeAll(blocksToRemove);
}
}

Expand Down

0 comments on commit c1582a8

Please sign in to comment.