diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java index aca10bfa..4fed28b7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java @@ -113,7 +113,7 @@ public class BotManager { if (room != null && bot != null && habbo != null) { if (room.getRoomInfo().isRoomOwner(habbo) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_PLACEFURNI)) { - if (room.getRoomUnitManager().getCurrentRoomBots().size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) { + if (room.getRoomUnitManager().getCurrentBots().size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) { habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS)); return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java b/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java index 23c88dbf..f86d8612 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/layouts/RoomBundleLayout.java @@ -190,10 +190,10 @@ public class RoomBundleLayout extends SingleBundle { if (Emulator.getConfig().getBoolean("bundle.bots.enabled")) { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO bots (user_id, room_id, name, motto, figure, gender, x, y, z, chat_lines, chat_auto, chat_random, chat_delay, dance, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { - synchronized (this.room.getRoomUnitManager().getCurrentRoomBots()) { + synchronized (this.room.getRoomUnitManager().getCurrentBots()) { statement.setInt(1, userId); statement.setInt(2, roomId); - for (Bot bot : this.room.getRoomUnitManager().getCurrentRoomBots().values()) { + for (Bot bot : this.room.getRoomUnitManager().getCurrentBots().values()) { statement.setString(3, bot.getName()); statement.setString(4, bot.getMotto()); statement.setString(5, bot.getFigure()); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/CommandsManager.java b/src/main/java/com/eu/habbo/habbohotel/commands/CommandsManager.java index 186db286..8d717d63 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/CommandsManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/CommandsManager.java @@ -149,11 +149,11 @@ public class CommandsManager { Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - if (room.getRoomUnitManager().getCurrentRoomPets().isEmpty()) { + if (room.getRoomUnitManager().getCurrentPets().isEmpty()) { return false; } - for(Pet pet : room.getRoomUnitManager().getCurrentRoomPets().values()) { + for(Pet pet : room.getRoomUnitManager().getCurrentPets().values()) { if (pet != null && pet.getName().equalsIgnoreCase(args[0])) { StringBuilder commandBuilder = new StringBuilder(); @@ -166,7 +166,7 @@ public class CommandsManager { for (PetCommand command : pet.getPetData().getPetCommands()) { if (command.getKey().equalsIgnoreCase(commandKey)) { if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() == gameClient.getHabbo().getHabboInfo().getId()) { - rideablePet.getRider().getHabboInfo().dismountPet(room); + rideablePet.getRider().getRoomUnit().dismountPet(false); break; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/BotsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/BotsCommand.java index fc882898..494aab57 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/BotsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/BotsCommand.java @@ -15,9 +15,9 @@ public class BotsCommand extends Command { if (gameClient.getHabbo().getRoomUnit().getRoom() == null || !gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo())) return false; - StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentRoomBots().values().size()); + StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values().size()); - for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentRoomBots().values()) { + for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values()) { data.append("\r"); data.append(""); data.append(Emulator.getTexts().getValue("generic.bot.name")); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/PetInfoCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/PetInfoCommand.java index b7e27792..e93e7602 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/PetInfoCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/PetInfoCommand.java @@ -21,7 +21,7 @@ public class PetInfoCommand extends Command { String name = params[1]; - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentRoomPets().forEach((a, pet) -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentPets().forEach((a, pet) -> { if (pet.getName().equalsIgnoreCase(name)) { gameClient.getHabbo().alert("" + getTextsValue("commands.generic.cmd_pet_info.title") + ": " + pet.getName() + "\r\n" + diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/ReloadRoomCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/ReloadRoomCommand.java index 371a0e7d..a9a67383 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/ReloadRoomCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/ReloadRoomCommand.java @@ -21,7 +21,7 @@ public class ReloadRoomCommand extends Command { Emulator.getThreading().run(() -> { Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room != null) { - Collection habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbos()); + Collection habbos = new ArrayList<>(room.getRoomUnitManager().getCurrentHabbos().values()); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId()); ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose(); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomDanceCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomDanceCommand.java index 90ef6b57..f2cad1cc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomDanceCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomDanceCommand.java @@ -28,7 +28,7 @@ public class RoomDanceCommand extends Command { return true; } - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> { habbo.getRoomUnit().setDanceType(DanceType.values()[danceId]); habbo.getRoomUnit().getRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose()); }); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomEffectCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomEffectCommand.java index 946ebac7..2ba5902c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomEffectCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomEffectCommand.java @@ -22,7 +22,7 @@ public class RoomEffectCommand extends Command { if (effectId >= 0) { Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - room.getRoomUnitManager().getRoomHabbos().forEach(habbo -> habbo.getRoomUnit().giveEffect(effectId, -1)); + room.getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> habbo.getRoomUnit().giveEffect(effectId, -1)); } else { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_roomeffect.positive"), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomItemCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomItemCommand.java index d58b7e89..e7f5670e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomItemCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomItemCommand.java @@ -29,7 +29,7 @@ public class RoomItemCommand extends Command { } } - for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) { habbo.getRoomUnit().setHandItem(itemId); habbo.getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomKickCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomKickCommand.java index aa8d24ca..f7caa38b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomKickCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomKickCommand.java @@ -24,7 +24,7 @@ public class RoomKickCommand extends Command { room.sendComposer(new HabboBroadcastMessageComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername()).compose()); } - for (Habbo habbo : room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : room.getRoomUnitManager().getCurrentHabbos().values()) { if (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo))) { room.kickHabbo(habbo, true); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomSitCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomSitCommand.java index bbe77246..8071ffa5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomSitCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomSitCommand.java @@ -11,7 +11,7 @@ public class RoomSitCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> { if (habbo.getRoomUnit().isWalking()) { habbo.getRoomUnit().stopWalking(); } else if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) { diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SayAllCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SayAllCommand.java index ed798452..d4127436 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SayAllCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SayAllCommand.java @@ -21,7 +21,7 @@ public class SayAllCommand extends Command { String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> habbo.talk(message)); + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> habbo.talk(message)); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutAllCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutAllCommand.java index 73befe08..40d79756 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutAllCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutAllCommand.java @@ -22,7 +22,7 @@ public class ShoutAllCommand extends Command { String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); - for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) { habbo.shout(message); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/RoomBadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/RoomBadgeCommand.java index ee2ee8c8..62c777a9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/RoomBadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/RoomBadgeCommand.java @@ -20,7 +20,7 @@ public class RoomBadgeCommand extends BaseBadgeCommand { if (!badge.isEmpty()) { ServerMessage message = createServerMessage(badge); - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos() + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values() .forEach(habbo -> sendBadgeToClient(badge, message, habbo)); } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/RoomCreditsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/RoomCreditsCommand.java index d3193eb5..1296233d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/RoomCreditsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/RoomCreditsCommand.java @@ -22,7 +22,7 @@ public class RoomCreditsCommand extends BaseCreditsCommand { if (amount != 0) { final String message = replaceAmount(getTextsValue("commands.generic.cmd_credits.received"), amount + ""); - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> { habbo.giveCredits(amount); habbo.whisper(message, RoomChatMessageBubbles.ALERT); }); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/RoomGiftCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/RoomGiftCommand.java index a590effb..edc30c8e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/RoomGiftCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/RoomGiftCommand.java @@ -17,7 +17,7 @@ public class RoomGiftCommand extends BaseGiftCommand { final String finalMessage = getFinalMessage(params); - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> { createGift(finalMessage, habbo, params); habbo.getClient().sendResponse(new WiredRewardResultMessageComposer(WiredRewardResultMessageComposer.REWARD_RECEIVED_ITEM)); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/RoomPixelsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/RoomPixelsCommand.java index 518e3bb4..b5ec0e96 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/RoomPixelsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/RoomPixelsCommand.java @@ -22,7 +22,7 @@ public class RoomPixelsCommand extends BasePixelsCommand { if (amount != 0) { final String message = replaceAmount(getTextsValue("commands.generic.cmd_duckets.received"), amount + ""); - gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos().forEach(habbo -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> { habbo.givePixels(amount); habbo.whisper(message, RoomChatMessageBubbles.ALERT); }); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/points/RoomPointsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/points/RoomPointsCommand.java index e431be43..8b50d3d5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/points/RoomPointsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/points/RoomPointsCommand.java @@ -55,7 +55,7 @@ public class RoomPointsCommand extends BasePointsCommand { if (amount != 0) { final String message = replaceAmountAndType(getTextsValue("commands.generic.cmd_points.received"), amount + "", getTextsValue("seasonal.name." + type)); - for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) { habbo.givePoints(type, amount); habbo.whisper(message, RoomChatMessageBubbles.ALERT); } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java index 71ccb521..2abe1ff4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGame.java @@ -189,7 +189,7 @@ public class FreezeGame extends Game { super.start(); if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) { - for (Habbo habbo : this.room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) { if (this.getTeamForHabbo(habbo) == null) { for (RoomItem item : this.room.getRoomItemManager().getItemsAt(habbo.getRoomUnit().getCurrentPosition())) { if (item instanceof InteractionFreezeTile) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java index 362793cc..3095e6f0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMultiHeight.java @@ -83,8 +83,9 @@ public class InteractionMultiHeight extends RoomItem { Collection unitsOnItem = room.getRoomUnitManager().getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY())); for (RoomUnit unit : unitsOnItem) { - if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) + if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) { continue; + } if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) { unit.setSitUpdate(true); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveRoom.java index 96732a4c..be439213 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveRoom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveRoom.java @@ -30,9 +30,9 @@ public class WiredConditionFurniHaveRoom extends InteractionWiredCondition { return true; } - Collection habbos = room.getRoomUnitManager().getRoomHabbos(); - Collection bots = room.getRoomUnitManager().getCurrentRoomBots().values(); - Collection pets = room.getRoomUnitManager().getCurrentRoomPets().values(); + Collection habbos = room.getRoomUnitManager().getCurrentHabbos().values(); + Collection bots = room.getRoomUnitManager().getCurrentBots().values(); + Collection pets = room.getRoomUnitManager().getCurrentPets().values(); return this.getWiredSettings().getItems(room).stream().allMatch(item -> { THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveRoom.java index cd64c515..60d9c148 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveRoom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveRoom.java @@ -30,9 +30,9 @@ public class WiredConditionNotFurniHaveRoom extends InteractionWiredCondition { return true; } - Collection habbos = room.getRoomUnitManager().getRoomHabbos(); - Collection bots = room.getRoomUnitManager().getCurrentRoomBots().values(); - Collection pets = room.getRoomUnitManager().getCurrentRoomPets().values(); + Collection habbos = room.getRoomUnitManager().getCurrentHabbos().values(); + Collection bots = room.getRoomUnitManager().getCurrentBots().values(); + Collection pets = room.getRoomUnitManager().getCurrentPets().values(); return this.getWiredSettings().getItems(room).stream().noneMatch(item -> { THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java index b6348162..c810d135 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java @@ -45,7 +45,7 @@ public class WiredEffectWhisper extends InteractionWiredEffect { return true; } } else { - for (Habbo h : room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo h : room.getRoomUnitManager().getCurrentHabbos().values()) { h.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam().replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED))); } diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java index 27e7c1d5..d298f236 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -483,7 +483,7 @@ public class ModToolManager { } if (roomActionEvent.isKickUsers()) { - for (Habbo habbo : room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : room.getRoomUnitManager().getCurrentHabbos().values()) { if (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo))) { room.kickHabbo(habbo, false); } diff --git a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionGroup.java b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionGroup.java index 87ea6450..c3e61a77 100644 --- a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionGroup.java +++ b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionGroup.java @@ -116,9 +116,9 @@ public class PermissionGroup { } } - public boolean canExecuteCommand(String key, boolean hasRoomRights) { + public boolean canExecuteCommand(String commandName, boolean hasRoomRights) { PermissionsManager permissionsManager = Emulator.getGameEnvironment().getPermissionsManager(); - PermissionCommand command = permissionsManager.getCommandByKey(key); + PermissionCommand command = permissionsManager.getCommandByKey(commandName); if(command == null) { return false; @@ -141,11 +141,10 @@ public class PermissionGroup { return false; } - public boolean hasPermissionRight(String name, boolean hasRoomRights) { - PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(name); - if(right != null && this.rights.containsKey(right)) { - PermissionSetting setting = this.rights.get(right); - return (setting == PermissionSetting.ALLOWED || (setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights)); + public boolean hasPermissionRight(String rightName, boolean hasRoomRights) { + if(this.rights.containsKey(rightName)) { + PermissionSetting setting = this.rights.get(rightName); + return setting == PermissionSetting.ALLOWED || setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights; } return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java index 8b804076..4b09df66 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java @@ -334,16 +334,16 @@ public class Pet extends Unit implements ISerialize, Runnable { public void cycle() { this.idleCommandTicks++; - int time = Emulator.getIntUnixTimestamp(); + int currentTime = Emulator.getIntUnixTimestamp(); + if (this.getRoomUnit() != null && this.task != PetTasks.RIDE) { - if (time - this.gestureTickTimeout > 5 && this.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { + if (currentTime - this.gestureTickTimeout > 5 && this.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); - this.setPacketUpdate(true); } - if (time - this.postureTimeout > 1 && this.task == null) { + if (currentTime - this.postureTimeout > 1 && this.task == null) { this.clearPosture(); - this.postureTimeout = time + 120; + this.postureTimeout = currentTime + 120; } if (this.freeCommandTicks > 0) { @@ -355,7 +355,7 @@ public class Pet extends Unit implements ISerialize, Runnable { } if (!this.getRoomUnit().isWalking()) { - if (this.getRoomUnit().getWalkTimeOut() < time && this.canWalk()) { + if (this.getRoomUnit().getWalkTimeOut() < currentTime && this.canWalk()) { RoomTile tile = this.room.getRandomWalkableTile(); if (tile != null) { @@ -379,7 +379,7 @@ public class Pet extends Unit implements ISerialize, Runnable { this.getRoomUnit().setGoalLocation(this.room.getRandomWalkableTile()); this.task = null; this.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, PetGestures.ENERGY.getKey()); - this.gestureTickTimeout = time; + this.gestureTickTimeout = currentTime; } } /* this is regeneration, add back if needed else if (this.tickTimeout >= 5) { @@ -401,7 +401,7 @@ public class Pet extends Unit implements ISerialize, Runnable { this.getRoomUnit().setCanWalk(true); } } else { - this.getRoomUnit().setWalkTimeOut(20 + time); + this.getRoomUnit().setWalkTimeOut(20 + currentTime); if (this.energy >= 2) this.addEnergy(-1); @@ -413,20 +413,20 @@ public class Pet extends Unit implements ISerialize, Runnable { if (this.levelThirst < 100) this.levelThirst++; - if (this.happiness > 0 && time - this.happinessDelay >= 30) { + if (this.happiness > 0 && currentTime - this.happinessDelay >= 30) { this.happiness--; - this.happinessDelay = time; + this.happinessDelay = currentTime; } } - if (time - this.gestureTickTimeout > 15) { - this.updateGesture(time); - } else if (time - this.randomActionTickTimeout > 30) { + if (currentTime - this.gestureTickTimeout > 15) { + this.updateGesture(currentTime); + } else if (currentTime - this.randomActionTickTimeout > 30) { this.randomAction(); - this.randomActionTickTimeout = time + (10 * Emulator.getRandom().nextInt(60)); + this.randomActionTickTimeout = currentTime + (10 * Emulator.getRandom().nextInt(60)); } - if (!this.muted && this.chatTimeout <= time) { + if (!this.muted && this.chatTimeout <= currentTime) { if (this.energy <= 30) { this.say(this.petData.randomVocal(PetVocalsType.TIRED)); if (this.energy <= 10) @@ -444,7 +444,7 @@ public class Pet extends Unit implements ISerialize, Runnable { } int timeOut = Emulator.getRandom().nextInt(30); - this.chatTimeout = time + (timeOut < 3 ? 30 : timeOut); + this.chatTimeout = currentTime + (timeOut < 3 ? 30 : timeOut); } } } 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 e8f5f1bf..b27bd14e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -20,7 +20,6 @@ import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; -import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet; import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.Habbo; @@ -92,9 +91,11 @@ public class Room implements Comparable, ISerialize, Runnable { @Getter private RoomTraxManager roomTraxManager; private static final String CAUGHT_EXCEPTION = "Caught exception"; - public static final Comparator SORT_SCORE = (o1, o2) -> o2.roomInfo.getScore() - o1.roomInfo.getScore(); - public static final Comparator SORT_ID = (o1, o2) -> o2.roomInfo.getId() - o1.roomInfo.getId(); - //Configuration. Loaded from database & updated accordingly. + public static final Comparator SORT_SCORE = Comparator.comparingInt(room -> room.roomInfo.getScore()); + public static final Comparator SORT_ID = Comparator.comparingInt(room -> room.roomInfo.getId()); + public static final Comparator SORT_USERS_COUNT = Comparator + .comparingInt((Room room) -> room.roomUnitManager.getRoomHabbosCount()) + .thenComparing(Room.SORT_ID); public static boolean HABBO_CHAT_DELAY = false; public static int MAXIMUM_BOTS = 10; public static int MAXIMUM_PETS = 10; @@ -507,171 +508,6 @@ public class Room implements Comparable, ISerialize, Runnable { return null; } - public synchronized void dispose() { - synchronized (this.loadLock) { - if (this.preventUnloading) - return; - - if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled()) - return; - - if (this.loaded) { - try { - - if (this.roomTraxManager != null && !this.roomTraxManager.disposed()) { - this.roomTraxManager.dispose(); - } - - this.roomCycleTask.cancel(false); - this.scheduledTasks.clear(); - this.scheduledComposers.clear(); - this.loaded = false; - - this.tileCache.clear(); - - synchronized (this.mutedHabbos) { - this.mutedHabbos.clear(); - } - - for (InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) { - timer.setRunning(false); - } - - for (Game game : this.games) { - game.dispose(); - } - this.games.clear(); - - this.roomUnitManager.removeAllPetsExceptRoomOwner(); - - this.roomItemManager.dispose(); - - if (this.roomSpecialTypes != null) { - this.roomSpecialTypes.dispose(); - } - - synchronized (this.habboQueue) { - this.habboQueue.clear(); - } - - this.roomUnitManager.dispose(); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - - try { - this.wordQuiz = ""; - this.yesVotes = 0; - this.noVotes = 0; - this.updateDatabaseUserCount(); - this.preLoaded = true; - this.layout = null; - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - - Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this)); - } - - @Override - public int compareTo(Room o) { - if (o.roomUnitManager.getRoomHabbosCount() != this.roomUnitManager.getRoomHabbosCount()) { - return o.roomUnitManager.getCurrentRoomHabbos().size() - this.roomUnitManager.getCurrentRoomHabbos().size(); - } - - return this.roomInfo.getId() - o.roomInfo.getId(); - } - - @Override - public void serialize(ServerMessage message) { - message.appendInt(this.roomInfo.getId()); - message.appendString(this.roomInfo.getName()); - - if (this.roomInfo.isPublicRoom()) { - message.appendInt(0); - message.appendString(""); - } else { - message.appendInt(this.roomInfo.getOwnerInfo().getId()); - message.appendString(this.roomInfo.getOwnerInfo().getUsername()); - } - - message.appendInt(this.roomInfo.getState().ordinal()); - message.appendInt(this.roomUnitManager.getRoomHabbosCount()); - message.appendInt(this.roomInfo.getMaxUsers()); - message.appendString(this.roomInfo.getDescription()); - message.appendInt(this.roomInfo.getTradeMode()); - message.appendInt(this.roomInfo.getScore()); - message.appendInt(0); - message.appendInt(this.roomInfo.getCategory().getId()); - - String[] tags = Arrays.stream(this.roomInfo.getTags().split(";")).filter(t -> !t.isEmpty()).toArray(String[]::new); - message.appendInt(tags.length); - for (String s : tags) { - message.appendString(s); - } - - int base = 0; - - if (this.roomInfo.hasGuild()) { - base = base | 2; - } - - if (this.roomInfo.isPromoted()) { - base = base | 4; - } - - if (!this.roomInfo.isPublicRoom()) { - base = base | 8; - } - - if (this.roomInfo.isAllowPets()) { - base = base | 16; - } - - message.appendInt(base); - - - if (this.roomInfo.hasGuild()) { - message.appendInt(this.roomInfo.getGuild().getId()); - message.appendString(this.roomInfo.getGuild().getName()); - message.appendString(this.roomInfo.getGuild().getBadge()); - } - - if (this.roomInfo.isPromoted()) { - message.appendString(this.promotion.getTitle()); - message.appendString(this.promotion.getDescription()); - message.appendInt((this.promotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60); - } - } - - @Override - public void run() { - synchronized (this.loadLock) { - if (this.loaded) { - try { - Emulator.getThreading().run(Room.this::cycle); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - } - - this.save(); - } - - public void save() { - if (this.needsUpdate) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { - this.roomInfo.update(connection); - this.needsUpdate = false; - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - } - } - public void updateDatabaseUserCount() { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET users = ? WHERE id = ? LIMIT 1")) { statement.setInt(1, this.roomUnitManager.getRoomHabbosCount()); @@ -686,7 +522,7 @@ public class Room implements Comparable, ISerialize, Runnable { this.cycleOdd = !this.cycleOdd; this.cycleTimestamp = System.currentTimeMillis(); final boolean[] foundRightHolder = {false}; - + boolean loaded; synchronized (this.loadLock) { loaded = this.loaded; @@ -706,7 +542,7 @@ public class Room implements Comparable, ISerialize, Runnable { task.cycle(this); } - if (!this.roomUnitManager.getCurrentRoomHabbos().isEmpty()) { + if (!this.roomUnitManager.getCurrentHabbos().isEmpty()) { this.roomIdleCycles = 0; THashSet updatedUnit = new THashSet<>(); @@ -714,18 +550,11 @@ public class Room implements Comparable, ISerialize, Runnable { final long millis = System.currentTimeMillis(); - for (Habbo habbo : this.roomUnitManager.getCurrentRoomHabbos().values()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (!foundRightHolder[0]) { foundRightHolder[0] = habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE; } - /* Habbo doesn't remove the handitem anymore, checked on February 25 2023 - if (habbo.getRoomUnit().getHandItem() > 0 && millis - habbo.getRoomUnit().getHandItemTimestamp() > (Room.HAND_ITEM_TIME * 1000L)) { - this.giveHandItem(habbo, 0); - } - - */ - if (habbo.getRoomUnit().getEffectId() > 0 && millis / 1000 > habbo.getRoomUnit().getEffectEndTimestamp()) { habbo.getRoomUnit().giveEffect(0, -1); } @@ -798,8 +627,8 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (!this.roomUnitManager.getCurrentRoomBots().isEmpty()) { - Iterator botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator(); + if (!this.roomUnitManager.getCurrentBots().isEmpty()) { + Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); while(botIterator.hasNext()) { try { @@ -831,8 +660,8 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (!this.roomUnitManager.getCurrentRoomPets().isEmpty() && this.allowBotsWalk) { - Iterator petIterator = this.roomUnitManager.getCurrentRoomPets().values().iterator(); + if (!this.roomUnitManager.getCurrentPets().isEmpty() && this.allowBotsWalk) { + Iterator petIterator = this.roomUnitManager.getCurrentPets().values().iterator(); while(petIterator.hasNext()) { final Pet pet; try { @@ -841,16 +670,12 @@ public class Room implements Comparable, ISerialize, Runnable { break; } - if (this.cycleRoomUnit(pet.getRoomUnit())) { - pet.getRoomUnit().setStatusUpdateNeeded(false); - updatedUnit.add(pet.getRoomUnit()); - } - + pet.getRoomUnit().cycle(this); pet.cycle(); - if (pet.isPacketUpdate()) { + if(pet.getRoomUnit().isStatusUpdateNeeded()) { + pet.getRoomUnit().setStatusUpdateNeeded(false); updatedUnit.add(pet.getRoomUnit()); - pet.setPacketUpdate(false); } if (pet.getRoomUnit().isWalking() && pet.getRoomUnit().getPath().size() == 1 && pet.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { @@ -1136,60 +961,165 @@ public class Room implements Comparable, ISerialize, Runnable { } } - private boolean cycleRoomUnit(RoomUnit unit) { - //Si esta caminando y su path no es nulo ni esta vacio - if (unit.isWalking() && unit.getPath() != null && !unit.getPath().isEmpty()) { - unit.cycle(this); - //Si no esta caminando o su path tiene errores + @Override + public void run() { + synchronized (this.loadLock) { + if (this.loaded) { + try { + Emulator.getThreading().run(Room.this::cycle); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); + } + } + } + + this.save(); + } + + public void save() { + if (this.needsUpdate) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { + this.roomInfo.update(connection); + this.needsUpdate = false; + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + } + } + + @Override + public void serialize(ServerMessage message) { + message.appendInt(this.roomInfo.getId()); + message.appendString(this.roomInfo.getName()); + + if (this.roomInfo.isPublicRoom()) { + message.appendInt(0); + message.appendString(""); } else { - //Y tiene el status de move, quitaselo y ocupa update - if (unit.hasStatus(RoomUnitStatus.MOVE) && !unit.isAnimateWalk()) { - unit.removeStatus(RoomUnitStatus.MOVE); + message.appendInt(this.roomInfo.getOwnerInfo().getId()); + message.appendString(this.roomInfo.getOwnerInfo().getUsername()); + } + + message.appendInt(this.roomInfo.getState().ordinal()); + message.appendInt(this.roomUnitManager.getRoomHabbosCount()); + message.appendInt(this.roomInfo.getMaxUsers()); + message.appendString(this.roomInfo.getDescription()); + message.appendInt(this.roomInfo.getTradeMode()); + message.appendInt(this.roomInfo.getScore()); + message.appendInt(0); + message.appendInt(this.roomInfo.getCategory().getId()); + + String[] tags = Arrays.stream(this.roomInfo.getTags().split(";")).filter(t -> !t.isEmpty()).toArray(String[]::new); + message.appendInt(tags.length); + for (String s : tags) { + message.appendString(s); + } + + int base = 0; + + if (this.roomInfo.hasGuild()) { + base = base | 2; + } + + if (this.roomInfo.isPromoted()) { + base = base | 4; + } + + if (!this.roomInfo.isPublicRoom()) { + base = base | 8; + } + + if (this.roomInfo.isAllowPets()) { + base = base | 16; + } + + message.appendInt(base); + + + if (this.roomInfo.hasGuild()) { + message.appendInt(this.roomInfo.getGuild().getId()); + message.appendString(this.roomInfo.getGuild().getName()); + message.appendString(this.roomInfo.getGuild().getBadge()); + } + + if (this.roomInfo.isPromoted()) { + message.appendString(this.promotion.getTitle()); + message.appendString(this.promotion.getDescription()); + message.appendInt((this.promotion.getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60); + } + } + + @Override + public int compareTo(Room room) { + return SORT_USERS_COUNT.compare(this, room); + } + + public synchronized void dispose() { + synchronized (this.loadLock) { + if (this.preventUnloading) + return; + + if (Emulator.getPluginManager().fireEvent(new RoomUnloadingEvent(this)).isCancelled()) + return; + + if (this.loaded) { + try { + + if (this.roomTraxManager != null && !this.roomTraxManager.disposed()) { + this.roomTraxManager.dispose(); + } + + this.roomCycleTask.cancel(false); + this.scheduledTasks.clear(); + this.scheduledComposers.clear(); + this.loaded = false; + + this.tileCache.clear(); + + synchronized (this.mutedHabbos) { + this.mutedHabbos.clear(); + } + + for (InteractionGameTimer timer : this.getRoomSpecialTypes().getGameTimers().values()) { + timer.setRunning(false); + } + + for (Game game : this.games) { + game.dispose(); + } + this.games.clear(); + + this.roomUnitManager.removeAllPetsExceptRoomOwner(); + + this.roomItemManager.dispose(); + + if (this.roomSpecialTypes != null) { + this.roomSpecialTypes.dispose(); + } + + synchronized (this.habboQueue) { + this.habboQueue.clear(); + } + + this.roomUnitManager.dispose(); + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); + } } - if (!unit.isWalking() && !unit.isCmdSitEnabled()) { - RoomTile thisTile = this.layout.getTile(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY()); - RoomItem topItem = this.roomItemManager.getTallestChair(thisTile); - - if (topItem == null || !topItem.getBaseItem().allowSit()) { - if (unit.hasStatus(RoomUnitStatus.SIT)) { - unit.removeStatus(RoomUnitStatus.SIT); - } - } else if (thisTile.getState() == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.isSitUpdate())) { - if(unit instanceof RoomAvatar roomAvatar) { - roomAvatar.setDance(DanceType.NONE); - } - unit.setStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(topItem))); - unit.setCurrentZ(topItem.getZ()); - unit.setRotation(RoomRotation.values()[topItem.getRotation()]); - unit.setSitUpdate(false); - return true; - } + try { + this.wordQuiz = ""; + this.yesVotes = 0; + this.noVotes = 0; + this.updateDatabaseUserCount(); + this.preLoaded = true; + this.layout = null; + } catch (Exception e) { + log.error(CAUGHT_EXCEPTION, e); } } - if (!unit.isWalking() && !unit.isCmdLayEnabled()) { - RoomItem topItem = this.roomItemManager.getTopItemAt(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY()); - - if (topItem == null || !topItem.getBaseItem().allowLay()) { - if (unit.hasStatus(RoomUnitStatus.LAY)) { - unit.removeStatus(RoomUnitStatus.LAY); - } - } else { - if (!unit.hasStatus(RoomUnitStatus.LAY)) { - unit.setStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(topItem))); - unit.setRotation(RoomRotation.values()[topItem.getRotation() % 4]); - - if (topItem.getRotation() == 0 || topItem.getRotation() == 4) { - unit.setLocation(this.layout.getTile(unit.getCurrentPosition().getX(), topItem.getY())); - } else { - unit.setLocation(this.layout.getTile(topItem.getX(), unit.getCurrentPosition().getY())); - } - } - } - } - - return unit.isStatusUpdateNeeded(); + Emulator.getPluginManager().fireEvent(new RoomUnloadedEvent(this)); } public void setDiagonalMoveEnabled(boolean moveDiagonally) { @@ -1444,11 +1374,11 @@ public class Room implements Comparable, ISerialize, Runnable { public void habboEntered(Habbo habbo) { habbo.getRoomUnit().setAnimateWalk(false); - synchronized (this.roomUnitManager.getCurrentRoomBots()) { + synchronized (this.roomUnitManager.getCurrentBots()) { if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) return; - Iterator botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator(); + Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); while (botIterator.hasNext()) { try { @@ -1613,7 +1543,7 @@ public class Room implements Comparable, ISerialize, Runnable { final ServerMessage message = new WhisperMessageComposer(roomChatMessage).compose(); final ServerMessage staffMessage = new WhisperMessageComposer(staffChatMessage).compose(); - for (Habbo h : this.roomUnitManager.getRoomHabbos()) { + for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) { if (h == roomChatMessage.getTargetHabbo() || h == habbo) { if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { if (prefixMessage != null) { @@ -1636,7 +1566,7 @@ public class Room implements Comparable, ISerialize, Runnable { ServerMessage message = new ChatMessageComposer(roomChatMessage).compose(); boolean noChatLimit = habbo.hasPermissionRight(Permission.ACC_CHAT_NO_LIMIT); - for (Habbo h : this.roomUnitManager.getRoomHabbos()) { + for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) { if ((h.getRoomUnit().getCurrentPosition().distance(habbo.getRoomUnit().getCurrentPosition()) <= this.roomInfo.getChatDistance() || h.equals(habbo) || this.roomRightsManager.hasRights(h) || @@ -1658,7 +1588,7 @@ public class Room implements Comparable, ISerialize, Runnable { } else if (chatType == RoomChatType.SHOUT) { ServerMessage message = new ShoutMessageComposer(roomChatMessage).compose(); - for (Habbo h : this.roomUnitManager.getRoomHabbos()) { + for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) { // Show the message // If the receiving Habbo has not ignored the sending Habbo // AND the sending Habbo is NOT in a tent OR the receiving Habbo is in the same tent as the sending Habbo @@ -1678,8 +1608,8 @@ public class Room implements Comparable, ISerialize, Runnable { } if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) { - synchronized (this.roomUnitManager.getCurrentRoomBots()) { - Iterator botIterator = this.roomUnitManager.getCurrentRoomBots().values().iterator(); + synchronized (this.roomUnitManager.getCurrentBots()) { + Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); while (botIterator.hasNext()) { try { @@ -1831,18 +1761,6 @@ public class Room implements Comparable, ISerialize, Runnable { return this.getStackHeight(x, y, calculateHeightmap, null); } - public boolean hasObjectTypeAt(Class type, int x, int y) { - THashSet items = this.roomItemManager.getItemsAt(x, y); - - for (RoomItem item : items) { - if (item.getClass() == type) { - return true; - } - } - - return false; - } - public boolean canSitOrLayAt(int x, int y) { RoomTile tile = this.layout.getTile((short) x, (short) y); @@ -1871,38 +1789,6 @@ public class Room implements Comparable, ISerialize, Runnable { return this.canSitAt(this.roomItemManager.getItemsAt(x, y)); } - boolean canWalkAt(RoomTile roomTile) { - if (roomTile == null) { - return false; - } - - if (roomTile.getState() == RoomTileState.INVALID) - return false; - - RoomItem topItem = null; - boolean canWalk = true; - THashSet items = this.roomItemManager.getItemsAt(roomTile); - if (items != null) { - for (RoomItem item : items) { - if (topItem == null) { - topItem = item; - } - - if (item.getZ() > topItem.getZ()) { - topItem = item; - canWalk = topItem.isWalkable() || topItem.getBaseItem().allowWalk(); - } else if (item.getZ() == topItem.getZ() && canWalk) { - if ((!topItem.isWalkable() && !topItem.getBaseItem().allowWalk()) - || (!item.getBaseItem().allowWalk() && !item.isWalkable())) { - canWalk = false; - } - } - } - } - - return canWalk; - } - boolean canSitAt(THashSet items) { if (items == null) return false; @@ -1957,7 +1843,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public void sendComposer(ServerMessage message) { - for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (habbo.getClient() == null) continue; habbo.getClient().sendResponse(message); @@ -1965,7 +1851,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public void petChat(ServerMessage message) { - for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (!habbo.getHabboStats().isIgnorePets()) habbo.getClient().sendResponse(message); } @@ -1976,7 +1862,7 @@ public class Room implements Comparable, ISerialize, Runnable { return; } - for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (habbo == null) { return ; } if (!habbo.getHabboStats().isIgnoreBots()) habbo.getClient().sendResponse(message); @@ -2101,7 +1987,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (guild.getRoomId() == this.roomInfo.getId()) { THashSet members = Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild.getId()); - for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { Optional member = members.stream().filter(m -> m.getUserId() == habbo.getHabboInfo().getId()).findAny(); if (member.isEmpty()) continue; @@ -2128,7 +2014,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public void refreshGuildRightsInRoom() { - for (Habbo habbo : this.roomUnitManager.getRoomHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if ((habbo.getRoomUnit().getRoom() == this && habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) && (!(habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_MOVEROTATE)))) this.getRoomRightsManager().refreshRightsForHabbo(habbo); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java index 1c346abc..9fb490ef 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -427,7 +427,7 @@ public class RoomManager { room.getRoomInfo().setScore(room.getRoomInfo().getScore() + 1); room.setNeedsUpdate(true); habbo.getHabboStats().getVotedRooms().push(room.getRoomInfo().getId()); - for (Habbo h : room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo h : room.getRoomUnitManager().getCurrentHabbos().values()) { h.getClient().sendResponse(new RoomRatingComposer(room.getRoomInfo().getScore(), !this.hasVotedForRoom(h, room))); } @@ -523,7 +523,7 @@ public class RoomManager { boolean habbosWithRights = false; synchronized (room.getRoomUnitManager().roomUnitLock) { - for (Habbo current : room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo current : room.getRoomUnitManager().getCurrentHabbos().values()) { if (room.getRoomRightsManager().hasRights(current) || current.getHabboInfo().getId() == room.getRoomInfo().getOwnerInfo().getId() || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(current).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { current.getClient().sendResponse(new DoorbellMessageComposer(habbo.getHabboInfo().getUsername())); habbosWithRights = true; @@ -681,9 +681,9 @@ public class RoomManager { List visibleHabbos = new ArrayList<>(); - if (!room.getRoomUnitManager().getCurrentRoomHabbos().isEmpty()) { - Collection habbosToSendEnter = room.getRoomUnitManager().getRoomHabbos(); - Collection allHabbos = room.getRoomUnitManager().getRoomHabbos(); + if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) { + Collection habbosToSendEnter = room.getRoomUnitManager().getCurrentHabbos().values(); + Collection allHabbos = room.getRoomUnitManager().getCurrentHabbos().values(); if (Emulator.getPluginManager().isRegistered(HabboAddedToRoomEvent.class, false)) { HabboAddedToRoomEvent event = Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room, habbosToSendEnter, allHabbos)); @@ -716,14 +716,14 @@ public class RoomManager { } - habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentRoomBots().values(), true)); + habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values(), true)); - if (!room.getRoomUnitManager().getCurrentRoomBots().isEmpty()) { - room.getRoomUnitManager().getCurrentRoomBots().values().stream() + if (!room.getRoomUnitManager().getCurrentBots().isEmpty()) { + room.getRoomUnitManager().getCurrentBots().values().stream() .filter(b -> !b.getRoomUnit().getDanceType().equals(DanceType.NONE)) .forEach(b -> habbo.getClient().sendResponse(new DanceMessageComposer(b.getRoomUnit()))); - room.getRoomUnitManager().getCurrentRoomBots().values() + room.getRoomUnitManager().getCurrentBots().values() .forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getCurrentZ()))); } @@ -760,9 +760,9 @@ public class RoomManager { habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems)); floorItems.clear(); - if (!room.getRoomUnitManager().getCurrentRoomPets().isEmpty()) { - habbo.getClient().sendResponse(new RoomPetComposer(room.getRoomUnitManager().getCurrentRoomPets())); - room.getRoomUnitManager().getCurrentRoomPets().values().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit()))); + if (!room.getRoomUnitManager().getCurrentPets().isEmpty()) { + habbo.getClient().sendResponse(new RoomPetComposer(room.getRoomUnitManager().getCurrentPets())); + room.getRoomUnitManager().getCurrentPets().values().forEach(pet -> habbo.getClient().sendResponse(new UserUpdateComposer(pet.getRoomUnit()))); } if (!habbo.getHabboStats().allowTalk()) { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java index dfbb3c12..fdc97e94 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java @@ -55,7 +55,7 @@ public class RoomRightsManager { } public boolean hasRights(Habbo habbo) { - return this.room.getRoomInfo().isRoomOwner(habbo) || this.rights.contains(habbo.getHabboInfo().getId()) || (habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE && this.room.getRoomUnitManager().getCurrentRoomHabbos().containsKey(habbo.getHabboInfo().getId())); + return this.room.getRoomInfo().isRoomOwner(habbo) || this.rights.contains(habbo.getHabboInfo().getId()) || (habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE && this.room.getRoomUnitManager().getCurrentHabbos().containsKey(habbo.getHabboInfo().getId())); } public HashMap getUsersWithRights() { @@ -167,7 +167,7 @@ public class RoomRightsManager { } private void refreshRightsInRoom() { - for (Habbo habbo : this.room.getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) { if (habbo.getRoomUnit().getRoom() == room) { this.refreshRightsForHabbo(habbo); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java index 4c84821f..fff25fd9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java @@ -395,7 +395,7 @@ public class RoomTraxManager implements Disposable { } public void sendUpdatedSongList() { - this.room.getRoomUnitManager().getRoomHabbos().forEach(h -> { + this.room.getRoomUnitManager().getCurrentHabbos().values().forEach(h -> { GameClient client = h.getClient(); if (client != null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java index 4a2c87f2..26b4bd39 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java @@ -38,18 +38,18 @@ import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; public class RoomUnitManager { private final Room room; private final ConcurrentHashMap currentRoomUnits; - private final ConcurrentHashMap currentRoomHabbos; - private final ConcurrentHashMap currentRoomBots; - private final ConcurrentHashMap currentRoomPets; + private final ConcurrentHashMap currentHabbos; + private final ConcurrentHashMap currentBots; + private final ConcurrentHashMap currentPets; private volatile int roomUnitCounter; public final Object roomUnitLock; public RoomUnitManager(Room room) { this.room = room; this.currentRoomUnits = new ConcurrentHashMap<>(); - this.currentRoomHabbos = new ConcurrentHashMap<>(); - this.currentRoomBots = new ConcurrentHashMap<>(); - this.currentRoomPets = new ConcurrentHashMap<>(); + this.currentHabbos = new ConcurrentHashMap<>(); + this.currentBots = new ConcurrentHashMap<>(); + this.currentPets = new ConcurrentHashMap<>(); this.roomUnitCounter = 0; this.roomUnitLock = new Object(); } @@ -60,7 +60,7 @@ public class RoomUnitManager { } private synchronized void loadBots(Connection connection) { - this.currentRoomBots.clear(); + this.currentBots.clear(); try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?")) { statement.setInt(1, this.room.getRoomInfo().getId()); @@ -100,7 +100,7 @@ public class RoomUnitManager { } private synchronized void loadPets(Connection connection) { - this.currentRoomPets.clear(); + this.currentPets.clear(); try (PreparedStatement statement = connection.prepareStatement("SELECT users.username as pet_owner_name, users_pets.* FROM users_pets INNER JOIN users ON users_pets.user_id = users.id WHERE room_id = ?")) { statement.setInt(1, this.room.getRoomInfo().getId()); @@ -141,12 +141,12 @@ public class RoomUnitManager { switch (unit.getRoomUnit().getRoomUnitType()) { case HABBO -> { - this.currentRoomHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit); + this.currentHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit); unit.getRoomUnit().getRoom().updateDatabaseUserCount(); } - case BOT -> this.currentRoomBots.put(((Bot) unit).getId(), (Bot) unit); + case BOT -> this.currentBots.put(((Bot) unit).getId(), (Bot) unit); case PET -> { - this.currentRoomPets.put(((Pet) unit).getId(), (Pet) unit); + this.currentPets.put(((Pet) unit).getId(), (Pet) unit); Habbo habbo = this.getRoomHabboById(((Pet) unit).getUserId()); if (habbo != null) { unit.getRoomUnit().getRoom().getFurniOwnerNames().put(((Pet) unit).getUserId(), this.getRoomHabboById(((Pet) unit).getUserId()).getHabboInfo().getUsername()); @@ -164,66 +164,62 @@ public class RoomUnitManager { return this.currentRoomUnits.values().stream().anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile)); } - public Collection getAvatarsAt(RoomTile tile) { + public List getAvatarsAt(RoomTile tile) { return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList()); } - public Collection getRoomHabbos() { - return this.currentRoomHabbos.values(); - } - public int getRoomHabbosCount() { - return this.currentRoomHabbos.size(); + return this.currentHabbos.size(); } public boolean hasHabbosAt(RoomTile tile) { - return this.currentRoomHabbos.values().stream().anyMatch(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)); + return this.currentHabbos.values().stream().anyMatch(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)); } public Collection getHabbosAt(RoomTile tile) { - return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); } public Habbo getRoomHabboById(int habboId) { - return this.currentRoomHabbos.get(habboId); + return this.currentHabbos.get(habboId); } public Habbo getRoomHabboByUsername(String username) { - return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getHabboInfo().getUsername().equalsIgnoreCase(username)).findFirst().orElse(null); + return this.currentHabbos.values().stream().filter(habbo -> habbo.getHabboInfo().getUsername().equalsIgnoreCase(username)).findFirst().orElse(null); } public Habbo getHabboByVirtualId(int virtualId) { - return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getVirtualId() == virtualId).findFirst().orElse(null); + return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getVirtualId() == virtualId).findFirst().orElse(null); } public Habbo getHabboByRoomUnit(RoomUnit roomUnit) { - return this.currentRoomHabbos.values().stream().filter(habbo -> habbo.getRoomUnit() == roomUnit).findFirst().orElse(null); + return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit() == roomUnit).findFirst().orElse(null); } public Bot getRoomBotById(int botId) { - return this.currentRoomBots.get(botId); + return this.currentBots.get(botId); } public List getBotsByName(String name) { - synchronized (this.currentRoomBots) { - return currentRoomBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList(); + synchronized (this.currentBots) { + return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList(); } } public Bot getBotByRoomUnit(RoomUnit roomUnit) { - return this.currentRoomBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null); + return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null); } public boolean hasBotsAt(RoomTile tile) { - return this.currentRoomBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)); + return this.currentBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)); } public Collection getBotsAt(RoomTile tile) { - return this.currentRoomBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); } public void placePet(Pet pet, Room room, short x, short y, double z) { - synchronized (this.currentRoomPets) { + synchronized (this.currentPets) { RoomTile tile = room.getLayout().getTile(x, y); if (tile == null) { @@ -255,26 +251,26 @@ public class RoomUnitManager { } public boolean hasPetsAt(RoomTile tile) { - return this.currentRoomPets.values().stream().anyMatch(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)); + return this.currentPets.values().stream().anyMatch(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)); } public Collection getPetsAt(RoomTile tile) { - return this.currentRoomPets.values().stream().filter(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + return this.currentPets.values().stream().filter(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); } public Pet getRoomPetById(int petId) { - return this.currentRoomPets.get(petId); + return this.currentPets.get(petId); } public Pet getPetByRoomUnit(RoomUnit roomUnit) { - return this.currentRoomPets.values().stream().filter(pet -> pet.getRoomUnit() == roomUnit).findFirst().orElse(null); + return this.currentPets.values().stream().filter(pet -> pet.getRoomUnit() == roomUnit).findFirst().orElse(null); } public void pickUpMyPets(Habbo owner) { THashSet pets = new THashSet<>(); - synchronized (this.currentRoomPets) { - for (Pet pet : this.currentRoomPets.values()) { + synchronized (this.currentPets) { + for (Pet pet : this.currentPets.values()) { if (pet.getUserId() == owner.getHabboInfo().getId()) { pets.add(pet); } @@ -286,12 +282,12 @@ public class RoomUnitManager { Emulator.getThreading().run(pet); owner.getInventory().getPetsComponent().addPet(pet); owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); - this.currentRoomPets.remove(pet.getId()); + this.currentPets.remove(pet.getId()); } } public void removeHabbo(Habbo habbo, boolean sendRemovePacket) { - if(!this.currentRoomHabbos.containsKey(habbo.getHabboInfo().getId())) { + if(!this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) { return; } @@ -306,7 +302,7 @@ public class RoomUnitManager { } synchronized (this.roomUnitLock) { - this.currentRoomHabbos.remove(habbo.getHabboInfo().getId()); + this.currentHabbos.remove(habbo.getHabboInfo().getId()); this.currentRoomUnits.remove(roomHabbo.getVirtualId()); } @@ -342,13 +338,13 @@ public class RoomUnitManager { } public boolean removeBot(Bot bot) { - synchronized (this.currentRoomBots) { - if (this.currentRoomBots.containsKey(bot.getId())) { + synchronized (this.currentBots) { + if (this.currentBots.containsKey(bot.getId())) { if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentPosition() != null) { bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit()); } - this.currentRoomBots.remove(bot.getId()); + this.currentBots.remove(bot.getId()); this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId()); bot.getRoomUnit().setInRoom(false); @@ -363,16 +359,16 @@ public class RoomUnitManager { } public Pet removePet(int petId) { - Pet pet = this.currentRoomPets.get(petId); + Pet pet = this.currentPets.get(petId); this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); - return this.currentRoomPets.remove(petId); + return this.currentPets.remove(petId); } public void removeAllPetsExceptRoomOwner() { ArrayList toRemovePets = new ArrayList<>(); ArrayList removedPets = new ArrayList<>(); - synchronized (this.currentRoomPets) { - for (Pet pet : this.currentRoomPets.values()) { + synchronized (this.currentPets) { + for (Pet pet : this.currentPets.values()) { try { if (pet.getUserId() != pet.getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId()) { toRemovePets.add(pet); @@ -401,7 +397,7 @@ public class RoomUnitManager { } for (Pet pet : removedPets) { - this.currentRoomPets.remove(pet.getId()); + this.currentPets.remove(pet.getId()); this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); } } @@ -409,23 +405,23 @@ public class RoomUnitManager { public void clear() { synchronized (this.roomUnitLock) { this.currentRoomUnits.clear(); - this.currentRoomHabbos.clear(); - this.currentRoomBots.clear(); - this.currentRoomPets.clear(); + this.currentHabbos.clear(); + this.currentBots.clear(); + this.currentPets.clear(); this.roomUnitCounter = 0; } } public void dispose() { - for(Habbo habbo : this.currentRoomHabbos.values()) { + for(Habbo habbo : this.currentHabbos.values()) { Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room); } this.room.sendComposer(new CloseConnectionMessageComposer().compose()); - this.currentRoomHabbos.clear(); + this.currentHabbos.clear(); - Iterator botIterator = this.currentRoomBots.values().iterator(); + Iterator botIterator = this.currentBots.values().iterator(); while(botIterator.hasNext()) { try { @@ -438,8 +434,8 @@ public class RoomUnitManager { } } - this.currentRoomBots.clear(); - this.currentRoomPets.clear(); + this.currentBots.clear(); + this.currentPets.clear(); this.currentRoomUnits.clear(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java index ef25ca41..9b076d29 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java @@ -2,12 +2,10 @@ package com.eu.habbo.habbohotel.rooms.entities.units; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWater; import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomRightLevels; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.entities.RoomEntity; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; @@ -188,6 +186,7 @@ public abstract class RoomUnit extends RoomEntity { } } + this.statusUpdateNeeded = true; return this; } @@ -449,6 +448,60 @@ public abstract class RoomUnit extends RoomEntity { ); } + public boolean handleSitStatus(RoomItem topItem) { + if(topItem == null || !topItem.getBaseItem().allowSit()) { + return false; + } + + if(!this.isCmdSitEnabled()) { + if(this.getCurrentPosition().getState().equals(RoomTileState.SIT) && !this.hasStatus(RoomUnitStatus.SIT)) { + this.setStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(topItem))); + this.setCurrentZ(topItem.getZ()); + this.setRotation(RoomRotation.values()[topItem.getRotation()]); + return true; + } else if(!topItem.getBaseItem().allowSit() && this.hasStatus(RoomUnitStatus.SIT)) { + this.removeStatus(RoomUnitStatus.SIT); + this.instantUpdate(); + return true; + } + } + + return false; + } + + public boolean handleLayStatus(RoomItem topItem) { + if(topItem == null || !topItem.getBaseItem().allowLay()) { + return false; + } + + if(!this.isCmdLayEnabled()) { + if(this.getCurrentPosition().getState().equals(RoomTileState.LAY) && !this.hasStatus(RoomUnitStatus.LAY)) { + this.setStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(topItem))); + this.setRotation(RoomRotation.values()[topItem.getRotation() % 4]); + + if (topItem.getRotation() == 0 || topItem.getRotation() == 4) { + this.setLocation(this.getRoom().getLayout().getTile(this.getCurrentPosition().getX(), topItem.getY())); + } else { + this.setLocation(this.getRoom().getLayout().getTile(topItem.getX(), this.getCurrentPosition().getY())); + } + return true; + } else if (!topItem.getBaseItem().allowLay() && this.hasStatus(RoomUnitStatus.LAY)) { + this.removeStatus(RoomUnitStatus.LAY); + this.instantUpdate(); + return true; + } + } + + return false; + } + + public void instantUpdate() { + if(this.statusUpdateNeeded) { + this.statusUpdateNeeded = false; + this.getRoom().sendComposer(new UserUpdateComposer(this).compose()); + } + } + public void clear() { this.setRoom(null); this.canWalk = true; diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java index 4cbfe873..a985266e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.rooms.entities.units.types; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate; +import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; @@ -25,9 +26,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; -import java.util.Deque; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; @Slf4j @Getter @@ -35,6 +34,7 @@ import java.util.Map; @Accessors(chain = true) public class RoomAvatar extends RoomUnit { private RideablePet rideablePet; + private boolean rideLock; private DanceType danceType; private int handItem; private long handItemTimestamp; @@ -75,11 +75,12 @@ public class RoomAvatar extends RoomUnit { } } - Habbo habboT = room.getRoomUnitManager().getHabboByRoomUnit(this); + Habbo habbo = null; + boolean canFastWalk = false; - if (!this.isWalking() && !this.isKicked() && this.removeStatus(RoomUnitStatus.MOVE) == null && habboT != null) { - habboT.getHabboInfo().getRiding().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); - return true; + if(this instanceof RoomHabbo roomHabbo) { + habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomHabbo); + canFastWalk = habbo == null || habbo.getHabboInfo().getRiding() == null; } for (Map.Entry set : this.getStatuses().entrySet()) { @@ -92,10 +93,7 @@ public class RoomAvatar extends RoomUnit { return true; } - boolean canFastWalk = habboT == null || habboT.getHabboInfo().getRiding() == null; - RoomTile next = this.getPath().poll(); - boolean overrideTile = next != null && this.canOverrideTile(next); if (this.getPath().isEmpty()) { @@ -139,19 +137,16 @@ public class RoomAvatar extends RoomUnit { return true; } - Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(this); - this.removeStatus(RoomUnitStatus.DEAD); if (habbo != null) { - if(this instanceof RoomHabbo roomHabbo) { - if (roomHabbo.isIdle()) { - UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); - Emulator.getPluginManager().fireEvent(event); + RoomHabbo roomHabbo = (RoomHabbo) this; + if (roomHabbo.isIdle()) { + UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); + Emulator.getPluginManager().fireEvent(event); - if (!event.isCancelled() && !event.isIdle()) { - roomHabbo.unIdle(); - } + if (!event.isCancelled() && !event.isIdle()) { + roomHabbo.unIdle(); } } @@ -180,7 +175,6 @@ public class RoomAvatar extends RoomUnit { return false; } next = this.getPath().pop(); - } boolean canSitNextTile = room.canSitAt(next.getX(), next.getY()); @@ -222,7 +216,7 @@ public class RoomAvatar extends RoomUnit { this.decrementTilesMoved(); this.setGoalLocation(this.getCurrentPosition()); this.removeStatus(RoomUnitStatus.MOVE); - room.sendComposer(new UserUpdateComposer(this).compose()); + this.instantUpdate(); if(this instanceof RoomHabbo) { conditionalGate.onRejected(this, this.getRoom(), new Object[]{}); @@ -243,7 +237,6 @@ public class RoomAvatar extends RoomUnit { zHeight += room.getLayout().getHeightAtSquare(next.getX(), next.getY()); } - this.setPreviousLocation(this.getCurrentPosition()); this.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + zHeight); @@ -293,6 +286,41 @@ public class RoomAvatar extends RoomUnit { } } + public void dismountPet(boolean isRemoving) { + Habbo habbo = null; + + if(this instanceof RoomHabbo roomHabbo) { + habbo = this.getRoom().getRoomUnitManager().getHabboByRoomUnit(roomHabbo); + } + + if(habbo == null || habbo.getHabboInfo().getRiding() == null) { + return; + } + + RideablePet ridingPet = habbo.getHabboInfo().getRiding(); + + ridingPet.setRider(null); + ridingPet.setTask(PetTasks.FREE); + + habbo.getHabboInfo().setRiding(null); + + this.giveEffect(0, -1); + this.setCurrentZ(ridingPet.getRoomUnit().getCurrentZ()); + this.setPreviousLocationZ(ridingPet.getRoomUnit().getCurrentZ()); + this.stopWalking(); + + ridingPet.getRoomUnit().stopWalking(); + + this.instantUpdate(); + ridingPet.getRoomUnit().instantUpdate(); + + List availableTiles = isRemoving ? new ArrayList<>() : this.getRoom().getLayout().getWalkableTilesAround(this.getCurrentPosition()); + + RoomTile tile = availableTiles.isEmpty() ? this.getCurrentPosition() : availableTiles.get(0); + this.setGoalLocation(tile); + this.setStatusUpdateNeeded(true); + } + public void setDance(DanceType danceType) { if (this.danceType != danceType) { boolean isDancing = !this.danceType.equals(DanceType.NONE); @@ -336,57 +364,13 @@ public class RoomAvatar extends RoomUnit { } if ((this.getRoom().isAllowEffects() || forceEffect) && !this.isSwimming()) { - this.setEffectId(effectId); - this.setEffectEndTimestamp(duration); + this.effectId = effectId; + this.effectEndTimestamp = duration; + this.getRoom().sendComposer(new AvatarEffectMessageComposer(this).compose()); } } - private boolean handleSitStatus(RoomItem topItem) { - if(topItem == null || !topItem.getBaseItem().allowSit()) { - return false; - } - - if(!this.isCmdSitEnabled()) { - if(this.getCurrentPosition().getState().equals(RoomTileState.SIT) && !this.hasStatus(RoomUnitStatus.SIT)) { - this.setStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(topItem))); - this.setCurrentZ(topItem.getZ()); - this.setRotation(RoomRotation.values()[topItem.getRotation()]); - return true; - } else if(!topItem.getBaseItem().allowSit() && this.hasStatus(RoomUnitStatus.SIT)) { - this.removeStatus(RoomUnitStatus.SIT); - return true; - } - } - - return false; - } - - private boolean handleLayStatus(RoomItem topItem) { - if(topItem == null || !topItem.getBaseItem().allowLay()) { - return false; - } - - if(!this.isCmdLayEnabled()) { - if(this.getCurrentPosition().getState().equals(RoomTileState.LAY) && !this.hasStatus(RoomUnitStatus.LAY)) { - this.setStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(topItem))); - this.setRotation(RoomRotation.values()[topItem.getRotation() % 4]); - - if (topItem.getRotation() == 0 || topItem.getRotation() == 4) { - this.setLocation(this.getRoom().getLayout().getTile(this.getCurrentPosition().getX(), topItem.getY())); - } else { - this.setLocation(this.getRoom().getLayout().getTile(topItem.getX(), this.getCurrentPosition().getY())); - } - return true; - } else if (!topItem.getBaseItem().allowLay() && this.hasStatus(RoomUnitStatus.LAY)) { - this.removeStatus(RoomUnitStatus.LAY); - return true; - } - } - - return false; - } - @Override public void clear() { super.clear(); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomPet.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomPet.java index 53efc1a1..4a704659 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomPet.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomPet.java @@ -10,7 +10,6 @@ import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import com.eu.habbo.util.pathfinding.Rotation; import lombok.extern.slf4j.Slf4j; @@ -29,12 +28,23 @@ public class RoomPet extends RoomUnit { try { Pet pet = this.getRoom().getRoomUnitManager().getPetByRoomUnit(this); - if (this.handleRider(pet, room)) { - return this.isStatusUpdateNeeded(); + if(pet == null) { + return false; } - if (this.removeStatus(RoomUnitStatus.SIT) != null || this.removeStatus(RoomUnitStatus.MOVE) != null || this.removeStatus(RoomUnitStatus.LAY) != null) { - this.setStatusUpdateNeeded(true); + if (this.handleRider(pet, room)) { + return true; + } + + if(!this.isWalking() || this.getPath() == null || this.getPath().isEmpty()) { + if (this.hasStatus(RoomUnitStatus.MOVE) && !this.isAnimateWalk()) { + this.removeStatus(RoomUnitStatus.MOVE); + } + + if(!this.isWalking()) { + RoomItem topItem = this.getRoom().getRoomItemManager().getTopItemAt(this.getCurrentPosition()); + return this.handleSitStatus(topItem) || this.handleLayStatus(topItem); + } } for (Map.Entry set : this.getStatuses().entrySet()) { @@ -44,7 +54,6 @@ public class RoomPet extends RoomUnit { } if (this.getPath() == null || this.getPath().isEmpty()) { - this.setStatusUpdateNeeded(true); return true; } @@ -55,14 +64,15 @@ public class RoomPet extends RoomUnit { this.setSitUpdate(true); if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) { - this.setStatusUpdateNeeded(false); return false; } } Deque peekPath = room.getLayout().findPath(this.getCurrentPosition(), this.getPath().peek(), this.getGoalLocation(), this); - if (peekPath == null) peekPath = new LinkedList<>(); + if (peekPath == null) { + peekPath = new LinkedList<>(); + } if (peekPath.size() >= 3) { if (this.getPath().isEmpty()) { @@ -93,13 +103,11 @@ public class RoomPet extends RoomUnit { double height = next.getStackHeight() - this.getCurrentPosition().getStackHeight(); if (!room.getLayout().tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.getState() == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) { - this.setRoom(room); this.getPath().clear(); this.findPath(); if (this.getPath().isEmpty()) { this.removeStatus(RoomUnitStatus.MOVE); - this.setStatusUpdateNeeded(false); return false; } next = this.getPath().pop(); @@ -117,7 +125,6 @@ public class RoomPet extends RoomUnit { if (next.equals(this.getGoalLocation()) && next.getState() == RoomTileState.SIT && !overrideChecks && (item == null || item.getZ() - this.getCurrentZ() > RoomLayout.MAXIMUM_STEP_HEIGHT)) { this.removeStatus(RoomUnitStatus.MOVE); - this.setStatusUpdateNeeded(false); return false; } @@ -141,9 +148,8 @@ public class RoomPet extends RoomUnit { this.decrementTilesMoved(); this.setGoalLocation(this.getCurrentPosition()); this.removeStatus(RoomUnitStatus.MOVE); - room.sendComposer(new UserUpdateComposer(this).compose()); + this.instantUpdate(); - this.setStatusUpdateNeeded(false); return false; } } else { @@ -167,7 +173,6 @@ public class RoomPet extends RoomUnit { this.setCurrentZ(zHeight); this.setCurrentPosition(room.getLayout().getTile(next.getX(), next.getY())); - this.setStatusUpdateNeeded(false); return false; } catch (Exception e) { log.error("Caught exception", e); @@ -187,7 +192,7 @@ public class RoomPet extends RoomUnit { } // copy things from rider - if (this.hasStatus(RoomUnitStatus.MOVE) && !rider.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) { + if (this.hasStatus(RoomUnitStatus.MOVE) && !rider.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || !rider.getRoomUnit().isWalking()) { this.removeStatus(RoomUnitStatus.MOVE); } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java index 3f64b505..fb3a8f01 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboInfo.java @@ -8,12 +8,7 @@ import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.messenger.MessengerCategory; import com.eu.habbo.habbohotel.navigation.NavigatorSavedSearch; import com.eu.habbo.habbohotel.permissions.PermissionGroup; -import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.pets.RideablePet; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; -import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import gnu.trove.map.hash.TIntIntHashMap; import lombok.Getter; import lombok.Setter; @@ -271,44 +266,6 @@ public class HabboInfo implements Runnable { this.run(); } - public void dismountPet(Room room) { - this.dismountPet(false, room); - } - - public void dismountPet(boolean isRemoving, Room room) { - if (this.getRiding() == null) - return; - - Habbo habbo = room.getRoomUnitManager().getRoomHabboById(this.getId()); - - if (habbo == null) - return; - - RideablePet riding = this.getRiding(); - - riding.setRider(null); - riding.setTask(PetTasks.FREE); - this.setRiding(null); - - habbo.getRoomUnit().giveEffect(0, -1); - - RoomUnit roomUnit = habbo.getRoomUnit(); - if (roomUnit == null) - return; - - roomUnit.setCurrentZ(riding.getRoomUnit().getCurrentZ()); - roomUnit.setPreviousLocationZ(riding.getRoomUnit().getCurrentZ()); - roomUnit.stopWalking(); - - room.sendComposer(new UserUpdateComposer(roomUnit).compose()); - - List availableTiles = isRemoving ? new ArrayList<>() : room.getLayout().getWalkableTilesAround(roomUnit.getCurrentPosition()); - - RoomTile tile = availableTiles.isEmpty() ? roomUnit.getCurrentPosition() : availableTiles.get(0); - roomUnit.setGoalLocation(tile); - roomUnit.setStatusUpdateNeeded(true); - } - public boolean isInGame() { return this.currentGame != null; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/UpdateFloorPropertiesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/UpdateFloorPropertiesEvent.java index df4c02b2..08df20b8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/UpdateFloorPropertiesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/UpdateFloorPropertiesEvent.java @@ -173,7 +173,7 @@ public class UpdateFloorPropertiesEvent extends MessageHandler { room.getRoomInfo().setWallHeight(wallHeight); room.save(); Collection habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbosCount()); - habbos.addAll(room.getRoomUnitManager().getRoomHabbos()); + habbos.addAll(room.getRoomUnitManager().getCurrentHabbos().values()); Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId()); ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/CreateGuildEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/CreateGuildEvent.java index 998afd70..10209066 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/CreateGuildEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/CreateGuildEvent.java @@ -72,7 +72,7 @@ public class CreateGuildEvent extends GuildBadgeEvent { this.client.sendResponse(new PurchaseOKMessageComposer()); this.client.sendResponse(new GuildCreatedMessageComposer(guild)); - for (Habbo habbo : r.getRoomUnitManager().getRoomHabbos()) { + for (Habbo habbo : r.getRoomUnitManager().getCurrentHabbos().values()) { habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, null)); } r.refreshGuild(guild); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildIdentityEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildIdentityEvent.java index 324b9c44..a7d5f72f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildIdentityEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildIdentityEvent.java @@ -36,7 +36,7 @@ public class UpdateGuildIdentityEvent extends MessageHandler { Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); if (room != null) { - if (!room.getRoomUnitManager().getCurrentRoomHabbos().isEmpty()) { + if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) { room.refreshGuild(guild); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/DeleteRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/DeleteRoomEvent.java index e65c8dff..b4a4d7c0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/DeleteRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/DeleteRoomEvent.java @@ -42,16 +42,16 @@ public class DeleteRoomEvent extends MessageHandler { room.getRoomItemManager().ejectAllFurni(); room.getRoomItemManager().ejectUserFurni(room.getRoomInfo().getOwnerInfo().getId()); - List bots = new ArrayList<>(room.getRoomUnitManager().getCurrentRoomBots().values()); + List bots = new ArrayList<>(room.getRoomUnitManager().getCurrentBots().values()); for (Bot bot : bots) { Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null, room); } - List pets = new ArrayList<>(room.getRoomUnitManager().getCurrentRoomPets().values()); + List pets = new ArrayList<>(room.getRoomUnitManager().getCurrentPets().values()); for (Pet pet : pets) { if (pet instanceof RideablePet rideablePet) { if (rideablePet.getRider() != null) { - rideablePet.getRider().getHabboInfo().dismountPet(true, room); + rideablePet.getRider().getRoomUnit().dismountPet(true); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java index 6459545e..298db957 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseFurnitureEvent.java @@ -50,7 +50,7 @@ public class UseFurnitureEvent extends MessageHandler { if (PET_PRESENTS.contains(item.getBaseItem().getName().toLowerCase())) { - if (room.getRoomUnitManager().getCurrentRoomPets().size() < Room.MAXIMUM_PETS) { + if (room.getRoomUnitManager().getCurrentPets().size() < Room.MAXIMUM_PETS) { this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item)); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MountPetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MountPetEvent.java index fce34f12..291983e0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MountPetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MountPetEvent.java @@ -30,31 +30,35 @@ public class MountPetEvent extends MessageHandler { //dismount if (habbo.getHabboInfo().getRiding() != null) { - boolean mountAgain = petId != habbo.getHabboInfo().getRiding().getId(); + boolean mountAnotherPet = petId != habbo.getHabboInfo().getRiding().getId(); - habbo.getHabboInfo().dismountPet(room); + habbo.getRoomUnit().dismountPet(false); - if(!mountAgain) { + if(!mountAnotherPet) { return; } } // someone is already on it - if (rideablePet.getRider() != null) + if (rideablePet.getRider() != null) { return; + } // check if able to ride - if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) + if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) { return; + } List availableTiles = room.getLayout().getWalkableTilesAround(pet.getRoomUnit().getCurrentPosition()); // if cant reach it then cancel - if (availableTiles.isEmpty()) + if (availableTiles.isEmpty()) { return; + } RoomTile goalTile = availableTiles.get(0); habbo.getRoomUnit().setGoalLocation(goalTile); + habbo.getRoomUnit().setRideLock(true); Emulator.getThreading().run(new RoomUnitRidePet(rideablePet, habbo, goalTile)); rideablePet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp()); rideablePet.getRoomUnit().stopWalking(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PlacePetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PlacePetEvent.java index 8cb46f19..6dab7341 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PlacePetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/PlacePetEvent.java @@ -36,7 +36,7 @@ public class PlacePetEvent extends MessageHandler { if (pet == null) { return; } - if (room.getRoomUnitManager().getCurrentRoomPets().size() >= Room.MAXIMUM_PETS && !this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_PETS)) { + if (room.getRoomUnitManager().getCurrentPets().size() >= Room.MAXIMUM_PETS && !this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_PETS)) { this.client.sendResponse(new PetPlacingErrorComposer(PetPlacingErrorComposer.ROOM_ERROR_MAX_PETS)); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemovePetFromFlatEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemovePetFromFlatEvent.java index 3975ab77..c0452168 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemovePetFromFlatEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemovePetFromFlatEvent.java @@ -31,7 +31,7 @@ public class RemovePetFromFlatEvent extends MessageHandler { if (pet instanceof RideablePet rideablePet) { if (rideablePet.getRider() != null) { - rideablePet.getRider().getHabboInfo().dismountPet(true, room); + rideablePet.getRider().getRoomUnit().dismountPet(true); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetRidingPermissionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetRidingPermissionEvent.java index 4eabeea3..368b837a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetRidingPermissionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetRidingPermissionEvent.java @@ -23,7 +23,7 @@ public class TogglePetRidingPermissionEvent extends MessageHandler { rideablePet.setNeedsUpdate(true); if (!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) { - rideablePet.getRider().getHabboInfo().dismountPet(this.client.getHabbo().getRoomUnit().getRoom()); + rideablePet.getRider().getRoomUnit().dismountPet(false); } if (pet instanceof HorsePet) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/MoveAvatarEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/MoveAvatarEvent.java index 5ac62007..5c82f48b 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/MoveAvatarEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/MoveAvatarEvent.java @@ -53,6 +53,11 @@ public class MoveAvatarEvent extends MessageHandler { return; } + //Is going to ride a pet, can't cancel + if(roomHabbo.isRideLock()) { + return; + } + // Get the room the habbo is in Room room = habbo.getRoomUnit().getRoom(); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorRoomInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorRoomInfoComposer.java index 44d93cdd..774320c9 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorRoomInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorRoomInfoComposer.java @@ -14,7 +14,7 @@ public class ModeratorRoomInfoComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.moderatorRoomInfoComposer); this.response.appendInt(this.room.getRoomInfo().getId()); - this.response.appendInt(this.room.getRoomUnitManager().getCurrentRoomHabbos().size()); + this.response.appendInt(this.room.getRoomUnitManager().getCurrentHabbos().values().size()); this.response.appendBoolean(this.room.getRoomUnitManager().getRoomHabboById(this.room.getRoomInfo().getOwnerInfo().getId()) != null); this.response.appendInt(this.room.getRoomInfo().getOwnerInfo().getId()); this.response.appendString(this.room.getRoomInfo().getOwnerInfo().getUsername()); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java index 78dfebf2..79743b4b 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java @@ -30,7 +30,7 @@ public class RoomUnitRidePet implements Runnable { habbo.getRoomUnit().setCurrentZ(this.pet.getRoomUnit().getCurrentZ() + 1); habbo.getRoomUnit().setPreviousLocationZ(this.pet.getRoomUnit().getCurrentZ() + 1); habbo.getRoomUnit().setRotation(this.pet.getRoomUnit().getBodyRotation()); - habbo.getRoomUnit().setStatusUpdateNeeded(true); + habbo.getRoomUnit().setRideLock(false); pet.setRider(habbo); habbo.getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose()); habbo.getRoomUnit().getRoom().sendComposer(new AvatarEffectMessageComposer(habbo.getRoomUnit()).compose()); diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java index dde2cf2a..67e59b84 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionThree.java @@ -64,7 +64,6 @@ class TeleportActionThree implements Runnable { } this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[targetTeleport.getRotation() % 8]); - this.client.getHabbo().getRoomUnit().setStatusUpdateNeeded(true); targetTeleport.setExtradata("2"); targetRoom.updateItem(targetTeleport);