From cb8df7ce6e47266963f086d4155171a9bedefeed Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Mon, 5 Aug 2019 19:35:26 +0300 Subject: [PATCH] Fix exceptions --- .../eu/habbo/habbohotel/commands/UnmuteCommand.java | 4 ++-- .../java/com/eu/habbo/habbohotel/games/GameTeam.java | 2 ++ .../habbohotel/games/freeze/FreezeGameTeam.java | 2 ++ .../eu/habbo/habbohotel/items/CrackableReward.java | 2 ++ .../java/com/eu/habbo/habbohotel/rooms/Room.java | 9 ++++++++- .../java/com/eu/habbo/habbohotel/users/Habbo.java | 12 ++++++++---- .../eu/habbo/habbohotel/users/HabboInventory.java | 8 +++++--- .../rooms/users/RoomUnitOnRollerComposer.java | 2 +- .../runnables/teleport/TeleportActionFive.java | 2 ++ 9 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/UnmuteCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/UnmuteCommand.java index 9e88bd8b..376f8b94 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/UnmuteCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/UnmuteCommand.java @@ -23,12 +23,12 @@ public class UnmuteCommand extends Command { gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_unmute.not_found").replace("%user%", params[1]), RoomChatMessageBubbles.ALERT); return true; } else { - if (!habbo.getHabboStats().allowTalk() || habbo.getHabboInfo().getCurrentRoom().isMuted(habbo)) { + if (!habbo.getHabboStats().allowTalk() || (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom().isMuted(habbo))) { if (!habbo.getHabboStats().allowTalk()) { habbo.unMute(); } - if (habbo.getHabboInfo().getCurrentRoom().isMuted(habbo)) { + if (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom().isMuted(habbo)) { habbo.getHabboInfo().getCurrentRoom().muteHabbo(habbo, 1); } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java index 67fa54e0..79dbc2aa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/GameTeam.java @@ -70,6 +70,8 @@ public class GameTeam { public void clearMembers() { for (GamePlayer player : this.members) { + if (player == null || player.getHabbo() == null) continue; + player.getHabbo().getHabboInfo().getGamePlayer().reset(); player.getHabbo().getHabboInfo().setCurrentGame(null); player.getHabbo().getHabboInfo().setGamePlayer(null); diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java index 133cf431..ab57f565 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java @@ -14,6 +14,8 @@ public class FreezeGameTeam extends GameTeam { @Override public void removeMember(GamePlayer gamePlayer) { + if (gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getHabboInfo().getCurrentRoom() == null) return; + Game game = gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().getGame(FreezeGame.class); Room room = gamePlayer.getHabbo().getRoomUnit().getRoom(); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java b/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java index f3dbafe7..87e1caf6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/CrackableReward.java @@ -43,6 +43,8 @@ public class CrackableReward { if (prize.contains(":") && prize.split(":").length == 2) { itemId = Integer.valueOf(prize.split(":")[0]); chance = Integer.valueOf(prize.split(":")[1]); + } else if (prize.contains(":")) { + Emulator.getLogging().logErrorLine("Invalid configuration of crackable prizes (item id: " + this.itemId + "). '" + prize + "' format should be itemId:chance."); } else { itemId = Integer.valueOf(prize.replace(":", "")); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java index a0cffa30..560e90a5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -3413,11 +3413,14 @@ public class Room implements Comparable, ISerialize, Runnable { continue; } + if (this.layout == null) continue; + THashSet tiles = this.layout.getTilesAt( this.layout.getTile(habboItem.getX(), habboItem.getY()), habboItem.getBaseItem().getWidth(), habboItem.getBaseItem().getLength(), - habboItem.getRotation()); + habboItem.getRotation() + ); for (RoomTile tile : tiles) { if (((tile.x == x) && (tile.y == y))) { @@ -3682,6 +3685,10 @@ public class Room implements Comparable, ISerialize, Runnable { public void sendComposer(ServerMessage message) { for (Habbo habbo : this.getHabbos()) { + if (habbo.getClient() == null) { + this.removeHabbo(habbo, true); + } + habbo.getClient().sendResponse(message); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index 0876aec3..0838c76f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -22,6 +22,7 @@ import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.sql.ResultSet; import java.util.*; import java.util.stream.Collectors; @@ -110,7 +111,9 @@ public class Habbo implements Runnable { public void connect() { if (!Emulator.getConfig().getBoolean("networking.tcp.proxy") && this.client.getChannel().remoteAddress() != null) { - this.habboInfo.setIpLogin(((InetSocketAddress) this.client.getChannel().remoteAddress()).getAddress().getHostAddress()); + SocketAddress address = this.client.getChannel().remoteAddress(); + + if (address != null) this.habboInfo.setIpLogin(((InetSocketAddress) address).getAddress().getHostAddress()); } this.habboInfo.setMachineID(this.client.getMachineId()); @@ -199,7 +202,8 @@ public class Habbo implements Runnable { return; this.getHabboInfo().addCredits(event.credits); - this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); + + if (this.client != null) this.client.sendResponse(new UserCreditsComposer(this.client.getHabbo())); } @@ -213,7 +217,7 @@ public class Habbo implements Runnable { return; this.getHabboInfo().addPixels(event.points); - this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); + if (this.client != null) this.client.sendResponse(new UserCurrencyComposer(this.client.getHabbo())); } @@ -231,7 +235,7 @@ public class Habbo implements Runnable { return; this.getHabboInfo().addCurrencyAmount(event.type, event.points); - this.client.sendResponse(new UserPointsComposer(this.client.getHabbo().getHabboInfo().getCurrencyAmount(type), event.points, event.type)); + if (this.client != null) this.client.sendResponse(new UserPointsComposer(this.client.getHabbo().getHabboInfo().getCurrencyAmount(type), event.points, event.type)); } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboInventory.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboInventory.java index e227aaba..52db8cf6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInventory.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInventory.java @@ -147,9 +147,11 @@ public class HabboInventory { } public MarketPlaceOffer getOffer(int id) { - for (MarketPlaceOffer offer : this.items) { - if (offer.getOfferId() == id) - return offer; + synchronized (this.items) { + for (MarketPlaceOffer offer : this.items) { + if (offer.getOfferId() == id) + return offer; + } } return null; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java index 8537ac4a..9f30152a 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java @@ -55,7 +55,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { this.response.appendString(this.oldZ + ""); this.response.appendString(this.newZ + ""); - if (this.roller != null) { + if (this.roller != null && room.getLayout() != null) { RoomTile rollerTile = room.getLayout().getTile(this.roller.getX(), this.roller.getY()); Emulator.getThreading().run(() -> { diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index f8abd365..674dfba3 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java @@ -37,6 +37,8 @@ class TeleportActionFive implements Runnable { //if (!(this.currentTeleport instanceof InteractionTeleportTile)) + if (this.room.getLayout() == null || this.currentTeleport == null) return; + RoomTile currentLocation = this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()); RoomTile tile = this.room.getLayout().getTileInFront(currentLocation, this.currentTeleport.getRotation());