From 7cbc8cc162a6de27ef4ad9d7abb52fe5ed304b6b Mon Sep 17 00:00:00 2001 From: ArpyAge Date: Sat, 4 Sep 2021 03:12:37 +0200 Subject: [PATCH] Battle Banzai nullpointers and disconnect fix --- .../games/battlebanzai/BattleBanzaiGame.java | 97 ++++++++++--------- .../InteractionWiredHighscore.java | 18 +++- .../wired/effects/WiredEffectGiveScore.java | 18 +++- 3 files changed, 78 insertions(+), 55 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 b2ee6dcf..c14f6408 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 @@ -203,8 +203,9 @@ public class BattleBanzaiGame extends Game { item.setExtradata((6 + winningTeam.teamColor.type) + ""); this.room.updateItemState(item); } - - Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room)); + synchronized (this.lockedTiles) { + Emulator.getThreading().run(new BattleBanzaiTilesFlicker(this.lockedTiles.get(winningTeam.teamColor), winningTeam.teamColor, this.room)); + } } super.onEnd(); @@ -222,7 +223,9 @@ public class BattleBanzaiGame extends Game { this.room.updateItem(tile); } } - this.lockedTiles.clear(); + synchronized (this.lockedTiles) { + this.lockedTiles.clear(); + } } @@ -249,52 +252,54 @@ public class BattleBanzaiGame extends Game { } public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo, boolean doNotCheckFill) { - if (item instanceof InteractionBattleBanzaiTile) { - if (!this.lockedTiles.containsKey(teamColor)) { - this.lockedTiles.put(teamColor, new THashSet<>()); - } - - this.lockedTiles.get(teamColor).add(item); - } - - if (habbo != null) { - AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallTilesLocked")); - } - - if (doNotCheckFill) return; - - final int x = item.getX(); - final int y = item.getY(); - - final List> filledAreas = new ArrayList<>(); - final THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); - - executor.execute(() -> { - 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)); - - if (largestAreaOfAll.isPresent()) { - for (RoomTile tile : largestAreaOfAll.get()) { - Optional tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.x && i.getY() == tile.y && i instanceof InteractionBattleBanzaiTile).findAny(); - - tileItem.ifPresent(habboItem -> { - this.tileLocked(teamColor, habboItem, habbo, true); - - habboItem.setExtradata((2 + (teamColor.type * 3)) + ""); - this.room.updateItem(habboItem); - }); + synchronized (this.lockedTiles) { + if (item instanceof InteractionBattleBanzaiTile) { + if (!this.lockedTiles.containsKey(teamColor)) { + this.lockedTiles.put(teamColor, new THashSet<>()); } - this.refreshCounters(teamColor); - if (habbo != null) { - habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size()); - } + this.lockedTiles.get(teamColor).add(item); } - }); + + if (habbo != null) { + AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("BattleBallTilesLocked")); + } + + if (doNotCheckFill) return; + + final int x = item.getX(); + final int y = item.getY(); + + final List> filledAreas = new ArrayList<>(); + final THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); + + executor.execute(() -> { + 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)); + + if (largestAreaOfAll.isPresent()) { + for (RoomTile tile : largestAreaOfAll.get()) { + Optional tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.x && i.getY() == tile.y && i instanceof InteractionBattleBanzaiTile).findAny(); + + tileItem.ifPresent(habboItem -> { + this.tileLocked(teamColor, habboItem, habbo, true); + + habboItem.setExtradata((2 + (teamColor.type * 3)) + ""); + this.room.updateItem(habboItem); + }); + } + + this.refreshCounters(teamColor); + if (habbo != null) { + habbo.getHabboInfo().getGamePlayer().addScore(BattleBanzaiGame.POINTS_LOCK_TILE * largestAreaOfAll.get().size()); + } + } + }); + } } private List floodFill(int x, int y, THashSet lockedTiles, List stack, GameTeamColors color) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java index 8fb95dd4..6c8be89c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java @@ -110,15 +110,23 @@ public class InteractionWiredHighscore extends HabboItem { serverMessage.appendInt(this.clearType.type); if (this.data != null) { - serverMessage.appendInt(this.data.size()); + int size = this.data.size(); + if(size > 50) { + size = 50; + } + serverMessage.appendInt(size); + int count = 0; for (WiredHighscoreRow row : this.data) { - serverMessage.appendInt(row.getValue()); + if(count < 50) { + serverMessage.appendInt(row.getValue()); - serverMessage.appendInt(row.getUsers().size()); - for (String username : row.getUsers()) { - serverMessage.appendString(username); + serverMessage.appendInt(row.getUsers().size()); + for (String username : row.getUsers()) { + serverMessage.appendString(username); + } } + count++; } } else { serverMessage.appendInt(0); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java index 5a326356..6632c2e4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java @@ -52,15 +52,19 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { if (game == null) return false; - TObjectIntIterator> iterator = this.data.iterator(); + int gameStartTime = game.getStartTime(); - for (int i = this.data.size(); i-- > 0; ) { + TObjectIntMap> dataClone = new TObjectIntHashMap<>(this.data); + + TObjectIntIterator> iterator = dataClone.iterator(); + + for (int i = dataClone.size(); i-- > 0; ) { iterator.advance(); Map.Entry map = iterator.key(); if (map.getValue() == habbo.getHabboInfo().getId()) { - if (map.getKey() == game.getStartTime()) { + if (map.getKey() == gameStartTime) { if (iterator.value() < this.count) { iterator.setValue(iterator.value() + 1); @@ -74,7 +78,13 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { } } - this.data.put(new AbstractMap.SimpleEntry<>(game.getStartTime(), habbo.getHabboInfo().getId()), 1); + try { + this.data.put(new AbstractMap.SimpleEntry<>(gameStartTime, habbo.getHabboInfo().getId()), 1); + } + catch(IllegalArgumentException e) { + + } + if (habbo.getHabboInfo().getGamePlayer() != null) { habbo.getHabboInfo().getGamePlayer().addScore(this.score, true);