From 775d4298337ee777af2c829b22dde5fec567ec12 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Sat, 18 May 2019 21:21:27 +0300 Subject: [PATCH] Fix ConcurrentModificationException in BB tile filling --- .../games/battlebanzai/BattleBanzaiGame.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java index a3733c23..cc4139a5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java @@ -18,6 +18,7 @@ import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserActionComposer; import com.eu.habbo.threading.runnables.BattleBanzaiTilesFlicker; +import gnu.trove.impl.hash.THash; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; @@ -295,10 +296,11 @@ public class BattleBanzaiGame extends Game int y = item.getY(); List> filledAreas = new ArrayList<>(); - filledAreas.add(this.floodFill(x, y - 1, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); - filledAreas.add(this.floodFill(x, y + 1, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); - filledAreas.add(this.floodFill(x - 1, y, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); - filledAreas.add(this.floodFill(x + 1, y, this.lockedTiles.get(teamColor), new ArrayList<>(), teamColor)); + THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); + filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x, y + 1, lockedTiles, new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x - 1, y, lockedTiles, new ArrayList<>(), teamColor)); + filledAreas.add(this.floodFill(x + 1, y, lockedTiles, new ArrayList<>(), teamColor)); Optional> largestAreaOfAll = filledAreas.stream().filter(Objects::nonNull).max(Comparator.comparing(List::size)); @@ -335,10 +337,10 @@ public class BattleBanzaiGame extends Game stack.add(tile); List> result = new ArrayList<>(); - result.add(this.floodFill(x, y - 1, lockedTiles, stack, color)); - result.add(this.floodFill(x, y + 1, lockedTiles, stack, color)); - result.add(this.floodFill(x - 1, y, lockedTiles, stack, color)); - result.add(this.floodFill(x + 1, y, lockedTiles, stack, color)); + result.add(this.floodFill(x, y - 1, new THashSet<>(lockedTiles), stack, color)); + result.add(this.floodFill(x, y + 1, new THashSet<>(lockedTiles), stack, color)); + result.add(this.floodFill(x - 1, y, new THashSet<>(lockedTiles), stack, color)); + result.add(this.floodFill(x + 1, y, new THashSet<>(lockedTiles), stack, color)); if (result.contains(null)) return null; @@ -350,7 +352,7 @@ public class BattleBanzaiGame extends Game private boolean hasLockedTileAtCoordinates(int x, int y, THashSet lockedTiles) { - for (HabboItem item: lockedTiles) + for (HabboItem item : lockedTiles) { if (item.getX() == x && item.getY() == y) return true; } @@ -360,7 +362,7 @@ public class BattleBanzaiGame extends Game private boolean isOutOfBounds(int x, int y) { - for (HabboItem item: this.gameTiles.values()) + for (HabboItem item : this.gameTiles.values()) { if (item.getX() == x && item.getY() == y) return false; }