diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java index e446892b..a99f0d6d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.constants.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.rooms.constants.RoomUserAction; -import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; +import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot; import com.eu.habbo.habbohotel.units.type.Avatar; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; 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 f14b26f6..27033576 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java @@ -107,7 +107,7 @@ public class BotManager { } bot.onPickUp(habbo, room); - room.getRoomUnitManager().removeBot(bot); + room.getRoomUnitManager().getRoomBotManager().removeBot(bot); bot.setFollowingHabboId(0); bot.setOwnerId(botOwnerInfo.getId()); bot.setOwnerName(botOwnerInfo.getUsername()); 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 60baa9f8..3e3b75f2 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 (owner_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().getCurrentBots()) { + synchronized (this.room.getRoomUnitManager().getRoomBotManager().getCurrentBots()) { statement.setInt(1, userId); statement.setInt(2, roomId); - for (Bot bot : this.room.getRoomUnitManager().getCurrentBots().values()) { + for (Bot bot : this.room.getRoomUnitManager().getRoomBotManager().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/list/BotsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/BotsCommand.java index 494aab57..a747ec9e 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().getCurrentBots().values().size()); + StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomBotManager().getCurrentBots().values().size()); - for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values()) { + for (Bot bot : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomBotManager().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/items/interactions/InteractionEffectTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java index a89643ef..64105177 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectTile.java @@ -60,7 +60,7 @@ public class InteractionEffectTile extends InteractionPressurePlate { this.giveEffect(room, roomUnit, habbo.getHabboInfo().getGender()); } } else if (roomUnit.getRoomUnitType() == RoomUnitType.BOT) { - Bot bot = room.getRoomUnitManager().getRoomBotById(roomUnit.getVirtualId()); + Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(roomUnit.getVirtualId()); if (bot != null) { this.giveEffect(room, roomUnit, bot.getGender()); 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 498f74ff..89fbe17d 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 @@ -32,7 +32,7 @@ public class WiredConditionFurniHaveRoom extends InteractionWiredCondition { } Collection habbos = room.getRoomUnitManager().getCurrentHabbos().values(); - Collection bots = room.getRoomUnitManager().getCurrentBots().values(); + Collection bots = room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values(); Collection pets = room.getRoomUnitManager().getCurrentPets().values(); return this.getWiredSettings().getItems(room).stream().allMatch(item -> { 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 bd60b14a..be7baf1e 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 @@ -32,7 +32,7 @@ public class WiredConditionNotFurniHaveRoom extends InteractionWiredCondition { } Collection habbos = room.getRoomUnitManager().getCurrentHabbos().values(); - Collection bots = room.getRoomUnitManager().getCurrentBots().values(); + Collection bots = room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values(); Collection pets = room.getRoomUnitManager().getCurrentPets().values(); return this.getWiredSettings().getItems(room).stream().noneMatch(item -> { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java index cef31e8d..086dfc6c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java @@ -29,7 +29,7 @@ public class WiredEffectBotClothes extends InteractionWiredEffect { String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); String botLook = stringParams[1]; - List bots = room.getRoomUnitManager().getBotsByName(botName); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName); if(bots.size() == 0) { return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowRoom.java index f7f29026..31004acc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowRoom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowRoom.java @@ -29,7 +29,7 @@ public class WiredEffectBotFollowRoom extends InteractionWiredEffect { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); - List bots = room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam()); if (habbo != null && bots.size() == 1) { Bot bot = bots.get(0); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index 9fd302a5..67efc8de 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -38,7 +38,7 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { } Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar); - List bots = room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam()); int itemId = this.getWiredSettings().getIntegerParams().get(PARAM_ITEM_ID); if (habbo != null && bots.size() == 1) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java index 8377b39c..7a256a00 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalk.java @@ -48,7 +48,7 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getRoomUnitManager().getRoomHabbosCount() + ""); } - List bots = room.getRoomUnitManager().getBotsByName(botName); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName); if (bots.size() == 1) { Bot bot = bots.get(0); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToRoom.java index a74dd952..17e64a70 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToRoom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToRoom.java @@ -47,7 +47,7 @@ public class WiredEffectBotTalkToRoom extends InteractionWiredEffect { .replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getRoomInfo().getName()) .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getRoomUnitManager().getRoomHabbosCount() + ""); - List bots = room.getRoomUnitManager().getBotsByName(botName); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName); if (bots.size() != 1) { return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java index 609d9600..22c4ef17 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java @@ -9,7 +9,7 @@ import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; -import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; +import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot; import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; @@ -38,7 +38,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { } String botName = this.getWiredSettings().getStringParam(); - List bots = room.getRoomUnitManager().getBotsByName(botName); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName); if (bots.size() == 0) { return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java index 28347e23..316ee22f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java @@ -31,7 +31,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { } String botName = this.getWiredSettings().getStringParam(); - List bots = room.getRoomUnitManager().getBotsByName(botName); + List bots = room.getRoomUnitManager().getRoomBotManager().getBotsByName(botName); if (bots.size() == 0) { return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java index 34617c12..a2d8b7b4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedFurni.java @@ -29,7 +29,7 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { } if (stuff[0] instanceof RoomItem) { - return this.getWiredSettings().getItems(room).contains(stuff[0]) && room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); + return this.getWiredSettings().getItems(room).contains(stuff[0]) && room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); } return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedRoom.java index 93758c00..99f120e0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedRoom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedRoom.java @@ -21,7 +21,7 @@ public class WiredTriggerBotReachedRoom extends InteractionWiredTrigger { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - return room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); + return room.getRoomUnitManager().getRoomBotManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); } @Override 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 3d0ce1dd..4616cd61 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -516,8 +516,8 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (!this.roomUnitManager.getCurrentBots().isEmpty()) { - Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); + if (!this.roomUnitManager.getRoomBotManager().getCurrentBots().isEmpty()) { + Iterator botIterator = this.roomUnitManager.getRoomBotManager().getCurrentBots().values().iterator(); while(botIterator.hasNext()) { try { @@ -1196,7 +1196,7 @@ public class Room implements Comparable, ISerialize, Runnable { for (short x = item.getCurrentPosition().getX(); x < item.getCurrentPosition().getX() + item.getBaseItem().getLength(); x++) { for (short y = item.getCurrentPosition().getY(); y < item.getCurrentPosition().getY() + item.getBaseItem().getWidth(); y++) { RoomTile tile = this.layout.getTile(x, y); - bots.addAll(this.roomUnitManager.getBotsAt(tile)); + bots.addAll(this.roomUnitManager.getRoomBotManager().getBotsAt(tile)); } } @@ -1260,11 +1260,11 @@ public class Room implements Comparable, ISerialize, Runnable { } public void habboEntered(Habbo habbo) { - synchronized (this.roomUnitManager.getCurrentBots()) { + synchronized (this.roomUnitManager.getRoomBotManager().getCurrentBots()) { if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) return; - Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); + Iterator botIterator = this.roomUnitManager.getRoomBotManager().getCurrentBots().values().iterator(); while (botIterator.hasNext()) { try { @@ -1494,8 +1494,8 @@ public class Room implements Comparable, ISerialize, Runnable { } if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) { - synchronized (this.roomUnitManager.getCurrentBots()) { - Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); + synchronized (this.roomUnitManager.getRoomBotManager().getCurrentBots()) { + Iterator botIterator = this.roomUnitManager.getRoomBotManager().getCurrentBots().values().iterator(); while (botIterator.hasNext()) { try { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java index aa4d29a1..8b9eb13c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; -import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; +import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot; import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.Setter; 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 47cbcd2f..c86e220b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -711,14 +711,14 @@ public class RoomManager { } - habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values())); + habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values())); - if (!room.getRoomUnitManager().getCurrentBots().isEmpty()) { - room.getRoomUnitManager().getCurrentBots().values().stream() + if (!room.getRoomUnitManager().getRoomBotManager().getCurrentBots().isEmpty()) { + room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values().stream() .filter(b -> !b.getRoomUnit().getDanceType().equals(DanceType.NONE)) .forEach(b -> habbo.getClient().sendResponse(new DanceMessageComposer(b.getRoomUnit()))); - room.getRoomUnitManager().getCurrentBots().values() + room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values() .forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getCurrentZ()))); } 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 2c4ae256..ba776da7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java @@ -2,33 +2,22 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.bots.BotManager; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetManager; +import com.eu.habbo.habbohotel.rooms.bots.RoomBotManager; import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; import com.eu.habbo.habbohotel.rooms.constants.RoomUnitStatus; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; -import com.eu.habbo.habbohotel.rooms.items.entities.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.RoomBot; import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; +import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem; import com.eu.habbo.habbohotel.units.Unit; -import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer; -import com.eu.habbo.messages.outgoing.inventory.BotAddedToInventoryComposer; -import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer; import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; -import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer; -import com.eu.habbo.plugin.Event; -import com.eu.habbo.plugin.events.bots.BotPickUpEvent; -import com.eu.habbo.plugin.events.bots.BotPlacedEvent; import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -50,68 +39,27 @@ public class RoomUnitManager { private final Room room; private final ConcurrentHashMap currentRoomUnits; private final ConcurrentHashMap currentHabbos; - private final ConcurrentHashMap currentBots; private final ConcurrentHashMap currentPets; private volatile int roomUnitCounter; public final Object roomUnitLock; + private final RoomBotManager roomBotManager; public RoomUnitManager(Room room) { this.room = room; this.currentRoomUnits = new ConcurrentHashMap<>(); this.currentHabbos = new ConcurrentHashMap<>(); - this.currentBots = new ConcurrentHashMap<>(); this.currentPets = new ConcurrentHashMap<>(); this.roomUnitCounter = 0; this.roomUnitLock = new Object(); + roomBotManager = new RoomBotManager(this); } public synchronized void load(Connection connection) { - this.loadBots(connection); + roomBotManager.loadBots(connection); this.loadPets(connection); } - private synchronized void loadBots(Connection connection) { - this.currentBots.clear(); - try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.owner_id = users.id WHERE room_id = ?")) { - statement.setInt(1, this.room.getRoomInfo().getId()); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - Bot bot = Emulator.getGameEnvironment().getBotManager().loadBot(set); - - if (bot != null) { - bot.getRoomUnit().setRoom(this.room); - - RoomTile spawnTile = this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y")); - - if(spawnTile == null) { - bot.getRoomUnit().setCanWalk(false); - } else { - if(spawnTile.getState().equals(RoomTileState.INVALID)) { - bot.getRoomUnit().setCanWalk(false); - } - - bot.getRoomUnit().setCurrentPosition(spawnTile); - bot.getRoomUnit().setCurrentZ(set.getDouble("z")); - bot.getRoomUnit().setRotation(RoomRotation.values()[set.getInt("rot")]); - bot.getRoomUnit().setSpawnTile(spawnTile); - bot.getRoomUnit().setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight()); - } - - bot.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]); - - bot.getRoomUnit().giveEffect(set.getInt("effect"), Integer.MAX_VALUE, false); - - this.addRoomUnit(bot); - } - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } catch (Exception e) { - log.error("Caught Exception", e); - } - } private synchronized void loadPets(Connection connection) { this.currentPets.clear(); @@ -160,7 +108,7 @@ public class RoomUnitManager { unit.getRoomUnit().getRoom().updateDatabaseUserCount(); } case BOT -> { - this.currentBots.put(((Bot) unit).getId(), (Bot) unit); + roomBotManager.addBot((Bot)unit); } case PET -> { this.currentPets.put(((Pet) unit).getId(), (Pet) unit); @@ -190,7 +138,7 @@ public class RoomUnitManager { } public List getAvatarsAt(RoomTile tile) { - return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList()); + return Stream.concat(this.getHabbosAt(tile).stream(), roomBotManager.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList()); } public int getRoomHabbosCount() { @@ -256,148 +204,9 @@ public class RoomUnitManager { } } - public Bot getRoomBotById(int botId) { - return this.currentBots.get(botId); - } - public List getBotsByName(String name) { - synchronized (this.currentBots) { - return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList(); - } - } - public Bot getBotByRoomUnit(RoomUnit roomUnit) { - return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null); - } - public boolean hasBotsAt(RoomTile tile) { - return this.currentBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)); - } - - public Collection getBotsAt(RoomTile tile) { - return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); - } - - public void placeBot(Bot bot, Habbo botOwner, int x, int y) { - synchronized (this.currentBots) { - RoomTile spawnTile = room.getLayout().getTile((short) x, (short) y); - - if(spawnTile == null || (!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || this.areRoomUnitsAt(spawnTile)) { - botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE)); - return; - } - - if (Emulator.getPluginManager().isRegistered(BotPlacedEvent.class, false)) { - Event event = new BotPlacedEvent(bot, spawnTile, botOwner); - Emulator.getPluginManager().fireEvent(event); - - if (event.isCancelled()) { - return; - } - } - - if(this.currentBots.size() >= Room.MAXIMUM_BOTS && !botOwner.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) { - botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS)); - return; - } - - RoomBot roomBot = bot.getRoomUnit(); - - roomBot.setRoom(this.room); - roomBot.setCurrentPosition(spawnTile); - roomBot.setCurrentZ(spawnTile.getStackHeight()); - roomBot.setRotation(RoomRotation.SOUTH); - roomBot.setSpawnTile(spawnTile); - roomBot.setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight()); - - bot.setSqlUpdateNeeded(true); - Emulator.getThreading().run(bot); - - this.addRoomUnit(bot); - - this.room.sendComposer(new RoomUsersComposer(bot).compose()); - - roomBot.instantUpdate(); - - botOwner.getInventory().getBotsComponent().removeBot(bot); - botOwner.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot)); - bot.onPlace(botOwner, room); - } - } - - public void updateBotsAt(RoomTile tile) { - Collection bots = this.getBotsAt(tile); - - if(bots == null || bots.isEmpty()) { - return; - } - - RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY()); - - bots.forEach(bot -> { - double z = bot.getRoomUnit().getCurrentPosition().getStackHeight(); - - if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !bot.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) { - bot.getRoomUnit().removeStatus(RoomUnitStatus.SIT); - } - - if (bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !bot.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) { - bot.getRoomUnit().removeStatus(RoomUnitStatus.LAY); - } - - if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) { - if(item.getBaseItem().allowSit()) { - bot.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item))); - } else if(item.getBaseItem().allowLay()) { - bot.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item))); - } - - bot.getRoomUnit().setCurrentZ(item.getCurrentZ()); - bot.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation())); - } else { - bot.getRoomUnit().setCurrentZ(z); - } - }); - } - - public void pickUpBot(Bot bot, Habbo picker) { - HabboInfo botOwnerInfo = picker == null ? bot.getOwnerInfo() : picker.getHabboInfo(); - - BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, picker); - Emulator.getPluginManager().fireEvent(pickedUpEvent); - - if (pickedUpEvent.isCancelled()) - return; - - if (picker == null || (bot.getOwnerInfo().getId() == picker.getHabboInfo().getId() || picker.hasPermissionRight(Permission.ACC_ANYROOMOWNER))) { - if (picker != null && !picker.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && picker.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { - picker.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", String.valueOf(BotManager.MAXIMUM_BOT_INVENTORY_SIZE))); - return; - } - - bot.onPickUp(picker, this.room); - - bot.setFollowingHabboId(0); - - //@DEPRECATED - bot.setOwnerId(botOwnerInfo.getId()); - bot.setOwnerName(botOwnerInfo.getUsername()); - - bot.setOwnerInfo(botOwnerInfo); - - this.removeBot(bot); - - bot.setSqlUpdateNeeded(true); - Emulator.getThreading().run(bot); - - Habbo receiver = picker == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : picker; - - if (receiver != null) { - receiver.getInventory().getBotsComponent().addBot(bot); - receiver.getClient().sendResponse(new BotAddedToInventoryComposer(bot)); - } - } - } public void placePet(Pet pet, Room room, short x, short y, double z) { synchronized (this.currentPets) { @@ -476,7 +285,7 @@ public class RoomUnitManager { synchronized (this.roomUnitLock) { this.currentHabbos.remove(habbo.getHabboInfo().getId()); - this.currentRoomUnits.remove(roomHabbo.getVirtualId()); + removeUnit(roomHabbo.getVirtualId()); } roomHabbo.getRoom().sendComposer(new UserRemoveMessageComposer(roomHabbo).compose()); @@ -510,25 +319,10 @@ public class RoomUnitManager { roomHabbo.clear(); } - public void removeBot(Bot bot) { - if (this.currentBots.containsKey(bot.getId())) { - //TODO gotta do a method to removeUnit and clear tile - if (bot.getRoomUnit().getCurrentPosition() != null) { - bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit()); - } - - this.currentBots.remove(bot.getId()); - this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId()); - - bot.getRoomUnit().setRoom(null); - - this.room.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose()); - } - } public Pet removePet(int petId) { Pet pet = this.currentPets.get(petId); - this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); + removeUnit(pet.getRoomUnit().getVirtualId()); return this.currentPets.remove(petId); } @@ -566,7 +360,7 @@ public class RoomUnitManager { for (Pet pet : removedPets) { this.currentPets.remove(pet.getId()); - this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); + removeUnit(pet.getRoomUnit().getVirtualId()); } } @@ -574,7 +368,7 @@ public class RoomUnitManager { synchronized (this.roomUnitLock) { this.currentRoomUnits.clear(); this.currentHabbos.clear(); - this.currentBots.clear(); + this.roomBotManager.clear(); this.currentPets.clear(); this.roomUnitCounter = 0; } @@ -587,21 +381,7 @@ public class RoomUnitManager { this.currentHabbos.clear(); - Iterator botIterator = this.currentBots.values().iterator(); - - while(botIterator.hasNext()) { - try { - Bot bot = botIterator.next(); - bot.setSqlUpdateNeeded(true); - Emulator.getThreading().run(bot); - } catch (NoSuchElementException e) { - log.error("Caught Exception", e); - break; - } - } - - this.currentBots.clear(); - + roomBotManager.dispose(); Iterator petIterator = this.currentPets.values().iterator(); while(petIterator.hasNext()) { @@ -618,4 +398,8 @@ public class RoomUnitManager { this.currentPets.clear(); this.currentRoomUnits.clear(); } + + public void removeUnit(int virtualId) { + this.currentRoomUnits.remove(virtualId); + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/bots/RoomBotManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/bots/RoomBotManager.java new file mode 100644 index 00000000..24c99516 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/bots/RoomBotManager.java @@ -0,0 +1,288 @@ +package com.eu.habbo.habbohotel.rooms.bots; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.bots.BotManager; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitManager; +import com.eu.habbo.habbohotel.rooms.bots.entities.RoomBot; +import com.eu.habbo.habbohotel.rooms.constants.RoomTileState; +import com.eu.habbo.habbohotel.rooms.constants.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomUnitSubManager; +import com.eu.habbo.habbohotel.rooms.items.entities.RoomItem; +import com.eu.habbo.habbohotel.users.DanceType; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer; +import com.eu.habbo.messages.outgoing.inventory.BotAddedToInventoryComposer; +import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; +import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer; +import com.eu.habbo.plugin.Event; +import com.eu.habbo.plugin.events.bots.BotPickUpEvent; +import com.eu.habbo.plugin.events.bots.BotPlacedEvent; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; + + +@Slf4j +public class RoomBotManager extends RoomUnitSubManager { + private final RoomUnitManager roomUnitManager; + + @Getter + private final ConcurrentHashMap currentBots; + + public RoomBotManager(RoomUnitManager roomUnitManager) { + super(roomUnitManager); + this.roomUnitManager = roomUnitManager; + currentBots = new ConcurrentHashMap<>(); + } + + public synchronized void loadBots(Connection connection) { + this.currentBots.clear(); + + try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.owner_id = users.id WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + Bot bot = Emulator.getGameEnvironment().getBotManager().loadBot(set); + + if (bot != null) { + bot.getRoomUnit().setRoom(this.room); + + RoomTile spawnTile = this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y")); + + if (spawnTile == null) { + bot.getRoomUnit().setCanWalk(false); + } else { + if (spawnTile.getState().equals(RoomTileState.INVALID)) { + bot.getRoomUnit().setCanWalk(false); + } + + bot.getRoomUnit().setCurrentPosition(spawnTile); + bot.getRoomUnit().setCurrentZ(set.getDouble("z")); + bot.getRoomUnit().setRotation(RoomRotation.values()[set.getInt("rot")]); + bot.getRoomUnit().setSpawnTile(spawnTile); + bot.getRoomUnit().setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight()); + } + + bot.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]); + + bot.getRoomUnit().giveEffect(set.getInt("effect"), Integer.MAX_VALUE, false); + + this.addBot(bot); + } + } + } + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error("Caught Exception", e); + } + } + + public Bot getRoomBotById(int botId) { + return this.currentBots.get(botId); + } + + public List getBotsByName(String name) { + synchronized (this.currentBots) { + return currentBots.values().stream().filter(bot -> bot.getName().equalsIgnoreCase(name)).toList(); + } + } + + public Bot getBotByRoomUnit(RoomUnit roomUnit) { + return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit() == roomUnit).findFirst().orElse(null); + } + + public boolean hasBotsAt(RoomTile tile) { + return this.currentBots.values().stream().anyMatch(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)); + } + + public Collection getBotsAt(RoomTile tile) { + return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + } + + public void placeBot(Bot bot, Habbo botOwner, int x, int y) { + synchronized (this.currentBots) { + RoomTile spawnTile = room.getLayout().getTile((short) x, (short) y); + + if (spawnTile == null || (!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || roomUnitManager.areRoomUnitsAt(spawnTile)) { + botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE)); + return; + } + + if (Emulator.getPluginManager().isRegistered(BotPlacedEvent.class, false)) { + Event event = new BotPlacedEvent(bot, spawnTile, botOwner); + Emulator.getPluginManager().fireEvent(event); + + if (event.isCancelled()) { + return; + } + } + + if (this.currentBots.size() >= Room.MAXIMUM_BOTS && !botOwner.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) { + botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS)); + return; + } + + RoomBot roomBot = bot.getRoomUnit(); + + roomBot.setRoom(this.room); + roomBot.setCurrentPosition(spawnTile); + roomBot.setCurrentZ(spawnTile.getStackHeight()); + roomBot.setRotation(RoomRotation.SOUTH); + roomBot.setSpawnTile(spawnTile); + roomBot.setSpawnHeight(spawnTile.getState().equals(RoomTileState.INVALID) ? 0 : spawnTile.getStackHeight()); + + bot.setSqlUpdateNeeded(true); + Emulator.getThreading().run(bot); + + this.addBot(bot); + + this.room.sendComposer(new RoomUsersComposer(bot).compose()); + + roomBot.instantUpdate(); + + botOwner.getInventory().getBotsComponent().removeBot(bot); + botOwner.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot)); + bot.onPlace(botOwner, room); + } + } + + public void updateBotsAt(RoomTile tile) { + Collection bots = this.getBotsAt(tile); + + if (bots == null || bots.isEmpty()) { + return; + } + + RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY()); + + bots.forEach(bot -> { + double z = bot.getRoomUnit().getCurrentPosition().getStackHeight(); + + if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !bot.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) { + bot.getRoomUnit().removeStatus(RoomUnitStatus.SIT); + } + + if (bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !bot.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) { + bot.getRoomUnit().removeStatus(RoomUnitStatus.LAY); + } + + if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) { + if (item.getBaseItem().allowSit()) { + bot.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item))); + } else if (item.getBaseItem().allowLay()) { + bot.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item))); + } + + bot.getRoomUnit().setCurrentZ(item.getCurrentZ()); + bot.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation())); + } else { + bot.getRoomUnit().setCurrentZ(z); + } + }); + } + + public void pickUpBot(Bot bot, Habbo picker) { + HabboInfo botOwnerInfo = picker == null ? bot.getOwnerInfo() : picker.getHabboInfo(); + + BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, picker); + Emulator.getPluginManager().fireEvent(pickedUpEvent); + + if (pickedUpEvent.isCancelled()) + return; + + if (picker == null || (bot.getOwnerInfo().getId() == picker.getHabboInfo().getId() || picker.hasPermissionRight(Permission.ACC_ANYROOMOWNER))) { + if (picker != null && !picker.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && picker.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { + picker.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", String.valueOf(BotManager.MAXIMUM_BOT_INVENTORY_SIZE))); + return; + } + + bot.onPickUp(picker, this.room); + + bot.setFollowingHabboId(0); + + //@DEPRECATED + bot.setOwnerId(botOwnerInfo.getId()); + bot.setOwnerName(botOwnerInfo.getUsername()); + + bot.setOwnerInfo(botOwnerInfo); + + this.removeBot(bot); + + bot.setSqlUpdateNeeded(true); + Emulator.getThreading().run(bot); + + Habbo receiver = picker == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : picker; + + if (receiver != null) { + receiver.getInventory().getBotsComponent().addBot(bot); + receiver.getClient().sendResponse(new BotAddedToInventoryComposer(bot)); + } + } + } + + + public void addBot(Bot unit) { + currentBots.put(unit.getId(), unit); + } + + public void removeBot(Bot bot) { + if (this.currentBots.containsKey(bot.getId())) { + //TODO gotta do a method to removeUnit and clear tile + if (bot.getRoomUnit().getCurrentPosition() != null) { + bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit()); + } + + this.currentBots.remove(bot.getId()); + roomUnitManager.removeUnit(bot.getRoomUnit().getVirtualId()); + + + bot.getRoomUnit().setRoom(null); + + this.room.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose()); + } + } + + public void clear() { + currentBots.clear(); + } + + public void dispose() { + Iterator botIterator = this.currentBots.values().iterator(); + + while (botIterator.hasNext()) { + try { + Bot bot = botIterator.next(); + bot.setSqlUpdateNeeded(true); + Emulator.getThreading().run(bot); + } catch (NoSuchElementException e) { + log.error("Caught Exception", e); + break; + } + } + + this.currentBots.clear(); + + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomBot.java b/src/main/java/com/eu/habbo/habbohotel/rooms/bots/entities/RoomBot.java similarity index 97% rename from src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomBot.java rename to src/main/java/com/eu/habbo/habbohotel/rooms/bots/entities/RoomBot.java index 59f47dd56..24d30e82 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/bots/entities/RoomBot.java @@ -1,4 +1,4 @@ -package com.eu.habbo.habbohotel.rooms.entities.units.types; +package com.eu.habbo.habbohotel.rooms.bots.entities; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; @@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.constants.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.constants.RoomUserAction; import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.outgoing.rooms.users.ChatMessageComposer; 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 65a09baa..cb94d790 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 @@ -166,7 +166,7 @@ public abstract class RoomUnit extends RoomEntity { super.setCurrentZ(currentZ); if (this.room != null) { - Bot bot = this.room.getRoomUnitManager().getRoomBotById(getVirtualId()); + Bot bot = this.room.getRoomUnitManager().getRoomBotManager().getRoomBotById(getVirtualId()); if (bot != null) { bot.setSqlUpdateNeeded(true); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomUnitSubManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomUnitSubManager.java new file mode 100644 index 00000000..ecb63b19 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomUnitSubManager.java @@ -0,0 +1,14 @@ +package com.eu.habbo.habbohotel.rooms.entities.units.types; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomUnitManager; + +public abstract class RoomUnitSubManager { + + protected RoomUnitManager roomUnitManager; + protected Room room; + public RoomUnitSubManager(RoomUnitManager roomUnitManager){ + this.roomUnitManager = roomUnitManager; + this.room = roomUnitManager.getRoom(); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/items/RoomItemManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/items/RoomItemManager.java index 51e868fb..595dd1b8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/items/RoomItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/items/RoomItemManager.java @@ -263,7 +263,7 @@ public class RoomItemManager { for (RoomTile t : occupiedTiles) { this.room.getRoomUnitManager().updateHabbosAt(t); - this.room.getRoomUnitManager().updateBotsAt(t); + this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(t); } Emulator.getThreading().run(item); @@ -343,7 +343,7 @@ public class RoomItemManager { if (checkForUnits && !magicTile) { if (this.room.getRoomUnitManager().hasHabbosAt(t)) return FurnitureMovementError.TILE_HAS_HABBOS; - if (!this.room.getRoomUnitManager().getBotsAt(t).isEmpty()) + if (!this.room.getRoomUnitManager().getRoomBotManager().getBotsAt(t).isEmpty()) return FurnitureMovementError.TILE_HAS_BOTS; if (this.room.getRoomUnitManager().hasPetsAt(t)) return FurnitureMovementError.TILE_HAS_PETS; @@ -459,7 +459,7 @@ public class RoomItemManager { //Update Habbos at old position for (RoomTile t : occupiedTiles) { this.room.getRoomUnitManager().updateHabbosAt(t); - this.room.getRoomUnitManager().updateBotsAt(t); + this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(t); } if (Emulator.getConfig().getBoolean("wired.place.under", false)) { @@ -520,7 +520,7 @@ public class RoomItemManager { updatedTiles.forEach(tile -> { this.room.getRoomUnitManager().updateHabbosAt(tile); - this.room.getRoomUnitManager().updateBotsAt(tile); + this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(tile); }); } else if (roomItem.getBaseItem().getType() == FurnitureType.WALL) { this.room.sendComposer(new ItemRemoveMessageComposer(roomItem).compose()); @@ -606,7 +606,7 @@ public class RoomItemManager { if (!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit() && !item.getBaseItem().allowLay())) { if (checkForUnits && this.room.getRoomUnitManager().hasHabbosAt(occupiedTile)) return FurnitureMovementError.TILE_HAS_HABBOS; - if (checkForUnits && this.room.getRoomUnitManager().hasBotsAt(occupiedTile)) + if (checkForUnits && this.room.getRoomUnitManager().getRoomBotManager().hasBotsAt(occupiedTile)) return FurnitureMovementError.TILE_HAS_BOTS; if (checkForUnits && this.room.getRoomUnitManager().hasPetsAt(occupiedTile)) return FurnitureMovementError.TILE_HAS_PETS; diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/items/entities/RoomItem.java b/src/main/java/com/eu/habbo/habbohotel/rooms/items/entities/RoomItem.java index e472da5a..857c3d24 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/items/entities/RoomItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/items/entities/RoomItem.java @@ -367,7 +367,7 @@ public abstract class RoomItem extends RoomEntity implements Runnable, IEventTri } RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); - for (Bot bot : room.getRoomUnitManager().getBotsAt(tile)) { + for (Bot bot : room.getRoomUnitManager().getRoomBotManager().getBotsAt(tile)) { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { bot.getRoomUnit().giveEffect(nextEffectM, -1); } @@ -397,12 +397,12 @@ public abstract class RoomItem extends RoomEntity implements Runnable, IEventTri for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) { oldHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile)); - oldBots.addAll(room.getRoomUnitManager().getBotsAt(tile)); + oldBots.addAll(room.getRoomUnitManager().getRoomBotManager().getBotsAt(tile)); } for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) { newHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile)); - newBots.addAll(room.getRoomUnitManager().getBotsAt(tile)); + newBots.addAll(room.getRoomUnitManager().getRoomBotManager().getBotsAt(tile)); } oldHabbos.removeAll(newHabbos); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java index d26dc17f..ff63c4d8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -347,7 +347,7 @@ public class Habbo extends Avatar implements Runnable { public void deleteBot(Bot bot) { this.removeBot(bot); - bot.getRoomUnit().getRoom().getRoomUnitManager().removeBot(bot); + bot.getRoomUnit().getRoom().getRoomUnitManager().getRoomBotManager().removeBot(bot); Emulator.getGameEnvironment().getBotManager().deleteBot(bot); } 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 25cf6167..42b2c00f 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 @@ -50,7 +50,7 @@ public class DeleteRoomEvent extends MessageHandler { room.getRoomItemManager().ejectAllFurni(); room.getRoomItemManager().ejectUserFurni(room.getRoomInfo().getOwnerInfo().getId()); - List bots = new ArrayList<>(room.getRoomUnitManager().getCurrentBots().values()); + List bots = new ArrayList<>(room.getRoomUnitManager().getRoomBotManager().getCurrentBots().values()); for (Bot bot : bots) { Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null, room); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/CommandBotEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/CommandBotEvent.java index 08befe11..c8bcd759 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/CommandBotEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/CommandBotEvent.java @@ -28,7 +28,7 @@ public class CommandBotEvent extends MessageHandler { if (room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { int botId = this.packet.readInt(); - Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); + Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(Math.abs(botId)); if (bot == null) { return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/GetBotCommandConfigurationDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/GetBotCommandConfigurationDataEvent.java index 7c9f337b..c7d88043 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/GetBotCommandConfigurationDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/GetBotCommandConfigurationDataEvent.java @@ -17,7 +17,7 @@ public class GetBotCommandConfigurationDataEvent extends MessageHandler { if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { int botId = this.packet.readInt(); - Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); + Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(Math.abs(botId)); if (bot == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/PlaceBotEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/PlaceBotEvent.java index 3e81a536..31a3dd8c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/PlaceBotEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/PlaceBotEvent.java @@ -22,6 +22,6 @@ public class PlaceBotEvent extends MessageHandler { int x = this.packet.readInt(); int y = this.packet.readInt(); - room.getRoomUnitManager().placeBot(bot, this.client.getHabbo(), x, y); + room.getRoomUnitManager().getRoomBotManager().placeBot(bot, this.client.getHabbo(), x, y); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/RemoveBotFromFlatEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/RemoveBotFromFlatEvent.java index d55a372a..971a37b3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/RemoveBotFromFlatEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/bots/RemoveBotFromFlatEvent.java @@ -17,12 +17,12 @@ public class RemoveBotFromFlatEvent extends MessageHandler { int botId = this.packet.readInt(); - Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); + Bot bot = room.getRoomUnitManager().getRoomBotManager().getRoomBotById(Math.abs(botId)); if(bot == null) { return; } - room.getRoomUnitManager().pickUpBot(bot, this.client.getHabbo()); + room.getRoomUnitManager().getRoomBotManager().pickUpBot(bot, this.client.getHabbo()); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java index c8533960..51da0ed1 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java @@ -55,7 +55,7 @@ public class RoomUnitTeleport implements Runnable { roomUnit.setWiredTeleporting(false); this.room.getRoomUnitManager().updateHabbosAt(newLocation); - this.room.getRoomUnitManager().updateBotsAt(newLocation); + this.room.getRoomUnitManager().getRoomBotManager().updateBotsAt(newLocation); topItem = room.getRoomItemManager().getTopItemAt(x, y); if (topItem != null && roomUnit.getCurrentPosition().equals(room.getLayout().getTile((short) x, (short) y))) {