diff --git a/featurelist.md b/featurelist.md index 7f494997..3a63b5ab 100644 --- a/featurelist.md +++ b/featurelist.md @@ -132,7 +132,7 @@ If you wish to contribute to this list, features are laid out in the following f > [`Habbo.getHabboStats()`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java#L94) > [`Habbo.getRoomUnit()`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java#L102) > [`HabboManager`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java) -> [`HabboManager.getOfflineHabboInfo()`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java#L47) +> [`Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo()`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java#L47) > [`HabboManager.getCloneAccounts()`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java#L203) > [`HabboManager.setRank()`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java#L243) > [`HabboInfo`](https://git.krews.org/morningstar/Arcturus-Community/-/blob/dev/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java) diff --git a/pom.xml b/pom.xml index 4f2ad716..ef4c1a5a 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,25 @@ 2.8.9 + + + com.fasterxml.jackson.core + jackson-core + 2.15.2 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.15.2 + + + + com.fasterxml.jackson.core + jackson-databind + 2.15.2 + + mysql diff --git a/src/main/java/com/eu/habbo/core/CreditsScheduler.java b/src/main/java/com/eu/habbo/core/CreditsScheduler.java index 2c691133..62e2cffd 100644 --- a/src/main/java/com/eu/habbo/core/CreditsScheduler.java +++ b/src/main/java/com/eu/habbo/core/CreditsScheduler.java @@ -45,7 +45,7 @@ public class CreditsScheduler extends Scheduler { try { if (habbo != null) { - if (habbo.getHabboInfo().getCurrentRoom() == null && IGNORE_HOTEL_VIEW) + if (habbo.getRoomUnit().getRoom() == null && IGNORE_HOTEL_VIEW) continue; if (habbo.getRoomUnit().isIdle() && IGNORE_IDLED) diff --git a/src/main/java/com/eu/habbo/core/Easter.java b/src/main/java/com/eu/habbo/core/Easter.java index 40b57a6c..0c0007bf 100644 --- a/src/main/java/com/eu/habbo/core/Easter.java +++ b/src/main/java/com/eu/habbo/core/Easter.java @@ -15,7 +15,7 @@ public class Easter { if (Emulator.getConfig().getBoolean("easter_eggs.enabled") && event.getNewMotto().equalsIgnoreCase("crickey!")) { event.habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(event.getNewMotto(), event.habbo, event.habbo, RoomChatMessageBubbles.ALERT))); - Room room = event.habbo.getHabboInfo().getCurrentRoom(); + Room room = event.habbo.getRoomUnit().getRoom(); room.sendComposer(new UserRemoveMessageComposer(event.habbo.getRoomUnit()).compose()); room.sendComposer(new RoomUserPetComposer(2, 1, "FFFFFF", event.habbo).compose()); diff --git a/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java b/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java index 8b19429c..66c70e8b 100644 --- a/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java +++ b/src/main/java/com/eu/habbo/core/GotwPointsScheduler.java @@ -45,7 +45,7 @@ public class GotwPointsScheduler extends Scheduler { try { if (habbo != null) { - if (habbo.getHabboInfo().getCurrentRoom() == null && IGNORE_HOTEL_VIEW) + if (habbo.getRoomUnit().getRoom() == null && IGNORE_HOTEL_VIEW) continue; if (habbo.getRoomUnit().isIdle() && IGNORE_IDLED) diff --git a/src/main/java/com/eu/habbo/core/PixelScheduler.java b/src/main/java/com/eu/habbo/core/PixelScheduler.java index ac36ec14..0bd440bf 100644 --- a/src/main/java/com/eu/habbo/core/PixelScheduler.java +++ b/src/main/java/com/eu/habbo/core/PixelScheduler.java @@ -40,7 +40,7 @@ public class PixelScheduler extends Scheduler { habbo = map.getValue(); try { if (habbo != null) { - if (habbo.getHabboInfo().getCurrentRoom() == null && IGNORE_HOTEL_VIEW) + if (habbo.getRoomUnit().getRoom() == null && IGNORE_HOTEL_VIEW) continue; if (habbo.getRoomUnit().isIdle() && IGNORE_IDLED) diff --git a/src/main/java/com/eu/habbo/core/PointsScheduler.java b/src/main/java/com/eu/habbo/core/PointsScheduler.java index 1fce2860..664026f3 100644 --- a/src/main/java/com/eu/habbo/core/PointsScheduler.java +++ b/src/main/java/com/eu/habbo/core/PointsScheduler.java @@ -44,7 +44,7 @@ public class PointsScheduler extends Scheduler { try { if (habbo != null) { - if (habbo.getHabboInfo().getCurrentRoom() == null && IGNORE_HOTEL_VIEW) + if (habbo.getRoomUnit().getRoom() == null && IGNORE_HOTEL_VIEW) continue; if (habbo.getRoomUnit().isIdle() && IGNORE_IDLED) diff --git a/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java b/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java index 515334d5..0b6926e5 100644 --- a/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java +++ b/src/main/java/com/eu/habbo/core/RoomUserPetComposer.java @@ -22,10 +22,10 @@ public class RoomUserPetComposer extends MessageComposer { this.response.appendString(this.habbo.getHabboInfo().getUsername()); this.response.appendString(""); this.response.appendString(this.petType + " " + this.race + " " + this.color + " 2 2 -1 0 3 -1 0"); - this.response.appendInt(this.habbo.getRoomUnit().getId()); - this.response.appendInt(this.habbo.getRoomUnit().getX()); - this.response.appendInt(this.habbo.getRoomUnit().getY()); - this.response.appendString(this.habbo.getRoomUnit().getZ() + ""); + this.response.appendInt(this.habbo.getRoomUnit().getVirtualId()); + this.response.appendInt(this.habbo.getRoomUnit().getCurrentPosition().getX()); + this.response.appendInt(this.habbo.getRoomUnit().getCurrentPosition().getY()); + this.response.appendString(this.habbo.getRoomUnit().getCurrentZ() + ""); this.response.appendInt(this.habbo.getRoomUnit().getBodyRotation().getValue()); this.response.appendInt(2); this.response.appendInt(this.petType); diff --git a/src/main/java/com/eu/habbo/database/DatabaseConstants.java b/src/main/java/com/eu/habbo/database/DatabaseConstants.java index 5b4a706f..4a55cb3f 100644 --- a/src/main/java/com/eu/habbo/database/DatabaseConstants.java +++ b/src/main/java/com/eu/habbo/database/DatabaseConstants.java @@ -4,4 +4,4 @@ public class DatabaseConstants { public static final String CAUGHT_SQL_EXCEPTION = "Caught SQL exception"; public final static String USER_ID = "user_id"; -} +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java b/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java index a7c23ace..37e1e048 100644 --- a/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/achievements/AchievementManager.java @@ -2,9 +2,9 @@ package com.eu.habbo.habbohotel.achievements; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.achievements.AchievementComposer; import com.eu.habbo.messages.outgoing.achievements.AchievementUnlockedComposer; import com.eu.habbo.messages.outgoing.achievements.talenttrack.TalentLevelUpComposer; @@ -17,7 +17,6 @@ import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.events.users.achievements.UserAchievementLeveledEvent; import com.eu.habbo.plugin.events.users.achievements.UserAchievementProgressEvent; import gnu.trove.map.hash.THashMap; -import gnu.trove.procedure.TObjectIntProcedure; import lombok.extern.slf4j.Slf4j; import java.sql.*; @@ -155,8 +154,8 @@ public class AchievementManager { Emulator.getThreading().run(badge); - if (badge.getSlot() > 0 && habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserBadgesComposer(habbo.getInventory().getBadgesComponent().getWearingBadges(), habbo.getHabboInfo().getId()).compose()); + if (badge.getSlot() > 0 && habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserBadgesComposer(habbo.getInventory().getBadgesComponent().getWearingBadges(), habbo.getHabboInfo().getId()).compose()); } habbo.getClient().sendResponse(new UnseenItemsComposer(badge.getId(), UnseenItemsComposer.AddHabboItemCategory.BADGE)); @@ -167,8 +166,8 @@ public class AchievementManager { habbo.givePoints(newLevel.getRewardType(), newLevel.getRewardAmount()); } - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); } } } @@ -339,7 +338,7 @@ public class AchievementManager { if (level != null) { if (level.items != null && !level.items.isEmpty()) { for (Item item : level.items) { - HabboItem rewardItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), item, 0, 0, ""); + RoomItem rewardItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), item, 0, 0, ""); habbo.getInventory().getItemsComponent().addItem(rewardItem); habbo.getClient().sendResponse(new UnseenItemsComposer(rewardItem)); habbo.getClient().sendResponse(new FurniListInvalidateComposer()); 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 b10086cf..c888aacb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java @@ -1,18 +1,26 @@ package com.eu.habbo.habbohotel.bots; import com.eu.habbo.Emulator; -import com.eu.habbo.database.DatabaseConstants; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomChatMessage; +import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.RoomUserAction; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot; +import com.eu.habbo.habbohotel.units.type.Avatar; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.plugin.events.bots.BotChatEvent; import com.eu.habbo.plugin.events.bots.BotShoutEvent; import com.eu.habbo.plugin.events.bots.BotTalkEvent; import com.eu.habbo.plugin.events.bots.BotWhisperEvent; -import com.eu.habbo.threading.runnables.BotFollowHabbo; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import java.sql.Connection; @@ -21,14 +29,14 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; @Slf4j -public class Bot implements Runnable { - public static final String NO_CHAT_SET = "${bot.skill.chatter.configuration.text.placeholder}"; - public static String[] PLACEMENT_MESSAGES = "Yo!;Hello I'm a real party animal!;Hello!".split(";"); - - private final ArrayList chatLines; +@Getter +@Setter +@Accessors(chain = true) +public class Bot extends Avatar implements Runnable { private transient int id; private String name; private String motto; @@ -36,45 +44,24 @@ public class Bot implements Runnable { private HabboGender gender; private int ownerId; private String ownerName; - private Room room; - private RoomUnit roomUnit; + + private HabboInfo ownerInfo; + private boolean chatAuto; private boolean chatRandom; private short chatDelay; private int chatTimeOut; private int chatTimestamp; private short lastChatIndex; - private final int bubble; - - + private final int bubbleId; private final String type; - - private int effect; - - private transient boolean canWalk = true; - - private boolean needsUpdate; - - + private boolean sqlUpdateNeeded; private transient int followingHabboId; - - public Bot(int id, String name, String motto, String figure, HabboGender gender, int ownerId, String ownerName) { - this.id = id; - this.name = name; - this.motto = motto; - this.figure = figure; - this.gender = gender; - this.ownerId = ownerId; - this.ownerName = ownerName; - this.chatAuto = false; - this.chatRandom = false; - this.chatDelay = 1000; - this.chatLines = new ArrayList<>(); - this.type = "generic_bot"; - this.room = null; - this.bubble = RoomChatMessageBubbles.BOT_RENTABLE.getType(); - } + protected final RoomBot roomUnit; + public static final String NO_CHAT_SET = "${bot.skill.chatter.configuration.text.placeholder}"; + public static String[] PLACEMENT_MESSAGES = "Yo!;Hello I'm a real party animal!;Hello!".split(";"); + private final ArrayList chatLines; public Bot(ResultSet set) throws SQLException { this.id = set.getInt("id"); @@ -82,69 +69,46 @@ public class Bot implements Runnable { this.motto = set.getString("motto"); this.figure = set.getString("figure"); this.gender = HabboGender.valueOf(set.getString("gender")); - this.ownerId = set.getInt(DatabaseConstants.USER_ID); + + //@Deprecated + this.ownerId = set.getInt("owner_id"); this.ownerName = set.getString("owner_name"); + + this.ownerInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(set.getInt("owner_id")); + this.chatAuto = set.getString("chat_auto").equals("1"); this.chatRandom = set.getString("chat_random").equals("1"); this.chatDelay = set.getShort("chat_delay"); this.chatLines = new ArrayList<>(Arrays.asList(set.getString("chat_lines").split("\r"))); this.type = set.getString("type"); this.effect = set.getInt("effect"); - this.canWalk = set.getString("freeroam").equals("1"); - this.room = null; - this.roomUnit = null; this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay; - this.needsUpdate = false; - this.bubble = set.getInt("bubble_id"); + this.sqlUpdateNeeded = false; + this.bubbleId = set.getInt("bubble_id"); + + this.roomUnit = new RoomBot(); + this.roomUnit.setUnit(this); + + this.roomUnit.setCanWalk(set.getString("freeroam").equals("1")); } - public Bot(Bot bot) { - this.name = bot.getName(); - this.motto = bot.getMotto(); - this.figure = bot.getFigure(); - this.gender = bot.getGender(); - this.ownerId = bot.getOwnerId(); - this.ownerName = bot.getOwnerName(); - this.chatAuto = true; - this.chatRandom = false; - this.chatDelay = 10; - this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay; - this.chatLines = new ArrayList<>(List.of("Default Message :D")); - this.type = bot.getType(); - this.effect = bot.getEffect(); - this.bubble = bot.getBubbleId(); - this.needsUpdate = false; - } + public static void initialise() {} - public static void initialise() { - - } - - public static void dispose() { - - } - - public void needsUpdate(boolean needsUpdate) { - this.needsUpdate = needsUpdate; - } - - public boolean needsUpdate() { - return this.needsUpdate; - } + public static void dispose() {} @Override public void run() { - if (this.needsUpdate) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) { + if (this.sqlUpdateNeeded) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, owner_id = ?, room_id = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ?, x = ?, y = ?, z = ? WHERE id = ?")) { statement.setString(1, this.name); statement.setString(2, this.motto); statement.setString(3, this.figure); statement.setString(4, this.gender.toString()); - statement.setInt(5, this.ownerId); - statement.setInt(6, this.room == null ? 0 : this.room.getId()); - statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getBodyRotation().getValue()); - statement.setInt(8, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType()); - statement.setString(9, this.canWalk ? "1" : "0"); + statement.setInt(5, this.ownerInfo.getId()); + statement.setInt(6, this.roomUnit.getRoom() == null ? 0 : this.roomUnit.getRoom().getRoomInfo().getId()); + statement.setInt(7, this.roomUnit.getBodyRotation().getValue()); + statement.setInt(8, this.roomUnit.getDanceType().getType()); + statement.setString(9, this.roomUnit.isCanWalk() ? "1" : "0"); StringBuilder text = new StringBuilder(); for (String s : this.chatLines) { text.append(s).append("\r"); @@ -154,90 +118,51 @@ public class Bot implements Runnable { statement.setString(12, this.chatRandom ? "1" : "0"); statement.setInt(13, this.chatDelay); statement.setInt(14, this.effect); - statement.setInt(15, this.bubble); - statement.setInt(16, this.id); + statement.setInt(15, this.bubbleId); + statement.setInt(16, this.roomUnit.getSpawnTile() == null ? 0 : this.roomUnit.getSpawnTile().getX()); + statement.setInt(17, this.roomUnit.getSpawnTile() == null ? 0 : this.roomUnit.getSpawnTile().getY()); + statement.setDouble(18, this.roomUnit.getSpawnHeight()); + statement.setInt(19, this.id); statement.execute(); - this.needsUpdate = false; + this.sqlUpdateNeeded = false; } catch (SQLException e) { - log.error("Caught SQL exception", e); - } - } - } - - public void cycle(boolean allowBotsWalk) { - if (this.roomUnit != null) { - if (allowBotsWalk && this.canWalk) { - if (!this.roomUnit.isWalking()) { - if (this.roomUnit.getWalkTimeOut() < Emulator.getIntUnixTimestamp() && this.followingHabboId == 0) { - this.roomUnit.setGoalLocation(Emulator.getConfig().getBoolean("hotel.bot.limit.walking.distance", true) ? this.room.getLayout().getRandomWalkableTilesAround(this.roomUnit, this.room.getLayout().getTile(this.roomUnit.getBotStartLocation().getX(), this.roomUnit.getBotStartLocation().getY()), this.room, Emulator.getConfig().getInt("hotel.bot.limit.walking.distance.radius", 5)) : this.room.getRandomWalkableTile()); - - int timeOut = Emulator.getRandom().nextInt(20) * 2; - this.roomUnit.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp()); - } - }/* else { - for (RoomTile t : this.room.getLayout().getTilesAround(this.room.getLayout().getTile(this.getRoomUnit().getX(), this.getRoomUnit().getY()))) { - WiredHandler.handle(WiredTriggerType.BOT_REACHED_STF, this.roomUnit, this.room, this.room.getItemsAt(t).toArray()); - } - }*/ - } - - if (!this.chatLines.isEmpty() && this.chatTimeOut <= Emulator.getIntUnixTimestamp() && this.chatAuto) { - if (this.room != null) { - this.lastChatIndex = (this.chatRandom ? (short) Emulator.getRandom().nextInt(this.chatLines.size()) : (this.lastChatIndex == (this.chatLines.size() - 1) ? 0 : this.lastChatIndex++)); - - if (this.lastChatIndex >= this.chatLines.size()) { - this.lastChatIndex = 0; - } - - String message = this.chatLines.get(this.lastChatIndex) - .replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), this.room.getOwnerName()) - .replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), this.room.itemCount() + "") - .replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.name) - .replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), this.room.getName()) - .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), this.room.getUserCount() + ""); - - if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{ message })) { - this.talk(message); - } - - this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay; - } + log.error(CAUGHT_SQL_EXCEPTION, e); } } } public void talk(String message) { - if (this.room != null) { + if (this.roomUnit.getRoom() != null) { BotChatEvent event = new BotTalkEvent(this, message); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) return; this.chatTimestamp = Emulator.getIntUnixTimestamp(); - this.room.botChat(new ChatMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose()); + this.roomUnit.getRoom().botChat(new ChatMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose()); if (message.equals("o/") || message.equals("_o/")) { - this.room.sendComposer(new ExpressionMessageComposer(this.roomUnit, RoomUserAction.WAVE).compose()); + this.roomUnit.getRoom().sendComposer(new ExpressionMessageComposer(this.roomUnit, RoomUserAction.WAVE).compose()); } } } public void shout(String message) { - if (this.room != null) { + if (this.roomUnit.getRoom() != null) { BotChatEvent event = new BotShoutEvent(this, message); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) return; this.chatTimestamp = Emulator.getIntUnixTimestamp(); - this.room.botChat(new ShoutMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose()); + this.roomUnit.getRoom().botChat(new ShoutMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose()); if (message.equals("o/") || message.equals("_o/")) { - this.room.sendComposer(new ExpressionMessageComposer(this.roomUnit, RoomUserAction.WAVE).compose()); + this.roomUnit.getRoom().sendComposer(new ExpressionMessageComposer(this.roomUnit, RoomUserAction.WAVE).compose()); } } } public void whisper(String message, Habbo habbo) { - if (this.room != null && habbo != null) { + if (this.roomUnit.getRoom() != null && habbo != null) { BotWhisperEvent event = new BotWhisperEvent(this, message, habbo); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) return; @@ -249,266 +174,147 @@ public class Bot implements Runnable { public void onPlace(Habbo habbo, Room room) { if (this.roomUnit != null) { - room.giveEffect(this.roomUnit, this.effect, -1); + this.roomUnit.giveEffect(this.effect, -1); } if(PLACEMENT_MESSAGES.length > 0) { String message = PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)]; - if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{message})) { + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.roomUnit, room, new Object[]{message})) { this.talk(message); } } } - public void onPickUp(Habbo habbo, Room room) { + public void onPickUp(Habbo habbo, Room room) {} - } - - public void onUserSay(final RoomChatMessage message) { - - } - - public int getId() { - return this.id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return this.name; - } - - public int getBubbleId() { - return bubble; - } + public void onUserSay(final RoomChatMessage message) {} public void setName(String name) { this.name = name; - this.needsUpdate = true; + this.sqlUpdateNeeded = true; //if(this.room != null) - //this.room.sendComposer(new ChangeNameUpdatedComposer(this.getRoomUnit(), this.getName()).compose()); - } - - public String getMotto() { - return this.motto; + //this.roomUnit.getRoom().sendComposer(new ChangeNameUpdatedComposer(this.roomUnit, this.getName()).compose()); } public void setMotto(String motto) { this.motto = motto; - this.needsUpdate = true; - } - - public String getFigure() { - return this.figure; + this.sqlUpdateNeeded = true; } public void setFigure(String figure) { this.figure = figure; - this.needsUpdate = true; - - if (this.room != null) - this.room.sendComposer(new RoomUsersComposer(this).compose()); - } - - public HabboGender getGender() { - return this.gender; + this.sqlUpdateNeeded = true; + this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose()); } public void setGender(HabboGender gender) { this.gender = gender; - this.needsUpdate = true; - - if (this.room != null) - this.room.sendComposer(new RoomUsersComposer(this).compose()); - } - - public int getOwnerId() { - return this.ownerId; + this.sqlUpdateNeeded = true; + this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose()); } public void setOwnerId(int ownerId) { this.ownerId = ownerId; - this.needsUpdate = true; + this.sqlUpdateNeeded = true; - if (this.room != null) - this.room.sendComposer(new RoomUsersComposer(this).compose()); - } - - public String getOwnerName() { - return this.ownerName; + if(this.roomUnit.getRoom() != null) { + this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose()); + } } public void setOwnerName(String ownerName) { this.ownerName = ownerName; - this.needsUpdate = true; + this.sqlUpdateNeeded = true; - if (this.room != null) - this.room.sendComposer(new RoomUsersComposer(this).compose()); - } - - public Room getRoom() { - return this.room; - } - - public void setRoom(Room room) { - this.room = room; - } - - public RoomUnit getRoomUnit() { - return this.roomUnit; - } - - public void setRoomUnit(RoomUnit roomUnit) { - this.roomUnit = roomUnit; - } - - public boolean isChatAuto() { - return this.chatAuto; + if(this.roomUnit.getRoom() != null) { + this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose()); + } } public void setChatAuto(boolean chatAuto) { this.chatAuto = chatAuto; - this.needsUpdate = true; - } - - public boolean isChatRandom() { - return this.chatRandom; + this.sqlUpdateNeeded = true; } public void setChatRandom(boolean chatRandom) { this.chatRandom = chatRandom; - this.needsUpdate = true; + this.sqlUpdateNeeded = true; } public boolean hasChat() { return !this.chatLines.isEmpty(); } - public int getChatDelay() { - return this.chatDelay; - } - public void setChatDelay(short chatDelay) { this.chatDelay = (short) Math.min(Math.max(chatDelay, BotManager.MINIMUM_CHAT_SPEED), BotManager.MAXIMUM_CHAT_SPEED); - this.needsUpdate = true; + this.sqlUpdateNeeded = true; this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay; } - public int getChatTimestamp() { - return this.chatTimestamp; - } - public void clearChat() { synchronized (this.chatLines) { this.chatLines.clear(); - this.needsUpdate = true; + this.sqlUpdateNeeded = true; } } - public String getType() { - return this.type; - } - - public int getEffect() { - return this.effect; - } - public void setEffect(int effect, int duration) { this.effect = effect; - this.needsUpdate = true; + this.sqlUpdateNeeded = true; - if (this.roomUnit != null) { - if (this.room != null) { - this.room.giveEffect(this.roomUnit, this.effect, duration); - } + if (this.roomUnit.getRoom() != null) { + this.roomUnit.giveEffect(this.effect, duration); } } public void addChatLines(ArrayList chatLines) { synchronized (this.chatLines) { this.chatLines.addAll(chatLines); - this.needsUpdate = true; + this.sqlUpdateNeeded = true; } } public void addChatLine(String chatLine) { synchronized (this.chatLines) { this.chatLines.add(chatLine); - this.needsUpdate = true; + this.sqlUpdateNeeded = true; } } - public ArrayList getChatLines() { - return this.chatLines; + public void incrementLastChatIndex() { + this.lastChatIndex++; } - public int getFollowingHabboId() { - return this.followingHabboId; + public void resetLastChatIndex() { + this.lastChatIndex = 0; } - public void startFollowingHabbo(Habbo habbo) { - this.followingHabboId = habbo.getHabboInfo().getId(); - - Emulator.getThreading().run(new BotFollowHabbo(this, habbo, habbo.getHabboInfo().getCurrentRoom())); + @Override + public void serialize(ServerMessage message) { + message.appendInt(-this.id); + message.appendString(this.name); + message.appendString(this.motto); + message.appendString(this.figure); + message.appendInt(this.roomUnit.getVirtualId()); + message.appendInt(this.roomUnit.getCurrentPosition() == null ? 0 : this.roomUnit.getCurrentPosition().getX()); + message.appendInt(this.roomUnit.getCurrentPosition() == null ? 0 : this.roomUnit.getCurrentPosition().getY()); + message.appendString(String.valueOf(this.roomUnit.getCurrentZ())); + message.appendInt(this.roomUnit.getBodyRotation().getValue()); + message.appendInt(4); + message.appendString(this.gender.name().toUpperCase()); + message.appendInt(this.ownerId); + message.appendString(this.ownerName); + message.appendInt(10); + message.appendShort(0); + message.appendShort(1); + message.appendShort(2); + message.appendShort(3); + message.appendShort(4); + message.appendShort(5); + message.appendShort(6); + message.appendShort(7); + message.appendShort(8); + message.appendShort(9); } - - public void stopFollowingHabbo() { - this.followingHabboId = 0; - } - - public boolean canWalk() { - return this.canWalk; - } - - public void setCanWalk(boolean canWalk) { - this.canWalk = canWalk; - } - - public void lookAt(Habbo habbo) { - this.lookAt(habbo.getRoomUnit().getCurrentLocation()); - } - - public void lookAt(RoomUnit roomUnit) { - this.lookAt(roomUnit.getCurrentLocation()); - } - - public void lookAt(RoomTile tile) { - this.roomUnit.lookAtPoint(tile); - this.roomUnit.statusUpdate(true); - } - - public void onPlaceUpdate() { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, x = ?, y = ?, z = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) { - statement.setString(1, this.name); - statement.setString(2, this.motto); - statement.setString(3, this.figure); - statement.setString(4, this.gender.toString()); - statement.setInt(5, this.ownerId); - statement.setInt(6, this.room == null ? 0 : this.room.getId()); - statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getX()); - statement.setInt(8, this.roomUnit == null ? 0 : this.roomUnit.getY()); - statement.setDouble(9, this.roomUnit == null ? 0 : this.roomUnit.getZ()); - statement.setInt(10, this.roomUnit == null ? 0 : this.roomUnit.getBodyRotation().getValue()); - statement.setInt(11, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType()); - statement.setString(12, this.canWalk ? "1" : "0"); - StringBuilder text = new StringBuilder(); - for (String s : this.chatLines) { - text.append(s).append("\r"); - } - statement.setString(13, text.toString()); - statement.setString(14, this.chatAuto ? "1" : "0"); - statement.setString(15, this.chatRandom ? "1" : "0"); - statement.setInt(16, this.chatDelay); - statement.setInt(17, this.effect); - statement.setInt(18, this.bubble); - statement.setInt(19, this.id); - statement.execute(); - } catch (SQLException e) { - log.error("Caught SQL exception", e); - } - } - } 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 2d5e03b8..f14b26f6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/BotManager.java @@ -2,25 +2,18 @@ package com.eu.habbo.habbohotel.bots; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer; -import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; -import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; 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.UserUpdateComposer; import com.eu.habbo.plugin.events.bots.BotPickUpEvent; -import com.eu.habbo.plugin.events.bots.BotPlacedEvent; import gnu.trove.map.hash.THashMap; import lombok.extern.slf4j.Slf4j; import java.lang.reflect.Method; import java.sql.*; import java.util.Map; + @Slf4j public class BotManager { @@ -68,7 +61,7 @@ public class BotManager { public Bot createBot(THashMap data, String type) { Bot bot = null; - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO bots (user_id, room_id, name, motto, figure, gender, type) VALUES (0, 0, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO bots (owner_id, room_id, name, motto, figure, gender, type) VALUES (0, 0, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { statement.setString(1, data.get("name")); statement.setString(2, data.get("motto")); statement.setString(3, data.get("figure")); @@ -77,7 +70,7 @@ public class BotManager { statement.execute(); try (ResultSet set = statement.getGeneratedKeys()) { if (set.next()) { - try (PreparedStatement stmt = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots LEFT JOIN users ON bots.user_id = users.id WHERE bots.id = ? LIMIT 1")) { + try (PreparedStatement stmt = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots LEFT JOIN users ON bots.owner_id = users.id WHERE bots.id = ? LIMIT 1")) { stmt.setInt(1, set.getInt(1)); try (ResultSet resultSet = stmt.executeQuery()) { if (resultSet.next()) { @@ -96,75 +89,9 @@ public class BotManager { return bot; } - public void placeBot(Bot bot, Habbo habbo, Room room, RoomTile location) { - BotPlacedEvent event = new BotPlacedEvent(bot, location, habbo); - Emulator.getPluginManager().fireEvent(event); + public void pickUpBot(Bot bot, Habbo habbo, Room room) { + HabboInfo botOwnerInfo = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabboInfo(bot.getOwnerId()) : habbo.getHabboInfo(); - if (event.isCancelled()) - return; - - if (room != null && bot != null && habbo != null) { - if (room.getOwnerId() == habbo.getHabboInfo().getId() || habbo.hasRight(Permission.ACC_ANYROOMOWNER) || habbo.hasRight(Permission.ACC_PLACEFURNI)) { - if (room.getCurrentBots().size() >= Room.MAXIMUM_BOTS && !habbo.hasRight(Permission.ACC_UNLIMITED_BOTS)) { - habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS)); - return; - } - - if (room.hasHabbosAt(location.getX(), location.getY()) || (!location.isWalkable() && location.getState() != RoomTileState.SIT && location.getState() != RoomTileState.LAY)) - return; - - if (room.hasBotsAt(location.getX(), location.getY())) { - habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE)); - return; - } - - RoomUnit roomUnit = new RoomUnit(); - roomUnit.setRotation(RoomUserRotation.SOUTH); - roomUnit.setLocation(location); - - double stackHeight = room.getTopHeightAt(location.getX(), location.getY()); - roomUnit.setPreviousLocationZ(stackHeight); - roomUnit.setZ(stackHeight); - - roomUnit.setPathFinderRoom(room); - roomUnit.setRoomUnitType(RoomUnitType.BOT); - roomUnit.setCanWalk(room.isAllowBotsWalk()); - bot.setRoomUnit(roomUnit); - bot.setRoom(room); - bot.onPlaceUpdate(); - room.addBot(bot); - Emulator.getThreading().run(bot); - room.sendComposer(new RoomUsersComposer(bot).compose()); - room.sendComposer(new UserUpdateComposer(bot.getRoomUnit()).compose()); - habbo.getInventory().getBotsComponent().removeBot(bot); - habbo.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot)); - bot.onPlace(habbo, room); - - HabboItem topItem = room.getTopItemAt(location.getX(), location.getY()); - - if (topItem != null) { - try { - topItem.onWalkOn(bot.getRoomUnit(), room, null); - } catch (Exception e) { - log.error("Caught exception", e); - } - } - - bot.cycle(false); - } else { - habbo.getClient().sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode())); - } - } - } - - public void pickUpBot(int botId, Habbo habbo) { - if (habbo.getHabboInfo().getCurrentRoom() != null) { - this.pickUpBot(habbo.getHabboInfo().getCurrentRoom().getBot(Math.abs(botId)), habbo); - } - } - - public void pickUpBot(Bot bot, Habbo habbo) { - HabboInfo receiverInfo = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabboInfo(bot.getOwnerId()) : habbo.getHabboInfo(); if (bot != null) { BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, habbo); @@ -173,21 +100,21 @@ public class BotManager { if (pickedUpEvent.isCancelled()) return; - if (habbo == null || (bot.getOwnerId() == habbo.getHabboInfo().getId() || habbo.hasRight(Permission.ACC_ANYROOMOWNER))) { - if (habbo != null && !habbo.hasRight(Permission.ACC_UNLIMITED_BOTS) && habbo.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { + if (habbo == null || (bot.getOwnerId() == habbo.getHabboInfo().getId() || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER))) { + if (habbo != null && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && habbo.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { habbo.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", BotManager.MAXIMUM_BOT_INVENTORY_SIZE + "")); return; } - bot.onPickUp(habbo, receiverInfo.getCurrentRoom()); - receiverInfo.getCurrentRoom().removeBot(bot); - bot.stopFollowingHabbo(); - bot.setOwnerId(receiverInfo.getId()); - bot.setOwnerName(receiverInfo.getUsername()); - bot.needsUpdate(true); + bot.onPickUp(habbo, room); + room.getRoomUnitManager().removeBot(bot); + bot.setFollowingHabboId(0); + bot.setOwnerId(botOwnerInfo.getId()); + bot.setOwnerName(botOwnerInfo.getUsername()); + bot.setSqlUpdateNeeded(true); Emulator.getThreading().run(bot); - Habbo receiver = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(receiverInfo.getId()) : habbo; + Habbo receiver = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : habbo; if (receiver != null) { receiver.getInventory().getBotsComponent().addBot(bot); receiver.getClient().sendResponse(new BotAddedToInventoryComposer(bot)); diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java index b3e992aa..c07261cc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import com.eu.habbo.messages.outgoing.rooms.users.CarryObjectMessageComposer; import com.eu.habbo.plugin.events.bots.BotServerItemEvent; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitWalkToRoomUnit; @@ -29,10 +30,6 @@ public class ButlerBot extends Bot { super(set); } - public ButlerBot(Bot bot) { - super(bot); - } - public static void initialise() { if (serveItems == null) serveItems = new THashMap<>(); @@ -57,11 +54,11 @@ public class ButlerBot extends Bot { @Override public void onUserSay(final RoomChatMessage message) { - if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || this.getRoom() == null) { + if (this.roomUnit.hasStatus(RoomUnitStatus.MOVE) || this.roomUnit.getRoom() == null) { return; } - double distanceBetweenBotAndHabbo = this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation()); + double distanceBetweenBotAndHabbo = this.roomUnit.getCurrentPosition().distance(message.getHabbo().getRoomUnit().getCurrentPosition()); if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance")) { @@ -80,26 +77,26 @@ public class ButlerBot extends Bot { } // Start give handitem process - if (this.getRoomUnit().canWalk()) { + if (this.roomUnit.isCanWalk()) { final String key = keyword; final Bot bot = this; // Step 1: Look at Habbo - bot.lookAt(serveEvent.getHabbo()); + bot.getRoomUnit().lookAtPoint(serveEvent.getHabbo().getRoomUnit().getCurrentPosition()); // Step 2: Prepare tasks for when the Bot (carrying the handitem) reaches the Habbo final List tasks = new ArrayList<>(); - tasks.add(new RoomUnitGiveHanditem(serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getHabboInfo().getCurrentRoom(), serveEvent.getItemId())); - tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.getHabbo().getHabboInfo().getCurrentRoom(), 0)); + tasks.add(new RoomUnitGiveHanditem(serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), serveEvent.getItemId())); + tasks.add(new RoomUnitGiveHanditem(this.roomUnit, serveEvent.getHabbo().getRoomUnit().getRoom(), 0)); tasks.add(() -> { - if (this.getRoom() != null) { + if (this.roomUnit.getRoom() != null) { String botMessage = Emulator.getTexts() .getValue("bots.butler.given") .replace("%key%", key) .replace("%username%", serveEvent.getHabbo().getHabboInfo().getUsername()); - if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{botMessage})) { + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.roomUnit, this.roomUnit.getRoom(), new Object[]{botMessage})) { bot.talk(botMessage); } } @@ -115,19 +112,20 @@ public class ButlerBot extends Bot { }); // Give bot the handitem that it's going to give the Habbo - Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.getHabbo().getHabboInfo().getCurrentRoom(), serveEvent.getItemId())); + Emulator.getThreading().run(new RoomUnitGiveHanditem(this.roomUnit, serveEvent.getHabbo().getRoomUnit().getRoom(), serveEvent.getItemId())); if (distanceBetweenBotAndHabbo > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) { - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getHabboInfo().getCurrentRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3))); + Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.roomUnit, serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3))); } else { Emulator.getThreading().run(failedReached.get(0), 1000); } } else { - if (this.getRoom() != null) { - this.getRoom().giveHandItem(serveEvent.getHabbo(), serveEvent.getItemId()); + if (this.roomUnit.getRoom() != null) { + serveEvent.getHabbo().getRoomUnit().setHandItem(serveEvent.getItemId()); + this.roomUnit.getRoom().sendComposer(new CarryObjectMessageComposer(serveEvent.getHabbo().getRoomUnit()).compose()); String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", keyword).replace("%username%", serveEvent.getHabbo().getHabboInfo().getUsername()); - if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) { + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.roomUnit, this.roomUnit.getRoom(), new Object[]{msg})) { this.talk(msg); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/VisitorBot.java b/src/main/java/com/eu/habbo/habbohotel/bots/VisitorBot.java index 130ff3b1..bcca553e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/VisitorBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/VisitorBot.java @@ -20,10 +20,6 @@ public class VisitorBot extends Bot { super(set); } - public VisitorBot(Bot bot) { - super(bot); - } - public static void initialise() { DATE_FORMAT = new SimpleDateFormat(Emulator.getConfig().getValue("bots.visitor.dateformat")); } @@ -55,8 +51,8 @@ public class VisitorBot extends Bot { public void onUserEnter(Habbo habbo) { if (!this.showedLog) { - if (habbo.getHabboInfo().getCurrentRoom() != null) { - this.visits = Emulator.getGameEnvironment().getModToolManager().getVisitsForRoom(habbo.getHabboInfo().getCurrentRoom(), 10, true, habbo.getHabboInfo().getLastOnline(), Emulator.getIntUnixTimestamp(), habbo.getHabboInfo().getCurrentRoom().getOwnerName()); + if (habbo.getRoomUnit().getRoom() != null) { + this.visits = Emulator.getGameEnvironment().getModToolManager().getVisitsForRoom(habbo.getRoomUnit().getRoom(), 10, true, habbo.getHabboInfo().getLastOnline(), Emulator.getIntUnixTimestamp(), habbo.getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getUsername()); if (this.visits.isEmpty()) { this.talk(Emulator.getTexts().getValue("bots.visitor.no_visits")); diff --git a/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarManager.java b/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarManager.java index 39e8d5e3..149edffa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarManager.java @@ -122,7 +122,7 @@ public class CalendarManager { if (object == null) return; long daysBetween = ChronoUnit.DAYS.between(new Timestamp(campaign.getStartTimestamp() * 1000L).toInstant(), new Date().toInstant()); - if (((daysBetween >= 0 && daysBetween <= campaign.getTotalDays()) && (((daysBetween - day <= 2 || !campaign.getLockExpired()) && daysBetween - day >= 0)) || (force && habbo.hasRight(Permission.ACC_CALENDAR_FORCE)))) { + if (((daysBetween >= 0 && daysBetween <= campaign.getTotalDays()) && (((daysBetween - day <= 2 || !campaign.getLockExpired()) && daysBetween - day >= 0)) || (force && habbo.hasPermissionRight(Permission.ACC_CALENDAR_FORCE)))) { if (Emulator.getPluginManager().fireEvent(new UserClaimRewardEvent(habbo, campaign, day, object, force)).isCancelled()) { return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardObject.java b/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardObject.java index d8b74fa3..e2832ab5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardObject.java +++ b/src/main/java/com/eu/habbo/habbohotel/campaign/CalendarRewardObject.java @@ -3,7 +3,7 @@ package com.eu.habbo.habbohotel.campaign; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionHabboClub; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; @@ -71,14 +71,14 @@ public class CalendarRewardObject { Item item = getItem(); if (item != null) { - HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem( + RoomItem roomItem = Emulator.getGameEnvironment().getItemManager().createItem( habbo.getHabboInfo().getId(), item, 0, 0, ""); - habbo.getInventory().getItemsComponent().addItem(habboItem); - habbo.getClient().sendResponse(new UnseenItemsComposer(habboItem)); + habbo.getInventory().getItemsComponent().addItem(roomItem); + habbo.getClient().sendResponse(new UnseenItemsComposer(roomItem)); habbo.getClient().sendResponse(new FurniListInvalidateComposer()); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java index babec10e..a29ef6d6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogLimitedConfiguration.java @@ -2,7 +2,7 @@ package com.eu.habbo.habbohotel.catalog; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -53,7 +53,7 @@ public class CatalogLimitedConfiguration implements Runnable { } } - public void limitedSold(int catalogItemId, Habbo habbo, HabboItem item) { + public void limitedSold(int catalogItemId, Habbo habbo, RoomItem item) { synchronized (lock) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE catalog_items_limited SET user_id = ?, timestamp = ?, item_id = ? WHERE catalog_item_id = ? AND number = ? AND user_id = 0 LIMIT 1")) { statement.setInt(1, habbo.getHabboInfo().getId()); diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java index 33fb7916..ba31a4f3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/CatalogManager.java @@ -14,10 +14,10 @@ import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.catalog.*; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -846,7 +846,7 @@ public class CatalogManager { } } - THashSet itemsList = new THashSet<>(); + HashSet itemsList = new HashSet<>(); if (amount > 1 && !CatalogItem.haveOffer(item)) { @@ -900,9 +900,13 @@ public class CatalogManager { Bot bot = Emulator.getGameEnvironment().getBotManager().createBot(data, type); if (bot != null) { + //TODO @Deprecated bot.setOwnerId(habbo.getClient().getHabbo().getHabboInfo().getId()); bot.setOwnerName(habbo.getClient().getHabbo().getHabboInfo().getUsername()); - bot.needsUpdate(true); + + bot.setOwnerInfo(habbo.getHabboInfo()); + + bot.setSqlUpdateNeeded(true); Emulator.getThreading().run(bot); habbo.getClient().getHabbo().getInventory().getBotsComponent().addBot(bot); habbo.getClient().sendResponse(new BotAddedToInventoryComposer(bot)); @@ -980,13 +984,13 @@ public class CatalogManager { } if (InteractionTeleport.class.isAssignableFrom(baseItem.getInteractionType().getType())) { - HabboItem teleportOne = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - HabboItem teleportTwo = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + RoomItem teleportOne = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + RoomItem teleportTwo = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); Emulator.getGameEnvironment().getItemManager().insertTeleportPair(teleportOne.getId(), teleportTwo.getId()); itemsList.add(teleportOne); itemsList.add(teleportTwo); } else if (baseItem.getInteractionType().getType() == InteractionHopper.class) { - HabboItem hopper = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + RoomItem hopper = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); Emulator.getGameEnvironment().getItemManager().insertHopper(hopper); @@ -1005,8 +1009,8 @@ public class CatalogManager { if (guild != null && Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo) != null) { InteractionGuildFurni habboItem = (InteractionGuildFurni) Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - habboItem.setExtradata(""); - habboItem.needsUpdate(true); + habboItem.setExtraData(""); + habboItem.setSqlUpdateNeeded(true); Emulator.getThreading().run(habboItem); Emulator.getGameEnvironment().getGuildManager().setGuild(habboItem, guildId); @@ -1027,15 +1031,15 @@ public class CatalogManager { } InteractionMusicDisc habboItem = (InteractionMusicDisc) Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, habbo.getClient().getHabbo().getHabboInfo().getUsername() + "\n" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "\n" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "\n" + Calendar.getInstance().get(Calendar.YEAR) + "\n" + track.getLength() + "\n" + track.getName() + "\n" + track.getId()); - habboItem.needsUpdate(true); + habboItem.setSqlUpdateNeeded(true); Emulator.getThreading().run(habboItem); itemsList.add(habboItem); AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MusicCollector")); } else { - HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); - itemsList.add(habboItem); + RoomItem roomItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getClient().getHabbo().getHabboInfo().getId(), baseItem, limitedStack, limitedNumber, extradata); + itemsList.add(roomItem); } } } @@ -1050,24 +1054,24 @@ public class CatalogManager { UserCatalogItemPurchasedEvent purchasedEvent = new UserCatalogItemPurchasedEvent(habbo, item, itemsList, totalCredits, totalPoints, badges); Emulator.getPluginManager().fireEvent(purchasedEvent); - if (!free && !habbo.getClient().getHabbo().hasRight(Permission.ACC_INFINITE_CREDITS) && purchasedEvent.getTotalCredits() > 0) { + if (!free && !habbo.getClient().getHabbo().hasPermissionRight(Permission.ACC_INFINITE_CREDITS) && purchasedEvent.getTotalCredits() > 0) { habbo.getClient().getHabbo().getHabboInfo().addCredits(-purchasedEvent.getTotalCredits()); habbo.getClient().sendResponse(new CreditBalanceComposer(habbo.getClient().getHabbo())); } - if (!free && !habbo.getClient().getHabbo().hasRight(Permission.ACC_INFINITE_POINTS) && purchasedEvent.getTotalPoints() > 0) { + if (!free && !habbo.getClient().getHabbo().hasPermissionRight(Permission.ACC_INFINITE_POINTS) && purchasedEvent.getTotalPoints() > 0) { habbo.getClient().getHabbo().getHabboInfo().addCurrencyAmount(item.getPointsType(), -purchasedEvent.getTotalPoints()); habbo.getClient().sendResponse(new HabboActivityPointNotificationMessageComposer(habbo.getClient().getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()), -purchasedEvent.getTotalPoints(), item.getPointsType())); } if (purchasedEvent.itemsList != null && !purchasedEvent.itemsList.isEmpty()) { habbo.getClient().getHabbo().getInventory().getItemsComponent().addItems(purchasedEvent.itemsList); - unseenItems.put(UnseenItemsComposer.AddHabboItemCategory.OWNED_FURNI, purchasedEvent.itemsList.stream().map(HabboItem::getId).toList()); + unseenItems.put(UnseenItemsComposer.AddHabboItemCategory.OWNED_FURNI, purchasedEvent.itemsList.stream().map(RoomItem::getId).toList()); Emulator.getPluginManager().fireEvent(new UserCatalogFurnitureBoughtEvent(habbo, item, purchasedEvent.itemsList)); if (limitedConfiguration != null) { - for (HabboItem itm : purchasedEvent.itemsList) { + for (RoomItem itm : purchasedEvent.itemsList) { limitedConfiguration.limitedSold(item.getId(), habbo, itm); } } @@ -1098,7 +1102,7 @@ public class CatalogManager { THashSet itemIds = new THashSet<>(); - for (HabboItem ix : purchasedEvent.itemsList) { + for (RoomItem ix : purchasedEvent.itemsList) { itemIds.add(ix.getId() + ""); } 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 de366cad..289e3940 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 @@ -6,8 +6,8 @@ import com.eu.habbo.habbohotel.catalog.CatalogItem; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomManager; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; import com.eu.habbo.messages.outgoing.navigator.CanCreateRoomComposer; @@ -40,7 +40,7 @@ public class RoomBundleLayout extends SingleBundle { if (this.room == null) { if (this.roomId > 0) { - this.room = Emulator.getGameEnvironment().getRoomManager().loadRoom(this.roomId); + this.room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.roomId); if (this.room != null) this.room.preventUnloading = true; @@ -73,7 +73,7 @@ public class RoomBundleLayout extends SingleBundle { THashMap items = new THashMap<>(); - for (HabboItem i : this.room.getFloorItems()) { + for (RoomItem i : this.room.getRoomItemManager().getFloorItems().values()) { if (!items.contains(i.getBaseItem())) { items.put(i.getBaseItem(), 0); } @@ -81,7 +81,7 @@ public class RoomBundleLayout extends SingleBundle { items.put(i.getBaseItem(), items.get(i.getBaseItem()) + 1); } - for (HabboItem i : this.room.getWallItems()) { + for (RoomItem i : this.room.getRoomItemManager().getWallItems().values()) { if (!items.contains(i.getBaseItem())) { items.put(i.getBaseItem(), 0); } @@ -123,7 +123,7 @@ public class RoomBundleLayout extends SingleBundle { public void buyRoom(Habbo habbo, int userId, String userName) { if (!this.loaded) { - this.loadItems(Emulator.getGameEnvironment().getRoomManager().loadRoom(this.roomId)); + this.loadItems(Emulator.getGameEnvironment().getRoomManager().getRoom(this.roomId)); } if (habbo != null) { @@ -141,11 +141,11 @@ public class RoomBundleLayout extends SingleBundle { this.room.save(); - for (HabboItem item : this.room.getFloorItems()) { + for (RoomItem item : this.room.getRoomItemManager().getFloorItems().values()) { item.run(); } - for (HabboItem item : this.room.getWallItems()) { + for (RoomItem item : this.room.getRoomItemManager().getWallItems().values()) { item.run(); } @@ -156,7 +156,7 @@ public class RoomBundleLayout extends SingleBundle { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO rooms (owner_id, owner_name, name, description, model, password, state, users_max, category, paper_floor, paper_wall, paper_landscape, thickness_wall, thickness_floor, moodlight_data, override_model) (SELECT ?, ?, name, description, model, password, state, users_max, category, paper_floor, paper_wall, paper_landscape, thickness_wall, thickness_floor, moodlight_data, override_model FROM rooms WHERE id = ?)", Statement.RETURN_GENERATED_KEYS)) { statement.setInt(1, userId); statement.setString(2, userName); - statement.setInt(3, this.room.getId()); + statement.setInt(3, this.room.getRoomInfo().getId()); statement.execute(); try (ResultSet set = statement.getGeneratedKeys()) { if (set.next()) { @@ -173,15 +173,15 @@ public class RoomBundleLayout extends SingleBundle { statement.setInt(2, roomId); statement.setString(3, "0:0"); statement.setInt(4, 0); - statement.setInt(5, this.room.getId()); + statement.setInt(5, this.room.getRoomInfo().getId()); statement.execute(); } - if (this.room.hasCustomLayout()) { + if (this.room.getRoomInfo().isModelOverridden()) { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO room_models_custom (id, name, door_x, door_y, door_dir, heightmap) (SELECT ?, ?, door_x, door_y, door_dir, heightmap FROM room_models_custom WHERE id = ? LIMIT 1)", Statement.RETURN_GENERATED_KEYS)) { statement.setInt(1, roomId); statement.setString(2, "custom_" + roomId); - statement.setInt(3, this.room.getId()); + statement.setInt(3, this.room.getRoomInfo().getId()); statement.execute(); } catch (SQLException e) { log.error("Caught SQL exception", e); @@ -189,18 +189,18 @@ 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.getCurrentBots()) { + 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()) { statement.setInt(1, userId); statement.setInt(2, roomId); - for (Bot bot : this.room.getCurrentBots().valueCollection()) { + for (Bot bot : this.room.getRoomUnitManager().getCurrentBots().values()) { statement.setString(3, bot.getName()); statement.setString(4, bot.getMotto()); statement.setString(5, bot.getFigure()); statement.setString(6, bot.getGender().name()); - statement.setInt(7, bot.getRoomUnit().getX()); - statement.setInt(8, bot.getRoomUnit().getY()); - statement.setDouble(9, bot.getRoomUnit().getZ()); + statement.setInt(7, bot.getRoomUnit().getCurrentPosition().getX()); + statement.setInt(8, bot.getRoomUnit().getCurrentPosition().getY()); + statement.setDouble(9, bot.getRoomUnit().getCurrentZ()); StringBuilder text = new StringBuilder(); for (String s : bot.getChatLines()) { text.append(s).append("\r"); @@ -221,17 +221,17 @@ public class RoomBundleLayout extends SingleBundle { log.error("Caught SQL exception", e); } - Room r = Emulator.getGameEnvironment().getRoomManager().loadRoom(roomId); - r.setWallHeight(this.room.getWallHeight()); - r.setFloorSize(this.room.getFloorSize()); - r.setWallPaint(this.room.getWallPaint()); - r.setFloorPaint(this.room.getFloorPaint()); - r.setScore(0); + Room r = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + r.getRoomInfo().setWallHeight(this.room.getRoomInfo().getWallHeight()); + r.getRoomInfo().setFloorThickness(this.room.getRoomInfo().getFloorThickness()); + r.getRoomInfo().setWallPaint(this.room.getRoomInfo().getWallPaint()); + r.getRoomInfo().setFloorPaint(this.room.getRoomInfo().getFloorPaint()); + r.getRoomInfo().setScore(0); r.setNeedsUpdate(true); THashMap keys = new THashMap<>(); - keys.put("ROOMNAME", r.getName()); - keys.put("ROOMID", r.getId() + ""); - keys.put("OWNER", r.getOwnerName()); + keys.put("ROOMNAME", r.getRoomInfo().getName()); + keys.put("ROOMID", r.getRoomInfo().getId() + ""); + keys.put("OWNER", r.getRoomInfo().getOwnerInfo().getUsername()); keys.put("image", "${image.library.url}/notifications/room_bundle_" + this.getId() + ".png"); if (habbo != null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java index e425f6ab..80668dee 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlace.java @@ -3,8 +3,8 @@ package com.eu.habbo.habbohotel.catalog.marketplace; import com.eu.habbo.Emulator; import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.incoming.catalog.marketplace.GetMarketplaceOffersEvent; import com.eu.habbo.messages.outgoing.catalog.marketplace.MarketplaceBuyOfferResultComposer; @@ -97,7 +97,7 @@ public class MarketPlace { selectItem.setInt(1, offer.getSoldItemId()); try (ResultSet set = selectItem.executeQuery()) { while (set.next()) { - HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set); + RoomItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set); habbo.getInventory().getItemsComponent().addItem(item); habbo.getClient().sendResponse(new MarketplaceCancelOfferResultComposer(offer, true)); habbo.getClient().sendResponse(new UnseenItemsComposer(item)); @@ -273,7 +273,7 @@ public class MarketPlace { updateOffer.execute(); } Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(set.getInt(DatabaseConstants.USER_ID)); - HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(itemSet); + RoomItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(itemSet); MarketPlaceItemSoldEvent event = new MarketPlaceItemSoldEvent(habbo, client.getHabbo(), item, set.getInt("price")); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) { @@ -281,8 +281,8 @@ public class MarketPlace { } event.price = calculateCommision(event.price); - item.setUserId(client.getHabbo().getHabboInfo().getId()); - item.needsUpdate(true); + item.setOwnerInfo(client.getHabbo().getHabboInfo()); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); client.getHabbo().getInventory().getItemsComponent().addItem(item); @@ -340,7 +340,7 @@ public class MarketPlace { } - public static boolean sellItem(GameClient client, HabboItem item, int price) { + public static boolean sellItem(GameClient client, RoomItem item, int price) { if (item == null || client == null) return false; @@ -362,8 +362,8 @@ public class MarketPlace { MarketPlaceOffer offer = new MarketPlaceOffer(event.getItem(), event.getPrice(), client.getHabbo()); client.getHabbo().getInventory().addMarketplaceOffer(offer); client.getHabbo().getInventory().getItemsComponent().removeHabboItem(event.getItem()); - item.setUserId(-1); - item.needsUpdate(true); + item.setOwnerInfo(null); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java index cada0040..481a79a2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java +++ b/src/main/java/com/eu/habbo/habbohotel/catalog/marketplace/MarketPlaceOffer.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -60,7 +60,7 @@ public class MarketPlaceOffer implements Runnable { } } - public MarketPlaceOffer(HabboItem item, int price, Habbo habbo) { + public MarketPlaceOffer(RoomItem item, int price, Habbo habbo) { this.price = price; this.baseItem = item.getBaseItem(); this.itemId = item.getId(); 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 160a354c..8d717d63 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/CommandsManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/CommandsManager.java @@ -3,12 +3,25 @@ package com.eu.habbo.habbohotel.commands; import com.eu.habbo.Emulator; import com.eu.habbo.core.CommandLog; import com.eu.habbo.habbohotel.commands.list.*; -import com.eu.habbo.habbohotel.commands.list.badge.*; -import com.eu.habbo.habbohotel.commands.list.bans.*; -import com.eu.habbo.habbohotel.commands.list.credits.*; -import com.eu.habbo.habbohotel.commands.list.gift.*; -import com.eu.habbo.habbohotel.commands.list.pixels.*; -import com.eu.habbo.habbohotel.commands.list.points.*; +import com.eu.habbo.habbohotel.commands.list.badge.BadgeCommand; +import com.eu.habbo.habbohotel.commands.list.badge.MassBadgeCommand; +import com.eu.habbo.habbohotel.commands.list.badge.RoomBadgeCommand; +import com.eu.habbo.habbohotel.commands.list.badge.TakeBadgeCommand; +import com.eu.habbo.habbohotel.commands.list.bans.BanCommand; +import com.eu.habbo.habbohotel.commands.list.bans.IPBanCommand; +import com.eu.habbo.habbohotel.commands.list.bans.MachineBanCommand; +import com.eu.habbo.habbohotel.commands.list.bans.SuperbanCommand; +import com.eu.habbo.habbohotel.commands.list.credits.CreditsCommand; +import com.eu.habbo.habbohotel.commands.list.credits.MassCreditsCommand; +import com.eu.habbo.habbohotel.commands.list.credits.RoomCreditsCommand; +import com.eu.habbo.habbohotel.commands.list.gift.GiftCommand; +import com.eu.habbo.habbohotel.commands.list.gift.MassGiftCommand; +import com.eu.habbo.habbohotel.commands.list.pixels.MassPixelsCommand; +import com.eu.habbo.habbohotel.commands.list.pixels.PixelCommand; +import com.eu.habbo.habbohotel.commands.list.pixels.RoomPixelsCommand; +import com.eu.habbo.habbohotel.commands.list.points.MassPointsCommand; +import com.eu.habbo.habbohotel.commands.list.points.PointsCommand; +import com.eu.habbo.habbohotel.commands.list.points.RoomPointsCommand; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.PermissionCommand; @@ -73,14 +86,17 @@ public class CommandsManager { } String commandKey = parts[0]; - Room currentRoom = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); - boolean hasRights = currentRoom != null && - (currentRoom.hasRights(gameClient.getHabbo())) || - gameClient.getHabbo().hasRight(Permission.ACC_PLACEFURNI) || - currentRoom.getGuildId() > 0 && currentRoom.getGuildRightLevel(gameClient.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS); + Room currentRoom = gameClient.getHabbo().getRoomUnit().getRoom(); + if(currentRoom == null) { + return false; + } - if (!gameClient.getHabbo().canExecuteCommand(commandKey, hasRights)) { + boolean hasRights = (currentRoom.getRoomRightsManager().hasRights(gameClient.getHabbo())) || gameClient.getHabbo().hasPermissionRight(Permission.ACC_PLACEFURNI) || (currentRoom.getRoomInfo().hasGuild() && currentRoom.getGuildRightLevel(gameClient.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS)); + + boolean canExecuteCommand = gameClient.getHabbo().canExecuteCommand(commandKey, hasRights); + + if (!canExecuteCommand) { return false; } @@ -127,17 +143,17 @@ public class CommandsManager { private boolean handlePetCommand(GameClient gameClient, String commandLine) { String[] args = commandLine.split(" "); - if (args.length <= 1 || gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) { + if (args.length <= 1 || gameClient.getHabbo().getRoomUnit().getRoom() == null) { return false; } - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - if (room.getCurrentPets().isEmpty()) { + if (room.getRoomUnitManager().getCurrentPets().isEmpty()) { return false; } - for(Pet pet : room.getCurrentPets().valueCollection()) { + for(Pet pet : room.getRoomUnitManager().getCurrentPets().values()) { if (pet != null && pet.getName().equalsIgnoreCase(args[0])) { StringBuilder commandBuilder = new StringBuilder(); @@ -150,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(); + rideablePet.getRider().getRoomUnit().dismountPet(false); break; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/ArcturusCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/ArcturusCommand.java index 6b3d8c94..d020247a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/ArcturusCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/ArcturusCommand.java @@ -11,7 +11,7 @@ public class ArcturusCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { gameClient.getHabbo().whisper("This hotel is powered by Arcturus Emulator! \r" + "Cet hôtel est alimenté par Arcturus émulateur! \r" + "Dit hotel draait op Arcturus Emulator! \r" + diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/BlockAlertCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/BlockAlertCommand.java index e7163ca4..bd95efcf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/BlockAlertCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/BlockAlertCommand.java @@ -11,7 +11,7 @@ public class BlockAlertCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { gameClient.getHabbo().getHabboStats().setBlockStaffAlerts(!gameClient.getHabbo().getHabboStats().isBlockStaffAlerts()); gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_blockalert").replace("%state%", (gameClient.getHabbo().getHabboStats().isBlockStaffAlerts() ? getTextsValue("generic.on") : getTextsValue("generic.off"))), RoomChatMessageBubbles.ALERT); 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 a5e8ac1d..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 @@ -12,12 +12,12 @@ public class BotsCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null || !gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) + if (gameClient.getHabbo().getRoomUnit().getRoom() == null || !gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo())) return false; - StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getCurrentBots().values().length); + StringBuilder data = new StringBuilder(getTextsValue("total") + ": " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentBots().values().size()); - for (Bot bot : gameClient.getHabbo().getHabboInfo().getCurrentRoom().getCurrentBots().valueCollection()) { + 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/CalendarCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/CalendarCommand.java index d996bebc..ae2b119a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/CalendarCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/CalendarCommand.java @@ -22,7 +22,7 @@ public class CalendarCommand extends Command { if (Emulator.getConfig().getBoolean("hotel.calendar.enabled")) { String campaignName = Emulator.getConfig().getValue("hotel.calendar.default"); - if (params.length > 1 && gameClient.getHabbo().hasCommand("cmd_calendar_staff")) { + if (params.length > 1 && gameClient.getHabbo().canExecuteCommand("cmd_calendar_staff")) { campaignName = params[1]; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/ChatTypeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/ChatTypeCommand.java index 95e25cef..5bca58a5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/ChatTypeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/ChatTypeCommand.java @@ -33,7 +33,7 @@ public class ChatTypeCommand extends Command { return true; } - if (!gameClient.getHabbo().hasRight(Permission.ACC_ANYCHATCOLOR)) { + if (!gameClient.getHabbo().hasPermissionRight(Permission.ACC_ANYCHATCOLOR)) { for (String s : Emulator.getConfig().getValue("commands.cmd_chatcolor.banned_numbers").split(";")) { if (Integer.parseInt(s) == chatColor) { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_chatcolor.banned"), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/CommandsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/CommandsCommand.java index 32a6727f..a6fe139a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/CommandsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/CommandsCommand.java @@ -1,11 +1,11 @@ package com.eu.habbo.habbohotel.commands.list; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.permissions.PermissionCommand; import java.util.Collections; -import java.util.Comparator; import java.util.List; public class CommandsCommand extends Command { @@ -17,13 +17,19 @@ public class CommandsCommand extends Command { public boolean handle(GameClient gameClient, String[] params) { StringBuilder message = new StringBuilder(getTextsValue("commands.generic.cmd_commands.text")); - List commands = gameClient.getHabbo().getHabboInfo().getPermissionGroup().getCommands(); + List commands = gameClient.getHabbo().getHabboInfo().getPermissionGroup().getCommands(); - Collections.sort(commands, Comparator.comparing(PermissionCommand::getName)); + Collections.sort(commands); message.append("(").append(commands.size()).append("):\r\n"); - for(PermissionCommand command : commands) { + for(String commandName : commands) { + PermissionCommand command = Emulator.getGameEnvironment().getPermissionsManager().getCommand(commandName); + + if(command == null) { + continue; + } + message.append(command.getDescription()).append("\r"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/ControlCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/ControlCommand.java index 76442da4..537e80bc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/ControlCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/ControlCommand.java @@ -12,7 +12,7 @@ public class ControlCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { if (params.length == 2) { Habbo target = getHabbo(params[1]); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/CoordsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/CoordsCommand.java index 0bbac1d8..09c043bd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/CoordsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/CoordsCommand.java @@ -12,24 +12,24 @@ public class CoordsCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getRoomUnit() == null || gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (gameClient.getHabbo().getRoomUnit() == null || gameClient.getHabbo().getRoomUnit().getRoom() == null) return false; if (params.length == 1) { gameClient.getHabbo().alert(getTextsValue("commands.generic.cmd_coords.title") + "\r\n" + - "x: " + gameClient.getHabbo().getRoomUnit().getX() + "\r" + - "y: " + gameClient.getHabbo().getRoomUnit().getY() + "\r" + - "z: " + (gameClient.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) ? gameClient.getHabbo().getRoomUnit().getStatus(RoomUnitStatus.SIT) : gameClient.getHabbo().getRoomUnit().getZ()) + "\r" + + "x: " + gameClient.getHabbo().getRoomUnit().getCurrentPosition().getX() + "\r" + + "y: " + gameClient.getHabbo().getRoomUnit().getCurrentPosition().getY() + "\r" + + "z: " + (gameClient.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) ? gameClient.getHabbo().getRoomUnit().getStatus(RoomUnitStatus.SIT) : gameClient.getHabbo().getRoomUnit().getCurrentZ()) + "\r" + getTextsValue("generic.rotation.head") + ": " + gameClient.getHabbo().getRoomUnit().getHeadRotation() + "-" + gameClient.getHabbo().getRoomUnit().getHeadRotation().getValue() + "\r" + getTextsValue("generic.rotation.body") + ": " + gameClient.getHabbo().getRoomUnit().getBodyRotation() + "-" + gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() + "\r" + getTextsValue("generic.sitting") + ": " + (gameClient.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.SIT) ? getTextsValue("generic.yes") : getTextsValue("generic.no")) + "\r" + - "Tile State: " + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getX(), gameClient.getHabbo().getRoomUnit().getY()).getState().name() + "\r" + - "Tile Walkable: " + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getX(), gameClient.getHabbo().getRoomUnit().getY()).isWalkable() + "\r" + - "Tile relative height: " + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getX(), gameClient.getHabbo().getRoomUnit().getY()).relativeHeight() + "\r" + - "Tile stack height: " + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getX(), gameClient.getHabbo().getRoomUnit().getY()).getStackHeight()); - + "Tile State: " + gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getCurrentPosition().getX(), gameClient.getHabbo().getRoomUnit().getCurrentPosition().getY()).getState().name() + "\r" + + "Tile Walkable: " + gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getCurrentPosition().getX(), gameClient.getHabbo().getRoomUnit().getCurrentPosition().getY()).isWalkable() + "\r" + + "Tile relative height: " + gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getCurrentPosition().getX(), gameClient.getHabbo().getRoomUnit().getCurrentPosition().getY()).relativeHeight() + "\r" + + "Tile stack height: " + gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTile(gameClient.getHabbo().getRoomUnit().getCurrentPosition().getX(), gameClient.getHabbo().getRoomUnit().getCurrentPosition().getY()).getStackHeight() + "\r" + + "Tile has Furni: " + (!gameClient.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getItemsAt(gameClient.getHabbo().getRoomUnit().getCurrentPosition()).isEmpty())); } else { - RoomTile tile = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(Short.parseShort(params[1]), Short.parseShort(params[2])); + RoomTile tile = gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTile(Short.parseShort(params[1]), Short.parseShort(params[2])); if (tile != null) { gameClient.getHabbo().alert(getTextsValue("commands.generic.cmd_coords.title") + "\r\n" + diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/DiagonalCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/DiagonalCommand.java index 6b841eea..d49942e3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/DiagonalCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/DiagonalCommand.java @@ -11,10 +11,10 @@ public class DiagonalCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) { - gameClient.getHabbo().getHabboInfo().getCurrentRoom().moveDiagonally(!gameClient.getHabbo().getHabboInfo().getCurrentRoom().moveDiagonally()); + if (gameClient.getHabbo().getRoomUnit().getRoom() != null && gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo())) { + gameClient.getHabbo().getRoomUnit().getRoom().setDiagonalMoveEnabled(!gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().isDiagonalMoveEnabled()); - if (!gameClient.getHabbo().getHabboInfo().getCurrentRoom().moveDiagonally()) { + if (!gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().isDiagonalMoveEnabled()) { gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_diagonal.disabled"), RoomChatMessageBubbles.ALERT); } else { gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_diagonal.enabled"), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/EjectAllCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/EjectAllCommand.java index b68e8c12..01a05e9f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/EjectAllCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/EjectAllCommand.java @@ -12,11 +12,12 @@ public class EjectAllCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - if (room != null && (room.isOwner(gameClient.getHabbo()) - || (room.hasGuild() && room.getGuildRightLevel(gameClient.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN)))) { - room.ejectAll(gameClient.getHabbo()); + if (room != null) { + if (room.getRoomInfo().isRoomOwner(gameClient.getHabbo()) || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(gameClient.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) { + room.getRoomItemManager().ejectAllFurni(gameClient.getHabbo()); + } } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyBotsInventoryCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyBotsInventoryCommand.java index 316c5421..f6be437c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyBotsInventoryCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyBotsInventoryCommand.java @@ -19,8 +19,8 @@ public class EmptyBotsInventoryCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length == 1 || (params.length >= 2 && !params[1].equals(getTextsValue("generic.yes")))) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom().getUserCount() > 10) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbosCount() > 10) { gameClient.getHabbo().alert(getTextsValue("commands.succes.cmd_empty_bots.verify").replace("%generic.yes%", getTextsValue("generic.yes"))); } else { gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_empty_bots.verify").replace("%generic.yes%", getTextsValue("generic.yes")), RoomChatMessageBubbles.ALERT); @@ -32,7 +32,7 @@ public class EmptyBotsInventoryCommand extends Command { if (params.length >= 2 && params[1].equalsIgnoreCase(getTextsValue("generic.yes"))) { - Habbo habbo = (params.length == 3 && gameClient.getHabbo().hasRight(Permission.ACC_EMPTY_OTHERS)) ? Emulator.getGameEnvironment().getHabboManager().getHabbo(params[2]) : gameClient.getHabbo(); + Habbo habbo = (params.length == 3 && gameClient.getHabbo().hasPermissionRight(Permission.ACC_EMPTY_OTHERS)) ? Emulator.getGameEnvironment().getHabboManager().getHabbo(params[2]) : gameClient.getHabbo(); if (habbo != null) { TIntObjectHashMap bots = new TIntObjectHashMap<>(); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyInventoryCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyInventoryCommand.java index 4298201e..9e77470c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyInventoryCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyInventoryCommand.java @@ -5,8 +5,8 @@ import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.inventory.FurniListComposer; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.threading.runnables.QueryDeleteHabboItems; @@ -21,8 +21,8 @@ public class EmptyInventoryCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length == 1 || (params.length == 2 && !params[1].equals(getTextsValue("generic.yes")))) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom().getUserCount() > 10) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbosCount() > 10) { gameClient.getHabbo().alert(getTextsValue("commands.succes.cmd_empty.verify").replace("%generic.yes%", getTextsValue("generic.yes"))); } else { gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_empty.verify").replace("%generic.yes%", getTextsValue("generic.yes")), RoomChatMessageBubbles.ALERT); @@ -34,10 +34,10 @@ public class EmptyInventoryCommand extends Command { if (params.length >= 2 && params[1].equalsIgnoreCase(getTextsValue("generic.yes"))) { - Habbo habbo = (params.length == 3 && gameClient.getHabbo().hasRight(Permission.ACC_EMPTY_OTHERS)) ? Emulator.getGameEnvironment().getHabboManager().getHabbo(params[2]) : gameClient.getHabbo(); + Habbo habbo = (params.length == 3 && gameClient.getHabbo().hasPermissionRight(Permission.ACC_EMPTY_OTHERS)) ? Emulator.getGameEnvironment().getHabboManager().getHabbo(params[2]) : gameClient.getHabbo(); if (habbo != null) { - TIntObjectMap items = new TIntObjectHashMap<>(); + TIntObjectMap items = new TIntObjectHashMap<>(); items.putAll(habbo.getInventory().getItemsComponent().getItems()); habbo.getInventory().getItemsComponent().getItems().clear(); Emulator.getThreading().run(new QueryDeleteHabboItems(items)); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyPetsInventoryCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyPetsInventoryCommand.java index d1679b9c..e35daa20 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyPetsInventoryCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/EmptyPetsInventoryCommand.java @@ -19,8 +19,8 @@ public class EmptyPetsInventoryCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length == 1 || (params.length >= 2 && !params[1].equals(getTextsValue("generic.yes")))) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom().getUserCount() > 10) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabbosCount() > 10) { gameClient.getHabbo().alert(getTextsValue("commands.succes.cmd_empty_pets.verify").replace("%generic.yes%", getTextsValue("generic.yes"))); } else { gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_empty_pets.verify").replace("%generic.yes%", getTextsValue("generic.yes")), RoomChatMessageBubbles.ALERT); @@ -32,7 +32,7 @@ public class EmptyPetsInventoryCommand extends Command { if (params.length >= 2 && params[1].equalsIgnoreCase(getTextsValue("generic.yes"))) { - Habbo habbo = (params.length == 3 && gameClient.getHabbo().hasRight(Permission.ACC_EMPTY_OTHERS)) ? Emulator.getGameEnvironment().getHabboManager().getHabbo(params[2]) : gameClient.getHabbo(); + Habbo habbo = (params.length == 3 && gameClient.getHabbo().hasPermissionRight(Permission.ACC_EMPTY_OTHERS)) ? Emulator.getGameEnvironment().getHabboManager().getHabbo(params[2]) : gameClient.getHabbo(); if (habbo != null) { TIntObjectHashMap pets = new TIntObjectHashMap<>(habbo.getInventory().getPetsComponent().getPets()); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/EnableCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/EnableCommand.java index d1ea3825..e1860133 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/EnableCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/EnableCommand.java @@ -31,15 +31,15 @@ public class EnableCommand extends Command { if (target == null) { return true; } - if (target == gameClient.getHabbo() || gameClient.getHabbo().hasRight(Permission.ACC_ENABLE_OTHERS)) { + if (target == gameClient.getHabbo() || gameClient.getHabbo().hasPermissionRight(Permission.ACC_ENABLE_OTHERS)) { try { - if (target.getHabboInfo().getCurrentRoom() != null && target.getHabboInfo().getRiding() == null) { + if (target.getRoomUnit().getRoom() != null && !target.getRoomUnit().isRiding()) { if (Emulator.getGameEnvironment().getPermissionsManager().isEffectBlocked(effectId, target.getHabboInfo().getPermissionGroup().getId())) { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_enable.not_allowed"), RoomChatMessageBubbles.ALERT); return true; } - target.getHabboInfo().getCurrentRoom().giveEffect(target, effectId, -1); + target.getRoomUnit().giveEffect(effectId, -1); } } catch (Exception e) { log.error("Caught exception", e); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/EventCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/EventCommand.java index 1ea5bf86..ed363e35 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/EventCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/EventCommand.java @@ -18,14 +18,14 @@ public class EventCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null || params.length < 2) { + if (gameClient.getHabbo().getRoomUnit().getRoom() == null || params.length < 2) { return false; } String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); THashMap codes = new THashMap<>(); - codes.put("ROOMNAME", gameClient.getHabbo().getHabboInfo().getCurrentRoom().getName()); - codes.put("ROOMID", gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId() + ""); + codes.put("ROOMNAME", gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getName()); + codes.put("ROOMID", gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId() + ""); codes.put("USERNAME", gameClient.getHabbo().getHabboInfo().getUsername()); codes.put("LOOK", gameClient.getHabbo().getHabboInfo().getLook()); codes.put("TIME", Emulator.getDate().toString()); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/FacelessCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/FacelessCommand.java index 88d9a95e..dbb4c7bd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/FacelessCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/FacelessCommand.java @@ -13,7 +13,7 @@ public class FacelessCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() == null) { return false; } @@ -34,7 +34,7 @@ public class FacelessCommand extends Command { gameClient.getHabbo().getHabboInfo().setLook(gameClient.getHabbo().getHabboInfo().getLook().replace(part, newHead)); gameClient.sendResponse(new FigureUpdateComposer(gameClient.getHabbo())); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(gameClient.getHabbo()).compose()); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(gameClient.getHabbo()).compose()); return true; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/FastwalkCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/FastwalkCommand.java index fc790173..cc5dfd75 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/FastwalkCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/FastwalkCommand.java @@ -11,10 +11,12 @@ public class FastwalkCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { + //TODO Make this an event plugin which fires that can be cancelled - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getRiding() != null) + if (gameClient.getHabbo().getRoomUnit().isRiding()) { return true; + } Habbo habbo = gameClient.getHabbo(); @@ -26,7 +28,8 @@ public class FastwalkCommand extends Command { if (habbo == null) return false; } - habbo.getRoomUnit().setFastWalk(!habbo.getRoomUnit().isFastWalk()); + + habbo.getRoomUnit().setCmdFastWalkEnabled(!habbo.getRoomUnit().isCmdFastWalkEnabled()); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeBotsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeBotsCommand.java index 3e579fa8..3737ee87 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeBotsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeBotsCommand.java @@ -12,14 +12,14 @@ public class FreezeBotsCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() == null) { return false; } - if (gameClient.getHabbo().getHabboInfo().getId() == gameClient.getHabbo().getHabboInfo().getCurrentRoom().getOwnerId() - || gameClient.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { - gameClient.getHabbo().getHabboInfo().getCurrentRoom().setAllowBotsWalk(!gameClient.getHabbo().getHabboInfo().getCurrentRoom().isAllowBotsWalk()); - gameClient.getHabbo().whisper(gameClient.getHabbo().getHabboInfo().getCurrentRoom().isAllowBotsWalk() ? getTextsValue("commands.succes.cmd_freeze_bots.unfrozen") : getTextsValue("commands.succes.cmd_freeze_bots.frozen"), RoomChatMessageBubbles.ALERT); + if (gameClient.getHabbo().getHabboInfo().getId() == gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId() + || gameClient.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + gameClient.getHabbo().getRoomUnit().getRoom().setAllowBotsWalk(!gameClient.getHabbo().getRoomUnit().getRoom().isAllowBotsWalk()); + gameClient.getHabbo().whisper(gameClient.getHabbo().getRoomUnit().getRoom().isAllowBotsWalk() ? getTextsValue("commands.succes.cmd_freeze_bots.unfrozen") : getTextsValue("commands.succes.cmd_freeze_bots.frozen"), RoomChatMessageBubbles.ALERT); } else { gameClient.getHabbo().whisper(getTextsValue("generic.cannot_do_that"), RoomChatMessageBubbles.ALERT); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeCommand.java index de2ed0b0..ac9e3895 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/FreezeCommand.java @@ -18,7 +18,7 @@ public class FreezeCommand extends Command { if (habbo == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_freeze.not_found"), params[1]), RoomChatMessageBubbles.ALERT); } else { - if (habbo.getRoomUnit().canWalk()) { + if (habbo.getRoomUnit().isCanWalk()) { habbo.getRoomUnit().setCanWalk(false); habbo.whisper(getTextsValue("commands.succes.cmd_freeze.frozen"), RoomChatMessageBubbles.ALERT); gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_freeze.user_frozen"), params[1]), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/GiveRankCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/GiveRankCommand.java index 3c832360..1e6dc93b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/GiveRankCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/GiveRankCommand.java @@ -6,7 +6,6 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.permissions.PermissionGroup; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import org.apache.commons.lang3.StringUtils; public class GiveRankCommand extends Command { @@ -40,7 +39,7 @@ public class GiveRankCommand extends Command { return true; } - HabboInfo habbo = HabboManager.getOfflineHabboInfo(params[1]); + HabboInfo habbo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); if (habbo != null) { if (habbo.getPermissionGroup().getId() > gameClient.getHabbo().getHabboInfo().getPermissionGroup().getId()) { diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/HabnamCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/HabnamCommand.java index 7c637fd4..b8e18ced 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/HabnamCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/HabnamCommand.java @@ -10,8 +10,8 @@ public class HabnamCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboStats().hasActiveClub() && gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { - gameClient.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(gameClient.getHabbo(), 140, 30); + if (gameClient.getHabbo().getHabboStats().hasActiveClub() && gameClient.getHabbo().getRoomUnit().getRoom() != null) { + gameClient.getHabbo().getRoomUnit().giveEffect(140, 30); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/HandItemCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/HandItemCommand.java index c14fba16..a2cd6844 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/HandItemCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/HandItemCommand.java @@ -13,10 +13,10 @@ public class HandItemCommand extends Command { public boolean handle(GameClient gameClient, String[] params) { if (params.length == 2) { try { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { int effectId = Integer.parseInt(params[1]); gameClient.getHabbo().getRoomUnit().setHandItem(effectId); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new CarryObjectMessageComposer(gameClient.getHabbo().getRoomUnit()).compose()); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(gameClient.getHabbo().getRoomUnit()).compose()); } } catch (Exception e) { //Don't handle incorrect parse exceptions :P diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/HideWiredCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/HideWiredCommand.java index a1a37ac0..b837f485 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/HideWiredCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/HideWiredCommand.java @@ -11,14 +11,14 @@ public class HideWiredCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room == null) { return true; } - if (room.isOwner(gameClient.getHabbo())) { - room.setHideWired(!room.isHideWired()); - gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_hidewired." + (room.isHideWired() ? "hidden" : "shown"))); + if (room.getRoomInfo().isRoomOwner(gameClient.getHabbo())) { + room.getRoomItemManager().getWiredManager().setHideWired(!room.getRoomInfo().isHiddenWiredEnabled()); + gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_hidewired." + (room.getRoomInfo().isHiddenWiredEnabled() ? "hidden" : "shown"))); } else { gameClient.getHabbo().whisper(getTextsValue("commands.errors.cmd_hidewired.permission")); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/InvisibleCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/InvisibleCommand.java index a89cf853..4e02621b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/InvisibleCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/InvisibleCommand.java @@ -3,7 +3,7 @@ package com.eu.habbo.habbohotel.commands.list; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; @@ -25,8 +25,7 @@ public class InvisibleCommand extends Command { new RoomUnitTeleport(roomUnit, roomUnit.getRoom(), roomLayout.getDoorTile().getX(), roomLayout.getDoorTile().getY(), roomLayout.getDoorTile().getZ(), 0).run(); - roomUnit.setInvisible(false) - .setInRoom(true); + roomUnit.setInvisible(false); roomUnit.getRoom().sendComposer(new RoomUsersComposer(gameClient.getHabbo()).compose()); roomUnit.getRoom().sendComposer(new UserUpdateComposer(roomUnit).compose()); @@ -41,7 +40,7 @@ public class InvisibleCommand extends Command { roomUnit.setInvisible(true); gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_invisible.updated")); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserRemoveMessageComposer(roomUnit).compose()); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new UserRemoveMessageComposer(roomUnit).compose()); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/LayCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/LayCommand.java index 0961d2ba..164b7fbb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/LayCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/LayCommand.java @@ -4,7 +4,7 @@ import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import java.util.stream.IntStream; @@ -19,24 +19,24 @@ public class LayCommand extends Command { if (gameClient.getHabbo().getRoomUnit() == null || !gameClient.getHabbo().getRoomUnit().canForcePosture()) return true; - gameClient.getHabbo().getRoomUnit().setCmdLay(true); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().updateHabbo(gameClient.getHabbo()); - gameClient.getHabbo().getRoomUnit().setCmdSit(true); - gameClient.getHabbo().getRoomUnit().setBodyRotation(RoomUserRotation.values()[gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() - gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() % 2]); + gameClient.getHabbo().getRoomUnit().setCmdLayEnabled(true); + gameClient.getHabbo().getRoomUnit().getRoom().updateRoomUnit(gameClient.getHabbo().getRoomUnit()); + gameClient.getHabbo().getRoomUnit().setCmdSitEnabled(true); + gameClient.getHabbo().getRoomUnit().setBodyRotation(RoomRotation.values()[gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() - gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue() % 2]); - RoomTile tile = gameClient.getHabbo().getRoomUnit().getCurrentLocation(); + RoomTile tile = gameClient.getHabbo().getRoomUnit().getCurrentPosition(); if (tile == null) { return false; } if (IntStream.range(0, 3) - .mapToObj(i -> gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(tile, gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue(), i)) + .mapToObj(i -> gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTileInFront(tile, gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue(), i)) .anyMatch(t -> t == null || !t.isWalkable())) { return false; } - gameClient.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.LAY, 0.5 + ""); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserUpdateComposer(gameClient.getHabbo().getRoomUnit()).compose()); + gameClient.getHabbo().getRoomUnit().addStatus(RoomUnitStatus.LAY, 0.5 + ""); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(gameClient.getHabbo().getRoomUnit()).compose()); return true; } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/MimicCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/MimicCommand.java index 91be1f99..f2053acd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/MimicCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/MimicCommand.java @@ -19,7 +19,7 @@ public class MimicCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length == 2) { - Habbo habbo = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(params[1]); + Habbo habbo = gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboByUsername(params[1]); if (habbo == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_mimic.not_found"), ""), RoomChatMessageBubbles.ALERT); @@ -29,17 +29,17 @@ public class MimicCommand extends Command { if (habbo == gameClient.getHabbo()) { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_mimic.not_self"), RoomChatMessageBubbles.ALERT); return true; - } else if (habbo.hasRight(Permission.ACC_NOT_MIMICED) && !gameClient.getHabbo().hasRight(Permission.ACC_NOT_MIMICED)) { + } else if (habbo.hasPermissionRight(Permission.ACC_NOT_MIMICED) && !gameClient.getHabbo().hasPermissionRight(Permission.ACC_NOT_MIMICED)) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_mimic.blocked"), params[1]).replace("%gender_name%", getGenderName(habbo)), RoomChatMessageBubbles.ALERT); return true; - } else if (!habbo.hasRight(Permission.ACC_MIMIC_UNREDEEMED) && FigureUtil.hasBlacklistedClothing(habbo.getHabboInfo().getLook(), gameClient.getHabbo().getForbiddenClothing())) { + } else if (!habbo.hasPermissionRight(Permission.ACC_MIMIC_UNREDEEMED) && FigureUtil.hasBlacklistedClothing(habbo.getHabboInfo().getLook(), gameClient.getHabbo().getForbiddenClothing())) { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_mimic.forbidden_clothing"), RoomChatMessageBubbles.ALERT); return true; } else { gameClient.getHabbo().getHabboInfo().setLook(ClothingValidationManager.VALIDATE_ON_MIMIC ? ClothingValidationManager.validateLook(gameClient.getHabbo(), habbo.getHabboInfo().getLook(), habbo.getHabboInfo().getGender().name()) : habbo.getHabboInfo().getLook()); gameClient.getHabbo().getHabboInfo().setGender(habbo.getHabboInfo().getGender()); gameClient.sendResponse(new UserObjectComposer(gameClient.getHabbo())); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(gameClient.getHabbo()).compose()); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(gameClient.getHabbo()).compose()); gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_mimic.copied"), params[1]).replace("%gender_name%", getGenderName(habbo)), RoomChatMessageBubbles.ALERT); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/MoonwalkCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/MoonwalkCommand.java index 5c03d536..191ffd98 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/MoonwalkCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/MoonwalkCommand.java @@ -10,12 +10,12 @@ public class MoonwalkCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboStats().hasActiveClub()) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null && gameClient.getHabbo().getHabboStats().hasActiveClub()) { int effect = 136; if (gameClient.getHabbo().getRoomUnit().getEffectId() == 136) effect = 0; - gameClient.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(gameClient.getHabbo(), effect, -1); + gameClient.getHabbo().getRoomUnit().giveEffect(effect, -1); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/MuteCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/MuteCommand.java index b92589b8..da3a6ab1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/MuteCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/MuteCommand.java @@ -46,8 +46,8 @@ public class MuteCommand extends Command { habbo.mute(duration, false); - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.MUTED).compose()); //: RoomUserIgnoredComposer.UNIGNORED + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.MUTED).compose()); //: RoomUserIgnoredComposer.UNIGNORED } gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_mute.muted"), params[1]), RoomChatMessageBubbles.ALERT); 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 5ffafb07..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 @@ -16,12 +16,12 @@ public class PetInfoCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_pet_info.pet_not_found"), RoomChatMessageBubbles.ALERT); return true; } - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (gameClient.getHabbo().getRoomUnit().getRoom() == null) return false; String name = params[1]; - gameClient.getHabbo().getHabboInfo().getCurrentRoom().getCurrentPets().forEachEntry((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" + @@ -37,11 +37,9 @@ public class PetInfoCommand extends Command { getTextsValue("generic.pet.level.thirst") + ": " + pet.levelThirst + "\r" + getTextsValue("generic.pet.level.hunger") + ": " + pet.levelHunger + "\r" + getTextsValue("generic.pet.current_action") + ": " + (pet.getTask() == null ? getTextsValue("generic.nothing") : pet.getTask().name()) + "\r" + - getTextsValue("generic.can.walk") + ": " + (pet.getRoomUnit().canWalk() ? getTextsValue("generic.yes") : getTextsValue("generic.no")) + "" + getTextsValue("generic.can.walk") + ": " + (pet.getRoomUnit().isCanWalk() ? getTextsValue("generic.yes") : getTextsValue("generic.no")) + "" ); } - - return true; }); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/PickallCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/PickallCommand.java index cd0d6887..f07f1bc1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/PickallCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/PickallCommand.java @@ -11,18 +11,18 @@ public class PickallCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room == null) { return true; } - if (room.isOwner(gameClient.getHabbo())) { - room.ejectAll(); + if (room.getRoomInfo().isRoomOwner(gameClient.getHabbo())) { + room.getRoomItemManager().ejectAllFurni(); return true; } - room.ejectUserFurni(gameClient.getHabbo().getHabboInfo().getId()); + room.getRoomItemManager().ejectUserFurni(gameClient.getHabbo().getHabboInfo().getId()); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/PullCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/PullCommand.java index 3b78f9db..da1c4285 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/PullCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/PullCommand.java @@ -17,7 +17,7 @@ public class PullCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length != 2) return true; - Habbo habbo = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(params[1]); + Habbo habbo = gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboByUsername(params[1]); if (habbo == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_pull.not_found"), params[1]), RoomChatMessageBubbles.ALERT); @@ -27,22 +27,22 @@ public class PullCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_pull.pull_self"), RoomChatMessageBubbles.ALERT); return true; } - int distanceX = habbo.getRoomUnit().getX() - gameClient.getHabbo().getRoomUnit().getX(); - int distanceY = habbo.getRoomUnit().getY() - gameClient.getHabbo().getRoomUnit().getY(); + int distanceX = habbo.getRoomUnit().getCurrentPosition().getX() - gameClient.getHabbo().getRoomUnit().getCurrentPosition().getX(); + int distanceY = habbo.getRoomUnit().getCurrentPosition().getY() - gameClient.getHabbo().getRoomUnit().getCurrentPosition().getY(); if (distanceX < -2 || distanceX > 2 || distanceY < -2 || distanceY > 2) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_pull.cant_reach"), params[1]), RoomChatMessageBubbles.ALERT); return true; } - RoomTile tile = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(gameClient.getHabbo().getRoomUnit().getCurrentLocation(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); + RoomTile tile = gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTileInFront(gameClient.getHabbo().getRoomUnit().getCurrentPosition(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); if (tile != null && tile.isWalkable()) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getDoorTile() == tile) { + if (gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getDoorTile() == tile) { gameClient.getHabbo().whisper(replaceUsername(getTextsValue("commands.error.cmd_pull.invalid"), params[1])); return true; } - habbo.getRoomUnit().setGoalLocation(tile); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(replaceUser(getTextsValue("commands.succes.cmd_pull.pull"), params[1]).replace("%gender_name%", (gameClient.getHabbo().getHabboInfo().getGender().equals(HabboGender.M) ? getTextsValue("gender.him") : getTextsValue("gender.her"))), gameClient.getHabbo(), gameClient.getHabbo(), RoomChatMessageBubbles.NORMAL)).compose()); + habbo.getRoomUnit().walkTo(tile); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(replaceUser(getTextsValue("commands.succes.cmd_pull.pull"), params[1]).replace("%gender_name%", (gameClient.getHabbo().getHabboInfo().getGender().equals(HabboGender.M) ? getTextsValue("gender.him") : getTextsValue("gender.her"))), gameClient.getHabbo(), gameClient.getHabbo(), RoomChatMessageBubbles.NORMAL)).compose()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/PushCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/PushCommand.java index e440af6f..a14768b6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/PushCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/PushCommand.java @@ -18,7 +18,7 @@ public class PushCommand extends Command { public boolean handle(GameClient gameClient, String[] params) { if (params.length != 2) return true; - Habbo habbo = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(params[1]); + Habbo habbo = gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboByUsername(params[1]); if (habbo == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_push.not_found"), params[1]), RoomChatMessageBubbles.ALERT); @@ -29,19 +29,19 @@ public class PushCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_push.push_self"), RoomChatMessageBubbles.ALERT); return true; } - RoomTile tFront = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(gameClient.getHabbo().getRoomUnit().getCurrentLocation(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); + RoomTile tFront = gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTileInFront(gameClient.getHabbo().getRoomUnit().getCurrentPosition(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); if (tFront != null && tFront.isWalkable()) { - if (tFront.getX() == habbo.getRoomUnit().getX() && tFront.getY() == habbo.getRoomUnit().getY()) { - RoomTile tFrontTarget = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(habbo.getRoomUnit().getCurrentLocation(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); + if (tFront.getX() == habbo.getRoomUnit().getCurrentPosition().getX() && tFront.getY() == habbo.getRoomUnit().getCurrentPosition().getY()) { + RoomTile tFrontTarget = gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTileInFront(habbo.getRoomUnit().getCurrentPosition(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); if (tFrontTarget != null && tFrontTarget.isWalkable()) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getDoorTile() == tFrontTarget) { + if (gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getDoorTile() == tFrontTarget) { gameClient.getHabbo().whisper(replaceUsername(getTextsValue("commands.error.cmd_push.invalid"), params[1])); return true; } - habbo.getRoomUnit().setGoalLocation(tFrontTarget); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer( + habbo.getRoomUnit().walkTo(tFrontTarget); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer( new ChatMessageComposer( new RoomChatMessage( replaceUser(getTextsValue("commands.succes.cmd_push.push"), params[1]) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RedeemCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RedeemCommand.java index a0b32f1c..6a939ff7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RedeemCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RedeemCommand.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.threading.runnables.QueryDeleteHabboItems; import gnu.trove.map.TIntIntMap; @@ -20,17 +20,17 @@ public class RedeemCommand extends Command { @Override public boolean handle(final GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(gameClient.getHabbo()) != null) + if (gameClient.getHabbo().getRoomUnit().getRoom().getActiveTradeForHabbo(gameClient.getHabbo()) != null) return false; - ArrayList items = new ArrayList<>(); + ArrayList items = new ArrayList<>(); int credits = 0; int pixels = 0; TIntIntMap points = new TIntIntHashMap(); - for (HabboItem item : gameClient.getHabbo().getInventory().getItemsComponent().getItemsAsValueCollection()) { - if ((item.getBaseItem().getName().startsWith("CF_") || item.getBaseItem().getName().startsWith("CFC_") || item.getBaseItem().getName().startsWith("DF_") || item.getBaseItem().getName().startsWith("PF_")) && item.getUserId() == gameClient.getHabbo().getHabboInfo().getId()) { + for (RoomItem item : gameClient.getHabbo().getInventory().getItemsComponent().getItemsAsValueCollection()) { + if ((item.getBaseItem().getName().startsWith("CF_") || item.getBaseItem().getName().startsWith("CFC_") || item.getBaseItem().getName().startsWith("DF_") || item.getBaseItem().getName().startsWith("PF_")) && item.getOwnerInfo().getId() == gameClient.getHabbo().getHabboInfo().getId()) { items.add(item); if ((item.getBaseItem().getName().startsWith("CF_") || item.getBaseItem().getName().startsWith("CFC_")) && !item.getBaseItem().getName().contains("_diamond_")) { try { @@ -63,7 +63,7 @@ public class RedeemCommand extends Command { } } - TIntObjectHashMap deleted = new TIntObjectHashMap<>(); + TIntObjectHashMap deleted = new TIntObjectHashMap<>(); items.forEach(item -> { gameClient.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); deleted.put(item.getId(), item); 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 0dbd9e8c..63c0947e 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 @@ -19,12 +19,12 @@ public class ReloadRoomCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { Emulator.getThreading().run(() -> { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room != null) { - Collection habbos = new ArrayList<>(room.getHabbos()); - Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); - room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); - ServerMessage message = new RoomForwardMessageComposer(room.getId()).compose(); + Collection habbos = new ArrayList<>(room.getRoomUnitManager().getCurrentHabbos().values()); + room.dispose(); + room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId()); + ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose(); habbos.forEach(habbo -> habbo.getClient().sendResponse(message)); } }, 100); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RightsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RightsCommand.java index 70ad2b80..7c75c86e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RightsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RightsCommand.java @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.commands.list; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.permissions.PermissionRight; @@ -15,11 +16,17 @@ public class RightsCommand extends Command { public boolean handle(GameClient gameClient, String[] params) throws Exception { StringBuilder message = new StringBuilder(getTextsValue("commands.generic.cmd_rights.text")); - Set rights = gameClient.getHabbo().getHabboInfo().getPermissionGroup().getRights(); + Set rights = gameClient.getHabbo().getHabboInfo().getPermissionGroup().getRights(); message.append("(").append(rights.size()).append("):\r\n"); - for(PermissionRight right : rights) { + for(String rightName : rights) { + PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(rightName); + + if(right == null) { + continue; + } + message.append(right.getName()).append(" - ").append(right.getDescription()).append("\r"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomAlertCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomAlertCommand.java index 36fff7ee..5a542b86 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomAlertCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomAlertCommand.java @@ -28,7 +28,7 @@ public class RoomAlertCommand extends Command { return true; } - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room != null) { room.sendComposer(new IssueCloseNotificationMessageComposer(message).compose()); return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomBundleCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomBundleCommand.java index 958be816..f59d01c1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomBundleCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomBundleCommand.java @@ -30,7 +30,7 @@ public class RoomBundleCommand extends Command { return true; } - if (Emulator.getGameEnvironment().getCatalogManager().getCatalogPage("room_bundle_" + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId()) != null) { + if (Emulator.getGameEnvironment().getCatalogManager().getCatalogPage("room_bundle_" + gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId()) != null) { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_bundle.duplicate"), RoomChatMessageBubbles.ALERT); return true; } @@ -40,7 +40,7 @@ public class RoomBundleCommand extends Command { points = Integer.parseInt(params[3]); pointsType = Integer.parseInt(params[4]); - CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().createCatalogPage("Room Bundle: " + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getName(), "room_bundle_" + gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId(), gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId(), 0, CatalogPageLayouts.room_bundle, gameClient.getHabbo().getHabboInfo().getPermissionGroup().getId(), parentId); + CatalogPage page = Emulator.getGameEnvironment().getCatalogManager().createCatalogPage("Room Bundle: " + gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getName(), "room_bundle_" + gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId(), gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId(), 0, CatalogPageLayouts.room_bundle, gameClient.getHabbo().getHabboInfo().getPermissionGroup().getId(), parentId); if (page instanceof RoomBundleLayout roomBundleLayout) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO catalog_items (page_id, item_ids, catalog_name, cost_credits, cost_points, points_type ) VALUES (?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { @@ -67,7 +67,7 @@ public class RoomBundleCommand extends Command { } catch (SQLException e) { log.error("Caught SQL exception", e); } - roomBundleLayout.loadItems(gameClient.getHabbo().getHabboInfo().getCurrentRoom()); + roomBundleLayout.loadItems(gameClient.getHabbo().getRoomUnit().getRoom()); gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_bundle").replace("%id%", roomBundleLayout.getId() + ""), RoomChatMessageBubbles.ALERT); } 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 bf39fef0..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,9 +28,9 @@ public class RoomDanceCommand extends Command { return true; } - gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbos().forEach(habbo -> { + gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values().forEach(habbo -> { habbo.getRoomUnit().setDanceType(DanceType.values()[danceId]); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose()); + habbo.getRoomUnit().getRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose()); }); } else { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_danceall.no_dance"), RoomChatMessageBubbles.ALERT); 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 d164a3a0..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 @@ -21,8 +21,8 @@ public class RoomEffectCommand extends Command { int effectId = Integer.parseInt(params[1]); if (effectId >= 0) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); - room.getHabbos().forEach(habbo -> room.giveEffect(habbo, effectId, -1)); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); + 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 0fd9b203..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,9 +29,9 @@ public class RoomItemCommand extends Command { } } - for (Habbo habbo : gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbos()) { + for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getCurrentHabbos().values()) { habbo.getRoomUnit().setHandItem(itemId); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose()); + habbo.getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose()); } if (itemId > 0) { 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 6b0e8ae9..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 @@ -17,15 +17,15 @@ public class RoomKickCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - final Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + final Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room != null) { if (params.length > 1) { String message = IntStream.range(1, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); room.sendComposer(new HabboBroadcastMessageComposer(message + "\r\n-" + gameClient.getHabbo().getHabboInfo().getUsername()).compose()); } - for (Habbo habbo : room.getHabbos()) { - if (!(habbo.hasRight(Permission.ACC_UNKICKABLE) || habbo.hasRight(Permission.ACC_SUPPORTTOOL) || room.isOwner(habbo))) { + 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/RoomMuteCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomMuteCommand.java index 3e97d0e6..d07c0bdc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomMuteCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/RoomMuteCommand.java @@ -13,7 +13,7 @@ public class RoomMuteCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); if (room != null) { room.setMuted(!room.isMuted()); 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 0f375fbe..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,13 +11,13 @@ public class RoomSitCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbos().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)) { return; } - gameClient.getHabbo().getHabboInfo().getCurrentRoom().makeSit(habbo); + gameClient.getHabbo().getRoomUnit().makeSit(); }); return true; 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 262a6ee0..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().getHabboInfo().getCurrentRoom().getHabbos().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/SayCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SayCommand.java index 3320b9d3..70dbe876 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SayCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SayCommand.java @@ -28,7 +28,7 @@ public class SayCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_say.user_not_found"), RoomChatMessageBubbles.ALERT); return true; } else { - if (target.getHabboInfo().getCurrentRoom() == null) { + if (target.getRoomUnit().getRoom() == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_say.hotel_view"), params[1]), RoomChatMessageBubbles.ALERT); return true; } @@ -39,7 +39,7 @@ public class SayCommand extends Command { message = IntStream.range(2, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); } - target.getHabboInfo().getCurrentRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(message, target, RoomChatMessageBubbles.NORMAL)).compose()); + target.getRoomUnit().getRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(message, target, RoomChatMessageBubbles.NORMAL)).compose()); gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_say"), params[1]).replace("%message%", message), RoomChatMessageBubbles.ALERT); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SetMaxCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SetMaxCommand.java index c512e42d..2081a269 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SetMaxCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SetMaxCommand.java @@ -20,7 +20,7 @@ public class SetMaxCommand extends Command { } if (max > 0 && max < 9999) { - gameClient.getHabbo().getHabboInfo().getCurrentRoom().setUsersMax(max); + gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().setMaxUsers(max); gameClient.getHabbo().whisper(getTextsValue("commands.success.cmd_setmax").replace("%value%", max + ""), RoomChatMessageBubbles.ALERT); } else { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_setmax.invalid_number"), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SetPollCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SetPollCommand.java index 3682b784..cc2e030f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SetPollCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SetPollCommand.java @@ -17,7 +17,7 @@ public class SetPollCommand extends Command { return true; } - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (gameClient.getHabbo().getRoomUnit().getRoom() != null) { int pollId = -1; try { pollId = Integer.parseInt(params[1]); @@ -25,7 +25,7 @@ public class SetPollCommand extends Command { if (pollId >= 0) { if (Emulator.getGameEnvironment().getPollManager().getPoll(pollId) != null) { - gameClient.getHabbo().getHabboInfo().getCurrentRoom().setPollId(pollId); + gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().setPollId(pollId); gameClient.getHabbo().whisper(getTextsValue("commands.succes.cmd_set_poll"), RoomChatMessageBubbles.ALERT); } else { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_set_poll.not_found"), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SetSpeedCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SetSpeedCommand.java index 9525c6fc..bf826518 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SetSpeedCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SetSpeedCommand.java @@ -13,10 +13,10 @@ public class SetSpeedCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() != null && gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasRights(gameClient.getHabbo())) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + if (gameClient.getHabbo().getRoomUnit().getRoom() != null && gameClient.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(gameClient.getHabbo())) { + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - int oldSpeed = room.getRollerSpeed(); + int oldSpeed = room.getRoomInfo().getRollerSpeed(); int newSpeed; try { 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 128339ac..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().getHabboInfo().getCurrentRoom().getHabbos()) { + 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/ShoutCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutCommand.java index a19529e2..32bb8a85 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/ShoutCommand.java @@ -29,7 +29,7 @@ public class ShoutCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_shout.user_not_found"), RoomChatMessageBubbles.ALERT); return true; } else { - if (target.getHabboInfo().getCurrentRoom() == null) { + if (target.getRoomUnit().getRoom() == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_shout.hotel_view"), params[1]), RoomChatMessageBubbles.ALERT); return true; } @@ -40,7 +40,7 @@ public class ShoutCommand extends Command { message = IntStream.range(2, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()); } - target.getHabboInfo().getCurrentRoom().sendComposer(new ShoutMessageComposer(new RoomChatMessage(message, target, RoomChatMessageBubbles.NORMAL)).compose()); + target.getRoomUnit().getRoom().sendComposer(new ShoutMessageComposer(new RoomChatMessage(message, target, RoomChatMessageBubbles.NORMAL)).compose()); gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_shout"), params[1]).replace("%message%", message), RoomChatMessageBubbles.ALERT); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SitCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SitCommand.java index 0e8703f0..66667785 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SitCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SitCommand.java @@ -10,8 +10,8 @@ public class SitCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getRiding() == null) //TODO Make this an event plugin which fires that can be cancelled - gameClient.getHabbo().getHabboInfo().getCurrentRoom().makeSit(gameClient.getHabbo()); + if (!gameClient.getHabbo().getRoomUnit().isRiding()) //TODO Make this an event plugin which fires that can be cancelled + gameClient.getHabbo().getRoomUnit().makeSit(); return true; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SoftKickCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SoftKickCommand.java index 8bd98051..7e97d4c1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SoftKickCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SoftKickCommand.java @@ -15,7 +15,7 @@ public class SoftKickCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length != 2) return true; - final Habbo habbo = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(params[1]); + final Habbo habbo = gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboByUsername(params[1]); if (habbo == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.keys.cmd_softkick_error"), params[1]), RoomChatMessageBubbles.ALERT); @@ -27,9 +27,9 @@ public class SoftKickCommand extends Command { return true; } - final Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + final Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - if (room != null && (!(habbo.hasRight(Permission.ACC_UNKICKABLE) || habbo.hasRight(Permission.ACC_SUPPORTTOOL) || room.isOwner(habbo)))) { + if (room != null && (!(habbo.hasPermissionRight(Permission.ACC_UNKICKABLE) || habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL) || room.getRoomInfo().isRoomOwner(habbo)))) { room.kickHabbo(habbo, false); } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/StalkCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/StalkCommand.java index 928a1d55..e1b41502 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/StalkCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/StalkCommand.java @@ -13,7 +13,7 @@ public class StalkCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (gameClient.getHabbo().getRoomUnit().getRoom() == null) return true; if (params.length >= 2) { @@ -24,7 +24,7 @@ public class StalkCommand extends Command { return true; } - if (habbo.getHabboInfo().getCurrentRoom() == null) { + if (habbo.getRoomUnit().getRoom() == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_stalk.not_room"), params[1]), RoomChatMessageBubbles.ALERT); return true; } @@ -34,12 +34,12 @@ public class StalkCommand extends Command { return true; } - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == habbo.getHabboInfo().getCurrentRoom()) { + if (gameClient.getHabbo().getRoomUnit().getRoom() == habbo.getRoomUnit().getRoom()) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.generic.cmd_stalk.same_room"), params[1]), RoomChatMessageBubbles.ALERT); return true; } - gameClient.sendResponse(new GetGuestRoomResultComposer(habbo.getHabboInfo().getCurrentRoom(), gameClient.getHabbo(), true, false)); + gameClient.sendResponse(new GetGuestRoomResultComposer(habbo.getRoomUnit().getRoom(), gameClient.getHabbo(), true, false)); } else { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_stalk.forgot_username"), RoomChatMessageBubbles.ALERT); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/StandCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/StandCommand.java index f14e36b6..9f65e5a0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/StandCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/StandCommand.java @@ -10,8 +10,10 @@ public class StandCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getRiding() == null) - gameClient.getHabbo().getHabboInfo().getCurrentRoom().makeStand(gameClient.getHabbo()); + if (!gameClient.getHabbo().getRoomUnit().isRiding()) { + gameClient.getHabbo().getRoomUnit().makeStand(); + } + return true; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SubscriptionCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SubscriptionCommand.java index 70618942..bd1e8f85 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SubscriptionCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SubscriptionCommand.java @@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.habbohotel.users.HabboStats; import com.eu.habbo.habbohotel.users.subscriptions.Subscription; @@ -45,7 +44,7 @@ public class SubscriptionCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_subscription.invalid_params", "Invalid command format"), RoomChatMessageBubbles.ALERT); return true; } - HabboInfo info = HabboManager.getOfflineHabboInfo(params[1]); + HabboInfo info = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); if (info == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_subscription.user_not_found", "%user% was not found"), params[1]), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonCommand.java index f889259b..1c679c37 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonCommand.java @@ -15,7 +15,7 @@ public class SummonCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (gameClient.getHabbo().getRoomUnit().getRoom() == null) return true; if (params.length < 2) { @@ -35,23 +35,23 @@ public class SummonCommand extends Command { return true; } - if (gameClient.getHabbo().getHabboInfo().getCurrentRoom() == habbo.getHabboInfo().getCurrentRoom()) { + if (gameClient.getHabbo().getRoomUnit().getRoom() == habbo.getRoomUnit().getRoom()) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.generic.cmd_summon.same_room"), params[1]), RoomChatMessageBubbles.ALERT); return true; } - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); + + //WHY? Why not just roomManager -> leaveRoom() if (room != null) { Emulator.getGameEnvironment().getRoomManager().logExit(habbo); - room.removeHabbo(habbo, true); - - habbo.getHabboInfo().setCurrentRoom(null); + room.getRoomUnitManager().removeHabbo(habbo, true); } - Emulator.getGameEnvironment().getRoomManager().enterRoom(habbo, gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId(), "", true); + Emulator.getGameEnvironment().getRoomManager().enterRoom(habbo, gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId(), "", true); - habbo.getClient().sendResponse(new RoomForwardMessageComposer(gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId())); + habbo.getClient().sendResponse(new RoomForwardMessageComposer(gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId())); gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_summon.summoned"), params[1]), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonRankCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonRankCommand.java index efc1ef4b..07e38c0b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonRankCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SummonRankCommand.java @@ -30,21 +30,19 @@ public class SummonRankCommand extends Command { if (habbo == gameClient.getHabbo()) continue; - if (habbo.getHabboInfo().getCurrentRoom() == gameClient.getHabbo().getHabboInfo().getCurrentRoom()) + if (habbo.getRoomUnit().getRoom() == gameClient.getHabbo().getRoomUnit().getRoom()) continue; - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); if (room != null) { Emulator.getGameEnvironment().getRoomManager().logExit(habbo); - room.removeHabbo(habbo, true); - - habbo.getHabboInfo().setCurrentRoom(null); + room.getRoomUnitManager().removeHabbo(habbo, true); } - Emulator.getGameEnvironment().getRoomManager().enterRoom(habbo, gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId(), "", true); + Emulator.getGameEnvironment().getRoomManager().enterRoom(habbo, gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId(), "", true); - habbo.getClient().sendResponse(new RoomForwardMessageComposer(gameClient.getHabbo().getHabboInfo().getCurrentRoom().getId())); + habbo.getClient().sendResponse(new RoomForwardMessageComposer(gameClient.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId())); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/SuperPullCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/SuperPullCommand.java index a783adea..852230a9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/SuperPullCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/SuperPullCommand.java @@ -20,7 +20,7 @@ public class SuperPullCommand extends Command { return true; } - Habbo habbo = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(params[1]); + Habbo habbo = gameClient.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboByUsername(params[1]); if (habbo == null) { gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.error.cmd_pull.not_found"), params[1]), RoomChatMessageBubbles.ALERT); @@ -29,15 +29,15 @@ public class SuperPullCommand extends Command { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_pull.pull_self"), RoomChatMessageBubbles.ALERT); return true; } else { - RoomTile tile = gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTileInFront(gameClient.getHabbo().getRoomUnit().getCurrentLocation(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); + RoomTile tile = gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getTileInFront(gameClient.getHabbo().getRoomUnit().getCurrentPosition(), gameClient.getHabbo().getRoomUnit().getBodyRotation().getValue()); if (tile != null && tile.isWalkable()) { - if (tile == gameClient.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getDoorTile()) { + if (tile == gameClient.getHabbo().getRoomUnit().getRoom().getLayout().getDoorTile()) { gameClient.getHabbo().whisper(replaceUsername(getTextsValue("commands.error.cmd_pull.invalid"), params[1]), RoomChatMessageBubbles.ALERT); return true; } - habbo.getRoomUnit().setGoalLocation(tile); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(replaceUser(getTextsValue("commands.succes.cmd_pull.pull"), params[1]).replace("%gender_name%", (gameClient.getHabbo().getHabboInfo().getGender().equals(HabboGender.M) ? getTextsValue("gender.him") : getTextsValue("gender.her"))), gameClient.getHabbo(), gameClient.getHabbo(), RoomChatMessageBubbles.NORMAL)).compose()); + habbo.getRoomUnit().walkTo(tile); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(replaceUser(getTextsValue("commands.succes.cmd_pull.pull"), params[1]).replace("%gender_name%", (gameClient.getHabbo().getHabboInfo().getGender().equals(HabboGender.M) ? getTextsValue("gender.him") : getTextsValue("gender.her"))), gameClient.getHabbo(), gameClient.getHabbo(), RoomChatMessageBubbles.NORMAL)).compose()); } } return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/TeleportCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/TeleportCommand.java index b39d024a..518b44fa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/TeleportCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/TeleportCommand.java @@ -12,16 +12,16 @@ public class TeleportCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo().getHabboInfo().getRiding() != null){ //TODO Make this an event plugin which fires that can be cancelled + if (gameClient.getHabbo().getRoomUnit().isRiding()){ //TODO Make this an event plugin which fires that can be cancelled return true; } - if (gameClient.getHabbo().getRoomUnit().isCmdTeleport()) { - gameClient.getHabbo().getRoomUnit().setCmdTeleport(false); + if (gameClient.getHabbo().getRoomUnit().isCmdTeleportEnabled()) { + gameClient.getHabbo().getRoomUnit().setCmdTeleportEnabled(false); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_teleport.disabled"), RoomChatMessageBubbles.ALERT); return true; } else { - gameClient.getHabbo().getRoomUnit().setCmdTeleport(true); + gameClient.getHabbo().getRoomUnit().setCmdTeleportEnabled(true); gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.succes.cmd_teleport.enabled"), RoomChatMessageBubbles.ALERT); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/TestCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/TestCommand.java index 6647cc5e..a397ccbe 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/TestCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/TestCommand.java @@ -1,10 +1,11 @@ package com.eu.habbo.habbohotel.commands.list; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; -import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; + +import java.util.Map; +import java.util.Set; public class TestCommand extends Command { public TestCommand() { @@ -13,35 +14,17 @@ public class TestCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (gameClient.getHabbo() != null || !gameClient.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL) || !Emulator.debugging) - return false; + StringBuilder message = new StringBuilder("RoomUnit Statuses"); - int header = Integer.parseInt(params[1]); + Set> statuses = gameClient.getHabbo().getRoomUnit().getStatuses().entrySet(); - ServerMessage message = new ServerMessage(header); + message.append("(").append(statuses.size()).append("):\r\n"); - for (int i = 1; i < params.length; i++) { - String[] data = params[i].split(":"); - - if (data[0].equalsIgnoreCase("b")) { - message.appendBoolean(data[1].equalsIgnoreCase("1")); - } else if (data[0].equalsIgnoreCase("s")) { - if (data.length > 1) { - message.appendString(data[1]); - } else { - message.appendString(""); - } - } else if (data[0].equals("i")) { - message.appendInt(Integer.parseInt(data[1])); - } else if (data[0].equalsIgnoreCase("by")) { - message.appendByte(Integer.parseInt(data[1])); - } else if (data[0].equalsIgnoreCase("sh")) { - message.appendShort(Integer.parseInt(data[1])); - } + for(Map.Entry status : statuses) { + message.append(status.getKey().toString()).append("\r"); } - gameClient.sendResponse(message); - + gameClient.getHabbo().alert(new String[]{message.toString()}); return true; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/TransformCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/TransformCommand.java index f59c6498..5f6f0b8d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/TransformCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/TransformCommand.java @@ -5,8 +5,8 @@ import com.eu.habbo.core.RoomUserPetComposer; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.pets.PetData; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUnitType; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; import com.eu.habbo.messages.outgoing.generic.alerts.MOTDNotificationComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer; @@ -57,8 +57,8 @@ public class TransformCommand extends Command { gameClient.getHabbo().getHabboStats().getCache().put("pet_type", petData); gameClient.getHabbo().getHabboStats().getCache().put("pet_race", race); gameClient.getHabbo().getHabboStats().getCache().put("pet_color", color); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserRemoveMessageComposer(gameClient.getHabbo().getRoomUnit()).compose()); - gameClient.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserPetComposer(petData.getType(), race, color, gameClient.getHabbo()).compose()); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new UserRemoveMessageComposer(gameClient.getHabbo().getRoomUnit()).compose()); + gameClient.getHabbo().getRoomUnit().getRoom().sendComposer(new RoomUserPetComposer(petData.getType(), race, color, gameClient.getHabbo()).compose()); } else { //Pet Not Found return true; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/UnloadRoomCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/UnloadRoomCommand.java index 99c157f5..f8bb0e38 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/UnloadRoomCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/UnloadRoomCommand.java @@ -13,9 +13,9 @@ public class UnloadRoomCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - Room room = gameClient.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = gameClient.getHabbo().getRoomUnit().getRoom(); - if (room != null && (room.isOwner(gameClient.getHabbo()) || (room.hasGuild() && room.getGuildRightLevel(gameClient.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) || gameClient.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room != null && (room.getRoomInfo().isRoomOwner(gameClient.getHabbo()) || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(gameClient.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) || gameClient.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { room.dispose(); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/UnmuteCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/UnmuteCommand.java index 29b65f1d..cb0c4e42 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/UnmuteCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/UnmuteCommand.java @@ -25,13 +25,13 @@ public class UnmuteCommand extends Command { return true; } - if (!habbo.getHabboStats().allowTalk() || (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom().isMuted(habbo))) { + if (!habbo.getHabboStats().allowTalk() || (habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom().isMuted(habbo))) { if (!habbo.getHabboStats().allowTalk()) { habbo.unMute(); } - if (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom().isMuted(habbo)) { - habbo.getHabboInfo().getCurrentRoom().muteHabbo(habbo, 1); + if (habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom().isMuted(habbo)) { + habbo.getRoomUnit().getRoom().muteHabbo(habbo, 1); } gameClient.getHabbo().whisper(replaceUser(getTextsValue("commands.succes.cmd_unmute"), params[1]), RoomChatMessageBubbles.ALERT); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/UpdateItemsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/UpdateItemsCommand.java index ccfeae37..b2e1be1c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/UpdateItemsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/UpdateItemsCommand.java @@ -19,7 +19,7 @@ public class UpdateItemsCommand extends Command { synchronized (Emulator.getGameEnvironment().getRoomManager().getActiveRooms()) { Emulator.getGameEnvironment().getRoomManager().getActiveRooms().stream() - .filter(room -> room.isLoaded() && room.getUserCount() > 0 && room.getLayout() != null) + .filter(room -> room.isLoaded() && room.getRoomUnitManager().getRoomHabbosCount() > 0 && room.getLayout() != null) .forEach(room -> room.sendComposer(new HeightMapComposer(room).compose())); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/UserInfoCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/UserInfoCommand.java index 39cb7f8f..871be6ec 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/UserInfoCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/UserInfoCommand.java @@ -8,7 +8,6 @@ import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import gnu.trove.iterator.TIntIntIterator; import java.text.SimpleDateFormat; @@ -30,7 +29,7 @@ public class UserInfoCommand extends Command { HabboInfo habbo = (onlineHabbo != null ? onlineHabbo.getHabboInfo() : null); if (habbo == null) { - habbo = HabboManager.getOfflineHabboInfo(params[1]); + habbo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); } if (habbo == null) { @@ -44,9 +43,9 @@ public class UserInfoCommand extends Command { getTextsValue("command.cmd_userinfo.motto") + ": " + habbo.getMotto().replace("<", "[").replace(">", "]") + "\r" + getTextsValue("command.cmd_userinfo.rank") + ": " + habbo.getPermissionGroup().getName() + " (" + habbo.getPermissionGroup().getId() + ") \r" + getTextsValue("command.cmd_userinfo.online") + ": " + (onlineHabbo == null ? getTextsValue("generic.no") : getTextsValue("generic.yes")) + "\r" + - ((habbo.getPermissionGroup().hasRight(Permission.ACC_HIDE_MAIL, true)) ? "" : getTextsValue("command.cmd_userinfo.email") + ": " + habbo.getMail() + "\r") + - ((habbo.getPermissionGroup().hasRight(Permission.ACC_HIDE_IP, true)) ? "" : getTextsValue("command.cmd_userinfo.ip_register") + ": " + habbo.getIpRegister() + "\r") + - ((habbo.getPermissionGroup().hasRight(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : getTextsValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getHabboInfo().getIpLogin() + "\r") + + ((habbo.getPermissionGroup().hasPermissionRight(Permission.ACC_HIDE_MAIL, true)) ? "" : getTextsValue("command.cmd_userinfo.email") + ": " + habbo.getMail() + "\r") + + ((habbo.getPermissionGroup().hasPermissionRight(Permission.ACC_HIDE_IP, true)) ? "" : getTextsValue("command.cmd_userinfo.ip_register") + ": " + habbo.getIpRegister() + "\r") + + ((habbo.getPermissionGroup().hasPermissionRight(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : getTextsValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getHabboInfo().getIpLogin() + "\r") + (onlineHabbo != null ? getTextsValue("command.cmd_userinfo.achievement_score") + ": " + onlineHabbo.getHabboStats().getAchievementScore() + "\r" : "")); ModToolBan ban = Emulator.getGameEnvironment().getModToolManager().checkForBan(habbo.getId()); @@ -71,7 +70,7 @@ public class UserInfoCommand extends Command { message.append(getTextsValue("seasonal.name." + iterator.key())).append(": ").append(iterator.value()).append("\r"); } - message.append("\r").append(onlineHabbo != null ? "" + getTextsValue("command.cmd_userinfo.current_activity") + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.room") + ": " + (onlineHabbo.getHabboInfo().getCurrentRoom() != null ? onlineHabbo.getHabboInfo().getCurrentRoom().getName() + "(" + onlineHabbo.getHabboInfo().getCurrentRoom().getId() + ")\r" : "-") : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.respect_left") + ": " + onlineHabbo.getHabboStats().getRespectPointsToGive() + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.pet_respect_left") + ": " + onlineHabbo.getHabboStats().getPetRespectPointsToGive() + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.allow_trade") + ": " + ((onlineHabbo.getHabboStats().allowTrade()) ? getTextsValue("generic.yes") : getTextsValue("generic.no")) + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.allow_follow") + ": " + ((onlineHabbo.getHabboStats().isBlockFollowing()) ? getTextsValue("generic.no") : getTextsValue("generic.yes")) + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.allow_friend_request") + ": " + ((onlineHabbo.getHabboStats().isBlockFriendRequests()) ? getTextsValue("generic.no") : getTextsValue("generic.yes")) + "\r" : ""); + message.append("\r").append(onlineHabbo != null ? "" + getTextsValue("command.cmd_userinfo.current_activity") + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.room") + ": " + (onlineHabbo.getRoomUnit().getRoom() != null ? onlineHabbo.getRoomUnit().getRoom().getRoomInfo().getName() + "(" + onlineHabbo.getRoomUnit().getRoom().getRoomInfo().getId() + ")\r" : "-") : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.respect_left") + ": " + onlineHabbo.getHabboStats().getRespectPointsToGive() + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.pet_respect_left") + ": " + onlineHabbo.getHabboStats().getPetRespectPointsToGive() + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.allow_trade") + ": " + ((onlineHabbo.getHabboStats().allowTrade()) ? getTextsValue("generic.yes") : getTextsValue("generic.no")) + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.allow_follow") + ": " + ((onlineHabbo.getHabboStats().isBlockFollowing()) ? getTextsValue("generic.no") : getTextsValue("generic.yes")) + "\r" : "").append(onlineHabbo != null ? getTextsValue("command.cmd_userinfo.allow_friend_request") + ": " + ((onlineHabbo.getHabboStats().isBlockFriendRequests()) ? getTextsValue("generic.no") : getTextsValue("generic.yes")) + "\r" : ""); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List> nameChanges = Emulator.getGameEnvironment().getHabboManager().getNameChanges(habbo.getId(), 3); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/WordQuizCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/WordQuizCommand.java index 8c5b8508..f3954e0b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/WordQuizCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/WordQuizCommand.java @@ -13,7 +13,7 @@ public class WordQuizCommand extends Command { @Override public boolean handle(GameClient gameClient, String[] params) { - if (!gameClient.getHabbo().getHabboInfo().getCurrentRoom().hasActiveWordQuiz()) { + if (!gameClient.getHabbo().getRoomUnit().getRoom().hasActiveWordQuiz()) { if(params.length == 1) { gameClient.getHabbo().whisper(getTextsValue("commands.description.cmd_word_quiz"), RoomChatMessageBubbles.ALERT); return true; @@ -31,7 +31,7 @@ public class WordQuizCommand extends Command { question.append(" ").append(params[i]); } - gameClient.getHabbo().getHabboInfo().getCurrentRoom().startWordQuiz(question.toString(), duration * 1000); + gameClient.getHabbo().getRoomUnit().getRoom().startWordQuiz(question.toString(), duration * 1000); } return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/BadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/BadgeCommand.java index 51a57aec..ae6e1f71 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/BadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/BadgeCommand.java @@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import lombok.extern.slf4j.Slf4j; import java.sql.Connection; @@ -42,7 +41,7 @@ public class BadgeCommand extends BaseBadgeCommand { return true; } else { - HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(params[1]); + HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); if (habboInfo == null) { gameClient.getHabbo().whisper(getTextsValue("commands.error.cmd_badge.unknown_user"), RoomChatMessageBubbles.ALERT); 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 45b38c4b..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().getHabbos() + 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/badge/TakeBadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/TakeBadgeCommand.java index 9ed7ffe4..d27c0bbb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/TakeBadgeCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/badge/TakeBadgeCommand.java @@ -6,7 +6,6 @@ import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.habbohotel.users.inventory.BadgesComponent; import com.eu.habbo.messages.outgoing.inventory.BadgesComposer; import com.eu.habbo.messages.outgoing.users.UserBadgesComposer; @@ -41,8 +40,8 @@ public class TakeBadgeCommand extends BaseBadgeCommand { } habbo.getClient().sendResponse(new BadgesComposer(habbo)); - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserBadgesComposer(habbo.getInventory().getBadgesComponent().getWearingBadges(), habbo.getHabboInfo().getId()).compose()); + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserBadgesComposer(habbo.getInventory().getBadgesComponent().getWearingBadges(), habbo.getHabboInfo().getId()).compose()); } } @@ -51,7 +50,7 @@ public class TakeBadgeCommand extends BaseBadgeCommand { if (habbo != null) userId = habbo.getHabboInfo().getId(); else { - HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(username); + HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(username); if (habboInfo != null) userId = habboInfo.getId(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BanCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BanCommand.java index 3215fb19..4839d98e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BanCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BanCommand.java @@ -8,7 +8,6 @@ import com.eu.habbo.habbohotel.modtool.ModToolBanType; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -54,7 +53,7 @@ public class BanCommand extends Command { if (t != null) { target = t.getHabboInfo(); } else { - target = HabboManager.getOfflineHabboInfo(params[1]); + target = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); } if (target == null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BaseBanCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BaseBanCommand.java index a0073c31..4bd23179 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BaseBanCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/bans/BaseBanCommand.java @@ -1,10 +1,10 @@ package com.eu.habbo.habbohotel.commands.list.bans; +import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.commands.Command; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -43,7 +43,7 @@ public abstract class BaseBanCommand extends Command { if (h != null) { return h.getHabboInfo(); } else { - return HabboManager.getOfflineHabboInfo(params[1]); + return Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); } } return null; diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/CreditsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/CreditsCommand.java index def03e2a..ecff906c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/CreditsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/CreditsCommand.java @@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; public class CreditsCommand extends BaseCreditsCommand { private static final String INVALID_AMOUNT = "commands.error.cmd_credits.invalid_amount"; @@ -17,7 +16,7 @@ public class CreditsCommand extends BaseCreditsCommand { @Override public boolean handle(GameClient gameClient, String[] params) { if (params.length == 3) { - HabboInfo info = HabboManager.getOfflineHabboInfo(params[1]); + HabboInfo info = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(params[1]); if (info != null) { Habbo habbo = getHabbo(params[1]); @@ -32,7 +31,7 @@ public class CreditsCommand extends BaseCreditsCommand { if (habbo != null) { if (credits != 0) { habbo.giveCredits(credits); - if (habbo.getHabboInfo().getCurrentRoom() != null) + if (habbo.getRoomUnit().getRoom() != null) habbo.whisper(replaceAmount(getTextsValue("commands.generic.cmd_credits.received"), params[2]), RoomChatMessageBubbles.ALERT); else habbo.alert(replaceAmount(getTextsValue("commands.generic.cmd_credits.received"), params[2])); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/MassCreditsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/MassCreditsCommand.java index 74f1ed68..7a68c283 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/MassCreditsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/credits/MassCreditsCommand.java @@ -32,7 +32,7 @@ public class MassCreditsCommand extends BaseCreditsCommand { habbo.giveCredits(amount); habbo.getClient().sendResponse(new CreditBalanceComposer(habbo)); - if (habbo.getHabboInfo().getCurrentRoom() != null) + if (habbo.getRoomUnit().getRoom() != null) habbo.whisper(replaceAmount(getTextsValue("commands.generic.cmd_credits.received"), amount + ""), RoomChatMessageBubbles.ALERT); } } 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 cb895fbb..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().getHabboInfo().getCurrentRoom().getHabbos().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/BaseGiftCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/BaseGiftCommand.java index efd07557..da9a9040 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/BaseGiftCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/BaseGiftCommand.java @@ -6,7 +6,7 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import java.util.stream.Collectors; @@ -49,7 +49,7 @@ public abstract class BaseGiftCommand extends Command { } protected void createGift(String finalMessage, Habbo habbo, String[] params) { - HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, getBaseItem(params), 0, 0, ""); + RoomItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, getBaseItem(params), 0, 0, ""); Item giftItem = Emulator.getGameEnvironment().getItemManager().getItem((Integer) Emulator.getGameEnvironment().getCatalogManager().giftFurnis.values().toArray()[Emulator.getRandom().nextInt(Emulator.getGameEnvironment().getCatalogManager().giftFurnis.size())]); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/GiftCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/GiftCommand.java index c360e3d6..c72b46ee 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/GiftCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/gift/GiftCommand.java @@ -4,10 +4,9 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; @@ -46,7 +45,7 @@ public class GiftCommand extends BaseGiftCommand { return true; } - HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(username); + HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(username); if (habboInfo == null) { gameClient.getHabbo().whisper(replaceUsername(getTextsValue("commands.error.cmd_gift.user_not_found"), username), RoomChatMessageBubbles.ALERT); @@ -55,7 +54,7 @@ public class GiftCommand extends BaseGiftCommand { String message = params.length > 3 ? IntStream.range(3, params.length).mapToObj(i -> params[i] + " ").collect(Collectors.joining()) : ""; - HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, 0, 0, ""); + RoomItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, 0, 0, ""); Item giftItem = Emulator.getGameEnvironment().getItemManager().getItem((Integer) Emulator.getGameEnvironment().getCatalogManager().giftFurnis.values().toArray()[Emulator.getRandom().nextInt(Emulator.getGameEnvironment().getCatalogManager().giftFurnis.size())]); String extraData = "1\t" + item.getId() + "\t0\t0\t0\t" + message + "\t0\t0"; 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 f36f9886..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().getHabboInfo().getCurrentRoom().getHabbos().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/MassPixelsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/MassPixelsCommand.java index 447f8cea..fd9eb5f2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/MassPixelsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/MassPixelsCommand.java @@ -30,7 +30,7 @@ public class MassPixelsCommand extends BasePixelsCommand { habbo.givePixels(amount); - if (habbo.getHabboInfo().getCurrentRoom() != null) + if (habbo.getRoomUnit().getRoom() != null) habbo.whisper(replaceAmount(getTextsValue("commands.generic.cmd_duckets.received"), amount + ""), RoomChatMessageBubbles.ALERT); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/PixelCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/PixelCommand.java index ec4c0a28..2cbc0f4f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/PixelCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/pixels/PixelCommand.java @@ -21,7 +21,7 @@ public class PixelCommand extends BasePixelsCommand { try { if (Integer.parseInt(params[2]) != 0) { habbo.givePixels(Integer.parseInt(params[2])); - if (habbo.getHabboInfo().getCurrentRoom() != null) + if (habbo.getRoomUnit().getRoom() != null) habbo.whisper(replaceAmount(getTextsValue("commands.generic.cmd_duckets.received"), params[2]), RoomChatMessageBubbles.ALERT); else habbo.alert(replaceAmount(getTextsValue("commands.generic.cmd_duckets.received"), params[2])); 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 ef838f7f..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().getHabboInfo().getCurrentRoom().getHabbos().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/MassPointsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/points/MassPointsCommand.java index c8890cdc..71ccb991 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/points/MassPointsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/points/MassPointsCommand.java @@ -58,7 +58,7 @@ public class MassPointsCommand extends BasePointsCommand { for (Habbo habbo : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().values()) { habbo.givePoints(type, amount); - if (habbo.getHabboInfo().getCurrentRoom() != null) + if (habbo.getRoomUnit().getRoom() != null) habbo.whisper(message, RoomChatMessageBubbles.ALERT); else habbo.alert(message); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/list/points/PointsCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/list/points/PointsCommand.java index 23b3451b..dce20efb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/list/points/PointsCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/list/points/PointsCommand.java @@ -48,7 +48,7 @@ public class PointsCommand extends BasePointsCommand { if (amount != 0) { habbo.givePoints(type, amount); - if (habbo.getHabboInfo().getCurrentRoom() != null) + if (habbo.getRoomUnit().getRoom() != null) habbo.whisper(replaceAmountAndType(getTextsValue("commands.generic.cmd_points.received"), amount + "", getTextsValue("seasonal.name." + type)), RoomChatMessageBubbles.ALERT); else habbo.alert(replaceAmountAndType(getTextsValue("commands.generic.cmd_points.received"), amount + "", getTextsValue("seasonal.name." + type))); 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 40f82a89..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().getHabboInfo().getCurrentRoom().getHabbos()) { + 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/gameclients/GameClientManager.java b/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java index 354429a3..e39b5fc3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/gameclients/GameClientManager.java @@ -152,7 +152,7 @@ public class GameClientManager { continue; if (client.getHabbo() != null) { - if (client.getHabbo().hasRight(minPermission)) { + if (client.getHabbo().hasPermissionRight(minPermission)) { client.sendResponse(message); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/Game.java b/src/main/java/com/eu/habbo/habbohotel/games/Game.java index aa50cea7..deae2ce4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/Game.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/Game.java @@ -8,8 +8,8 @@ import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamLoses; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.WiredTriggerTeamWins; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreDataEntry; import com.eu.habbo.messages.outgoing.guides.YouArePlayingGameMessageComposer; @@ -120,7 +120,7 @@ public abstract class Game implements Runnable { Emulator.getPluginManager().fireEvent(gameStartedEvent); } - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) { + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) { ((WiredBlob) item).onGameStart(this.room); } @@ -136,7 +136,7 @@ public abstract class Game implements Runnable { int totalPointsGained = this.teams.values().stream().mapToInt(GameTeam::getTotalScore).sum(); - Habbo roomOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.room.getOwnerId()); + Habbo roomOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.room.getRoomInfo().getOwnerInfo().getId()); if (roomOwner != null) { AchievementManager.progressAchievement(roomOwner, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GameAuthorExperience"), totalPointsGained); } @@ -161,7 +161,7 @@ public abstract class Game implements Runnable { } if (winningTeam.getMembers().size() > 0) { - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) { + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) { Emulator.getGameEnvironment().getItemManager().getHighscoreManager().addHighscoreData(new WiredHighscoreDataEntry(item.getId(), winningTeam.getMembers().stream().map(m -> m.getHabbo().getHabboInfo().getId()).collect(Collectors.toList()), winningTeam.getTotalScore(), true, Emulator.getIntUnixTimestamp())); } } @@ -174,19 +174,19 @@ public abstract class Game implements Runnable { } if (team.getMembers().size() > 0 && team.getTotalScore() > 0) { - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) { + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) { Emulator.getGameEnvironment().getItemManager().getHighscoreManager().addHighscoreData(new WiredHighscoreDataEntry(item.getId(), team.getMembers().stream().map(m -> m.getHabbo().getHabboInfo().getId()).collect(Collectors.toList()), team.getTotalScore(), false, Emulator.getIntUnixTimestamp())); } } } } - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) { + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class)) { ((InteractionWiredHighscore) item).reloadData(); this.room.updateItem(item); } - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) { + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(WiredBlob.class)) { ((WiredBlob) item).onGameEnd(this.room); } } @@ -209,7 +209,7 @@ public abstract class Game implements Runnable { this.state = GameState.IDLE; boolean gamesActive = false; - for (HabboItem timer : room.getFloorItems()) { + for (RoomItem timer : room.getRoomItemManager().getFloorItems().values()) { if (timer instanceof InteractionGameTimer) { if (((InteractionGameTimer) timer).isRunning()) gamesActive = true; diff --git a/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java b/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java index b3653c11..781bd3ac 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/GamePlayer.java @@ -24,7 +24,7 @@ public class GamePlayer { } public synchronized void addScore(int amount, boolean isWired) { - if (habbo.getHabboInfo().getGamePlayer() != null && this.habbo.getHabboInfo().getCurrentGame() != null && this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo) != null) { + if (habbo.getHabboInfo().getGamePlayer() != null && this.habbo.getHabboInfo().getCurrentGame() != null && this.habbo.getRoomUnit().getRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo) != null) { this.score += amount; if (this.score < 0) this.score = 0; @@ -33,7 +33,7 @@ public class GamePlayer { this.wiredScore += amount; } - WiredHandler.handle(WiredTriggerType.SCORE_ACHIEVED, this.habbo.getRoomUnit(), this.habbo.getHabboInfo().getCurrentRoom(), new Object[]{this.habbo.getHabboInfo().getCurrentRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo).getTotalScore(), amount}); + WiredHandler.handle(WiredTriggerType.SCORE_ACHIEVED, this.habbo.getRoomUnit(), this.habbo.getRoomUnit().getRoom(), new Object[]{this.habbo.getRoomUnit().getRoom().getGame(this.habbo.getHabboInfo().getCurrentGame()).getTeamForHabbo(this.habbo).getTotalScore(), amount}); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java index 33f83e3b..8968e945 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGame.java @@ -11,8 +11,8 @@ import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.scoreboards import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUserAction; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.rooms.users.ExpressionMessageComposer; import com.eu.habbo.threading.runnables.BattleBanzaiTilesFlicker; import gnu.trove.map.hash.THashMap; @@ -35,8 +35,8 @@ public class BattleBanzaiGame extends Game { public static final int POINTS_LOCK_TILE = Emulator.getConfig().getInt("hotel.banzai.points.tile.lock", 1); private static final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(Emulator.getConfig().getInt("hotel.banzai.fill.threads", 2)); - private final THashMap> lockedTiles; - private final THashMap gameTiles; + private final THashMap> lockedTiles; + private final THashMap gameTiles; private int tileCount; private int countDown; private int countDown2; @@ -69,8 +69,8 @@ public class BattleBanzaiGame extends Game { } } - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { - item.setExtradata("1"); + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { + item.setExtraData("1"); this.room.updateItemState(item); } @@ -104,13 +104,13 @@ public class BattleBanzaiGame extends Game { this.countDown--; if (this.countDown == 0) { - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { - item.setExtradata("1"); + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { + item.setExtraData("1"); this.room.updateItemState(item); if(this.countDown2 > 0) { this.countDown2--; if(this.countDown2 == 0) { - item.setExtradata("2"); + item.setExtraData("2"); this.room.updateItemState(item); } } @@ -130,7 +130,7 @@ public class BattleBanzaiGame extends Game { int total = 0; synchronized (this.lockedTiles) { - for (Map.Entry> set : this.lockedTiles.entrySet()) { + for (Map.Entry> set : this.lockedTiles.entrySet()) { total += set.getValue().size(); } } @@ -146,8 +146,8 @@ public class BattleBanzaiGame extends Game { } if (highestScore != null) { - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { - item.setExtradata((highestScore.teamColor.type + 2) + ""); + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { + item.setExtraData((highestScore.teamColor.type + 2) + ""); this.room.updateItemState(item); } } @@ -194,8 +194,8 @@ public class BattleBanzaiGame extends Game { } } - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { - item.setExtradata((6 + winningTeam.teamColor.type) + ""); + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { + item.setExtraData((6 + winningTeam.teamColor.type) + ""); this.room.updateItemState(item); } synchronized (this.lockedTiles) { @@ -212,9 +212,9 @@ public class BattleBanzaiGame extends Game { this.refreshGates(); - for (HabboItem tile : this.gameTiles.values()) { - if (tile.getExtradata().equals("1")) { - tile.setExtradata("0"); + for (RoomItem tile : this.gameTiles.values()) { + if (tile.getExtraData().equals("1")) { + tile.setExtraData("0"); this.room.updateItem(tile); } } @@ -226,27 +226,27 @@ public class BattleBanzaiGame extends Game { private synchronized void resetMap() { this.tileCount = 0; - for (HabboItem item : this.room.getFloorItems()) { + for (RoomItem item : this.room.getRoomItemManager().getFloorItems().values()) { if (item instanceof InteractionBattleBanzaiTile) { - item.setExtradata("1"); + item.setExtraData("1"); this.room.updateItemState(item); this.tileCount++; this.gameTiles.put(item.getId(), item); } if (item instanceof InteractionBattleBanzaiScoreboard) { - item.setExtradata("0"); + item.setExtraData("0"); this.room.updateItemState(item); } } } - public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo) { + public void tileLocked(GameTeamColors teamColor, RoomItem item, Habbo habbo) { this.tileLocked(teamColor, item, habbo, false); } - public void tileLocked(GameTeamColors teamColor, HabboItem item, Habbo habbo, boolean doNotCheckFill) { + public void tileLocked(GameTeamColors teamColor, RoomItem item, Habbo habbo, boolean doNotCheckFill) { synchronized (this.lockedTiles) { if (item instanceof InteractionBattleBanzaiTile) { if (!this.lockedTiles.containsKey(teamColor)) { @@ -262,11 +262,11 @@ public class BattleBanzaiGame extends Game { if (doNotCheckFill) return; - final int x = item.getX(); - final int y = item.getY(); + final int x = item.getCurrentPosition().getX(); + final int y = item.getCurrentPosition().getY(); final List> filledAreas = new ArrayList<>(); - final THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); + final THashSet lockedTiles = new THashSet<>(this.lockedTiles.get(teamColor)); executor.execute(() -> { filledAreas.add(this.floodFill(x, y - 1, lockedTiles, new ArrayList<>(), teamColor)); @@ -278,12 +278,12 @@ public class BattleBanzaiGame extends Game { if (largestAreaOfAll.isPresent()) { for (RoomTile tile : largestAreaOfAll.get()) { - Optional tileItem = this.gameTiles.values().stream().filter(i -> i.getX() == tile.getX() && i.getY() == tile.getY() && i instanceof InteractionBattleBanzaiTile).findAny(); + Optional tileItem = this.gameTiles.values().stream().filter(i -> i.getCurrentPosition().getX() == tile.getX() && i.getCurrentPosition().getY() == tile.getY() && i instanceof InteractionBattleBanzaiTile).findAny(); tileItem.ifPresent(habboItem -> { this.tileLocked(teamColor, habboItem, habbo, true); - habboItem.setExtradata((2 + (teamColor.type * 3)) + ""); + habboItem.setExtraData((2 + (teamColor.type * 3)) + ""); this.room.updateItem(habboItem); }); } @@ -297,7 +297,7 @@ public class BattleBanzaiGame extends Game { } } - private List floodFill(int x, int y, THashSet lockedTiles, List stack, GameTeamColors color) { + private List floodFill(int x, int y, THashSet lockedTiles, List stack, GameTeamColors color) { if (this.isOutOfBounds(x, y) || this.isForeignLockedTile(x, y, color)) return null; RoomTile tile = this.room.getLayout().getTile((short) x, (short) y); @@ -320,28 +320,28 @@ public class BattleBanzaiGame extends Game { } - private boolean hasLockedTileAtCoordinates(int x, int y, THashSet lockedTiles) { - for (HabboItem item : lockedTiles) { - if (item.getX() == x && item.getY() == y) return true; + private boolean hasLockedTileAtCoordinates(int x, int y, THashSet lockedTiles) { + for (RoomItem item : lockedTiles) { + if (item.getCurrentPosition().getX() == x && item.getCurrentPosition().getY() == y) return true; } return false; } private boolean isOutOfBounds(int x, int y) { - for (HabboItem item : this.gameTiles.values()) { - if (item.getX() == x && item.getY() == y) return false; + for (RoomItem item : this.gameTiles.values()) { + if (item.getCurrentPosition().getX() == x && item.getCurrentPosition().getY() == y) return false; } return true; } private boolean isForeignLockedTile(int x, int y, GameTeamColors color) { - for (HashMap.Entry> lockedTilesForColor : this.lockedTiles.entrySet()) { + for (HashMap.Entry> lockedTilesForColor : this.lockedTiles.entrySet()) { if (lockedTilesForColor.getKey() == color) continue; - for (HabboItem item : lockedTilesForColor.getValue()) { - if (item.getX() == x && item.getY() == y) return true; + for (RoomItem item : lockedTilesForColor.getValue()) { + if (item.getCurrentPosition().getX() == x && item.getCurrentPosition().getY() == y) return true; } } @@ -366,16 +366,16 @@ public class BattleBanzaiGame extends Game { THashMap scoreBoards = this.room.getRoomSpecialTypes().getBattleBanzaiScoreboards(teamColors); for (InteractionBattleBanzaiScoreboard scoreboard : scoreBoards.values()) { - if (scoreboard.getExtradata().isEmpty()) { - scoreboard.setExtradata("0"); + if (scoreboard.getExtraData().isEmpty()) { + scoreboard.setExtraData("0"); } - int oldScore = Integer.parseInt(scoreboard.getExtradata()); + int oldScore = Integer.parseInt(scoreboard.getExtraData()); if (oldScore == totalScore) continue; - scoreboard.setExtradata(totalScore + ""); + scoreboard.setExtraData(totalScore + ""); this.room.updateItemState(scoreboard); } } @@ -383,8 +383,8 @@ public class BattleBanzaiGame extends Game { private void refreshGates() { Collection gates = this.room.getRoomSpecialTypes().getBattleBanzaiGates().values(); THashSet tilesToUpdate = new THashSet<>(gates.size()); - for (HabboItem item : gates) { - tilesToUpdate.add(this.room.getLayout().getTile(item.getX(), item.getY())); + for (RoomItem item : gates) { + tilesToUpdate.add(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); } this.room.updateTiles(tilesToUpdate); @@ -410,7 +410,7 @@ public class BattleBanzaiGame extends Game { } this.refreshCounters(habbo.getHabboInfo().getGamePlayer().getTeamColor()); - tile.setExtradata(state + ""); + tile.setExtraData(state + ""); this.room.updateItem(tile); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java index 94725332..50460edc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/battlebanzai/BattleBanzaiGameTeam.java @@ -7,10 +7,10 @@ import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.games.freeze.FreezeGame; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; public class BattleBanzaiGameTeam extends GameTeam { public BattleBanzaiGameTeam(GameTeamColors teamColor) { @@ -20,25 +20,27 @@ public class BattleBanzaiGameTeam extends GameTeam { @Override public void addMember(GamePlayer gamePlayer) { super.addMember(gamePlayer); - RoomUnit roomUnit = gamePlayer.getHabbo().getRoomUnit(); - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); + RoomHabbo roomHabbo = gamePlayer.getHabbo().getRoomUnit(); + if (roomHabbo.getEffectId() > 0) { + roomHabbo.setPreviousEffectId(roomHabbo.getEffectId()); + roomHabbo.setPreviousEffectEndTimestamp(roomHabbo.getPreviousEffectEndTimestamp()); + } - gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(gamePlayer.getHabbo(), BattleBanzaiGame.effectId + this.teamColor.type, -1, true); + gamePlayer.getHabbo().getRoomUnit().giveEffect(BattleBanzaiGame.effectId + this.teamColor.type, -1, true); } @Override public void removeMember(GamePlayer gamePlayer) { super.removeMember(gamePlayer); - if (gamePlayer == null || gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (gamePlayer == null || gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getRoomUnit().getRoom() == null) return; Habbo habbo = gamePlayer.getHabbo(); - Game game = habbo.getHabboInfo().getCurrentRoom().getGame(FreezeGame.class); - RoomUnit roomUnit = habbo.getRoomUnit(); - Room room = roomUnit.getRoom(); + Game game = habbo.getRoomUnit().getRoom().getGame(FreezeGame.class); + RoomHabbo roomHabbo = habbo.getRoomUnit(); + Room room = roomHabbo.getRoom(); if(room == null) return; - HabboItem topItem = room.getTopItemAt(roomUnit.getCurrentLocation().getX(), roomUnit.getCurrentLocation().getY()); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(roomHabbo.getCurrentPosition().getX(), roomHabbo.getCurrentPosition().getY()); int nextEffectM = 0; int nextEffectF = 0; int nextEffectDuration = -1; @@ -46,22 +48,22 @@ public class BattleBanzaiGameTeam extends GameTeam { if (topItem != null) { nextEffectM = topItem.getBaseItem().getEffectM(); nextEffectF = topItem.getBaseItem().getEffectF(); - } else if (roomUnit.getPreviousEffectId() > 0) { - nextEffectF = roomUnit.getPreviousEffectId(); - nextEffectM = roomUnit.getPreviousEffectId(); - nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp(); + } else if (roomHabbo.getPreviousEffectId() > 0) { + nextEffectF = roomHabbo.getPreviousEffectId(); + nextEffectM = roomHabbo.getPreviousEffectId(); + nextEffectDuration = roomHabbo.getPreviousEffectEndTimestamp(); } if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) { - room.giveEffect(habbo, nextEffectM, nextEffectDuration, true); + habbo.getRoomUnit().giveEffect(nextEffectM, nextEffectDuration, true); return; } if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) { - room.giveEffect(habbo, nextEffectF, nextEffectDuration, true); + habbo.getRoomUnit().giveEffect(nextEffectF, nextEffectDuration, true); } - roomUnit.setCanWalk(true); + roomHabbo.setCanWalk(true); if (room.getRoomSpecialTypes() != null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java b/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java index 4039feb9..bed87dcd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/football/FootballGame.java @@ -6,8 +6,8 @@ import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards.InteractionFootballScoreboard; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUserAction; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.outgoing.rooms.users.ExpressionMessageComposer; @@ -35,11 +35,11 @@ public class FootballGame extends Game { if (this.room == null || !this.room.isLoaded()) return; - Habbo habbo = this.room.getHabbo(kicker); + Habbo habbo = this.room.getRoomUnitManager().getHabboByRoomUnit(kicker); if (habbo != null) { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("FootballGoalScored")); - if (habbo.getHabboInfo().getId() != this.room.getOwnerId()) { - AchievementManager.progressAchievement(this.room.getOwnerId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FootballGoalScoredInRoom")); + if (habbo.getHabboInfo().getId() != this.room.getRoomInfo().getOwnerInfo().getId()) { + AchievementManager.progressAchievement(this.room.getRoomInfo().getOwnerInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FootballGoalScoredInRoom")); } } 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 262f48db..f859c4f8 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 @@ -13,8 +13,8 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUserAction; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.rooms.users.ExpressionMessageComposer; import com.eu.habbo.plugin.EventHandler; import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; @@ -78,9 +78,9 @@ public class FreezeGame extends Game { } synchronized void resetMap() { - for (HabboItem item : this.room.getFloorItems()) { + for (RoomItem item : this.room.getRoomItemManager().getFloorItems().values()) { if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeScoreboard) { - item.setExtradata("0"); + item.setExtraData("0"); this.room.updateItemState(item); } } @@ -90,10 +90,10 @@ public class FreezeGame extends Game { if (!this.state.equals(GameState.RUNNING) || !habbo.getHabboInfo().isInGame() || habbo.getHabboInfo().getCurrentGame() != this.getClass()) return; - if (!item.getExtradata().equalsIgnoreCase("0") && !item.getExtradata().isEmpty()) + if (!item.getExtraData().equalsIgnoreCase("0") && !item.getExtraData().isEmpty()) return; - if (RoomLayout.tilesAdjecent(habbo.getRoomUnit().getCurrentLocation(), this.room.getLayout().getTile(item.getX(), item.getY()))) { + if (RoomLayout.tilesAdjecent(habbo.getRoomUnit().getCurrentPosition(), this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()))) { if (((FreezeGamePlayer) habbo.getHabboInfo().getGamePlayer()).canThrowSnowball()) { Emulator.getThreading().run(new FreezeThrowSnowball(habbo, item, this.room)); } @@ -147,7 +147,7 @@ public class FreezeGame extends Game { powerUp += Emulator.getRandom().nextInt(6) + 1; } - block.setExtradata((powerUp + 1) + String.format("%3d", delay)); + block.setExtraData((powerUp + 1) + String.format("%3d", delay)); this.room.updateItemState(block); } @@ -173,7 +173,7 @@ public class FreezeGame extends Game { Emulator.getThreading().run(new FreezeClearEffects(player.getHabbo()), 1000); if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) { InteractionFreezeExitTile tile = this.room.getRoomSpecialTypes().getRandomFreezeExitTile(); - tile.setExtradata("1"); + tile.setExtraData("1"); this.room.updateItemState(tile); this.room.teleportHabboToItem(player.getHabbo(), tile); } @@ -189,12 +189,12 @@ public class FreezeGame extends Game { super.start(); if (this.room.getRoomSpecialTypes().hasFreezeExitTile()) { - for (Habbo habbo : this.room.getHabbos()) { + for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) { if (this.getTeamForHabbo(habbo) == null) { - for (HabboItem item : this.room.getItemsAt(habbo.getRoomUnit().getCurrentLocation())) { + for (RoomItem item : this.room.getRoomItemManager().getItemsAt(habbo.getRoomUnit().getCurrentPosition())) { if (item instanceof InteractionFreezeTile) { - HabboItem exitTile = this.room.getRoomSpecialTypes().getRandomFreezeExitTile(); - WiredEffectTeleport.teleportUnitToTile(habbo.getRoomUnit(), this.room.getLayout().getTile(exitTile.getX(), exitTile.getY())); + RoomItem exitTile = this.room.getRoomSpecialTypes().getRandomFreezeExitTile(); + WiredEffectTeleport.teleportUnitToTile(habbo.getRoomUnit(), this.room.getLayout().getTile(exitTile.getCurrentPosition().getX(), exitTile.getCurrentPosition().getY())); } } } @@ -227,16 +227,16 @@ public class FreezeGame extends Game { THashMap scoreBoards = this.room.getRoomSpecialTypes().getFreezeScoreboards(team.teamColor); for (InteractionFreezeScoreboard scoreboard : scoreBoards.values()) { - if (scoreboard.getExtradata().isEmpty()) { - scoreboard.setExtradata("0"); + if (scoreboard.getExtraData().isEmpty()) { + scoreboard.setExtraData("0"); } - int oldScore = Integer.parseInt(scoreboard.getExtradata()); + int oldScore = Integer.parseInt(scoreboard.getExtraData()); if (oldScore == totalScore) continue; - scoreboard.setExtradata(totalScore + ""); + scoreboard.setExtraData(totalScore + ""); this.room.updateItemState(scoreboard); } } @@ -282,7 +282,7 @@ public class FreezeGame extends Game { for (Map.Entry set : this.room.getRoomSpecialTypes().getFreezeGates().entrySet()) { if (teamMemberCount.containsKey(set.getValue().teamColor)) { int amount = Math.min(teamMemberCount.get(set.getValue().teamColor), 5); - set.getValue().setExtradata(amount + ""); + set.getValue().setExtraData(amount + ""); teamMemberCount.put(set.getValue().teamColor, teamMemberCount.get(set.getValue().teamColor) - amount); this.room.updateItemState(set.getValue()); } @@ -295,7 +295,7 @@ public class FreezeGame extends Game { public void setFreezeTileState(String state) { this.room.getRoomSpecialTypes().getFreezeExitTiles().forEachValue(object -> { - object.setExtradata(state); + object.setExtraData(state); FreezeGame.this.room.updateItemState(object); return true; }); @@ -304,8 +304,8 @@ public class FreezeGame extends Game { private void refreshGates() { THashSet tilesToUpdate = new THashSet<>(); - for (HabboItem item : this.room.getRoomSpecialTypes().getFreezeGates().values()) { - tilesToUpdate.add(this.room.getLayout().getTile(item.getX(), item.getY())); + for (RoomItem item : this.room.getRoomSpecialTypes().getFreezeGates().values()) { + tilesToUpdate.add(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); } this.room.updateTiles(tilesToUpdate); diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGamePlayer.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGamePlayer.java index 7c14d9cb..80334649 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGamePlayer.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGamePlayer.java @@ -52,7 +52,7 @@ public class FreezeGamePlayer extends GamePlayer { public void addLife() { if (this.lives < FreezeGame.MAX_LIVES) { this.lives++; - super.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new GamePlayerValueMessageComposer(this).compose()); + super.getHabbo().getRoomUnit().getRoom().sendComposer(new GamePlayerValueMessageComposer(this).compose()); } } @@ -61,13 +61,13 @@ public class FreezeGamePlayer extends GamePlayer { if (this.lives == 0) { this.dead = true; - FreezeGame game = (FreezeGame) super.getHabbo().getHabboInfo().getCurrentRoom().getGame(FreezeGame.class); + FreezeGame game = (FreezeGame) super.getHabbo().getRoomUnit().getRoom().getGame(FreezeGame.class); if (game != null) { game.playerDies(this); } } else { - super.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new GamePlayerValueMessageComposer(this).compose()); + super.getHabbo().getRoomUnit().getRoom().sendComposer(new GamePlayerValueMessageComposer(this).compose()); } } @@ -208,6 +208,6 @@ public class FreezeGamePlayer extends GamePlayer { if (this.dead) return; - super.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(super.getHabbo(), this.correctEffectId(), -1, true); + super.getHabbo().getRoomUnit().giveEffect(this.correctEffectId(), -1, true); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java index 845a9bb6..a31f278d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/freeze/FreezeGameTeam.java @@ -6,10 +6,10 @@ import com.eu.habbo.habbohotel.games.GameTeam; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; public class FreezeGameTeam extends GameTeam { public FreezeGameTeam(GameTeamColors teamColor) { @@ -19,16 +19,16 @@ public class FreezeGameTeam extends GameTeam { @Override public void removeMember(GamePlayer gamePlayer) { super.removeMember(gamePlayer); - if (gamePlayer == null || gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (gamePlayer == null || gamePlayer.getHabbo() == null || gamePlayer.getHabbo().getRoomUnit().getRoom() == null) return; Habbo habbo = gamePlayer.getHabbo(); - Game game = habbo.getHabboInfo().getCurrentRoom().getGame(FreezeGame.class); - RoomUnit roomUnit = habbo.getRoomUnit(); - Room room = roomUnit.getRoom(); + Game game = habbo.getRoomUnit().getRoom().getGame(FreezeGame.class); + RoomHabbo roomHabbo = habbo.getRoomUnit(); + Room room = roomHabbo.getRoom(); if(room == null) return; - HabboItem topItem = room.getTopItemAt(roomUnit.getCurrentLocation().getX(), roomUnit.getCurrentLocation().getY()); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(roomHabbo.getCurrentPosition().getX(), roomHabbo.getCurrentPosition().getY()); int nextEffectM = 0; int nextEffectF = 0; int nextEffectDuration = -1; @@ -36,22 +36,22 @@ public class FreezeGameTeam extends GameTeam { if (topItem != null) { nextEffectM = topItem.getBaseItem().getEffectM(); nextEffectF = topItem.getBaseItem().getEffectF(); - } else if (roomUnit.getPreviousEffectId() > 0) { - nextEffectF = roomUnit.getPreviousEffectId(); - nextEffectM = roomUnit.getPreviousEffectId(); - nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp(); + } else if (roomHabbo.getPreviousEffectId() > 0) { + nextEffectF = roomHabbo.getPreviousEffectId(); + nextEffectM = roomHabbo.getPreviousEffectId(); + nextEffectDuration = roomHabbo.getPreviousEffectEndTimestamp(); } if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) { - room.giveEffect(habbo, nextEffectM, nextEffectDuration, true); + habbo.getRoomUnit().giveEffect(nextEffectM, nextEffectDuration, true); return; } if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) { - room.giveEffect(habbo, nextEffectF, nextEffectDuration, true); + habbo.getRoomUnit().giveEffect(nextEffectF, nextEffectDuration, true); } - roomUnit.setCanWalk(true); + roomHabbo.setCanWalk(true); if (room.getRoomSpecialTypes() != null) { for (InteractionGameGate gate : room.getRoomSpecialTypes().getFreezeGates().values()) { @@ -64,9 +64,9 @@ public class FreezeGameTeam extends GameTeam { public void addMember(GamePlayer gamePlayer) { super.addMember(gamePlayer); - RoomUnit roomUnit = gamePlayer.getHabbo().getRoomUnit(); - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - gamePlayer.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(gamePlayer.getHabbo(), FreezeGame.effectId + this.teamColor.type, -1, true); + RoomHabbo roomHabbo = gamePlayer.getHabbo().getRoomUnit(); + if (roomHabbo.getEffectId() > 0) + roomHabbo.setPreviousEffectId(roomHabbo.getEffectId(), roomHabbo.getPreviousEffectEndTimestamp()); + gamePlayer.getHabbo().getRoomUnit().giveEffect(FreezeGame.effectId + this.teamColor.type, -1, true); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/tag/TagGame.java b/src/main/java/com/eu/habbo/habbohotel/games/tag/TagGame.java index bd612428..743d9d56 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/tag/TagGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/tag/TagGame.java @@ -9,10 +9,10 @@ import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.plugin.EventHandler; import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; import com.eu.habbo.plugin.events.users.UserTakeStepEvent; @@ -34,8 +34,8 @@ public abstract class TagGame extends Game { public static void onUserLookAtPoint(RoomUnitLookAtPointEvent event) { if (event.room == null || event.roomUnit == null || event.location == null) return; - if (RoomLayout.tilesAdjecent(event.roomUnit.getCurrentLocation(), event.location)) { - Habbo habbo = event.room.getHabbo(event.roomUnit); + if (RoomLayout.tilesAdjecent(event.roomUnit.getCurrentPosition(), event.location)) { + Habbo habbo = event.room.getRoomUnitManager().getHabboByRoomUnit(event.roomUnit); if (habbo != null) { if (habbo.getHabboInfo().getCurrentGame() != null) { @@ -44,7 +44,7 @@ public abstract class TagGame extends Game { if (game != null) { if (game.isTagger(habbo)) { - for (Habbo tagged : event.room.getHabbosAt(event.location)) { + for (Habbo tagged : event.room.getRoomUnitManager().getHabbosAt(event.location)) { if (tagged == habbo || tagged.getHabboInfo().getCurrentGame() == null || tagged.getHabboInfo().getCurrentGame() != habbo.getHabboInfo().getCurrentGame()) { continue; } @@ -63,15 +63,15 @@ public abstract class TagGame extends Game { @EventHandler public static void onUserWalkEvent(UserTakeStepEvent event) { if (event.habbo.getHabboInfo().getCurrentGame() != null && TagGame.class.isAssignableFrom(event.habbo.getHabboInfo().getCurrentGame())) { - THashSet items = event.habbo.getHabboInfo().getCurrentRoom().getItemsAt(event.toLocation); + THashSet items = event.habbo.getRoomUnit().getRoom().getRoomItemManager().getItemsAt(event.toLocation); - TagGame game = (TagGame) event.habbo.getHabboInfo().getCurrentRoom().getGame(event.habbo.getHabboInfo().getCurrentGame()); + TagGame game = (TagGame) event.habbo.getRoomUnit().getRoom().getGame(event.habbo.getHabboInfo().getCurrentGame()); if (game != null) { - for (HabboItem item : items) { + for (RoomItem item : items) { if (item instanceof InteractionTagField && ((InteractionTagField) item).gameClazz == event.habbo.getHabboInfo().getCurrentGame()) { if (game.taggers.isEmpty()) { - game.tagged(event.habbo.getHabboInfo().getCurrentRoom(), null, event.habbo); + game.tagged(event.habbo.getRoomUnit().getRoom(), null, event.habbo); } return; } @@ -97,22 +97,22 @@ public abstract class TagGame extends Game { return; } - THashSet poles = room.getRoomSpecialTypes().getItemsOfType(this.getTagPole()); + THashSet poles = room.getRoomSpecialTypes().getItemsOfType(this.getTagPole()); InteractionTagPole pole = this.taggers.get(tagger); - room.giveEffect(tagged, this.getTaggedEffect(tagged), -1); + tagged.getRoomUnit().giveEffect(this.getTaggedEffect(tagged), -1); if (poles.size() > this.taggers.size()) { for (Map.Entry set : this.taggers.entrySet()) { poles.remove(set.getValue()); } - for (HabboItem item : poles) { - tagged.getHabboInfo().getCurrentRoom().giveEffect(tagged, this.getTaggedEffect(tagged), -1); + for (RoomItem item : poles) { + tagged.getRoomUnit().giveEffect(this.getTaggedEffect(tagged), -1); this.taggers.put(tagged, (InteractionTagPole) item); } } else { if (tagger != null) { - room.giveEffect(tagger, this.getEffect(tagger), -1); + tagger.getRoomUnit().giveEffect(this.getEffect(tagger), -1); this.taggers.remove(tagger); } @@ -120,7 +120,7 @@ public abstract class TagGame extends Game { } if (pole != null) { - pole.setExtradata("1"); + pole.setExtraData("1"); room.updateItemState(pole); Emulator.getThreading().run(new HabboItemNewState(pole, room, "0"), 1000); } @@ -130,39 +130,39 @@ public abstract class TagGame extends Game { public synchronized boolean addHabbo(Habbo habbo, GameTeamColors teamColor) { super.addHabbo(habbo, GameTeamColors.RED); - RoomUnit roomUnit = habbo.getRoomUnit(); + RoomHabbo roomHabbo = habbo.getRoomUnit(); if (this.getTagPole() != null) { - THashSet poles = habbo.getHabboInfo().getCurrentRoom().getRoomSpecialTypes().getItemsOfType(this.getTagPole()); + THashSet poles = habbo.getRoomUnit().getRoom().getRoomSpecialTypes().getItemsOfType(this.getTagPole()); if (poles.size() > this.taggers.size()) { for (Map.Entry set : this.taggers.entrySet()) { poles.remove(set.getValue()); } - TObjectHashIterator iterator = poles.iterator(); + TObjectHashIterator iterator = poles.iterator(); if ((iterator.hasNext())) { - HabboItem item = iterator.next(); - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, this.getEffect(habbo), -1, true); - this.room.scheduledTasks.add(() -> habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, this.getTaggedEffect(habbo), -1, true)); + RoomItem item = iterator.next(); + if (roomHabbo.getEffectId() > 0) + roomHabbo.setPreviousEffectId(roomHabbo.getEffectId(), roomHabbo.getPreviousEffectEndTimestamp()); + habbo.getRoomUnit().giveEffect(this.getEffect(habbo), -1, true); + this.room.scheduledTasks.add(() -> habbo.getRoomUnit().giveEffect(this.getTaggedEffect(habbo), -1, true)); this.taggers.put(habbo, (InteractionTagPole) item); return true; } } } else { if (this.taggers.isEmpty()) { - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, this.getEffect(habbo), -1, true); - this.room.scheduledTasks.add(() -> habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, this.getTaggedEffect(habbo), -1, true)); + if (roomHabbo.getEffectId() > 0) + roomHabbo.setPreviousEffectId(roomHabbo.getEffectId(), roomHabbo.getPreviousEffectEndTimestamp()); + habbo.getRoomUnit().giveEffect(this.getEffect(habbo), -1, true); + this.room.scheduledTasks.add(() -> habbo.getRoomUnit().giveEffect(this.getTaggedEffect(habbo), -1, true)); this.taggers.put(habbo, null); return true; } } - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, this.getEffect(habbo), -1, true); + if (roomHabbo.getEffectId() > 0) + roomHabbo.setPreviousEffectId(roomHabbo.getEffectId(), roomHabbo.getPreviousEffectEndTimestamp()); + habbo.getRoomUnit().giveEffect(this.getEffect(habbo), -1, true); return true; } @@ -172,11 +172,11 @@ public abstract class TagGame extends Game { super.removeHabbo(habbo); this.taggers.remove(habbo); - RoomUnit roomUnit = habbo.getRoomUnit(); - Room room = roomUnit.getRoom(); + RoomHabbo roomHabbo = habbo.getRoomUnit(); + Room room = roomHabbo.getRoom(); if (room == null) return; - HabboItem topItem = room.getTopItemAt(roomUnit.getCurrentLocation().getX(), roomUnit.getCurrentLocation().getY()); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(roomHabbo.getCurrentPosition().getX(), roomHabbo.getCurrentPosition().getY()); int nextEffectM = 0; int nextEffectF = 0; int nextEffectDuration = -1; @@ -184,19 +184,19 @@ public abstract class TagGame extends Game { if (topItem != null) { nextEffectM = topItem.getBaseItem().getEffectM(); nextEffectF = topItem.getBaseItem().getEffectF(); - } else if (roomUnit.getPreviousEffectId() > 0) { - nextEffectF = roomUnit.getPreviousEffectId(); - nextEffectM = roomUnit.getPreviousEffectId(); - nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp(); + } else if (roomHabbo.getPreviousEffectId() > 0) { + nextEffectF = roomHabbo.getPreviousEffectId(); + nextEffectM = roomHabbo.getPreviousEffectId(); + nextEffectDuration = roomHabbo.getPreviousEffectEndTimestamp(); } if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) { - room.giveEffect(habbo, nextEffectM, nextEffectDuration, true); + habbo.getRoomUnit().giveEffect(nextEffectM, nextEffectDuration, true); return; } if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) { - room.giveEffect(habbo, nextEffectF, nextEffectDuration, true); + habbo.getRoomUnit().giveEffect(nextEffectF, nextEffectDuration, true); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java b/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java index 9cb2a072..0bf1d1d6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java +++ b/src/main/java/com/eu/habbo/habbohotel/games/wired/WiredGame.java @@ -3,10 +3,10 @@ package com.eu.habbo.habbohotel.games.wired; import com.eu.habbo.habbohotel.games.*; import com.eu.habbo.habbohotel.games.freeze.FreezeGame; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; public class WiredGame extends Game { public GameState state = GameState.RUNNING; @@ -31,21 +31,21 @@ public class WiredGame extends Game { @Override public boolean addHabbo(Habbo habbo, GameTeamColors teamColor) { - RoomUnit roomUnit = habbo.getRoomUnit(); - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - this.room.giveEffect(habbo, FreezeGame.effectId + teamColor.type, -1, true); + RoomHabbo roomHabbo = habbo.getRoomUnit(); + if (roomHabbo.getEffectId() > 0) + roomHabbo.setPreviousEffectId(roomHabbo.getEffectId(), roomHabbo.getPreviousEffectEndTimestamp()); + roomHabbo.giveEffect(FreezeGame.effectId + teamColor.type, -1, true); return super.addHabbo(habbo, teamColor); } @Override public void removeHabbo(Habbo habbo) { super.removeHabbo(habbo); - RoomUnit roomUnit = habbo.getRoomUnit(); + RoomHabbo roomHabbo = habbo.getRoomUnit(); Room room = this.room; if (room == null) return; - HabboItem topItem = room.getTopItemAt(roomUnit.getCurrentLocation().getX(), roomUnit.getCurrentLocation().getY()); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(roomHabbo.getCurrentPosition().getX(), roomHabbo.getCurrentPosition().getY()); int nextEffectM = 0; int nextEffectF = 0; int nextEffectDuration = -1; @@ -53,19 +53,19 @@ public class WiredGame extends Game { if (topItem != null) { nextEffectM = topItem.getBaseItem().getEffectM(); nextEffectF = topItem.getBaseItem().getEffectF(); - } else if (roomUnit.getPreviousEffectId() > 0) { - nextEffectF = roomUnit.getPreviousEffectId(); - nextEffectM = roomUnit.getPreviousEffectId(); - nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp(); + } else if (roomHabbo.getPreviousEffectId() > 0) { + nextEffectF = roomHabbo.getPreviousEffectId(); + nextEffectM = roomHabbo.getPreviousEffectId(); + nextEffectDuration = roomHabbo.getPreviousEffectEndTimestamp(); } if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) { - room.giveEffect(habbo, nextEffectM, nextEffectDuration, true); + roomHabbo.giveEffect(nextEffectM, nextEffectDuration, true); return; } if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) { - room.giveEffect(habbo, nextEffectF, nextEffectDuration, true); + roomHabbo.giveEffect(nextEffectF, nextEffectDuration, true); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java index 06827a70..93217ee5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/guilds/GuildManager.java @@ -152,10 +152,10 @@ public class GuildManager { statement.execute(); } - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); if (room != null) { - room.setGuildId(0); + room.getRoomInfo().setGuild(null); } } catch (SQLException e) { log.error("Caught SQL exception", e); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/IEventTriggers.java b/src/main/java/com/eu/habbo/habbohotel/items/IEventTriggers.java index 788f92d8..57dd19c3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/IEventTriggers.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/IEventTriggers.java @@ -2,7 +2,7 @@ package com.eu.habbo.habbohotel.items; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; public interface IEventTriggers { void onClick(GameClient client, Room room, Object[] objects) throws Exception; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/Item.java b/src/main/java/com/eu/habbo/habbohotel/items/Item.java index bfb3c6a7..8827829d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/Item.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/Item.java @@ -2,7 +2,7 @@ package com.eu.habbo.habbohotel.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionMultiHeight; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ISerialize; import com.eu.habbo.messages.ServerMessage; import gnu.trove.list.array.TIntArrayList; @@ -12,7 +12,6 @@ import java.sql.ResultSet; import java.sql.SQLException; public class Item implements ISerialize { - @Getter private int id; @Getter @@ -33,7 +32,7 @@ public class Item implements ISerialize { private boolean allowWalk; private boolean allowSit; private boolean allowLay; - private boolean allowRecyle; + private boolean allowRecycle; private boolean allowTrade; private boolean allowMarketplace; private boolean allowGift; @@ -52,7 +51,6 @@ public class Item implements ISerialize { private String customParams; @Getter private String clothingOnWalk; - @Getter private ItemInteraction interactionType; @Getter @@ -66,15 +64,15 @@ public class Item implements ISerialize { return item.getName().toLowerCase().startsWith("a0 pet"); } - public static double getCurrentHeight(HabboItem item) { + public static double getCurrentHeight(RoomItem item) { if (item instanceof InteractionMultiHeight && item.getBaseItem().getMultiHeights().length > 0) { - if (item.getExtradata().isEmpty()) { - item.setExtradata("0"); + if (item.getExtraData().isEmpty()) { + item.setExtraData("0"); } try { - int index = Integer.parseInt(item.getExtradata()) % (item.getBaseItem().getMultiHeights().length); - return item.getBaseItem().getMultiHeights()[(item.getExtradata().isEmpty() ? 0 : index)]; + int index = Integer.parseInt(item.getExtraData()) % (item.getBaseItem().getMultiHeights().length); + return item.getBaseItem().getMultiHeights()[(item.getExtraData().isEmpty() ? 0 : index)]; } catch (NumberFormatException ignored) { } @@ -103,7 +101,7 @@ public class Item implements ISerialize { this.allowWalk = set.getBoolean("allow_walk"); this.allowSit = set.getBoolean("allow_sit"); this.allowLay = set.getBoolean("allow_lay"); - this.allowRecyle = set.getBoolean("allow_recycle"); + this.allowRecycle = set.getBoolean("allow_recycle"); this.allowTrade = set.getBoolean("allow_trade"); this.allowMarketplace = set.getBoolean("allow_marketplace_sell"); this.allowGift = set.getBoolean("allow_gift"); @@ -164,7 +162,7 @@ public class Item implements ISerialize { } public boolean allowRecyle() { - return this.allowRecyle; + return this.allowRecycle; } public boolean allowTrade() { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/ItemInteraction.java b/src/main/java/com/eu/habbo/habbohotel/items/ItemInteraction.java index fd32de85..2f830413 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemInteraction.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemInteraction.java @@ -1,6 +1,6 @@ package com.eu.habbo.habbohotel.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; import lombok.Getter; @@ -9,5 +9,5 @@ public class ItemInteraction { @Getter private final String name; @Getter - private final Class type; + private final Class type; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java index f798e0fe..125a12d3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/ItemManager.java @@ -51,8 +51,9 @@ import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraRandom; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraUnseen; import com.eu.habbo.habbohotel.items.interactions.wired.triggers.*; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreManager; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; import com.eu.habbo.plugin.events.emulator.EmulatorLoadItemsManagerEvent; @@ -147,9 +148,9 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("hopper", InteractionHopper.class)); this.interactionsList.add(new ItemInteraction("costume_hopper", InteractionCostumeHopper.class)); this.interactionsList.add(new ItemInteraction("effect_gate", InteractionEffectGate.class)); - this.interactionsList.add(new ItemInteraction("club_hopper", InteractionHabboClubHopper.class)); - this.interactionsList.add(new ItemInteraction("club_gate", InteractionHabboClubGate.class)); - this.interactionsList.add(new ItemInteraction("club_teleporttile", InteractionHabboClubTeleportTile.class)); + this.interactionsList.add(new ItemInteraction("club_hopper", InteractionRoomClubHopper.class)); + this.interactionsList.add(new ItemInteraction("club_gate", InteractionRoomClubGate.class)); + this.interactionsList.add(new ItemInteraction("club_teleporttile", InteractionRoomClubTeleportTile.class)); this.interactionsList.add(new ItemInteraction("onewaygate", InteractionOneWayGate.class)); this.interactionsList.add(new ItemInteraction("love_lock", InteractionLoveLock.class)); this.interactionsList.add(new ItemInteraction("clothing", InteractionClothing.class)); @@ -198,10 +199,10 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("game_timer", InteractionGameTimer.class)); - this.interactionsList.add(new ItemInteraction("wf_trg_walks_on_furni", WiredTriggerHabboWalkOnFurni.class)); - this.interactionsList.add(new ItemInteraction("wf_trg_walks_off_furni", WiredTriggerHabboWalkOffFurni.class)); - this.interactionsList.add(new ItemInteraction("wf_trg_enter_room", WiredTriggerHabboEntersRoom.class)); - this.interactionsList.add(new ItemInteraction("wf_trg_says_something", WiredTriggerHabboSaysKeyword.class)); + this.interactionsList.add(new ItemInteraction("wf_trg_walks_on_furni", WiredTriggerRoomWalkOnFurni.class)); + this.interactionsList.add(new ItemInteraction("wf_trg_walks_off_furni", WiredTriggerRoomWalkOffFurni.class)); + this.interactionsList.add(new ItemInteraction("wf_trg_enter_room", WiredTriggerRoomEntersRoom.class)); + this.interactionsList.add(new ItemInteraction("wf_trg_says_something", WiredTriggerRoomSaysKeyword.class)); this.interactionsList.add(new ItemInteraction("wf_trg_periodically", WiredTriggerRepeater.class)); this.interactionsList.add(new ItemInteraction("wf_trg_period_long", WiredTriggerRepeaterLong.class)); this.interactionsList.add(new ItemInteraction("wf_trg_state_changed", WiredTriggerFurniStateToggled.class)); @@ -211,7 +212,7 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("wf_trg_game_starts", WiredTriggerGameStarts.class)); this.interactionsList.add(new ItemInteraction("wf_trg_game_ends", WiredTriggerGameEnds.class)); this.interactionsList.add(new ItemInteraction("wf_trg_bot_reached_stf", WiredTriggerBotReachedFurni.class)); - this.interactionsList.add(new ItemInteraction("wf_trg_bot_reached_avtr", WiredTriggerBotReachedHabbo.class)); + this.interactionsList.add(new ItemInteraction("wf_trg_bot_reached_avtr", WiredTriggerBotReachedRoom.class)); this.interactionsList.add(new ItemInteraction("wf_trg_score_achieved", WiredTriggerScoreAchieved.class)); this.interactionsList.add(new ItemInteraction("wf_trg_game_team_win", WiredTriggerTeamWins.class)); this.interactionsList.add(new ItemInteraction("wf_trg_game_team_lose", WiredTriggerTeamLoses.class)); @@ -234,43 +235,43 @@ public class ItemManager { this.interactionsList.add(new ItemInteraction("wf_act_move_furni_to", WiredEffectMoveFurniTo.class)); this.interactionsList.add(new ItemInteraction("wf_act_give_reward", WiredEffectGiveReward.class)); this.interactionsList.add(new ItemInteraction("wf_act_call_stacks", WiredEffectTriggerStacks.class)); - this.interactionsList.add(new ItemInteraction("wf_act_kick_user", WiredEffectKickHabbo.class)); - this.interactionsList.add(new ItemInteraction("wf_act_mute_triggerer", WiredEffectMuteHabbo.class)); + this.interactionsList.add(new ItemInteraction("wf_act_kick_user", WiredEffectKickRoom.class)); + this.interactionsList.add(new ItemInteraction("wf_act_mute_triggerer", WiredEffectMuteRoom.class)); this.interactionsList.add(new ItemInteraction("wf_act_bot_teleport", WiredEffectBotTeleport.class)); this.interactionsList.add(new ItemInteraction("wf_act_bot_move", WiredEffectBotWalkToFurni.class)); this.interactionsList.add(new ItemInteraction("wf_act_bot_talk", WiredEffectBotTalk.class)); this.interactionsList.add(new ItemInteraction("wf_act_bot_give_handitem", WiredEffectBotGiveHandItem.class)); - this.interactionsList.add(new ItemInteraction("wf_act_bot_follow_avatar", WiredEffectBotFollowHabbo.class)); + this.interactionsList.add(new ItemInteraction("wf_act_bot_follow_avatar", WiredEffectBotFollowRoom.class)); this.interactionsList.add(new ItemInteraction("wf_act_bot_clothes", WiredEffectBotClothes.class)); - this.interactionsList.add(new ItemInteraction("wf_act_bot_talk_to_avatar", WiredEffectBotTalkToHabbo.class)); + this.interactionsList.add(new ItemInteraction("wf_act_bot_talk_to_avatar", WiredEffectBotTalkToRoom.class)); this.interactionsList.add(new ItemInteraction("wf_act_give_respect", WiredEffectGiveRespect.class)); this.interactionsList.add(new ItemInteraction("wf_act_alert", WiredEffectAlert.class)); this.interactionsList.add(new ItemInteraction("wf_act_give_handitem", WiredEffectGiveHandItem.class)); this.interactionsList.add(new ItemInteraction("wf_act_give_effect", WiredEffectGiveEffect.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_has_furni_on", WiredConditionFurniHaveFurni.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_furnis_hv_avtrs", WiredConditionFurniHaveHabbo.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_furnis_hv_avtrs", WiredConditionFurniHaveRoom.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_stuff_is", WiredConditionFurniTypeMatch.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_actor_in_group", WiredConditionGroupMember.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_user_count_in", WiredConditionHabboCount.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_wearing_effect", WiredConditionHabboHasEffect.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_wearing_badge", WiredConditionHabboWearsBadge.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_user_count_in", WiredConditionRoomCount.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_wearing_effect", WiredConditionRoomHasEffect.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_wearing_badge", WiredConditionRoomWearsBadge.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_time_less_than", WiredConditionLessTimeElapsed.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_match_snapshot", WiredConditionMatchStatePosition.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_time_more_than", WiredConditionMoreTimeElapsed.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_not_furni_on", WiredConditionNotFurniHaveFurni.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_not_hv_avtrs", WiredConditionNotFurniHaveHabbo.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_not_hv_avtrs", WiredConditionNotFurniHaveRoom.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_not_stuff_is", WiredConditionNotFurniTypeMatch.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_not_user_count", WiredConditionNotHabboCount.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_not_wearing_fx", WiredConditionNotHabboHasEffect.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_not_wearing_b", WiredConditionNotHabboWearsBadge.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_not_user_count", WiredConditionNotRoomCount.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_not_wearing_fx", WiredConditionNotRoomHasEffect.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_not_wearing_b", WiredConditionNotRoomWearsBadge.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_not_in_group", WiredConditionNotInGroup.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_not_in_team", WiredConditionNotInTeam.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_not_match_snap", WiredConditionNotMatchStatePosition.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_not_trggrer_on", WiredConditionNotTriggerOnFurni.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_actor_in_team", WiredConditionTeamMember.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_trggrer_on_frn", WiredConditionTriggerOnFurni.class)); - this.interactionsList.add(new ItemInteraction("wf_cnd_has_handitem", WiredConditionHabboHasHandItem.class)); + this.interactionsList.add(new ItemInteraction("wf_cnd_has_handitem", WiredConditionRoomHasHandItem.class)); this.interactionsList.add(new ItemInteraction("wf_cnd_date_rng_active", WiredConditionDateRangeActive.class)); @@ -363,7 +364,7 @@ public class ItemManager { } - public ItemInteraction getItemInteraction(Class type) { + public ItemInteraction getItemInteraction(Class type) { for (ItemInteraction interaction : this.interactionsList) { if (interaction.getType() == type) return interaction; @@ -477,7 +478,7 @@ public class ItemManager { return null; } - public HabboItem createItem(int habboId, Item item, int limitedStack, int limitedSells, String extraData) { + public RoomItem createItem(int habboId, Item item, int limitedStack, int limitedSells, String extraData) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO items (user_id, item_id, extra_data, limited_data) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { statement.setInt(1, habboId); statement.setInt(2, item.getId()); @@ -487,14 +488,15 @@ public class ItemManager { try (ResultSet set = statement.getGeneratedKeys()) { if (set.next()) { - Class itemClass = item.getInteractionType().getType(); + Class itemClass = item.getInteractionType().getType(); + HabboInfo userInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(habboId); if (itemClass != null) { try { - return itemClass.getDeclaredConstructor(int.class, int.class, Item.class, String.class, int.class, int.class).newInstance(set.getInt(1), habboId, item, extraData, limitedStack, limitedSells); + return itemClass.getDeclaredConstructor(int.class, HabboInfo.class, Item.class, String.class, int.class, int.class).newInstance(set.getInt(1), userInfo, item, extraData, limitedStack, limitedSells); } catch (Exception e) { log.error("Caught exception", e); - return new InteractionDefault(set.getInt(1), habboId, item, extraData, limitedStack, limitedSells); + return new InteractionDefault(set.getInt(1), userInfo, item, extraData, limitedStack, limitedSells); } } } @@ -537,7 +539,7 @@ public class ItemManager { return new ArrayList<>(this.newuserGifts.values()); } - public void deleteItem(HabboItem item) { + public void deleteItem(RoomItem item) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM items WHERE id = ?")) { statement.setInt(1, item.getId()); statement.execute(); @@ -546,10 +548,10 @@ public class ItemManager { } } - public HabboItem handleRecycle(Habbo habbo, String itemId) { + public RoomItem handleRecycle(Habbo habbo, String itemId) { String extradata = Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "-" + Calendar.getInstance().get(Calendar.YEAR); - HabboItem item = null; + RoomItem item = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO items (user_id, item_id, extra_data) VALUES (?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) { statement.setInt(1, habbo.getHabboInfo().getId()); statement.setInt(2, Emulator.getGameEnvironment().getCatalogManager().ecotronItem.getId()); @@ -562,7 +564,7 @@ public class ItemManager { preparedStatement.setInt(1, set.getInt(1)); preparedStatement.setInt(2, Integer.parseInt(itemId)); preparedStatement.addBatch(); - item = new InteractionDefault(set.getInt(1), habbo.getHabboInfo().getId(), Emulator.getGameEnvironment().getCatalogManager().ecotronItem, extradata, 0, 0); + item = new InteractionDefault(set.getInt(1), habbo.getHabboInfo(), Emulator.getGameEnvironment().getCatalogManager().ecotronItem, extradata, 0, 0); } preparedStatement.executeBatch(); @@ -575,9 +577,9 @@ public class ItemManager { return item; } - public HabboItem handleOpenRecycleBox(Habbo habbo, HabboItem box) { + public RoomItem handleOpenRecycleBox(Habbo habbo, RoomItem box) { Emulator.getThreading().run(new QueryDeleteHabboItem(box.getId())); - HabboItem item = null; + RoomItem item = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM items_presents WHERE item_id = ? LIMIT 1")) { statement.setInt(1, box.getId()); try (ResultSet rewardSet = statement.executeQuery()) { @@ -627,7 +629,7 @@ public class ItemManager { } } - public void insertHopper(HabboItem hopper) { + public void insertHopper(RoomItem hopper) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO items_hoppers VALUES (?, ?)")) { statement.setInt(1, hopper.getId()); statement.setInt(2, hopper.getBaseItem().getId()); @@ -637,7 +639,7 @@ public class ItemManager { } } - public int[] getTargetTeleportRoomId(HabboItem item) { + public int[] getTargetTeleportRoomId(RoomItem item) { int[] a = new int[]{}; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT items.id, items.room_id FROM items_teleports INNER JOIN items ON items_teleports.teleport_one_id = items.id OR items_teleports.teleport_two_id = items.id WHERE items.id != ? AND items.room_id > 0 LIMIT 1")) { @@ -654,8 +656,8 @@ public class ItemManager { return a; } - public HabboItem loadHabboItem(int itemId) { - HabboItem item = null; + public RoomItem loadHabboItem(int itemId) { + RoomItem item = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE id = ? LIMIT 1")) { statement.setInt(1, itemId); try (ResultSet set = statement.executeQuery()) { @@ -672,20 +674,26 @@ public class ItemManager { return item; } - public HabboItem loadHabboItem(ResultSet set) throws SQLException { + public RoomItem loadHabboItem(ResultSet set) throws SQLException { Item baseItem = this.getItem(set.getInt("item_id")); if (baseItem == null) return null; - Class itemClass = baseItem.getInteractionType().getType(); + Class itemClass = baseItem.getInteractionType().getType(); if (itemClass != null) { try { - Constructor c = itemClass.getConstructor(ResultSet.class, Item.class); + Constructor c = itemClass.getConstructor(ResultSet.class, Item.class); c.setAccessible(true); - return (HabboItem) c.newInstance(set, baseItem); + RoomItem item = c.newInstance(set, baseItem); + + if (item instanceof InteractionWired interactionWired) { + interactionWired.loadWiredSettings(set); + } + + return item; } catch (Exception e) { log.error("Caught exception", e); } @@ -694,7 +702,7 @@ public class ItemManager { return null; } - public HabboItem createGift(String username, Item item, String extraData, int limitedStack, int limitedSells) { + public RoomItem createGift(String username, Item item, String extraData, int limitedStack, int limitedSells) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(username); int userId = 0; @@ -722,7 +730,7 @@ public class ItemManager { return null; } - public HabboItem createGift(int userId, Item item, String extraData, int limitedStack, int limitedSells) { + public RoomItem createGift(int userId, Item item, String extraData, int limitedStack, int limitedSells) { if (userId == 0) return null; @@ -731,7 +739,7 @@ public class ItemManager { extraData = extraData.substring(0, 1000); } - HabboItem gift = this.createItem(userId, item, limitedStack, limitedSells, extraData); + RoomItem gift = this.createItem(userId, item, limitedStack, limitedSells, extraData); if (gift != null) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/NewUserGift.java b/src/main/java/com/eu/habbo/habbohotel/items/NewUserGift.java index eda6da13..6420116a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/NewUserGift.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/NewUserGift.java @@ -2,7 +2,7 @@ package com.eu.habbo.habbohotel.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ISerialize; import com.eu.habbo.messages.ServerMessage; import lombok.Getter; @@ -52,7 +52,7 @@ public class NewUserGift implements ISerialize { Item item = Emulator.getGameEnvironment().getItemManager().getItem(set.getKey()); if (item != null) { - HabboItem createdItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), item, 0, 0, ""); + RoomItem createdItem = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), item, 0, 0, ""); if (createdItem != null) { habbo.addFurniture(createdItem); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java index 890738e6..9239c6a4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBackgroundToner.java @@ -5,29 +5,30 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.BackgroundAnimation; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionBackgroundToner extends HabboItem { +public class InteractionBackgroundToner extends RoomItem { public InteractionBackgroundToner(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionBackgroundToner(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionBackgroundToner(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt(5 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(4); - if (this.getExtradata().split(":").length == 4) { - String[] colorData = this.getExtradata().split(":"); + if (this.getExtraData().split(":").length == 4) { + String[] colorData = this.getExtraData().split(":"); serverMessage.appendInt(Integer.parseInt(colorData[0])); serverMessage.appendInt(Integer.parseInt(colorData[1])); serverMessage.appendInt(Integer.parseInt(colorData[2])); @@ -37,8 +38,8 @@ public class InteractionBackgroundToner extends HabboItem { serverMessage.appendInt(126); serverMessage.appendInt(126); serverMessage.appendInt(126); - this.setExtradata("0:126:126:126"); - this.needsUpdate(true); + this.setExtraData("0:126:126:126"); + this.setSqlUpdateNeeded(true); Emulator.getThreading().run(this); } @@ -61,31 +62,31 @@ public class InteractionBackgroundToner extends HabboItem { if(client != null) { - if (!client.getHabbo().getRoomUnit().getRoom().hasRights(client.getHabbo())) { + if (!client.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(client.getHabbo())) { ScripterManager.scripterDetected( client, Emulator.getTexts().getValue("scripter.warning.item.bgtoner.permission").replace("%username%", client.getHabbo().getHabboInfo().getUsername()) - .replace("%room%", room.getName()) - .replace("%owner%", room.getOwnerName()) + .replace("%room%", room.getRoomInfo().getName()) + .replace("%owner%", room.getRoomInfo().getOwnerInfo().getUsername()) ); return; } - if (client.getHabbo().getRoomUnit().isCmdSit() && client.getHabbo().getRoomUnit().getEffectId() == 1337) { + if (client.getHabbo().getRoomUnit().isCmdSitEnabled() && client.getHabbo().getRoomUnit().getEffectId() == 1337) { new BackgroundAnimation(this, room).run(); return; } } - if (this.getExtradata().split(":").length == 4) { - String[] data = this.getExtradata().split(":"); - this.setExtradata((data[0].equals("0") ? "1" : "0") + ":" + data[1] + ":" + data[2] + ":" + data[3]); + if (this.getExtraData().split(":").length == 4) { + String[] data = this.getExtraData().split(":"); + this.setExtraData((data[0].equals("0") ? "1" : "0") + ":" + data[1] + ":" + data[2] + ":" + data[3]); room.updateItem(this); } else { - this.setExtradata("0:126:126:126"); + this.setExtraData("0:126:126:126"); room.updateItem(this); } - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); Emulator.getThreading().run(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBadgeDisplay.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBadgeDisplay.java index c34be7e5..d62cf21c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBadgeDisplay.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBadgeDisplay.java @@ -3,20 +3,21 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionBadgeDisplay extends HabboItem { +public class InteractionBadgeDisplay extends RoomItem { public InteractionBadgeDisplay(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionBadgeDisplay(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionBadgeDisplay(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -24,13 +25,13 @@ public class InteractionBadgeDisplay extends HabboItem { serverMessage.appendInt(2 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(4); serverMessage.appendString("0"); - String[] data = this.getExtradata().split((char) 9 + ""); + String[] data = this.getExtraData().split((char) 9 + ""); if (data.length == 3) { serverMessage.appendString(data[2]); serverMessage.appendString(data[1]); serverMessage.appendString(data[0]); } else { - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); serverMessage.appendString("Unknown User"); serverMessage.appendString("Unknown Date"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBlackHole.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBlackHole.java index f669479a..c8a6493a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBlackHole.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBlackHole.java @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -15,8 +16,8 @@ public class InteractionBlackHole extends InteractionGate { super(set, baseItem); } - public InteractionBlackHole(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionBlackHole(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -24,10 +25,10 @@ public class InteractionBlackHole extends InteractionGate { Achievement holeCountAchievement = Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHoleFurniCount"); int holesCountProgress = 0; - Habbo owner = room.getHabbo(this.getUserId()); + Habbo owner = room.getRoomUnitManager().getRoomHabboById(this.getOwnerInfo().getId()); if (owner == null) { - holesCountProgress = AchievementManager.getAchievementProgressForHabbo(this.getUserId(), holeCountAchievement); + holesCountProgress = AchievementManager.getAchievementProgressForHabbo(this.getOwnerInfo().getId(), holeCountAchievement); } else { holesCountProgress = owner.getHabboStats().getAchievementProgress(holeCountAchievement); } @@ -37,7 +38,7 @@ public class InteractionBlackHole extends InteractionGate { if (owner != null) { AchievementManager.progressAchievement(owner, holeCountAchievement, holeDifference); } else { - AchievementManager.progressAchievement(this.getUserId(), holeCountAchievement, holeDifference); + AchievementManager.progressAchievement(this.getOwnerInfo().getId(), holeCountAchievement, holeDifference); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java index f6877649..dff6cbd5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionBuildArea.java @@ -6,10 +6,9 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.outgoing.rooms.items.ObjectsMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; import gnu.trove.TCollections; @@ -39,8 +38,8 @@ public class InteractionBuildArea extends InteractionCustomValues { tiles = new THashSet<>(); } - public InteractionBuildArea(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, defaultValues); + public InteractionBuildArea(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, defaultValues); defaultValues.put("tilesLeft", "0"); defaultValues.put("tilesRight", "0"); defaultValues.put("tilesFront", "0"); @@ -69,7 +68,7 @@ public class InteractionBuildArea extends InteractionCustomValues { if (builder != null) { builderInfo = builder.getHabboInfo(); } else { - builderInfo = HabboManager.getOfflineHabboInfo(builderName); + builderInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(builderName); } if (builderInfo != null) { canBuild.add(builderInfo.getId()); @@ -78,10 +77,10 @@ public class InteractionBuildArea extends InteractionCustomValues { if (!canBuild.isEmpty()) { for (RoomTile tile : this.tiles) { - THashSet tileItems = room.getItemsAt(tile); - for (HabboItem tileItem : tileItems) { - if (canBuild.contains(tileItem.getUserId()) && tileItem != this) { - room.pickUpItem(tileItem, null); + THashSet tileItems = room.getRoomItemManager().getItemsAt(tile); + for (RoomItem tileItem : tileItems) { + if (canBuild.contains(tileItem.getOwnerInfo().getId()) && tileItem != this) { + room.getRoomItemManager().pickUpItem(tileItem, null); } } } @@ -103,7 +102,7 @@ public class InteractionBuildArea extends InteractionCustomValues { if (builder != null) { builderInfo = builder.getHabboInfo(); } else { - builderInfo = HabboManager.getOfflineHabboInfo(builderName); + builderInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(builderName); } if (builderInfo != null) { canBuild.add(builderInfo.getId()); @@ -127,11 +126,11 @@ public class InteractionBuildArea extends InteractionCustomValues { if (!canBuild.isEmpty()) { for (RoomTile tile : this.tiles) { - THashSet tileItems = room.getItemsAt(tile); + THashSet tileItems = room.getRoomItemManager().getItemsAt(tile); if (newTiles.contains(tile)) continue; - for (HabboItem tileItem : tileItems) { - if (canBuild.contains(tileItem.getUserId()) && tileItem != this) { - room.pickUpItem(tileItem, null); + for (RoomItem tileItem : tileItems) { + if (canBuild.contains(tileItem.getOwnerInfo().getId()) && tileItem != this) { + room.getRoomItemManager().pickUpItem(tileItem, null); } } } @@ -140,7 +139,7 @@ public class InteractionBuildArea extends InteractionCustomValues { } public boolean inSquare(RoomTile location) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = this.getRoom(); if (room != null && this.tiles.size() == 0) { regenAffectedTiles(room); @@ -151,10 +150,10 @@ public class InteractionBuildArea extends InteractionCustomValues { } private void regenAffectedTiles(Room room) { - int minX = Math.max(0, this.getX() - Integer.parseInt(this.values.get("tilesBack"))); - int minY = Math.max(0, this.getY() - Integer.parseInt(this.values.get("tilesRight"))); - int maxX = Math.min(room.getLayout().getMapSizeX(), this.getX() + Integer.parseInt(this.values.get("tilesFront"))); - int maxY = Math.min(room.getLayout().getMapSizeY(), this.getY() + Integer.parseInt(this.values.get("tilesLeft"))); + int minX = Math.max(0, this.getCurrentPosition().getX() - Integer.parseInt(this.values.get("tilesBack"))); + int minY = Math.max(0, this.getCurrentPosition().getY() - Integer.parseInt(this.values.get("tilesRight"))); + int maxX = Math.min(room.getLayout().getMapSizeX(), this.getCurrentPosition().getX() + Integer.parseInt(this.values.get("tilesFront"))); + int maxY = Math.min(room.getLayout().getMapSizeY(), this.getCurrentPosition().getY() + Integer.parseInt(this.values.get("tilesLeft"))); this.tiles.clear(); @@ -179,7 +178,7 @@ public class InteractionBuildArea extends InteractionCustomValues { if (builder != null) { builderInfo = builder.getHabboInfo(); } else { - builderInfo = HabboManager.getOfflineHabboInfo(builderName); + builderInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(builderName); } if (builderInfo != null) { canBuild.add(builderInfo.getId()); @@ -188,10 +187,10 @@ public class InteractionBuildArea extends InteractionCustomValues { THashSet oldTiles = new THashSet<>(); - int minX = Math.max(0, this.getX() - Integer.parseInt(oldValues.get("tilesBack"))); - int minY = Math.max(0, this.getY() - Integer.parseInt(oldValues.get("tilesRight"))); - int maxX = Math.min(room.getLayout().getMapSizeX(), this.getX() + Integer.parseInt(oldValues.get("tilesFront"))); - int maxY = Math.min(room.getLayout().getMapSizeY(), this.getY() + Integer.parseInt(oldValues.get("tilesLeft"))); + int minX = Math.max(0, this.getCurrentPosition().getX() - Integer.parseInt(oldValues.get("tilesBack"))); + int minY = Math.max(0, this.getCurrentPosition().getY() - Integer.parseInt(oldValues.get("tilesRight"))); + int maxX = Math.min(room.getLayout().getMapSizeX(), this.getCurrentPosition().getX() + Integer.parseInt(oldValues.get("tilesFront"))); + int maxY = Math.min(room.getLayout().getMapSizeY(), this.getCurrentPosition().getY() + Integer.parseInt(oldValues.get("tilesLeft"))); for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { @@ -202,10 +201,10 @@ public class InteractionBuildArea extends InteractionCustomValues { } if (!canBuild.isEmpty()) { for (RoomTile tile : oldTiles) { - THashSet tileItems = room.getItemsAt(tile); - for (HabboItem tileItem : tileItems) { - if (canBuild.contains(tileItem.getUserId()) && tileItem != this) { - room.pickUpItem(tileItem, null); + THashSet tileItems = room.getRoomItemManager().getItemsAt(tile); + for (RoomItem tileItem : tileItems) { + if (canBuild.contains(tileItem.getOwnerInfo().getId()) && tileItem != this) { + room.getRoomItemManager().pickUpItem(tileItem, null); } } } @@ -217,21 +216,21 @@ public class InteractionBuildArea extends InteractionCustomValues { if (effectItem != null) { TIntObjectMap ownerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); ownerNames.put(-1, "System"); - THashSet items = new THashSet<>(); + THashSet items = new THashSet<>(); int id = 0; for (RoomTile tile : this.tiles) { id--; - HabboItem item = new InteractionDefault(id, -1, effectItem, "1", 0, 0); - item.setX(tile.getX()); - item.setY(tile.getY()); - item.setZ(tile.relativeHeight()); + RoomItem item = new InteractionDefault(id, null, effectItem, "1", 0, 0); + + item.setCurrentPosition(tile); + item.setCurrentZ(tile.relativeHeight()); items.add(item); } client.sendResponse(new ObjectsMessageComposer(ownerNames, items)); Emulator.getThreading().run(() -> { - for (HabboItem item : items) { + for (RoomItem item : items) { client.sendResponse(new RemoveFloorItemComposer(item, true)); } }, 3000); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java index b1223794..114871a0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCannon.java @@ -5,8 +5,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.CannonKickAction; import com.eu.habbo.threading.runnables.CannonResetCooldownAction; @@ -15,23 +16,23 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -public class InteractionCannon extends HabboItem { +public class InteractionCannon extends RoomItem { public boolean cooldown = false; public InteractionCannon(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionCannon(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionCannon(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -55,22 +56,22 @@ public class InteractionCannon extends HabboItem { if (room == null) return; - RoomTile tile = room.getLayout().getTile(this.getX(), this.getY()); + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); RoomTile fuseTile = this.getRotation() >= 4 ? tile : room.getLayout().getTileInFront(tile, ((this.getRotation() % 2) + 2) % 8); List tiles = room.getLayout().getTilesAround(fuseTile); tiles.remove(room.getLayout().getTileInFront(tile, (this.getRotation() + (this.getRotation() >= 4 ? -1 : 0)) % 8)); tiles.remove(room.getLayout().getTileInFront(tile, (this.getRotation() + (this.getRotation() >= 4 ? 5 : 4)) % 8)); - if ((client == null || (tiles.contains(client.getHabbo().getRoomUnit().getCurrentLocation())) && client.getHabbo().getRoomUnit().canWalk()) && !this.cooldown) { + if ((client == null || (tiles.contains(client.getHabbo().getRoomUnit().getCurrentPosition())) && client.getHabbo().getRoomUnit().isCanWalk()) && !this.cooldown) { if (client != null) { client.getHabbo().getRoomUnit().setCanWalk(false); - client.getHabbo().getRoomUnit().setGoalLocation(client.getHabbo().getRoomUnit().getCurrentLocation()); + client.getHabbo().getRoomUnit().walkTo(client.getHabbo().getRoomUnit().getCurrentPosition()); client.getHabbo().getRoomUnit().lookAtPoint(fuseTile); - client.getHabbo().getRoomUnit().statusUpdate(true); + client.getHabbo().getRoomUnit().setStatusUpdateNeeded(true); } this.cooldown = true; - this.setExtradata(this.getExtradata().equals("1") ? "0" : "1"); + this.setExtraData(this.getExtraData().equals("1") ? "0" : "1"); room.updateItemState(this); Emulator.getThreading().run(new CannonKickAction(this, room, client), 750); Emulator.getThreading().run(new CannonResetCooldownAction(this), 2000); @@ -94,7 +95,7 @@ public class InteractionCannon extends HabboItem { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionClothing.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionClothing.java index 9bcd0794..d34bc24c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionClothing.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionClothing.java @@ -2,20 +2,21 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionClothing extends HabboItem { +public class InteractionClothing extends RoomItem { public InteractionClothing(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionClothing(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionClothing(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorPlate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorPlate.java index 9d181a92..c01803cc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorPlate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorPlate.java @@ -2,7 +2,8 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; @@ -15,8 +16,8 @@ public class InteractionColorPlate extends InteractionDefault { super(set, baseItem); } - public InteractionColorPlate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionColorPlate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -36,12 +37,12 @@ public class InteractionColorPlate extends InteractionDefault { private void change(Room room, int amount) { int state = 0; - if (this.getExtradata() == null || this.getExtradata().isEmpty()) { - this.setExtradata("0"); + if (this.getExtraData() == null || this.getExtraData().isEmpty()) { + this.setExtraData("0"); } try { - state = Integer.parseInt(this.getExtradata()); + state = Integer.parseInt(this.getExtraData()); } catch (Exception e) { log.error("Caught exception", e); } @@ -55,8 +56,8 @@ public class InteractionColorPlate extends InteractionDefault { state = 0; } - this.setExtradata(state + ""); - this.needsUpdate(true); + this.setExtraData(state + ""); + this.setSqlUpdateNeeded(true); room.updateItemState(this); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorWheel.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorWheel.java index 2f57bec8..f7c817ac 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorWheel.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionColorWheel.java @@ -4,8 +4,9 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.ItemUpdateMessageComposer; import com.eu.habbo.threading.runnables.RandomDiceNumber; @@ -13,21 +14,21 @@ import com.eu.habbo.threading.runnables.RandomDiceNumber; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionColorWheel extends HabboItem { +public class InteractionColorWheel extends RoomItem { private Runnable rollTaks; public InteractionColorWheel(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionColorWheel(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionColorWheel(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -46,11 +47,11 @@ public class InteractionColorWheel extends HabboItem { public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if (!room.hasRights(client.getHabbo())) + if (!room.getRoomRightsManager().hasRights(client.getHabbo())) return; - if (this.rollTaks == null && !this.getExtradata().equalsIgnoreCase("-1")) { - this.setExtradata("-1"); + if (this.rollTaks == null && !this.getExtraData().equalsIgnoreCase("-1")) { + this.setExtraData("-1"); room.sendComposer(new ItemUpdateMessageComposer(this).compose()); Emulator.getThreading().run(this); Emulator.getThreading().run(new RandomDiceNumber(this, room, this.getBaseItem().getStateCount()), 3000); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCostumeHopper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCostumeHopper.java index 96e83953..55ed6ed2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCostumeHopper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCostumeHopper.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.generic.alerts.CustomUserNotificationMessageComposer; import java.sql.ResultSet; @@ -13,8 +14,8 @@ public class InteractionCostumeHopper extends InteractionHopper { super(set, baseItem); } - public InteractionCostumeHopper(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionCostumeHopper(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java index 2ccdb52e..7ebe0137 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackable.java @@ -6,10 +6,11 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.CrackableReward; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionHabboClub; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.CrackableExplode; @@ -18,7 +19,7 @@ import com.eu.habbo.util.pathfinding.Rotation; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionCrackable extends HabboItem { +public class InteractionCrackable extends RoomItem { private final Object lock = new Object(); public boolean cracked = false; protected int ticks = 0; @@ -27,19 +28,19 @@ public class InteractionCrackable extends HabboItem { super(set, baseItem); } - public InteractionCrackable(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionCrackable(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) + this.setExtraData("0"); serverMessage.appendInt(7 + (this.isLimited() ? 256 : 0)); - serverMessage.appendString(Emulator.getGameEnvironment().getItemManager().calculateCrackState(Integer.parseInt(this.getExtradata()), Emulator.getGameEnvironment().getItemManager().getCrackableCount(this.getBaseItem().getId()), this.getBaseItem()) + ""); - serverMessage.appendInt(Integer.parseInt(this.getExtradata())); + serverMessage.appendString(Emulator.getGameEnvironment().getItemManager().calculateCrackState(Integer.parseInt(this.getExtraData()), Emulator.getGameEnvironment().getItemManager().getCrackableCount(this.getBaseItem().getId()), this.getBaseItem()) + ""); + serverMessage.appendInt(Integer.parseInt(this.getExtraData())); serverMessage.appendInt(Emulator.getGameEnvironment().getItemManager().getCrackableCount(this.getBaseItem().getId())); super.serializeExtradata(serverMessage); @@ -63,19 +64,19 @@ public class InteractionCrackable extends HabboItem { super.onClick(client, room, objects); synchronized (this.lock) { - if (this.getRoomId() == 0) + if (this.getRoom() == null) return; if (this.cracked) return; - if (this.userRequiredToBeAdjacent() && client.getHabbo().getRoomUnit().getCurrentLocation().distance(room.getLayout().getTile(this.getX(), this.getY())) > 1.5) { - client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), Rotation.Calculate(client.getHabbo().getRoomUnit().getX(), client.getHabbo().getRoomUnit().getY(), this.getX(), this.getY()))); + if (this.userRequiredToBeAdjacent() && client.getHabbo().getRoomUnit().getCurrentPosition().distance(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())) > 1.5) { + client.getHabbo().getRoomUnit().walkTo(room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), Rotation.Calculate(client.getHabbo().getRoomUnit().getCurrentPosition().getX(), client.getHabbo().getRoomUnit().getCurrentPosition().getY(), this.getCurrentPosition().getX(), this.getCurrentPosition().getY()))); return; } - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) + this.setExtraData("0"); if (this.getBaseItem().getEffectF() > 0) if (client.getHabbo().getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() == client.getHabbo().getRoomUnit().getEffectId()) @@ -92,7 +93,7 @@ public class InteractionCrackable extends HabboItem { public void onTick(Habbo habbo, Room room) { if (this.cracked) return; - if (this.allowAnyone() || this.getUserId() == habbo.getHabboInfo().getId()) { + if (this.allowAnyone() || this.getOwnerInfo().getId() == habbo.getHabboInfo().getId()) { CrackableReward rewardData = Emulator.getGameEnvironment().getItemManager().getCrackableData(this.getBaseItem().getId()); if (rewardData != null) { @@ -102,11 +103,11 @@ public class InteractionCrackable extends HabboItem { if(this.ticks < 1) { // If there are no ticks (for example because the room has been reloaded), check the current extradata of the item and update the ticks. - this.ticks = Integer.parseInt(this.getExtradata()); + this.ticks = Integer.parseInt(this.getExtraData()); } this.ticks++; - this.setExtradata("" + (this.ticks)); - this.needsUpdate(true); + this.setExtraData("" + (this.ticks)); + this.setSqlUpdateNeeded(true); room.updateItem(this); if (!rewardData.getAchievementTick().isEmpty()) { @@ -114,7 +115,7 @@ public class InteractionCrackable extends HabboItem { } if (!this.cracked && this.ticks == Emulator.getGameEnvironment().getItemManager().getCrackableCount(this.getBaseItem().getId())) { this.cracked = true; - Emulator.getThreading().run(new CrackableExplode(room, this, habbo, !this.placeInRoom(), this.getX(), this.getY()), 1500); + Emulator.getThreading().run(new CrackableExplode(room, this, habbo, !this.placeInRoom(), this.getCurrentPosition()), 1500); if (!rewardData.getAchievementCracked().isEmpty()) { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement(rewardData.getAchievementCracked())); @@ -168,7 +169,7 @@ public class InteractionCrackable extends HabboItem { public void reset(Room room) { this.cracked = false; this.ticks = 0; - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackableMaster.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackableMaster.java index 60244939..af4de4b3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackableMaster.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCrackableMaster.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,8 +11,8 @@ public class InteractionCrackableMaster extends InteractionCrackable { super(set, baseItem); } - public InteractionCrackableMaster(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionCrackableMaster(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java index 8f39af73..bb996240 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionCustomValues.java @@ -3,8 +3,9 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.map.hash.THashMap; @@ -12,7 +13,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map; -public abstract class InteractionCustomValues extends HabboItem { +public abstract class InteractionCustomValues extends RoomItem { public final THashMap values = new THashMap<>(); public InteractionCustomValues(ResultSet set, Item baseItem, THashMap defaultValues) throws SQLException { @@ -29,8 +30,8 @@ public abstract class InteractionCustomValues extends HabboItem { } } - public InteractionCustomValues(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, THashMap defaultValues) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionCustomValues(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, THashMap defaultValues) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.values.putAll(defaultValues); } @@ -52,7 +53,7 @@ public abstract class InteractionCustomValues extends HabboItem { @Override public void run() { - this.setExtradata(this.toExtraData()); + this.setExtraData(this.toExtraData()); super.run(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java index 255054ba..c3fcd2a5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDefault.java @@ -1,12 +1,14 @@ package com.eu.habbo.habbohotel.items.interactions; -import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ServerMessage; import lombok.extern.slf4j.Slf4j; @@ -15,20 +17,19 @@ import java.sql.ResultSet; import java.sql.SQLException; @Slf4j -public class InteractionDefault extends HabboItem { - +public class InteractionDefault extends RoomItem { public InteractionDefault(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionDefault(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionDefault(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -47,11 +48,16 @@ public class InteractionDefault extends HabboItem { public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { super.onMove(room, oldLocation, newLocation); - if (room.getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) { - for (RoomUnit unit : room.getRoomUnits()) { - if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) + //Check if there a no rollers + if (room.getRoomItemManager().getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) { + for (RoomUnit unit : room.getRoomUnitManager().getCurrentRoomUnits().values()) { + if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) { continue; // If the unit was previously on the furni... - if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore... + } + + if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) { + continue; // but is not anymore... + } try { this.onWalkOff(unit, room, new Object[]{oldLocation, newLocation}); // the unit walked off! @@ -69,20 +75,20 @@ public class InteractionDefault extends HabboItem { if (objects != null && objects.length > 0) { if (objects[0] instanceof Integer) { - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) + this.setExtraData("0"); if (this.getBaseItem().getStateCount() > 0) { int currentState = 0; try { - currentState = Integer.parseInt(this.getExtradata()); + currentState = Integer.parseInt(this.getExtraData()); } catch (NumberFormatException e) { - log.error("Incorrect extradata (" + this.getExtradata() + ") for item ID (" + this.getId() + ") of type (" + this.getBaseItem().getName() + ")"); + log.error("Incorrect extradata (" + this.getExtraData() + ") for item ID (" + this.getId() + ") of type (" + this.getBaseItem().getName() + ")"); } - this.setExtradata("" + (currentState + 1) % this.getBaseItem().getStateCount()); - this.needsUpdate(true); + this.setExtraData("" + (currentState + 1) % this.getBaseItem().getStateCount()); + this.setSqlUpdateNeeded(true); room.updateItemState(this); } @@ -99,114 +105,21 @@ public class InteractionDefault extends HabboItem { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - - if (roomUnit == null || (this.getBaseItem().getEffectF() == 0 && this.getBaseItem().getEffectM() == 0)) return; - if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo == null) return; - - if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1); - return; - } - - if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1); - } - } else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) { - Bot bot = room.getBot(roomUnit); - - if (bot == null) return; - - if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && roomUnit.getEffectId() != this.getBaseItem().getEffectM()) { - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectM(), -1); - return; - } - - if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && roomUnit.getEffectId() != this.getBaseItem().getEffectF()) { - if (roomUnit.getEffectId() > 0) - roomUnit.setPreviousEffectId(roomUnit.getEffectId(), roomUnit.getPreviousEffectEndTimestamp()); - room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectF(), -1); - } - } } @Override public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - - if (roomUnit != null) { - if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { - int nextEffectM = 0; - int nextEffectF = 0; - int nextEffectDuration = -1; - - if (objects != null && objects.length == 2) { - if (objects[0] instanceof RoomTile goalTile && objects[1] instanceof RoomTile) { - HabboItem topItem = room.getTopItemAt(goalTile.getX(), goalTile.getY(), (objects[0] != objects[1]) ? this : null); - - if (topItem != null && (topItem.getBaseItem().getEffectM() == this.getBaseItem().getEffectM() || topItem.getBaseItem().getEffectF() == this.getBaseItem().getEffectF())) { - return; - } - - if (topItem != null) { - nextEffectM = topItem.getBaseItem().getEffectM(); - nextEffectF = topItem.getBaseItem().getEffectF(); - } else if (roomUnit.getPreviousEffectId() > 0) { - nextEffectF = roomUnit.getPreviousEffectId(); - nextEffectM = roomUnit.getPreviousEffectId(); - nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp(); - } - } - } - - if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - - if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) { - room.giveEffect(habbo, nextEffectM, nextEffectDuration); - return; - } - - if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) { - room.giveEffect(habbo, nextEffectF, nextEffectDuration); - } - } - } else if (roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)) { - Bot bot = room.getBot(roomUnit); - - if (bot != null) { - if (bot.getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) { - room.giveEffect(roomUnit, nextEffectM, nextEffectDuration); - return; - } - - if (bot.getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) { - room.giveEffect(roomUnit, nextEffectF, nextEffectDuration); - } - } - } - } - } } public boolean canToggle(Habbo habbo, Room room) { - if (room.hasRights(habbo)) return true; + if (room.getRoomRightsManager().hasRights(habbo)) return true; if (!habbo.getHabboStats().isRentingSpace()) return false; - HabboItem rentSpace = room.getHabboItem(habbo.getHabboStats().getRentedItemId()); + RoomItem rentSpace = room.getRoomItemManager().getRoomItemById(habbo.getHabboStats().getRentedItemId()); - return rentSpace != null && RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getX(), rentSpace.getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(this.getX(), this.getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())); + return rentSpace != null && RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getCurrentPosition().getX(), rentSpace.getCurrentPosition().getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(this.getCurrentPosition().getX(), this.getCurrentPosition().getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDice.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDice.java index 896cf046..8f983a3d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDice.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionDice.java @@ -5,8 +5,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.plugin.events.furniture.FurnitureDiceRolledEvent; import com.eu.habbo.threading.runnables.RandomDiceNumber; @@ -14,9 +15,9 @@ import com.eu.habbo.threading.runnables.RandomDiceNumber; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionDice extends HabboItem { - public InteractionDice(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); +public class InteractionDice extends RoomItem { + public InteractionDice(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public InteractionDice(ResultSet set, Item baseItem) throws SQLException { @@ -26,7 +27,7 @@ public class InteractionDice extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -46,14 +47,14 @@ public class InteractionDice extends HabboItem { super.onClick(client, room, objects); if (client != null) { - if (RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), client.getHabbo().getRoomUnit().getCurrentLocation())) { - if (!this.getExtradata().equalsIgnoreCase("-1")) { + if (RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), client.getHabbo().getRoomUnit().getCurrentPosition())) { + if (!this.getExtraData().equalsIgnoreCase("-1")) { FurnitureDiceRolledEvent event = Emulator.getPluginManager().fireEvent(new FurnitureDiceRolledEvent(this, client.getHabbo(), -1)); if (event.isCancelled()) return; - this.setExtradata("-1"); + this.setExtraData("-1"); room.updateItemState(this); Emulator.getThreading().run(this); @@ -74,7 +75,7 @@ public class InteractionDice extends HabboItem { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java index eb0e8b19..e88ff3fd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGate.java @@ -5,7 +5,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.CloseGate; import java.sql.ResultSet; @@ -28,12 +30,12 @@ public class InteractionEffectGate extends InteractionDefault implements Conditi public InteractionEffectGate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionEffectGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionEffectGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -43,17 +45,16 @@ public class InteractionEffectGate extends InteractionDefault implements Conditi @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - if (roomUnit == null || room == null) + if (roomUnit == null || room == null || !(roomUnit instanceof RoomHabbo roomHabbo)) return false; String customparams = this.getBaseItem().getCustomParams().trim(); if (!customparams.isEmpty()) { - return Arrays.asList(customparams.split(";")) - .contains(String.valueOf(roomUnit.getEffectId())); + return Arrays.asList(customparams.split(";")).contains(String.valueOf(roomHabbo.getEffectId())); } - return defaultAllowedEnables.contains(roomUnit.getEffectId()); + return defaultAllowedEnables.contains(roomHabbo.getEffectId()); } @Override @@ -61,7 +62,7 @@ public class InteractionEffectGate extends InteractionDefault implements Conditi super.onWalkOn(roomUnit, room, objects); if (this.canWalkOn(roomUnit, room, objects)) { - this.setExtradata("1"); + this.setExtraData("1"); room.updateItemState(this); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGiver.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGiver.java index 4d8d011a..75781047 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGiver.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectGiver.java @@ -5,8 +5,10 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +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.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,38 +16,41 @@ import java.sql.SQLException; public class InteractionEffectGiver extends InteractionDefault { public InteractionEffectGiver(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionEffectGiver(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionEffectGiver(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentLocation(), room.getLayout().getTile(this.getX(), this.getY())) || - (client.getHabbo().getRoomUnit().getCurrentLocation().getX() == this.getX() && client.getHabbo().getRoomUnit().getCurrentLocation().getY() == this.getY())) { + if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentPosition(), room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())) || + (client.getHabbo().getRoomUnit().getCurrentPosition().getX() == this.getCurrentPosition().getX() && client.getHabbo().getRoomUnit().getCurrentPosition().getY() == this.getCurrentPosition().getY())) { this.handle(room, client.getHabbo().getRoomUnit()); } } protected void handle(Room room, RoomUnit roomUnit) { - if (this.getExtradata().isEmpty()) this.setExtradata("0"); + if (this.getExtraData().isEmpty()) this.setExtraData("0"); - if (!this.getExtradata().equals("0")) return; + if (!this.getExtraData().equals("0")) return; - HabboItem instance = this; - room.giveEffect(roomUnit, this.getBaseItem().getRandomVendingItem(), -1); + RoomItem instance = this; + + if(roomUnit instanceof RoomAvatar roomAvatar) { + roomAvatar.giveEffect(this.getBaseItem().getRandomVendingItem(), -1); + } if (this.getBaseItem().getStateCount() > 1) { - this.setExtradata("1"); + this.setExtraData("1"); room.updateItem(this); Emulator.getThreading().run(() -> { - InteractionEffectGiver.this.setExtradata("0"); + InteractionEffectGiver.this.setExtraData("0"); room.updateItem(instance); }, 500); } 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 ac10dcc7..a89643ef 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 @@ -4,10 +4,12 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUnitType; +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.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -19,8 +21,8 @@ public class InteractionEffectTile extends InteractionPressurePlate { super(set, baseItem); } - public InteractionEffectTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionEffectTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -51,14 +53,14 @@ public class InteractionEffectTile extends InteractionPressurePlate { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - if (roomUnit.getRoomUnitType() == RoomUnitType.USER) { - Habbo habbo = room.getHabbo(roomUnit); + if (roomUnit.getRoomUnitType() == RoomUnitType.HABBO) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { this.giveEffect(room, roomUnit, habbo.getHabboInfo().getGender()); } } else if (roomUnit.getRoomUnitType() == RoomUnitType.BOT) { - Bot bot = room.getBot(roomUnit); + Bot bot = room.getRoomUnitManager().getRoomBotById(roomUnit.getVirtualId()); if (bot != null) { this.giveEffect(room, roomUnit, bot.getGender()); @@ -67,10 +69,12 @@ public class InteractionEffectTile extends InteractionPressurePlate { } private void giveEffect(Room room, RoomUnit roomUnit, HabboGender gender) { - if (gender.equals(HabboGender.M)) { - room.giveEffect(roomUnit, this.getBaseItem().getEffectM(), -1); - } else { - room.giveEffect(roomUnit, this.getBaseItem().getEffectF(), -1); + if(roomUnit instanceof RoomAvatar roomAvatar) { + if (gender.equals(HabboGender.M)) { + roomAvatar.giveEffect(this.getBaseItem().getEffectM(), -1); + } else { + roomAvatar.giveEffect(this.getBaseItem().getEffectF(), -1); + } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectToggle.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectToggle.java index 3084f3e4..50a30309 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectToggle.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectToggle.java @@ -4,6 +4,7 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,19 +14,19 @@ public class InteractionEffectToggle extends InteractionDefault { super(set, baseItem); } - public InteractionEffectToggle(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionEffectToggle(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - if (this.getExtradata().isEmpty()) { - this.setExtradata("0"); + if (this.getExtraData().isEmpty()) { + this.setExtraData("0"); } if (client != null) { - if (room.hasRights(client.getHabbo())) { - if (Integer.parseInt(this.getExtradata()) < this.getBaseItem().getStateCount() - 1) { + if (room.getRoomRightsManager().hasRights(client.getHabbo())) { + if (Integer.parseInt(this.getExtraData()) < this.getBaseItem().getStateCount() - 1) { if ((client.getHabbo().getHabboInfo().getGender() == HabboGender.M && client.getHabbo().getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) || (client.getHabbo().getHabboInfo().getGender() == HabboGender.F && client.getHabbo().getRoomUnit().getEffectId() == this.getBaseItem().getEffectF())) { super.onClick(client, room, objects); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java index 49261af4..f579950b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachine.java @@ -2,7 +2,8 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,16 +11,16 @@ import java.sql.SQLException; public class InteractionEffectVendingMachine extends InteractionVendingMachine { public InteractionEffectVendingMachine(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionEffectVendingMachine(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionEffectVendingMachine(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override - public void giveVendingMachineItem(Room room, RoomUnit unit) { - room.giveEffect(unit, this.getBaseItem().getRandomVendingItem(), 30); + public void giveVendingMachineItem(Room room, RoomAvatar roomAvatar) { + roomAvatar.giveEffect(this.getBaseItem().getRandomVendingItem(), 30); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachineNoSides.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachineNoSides.java index 84f91edc..c7a77d10 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachineNoSides.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionEffectVendingMachineNoSides.java @@ -3,7 +3,8 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; @@ -12,17 +13,17 @@ import java.sql.SQLException; public class InteractionEffectVendingMachineNoSides extends InteractionVendingMachine { public InteractionEffectVendingMachineNoSides(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionEffectVendingMachineNoSides(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionEffectVendingMachineNoSides(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override - public void giveVendingMachineItem(Room room, RoomUnit unit) { - room.giveEffect(unit, this.getBaseItem().getRandomVendingItem(), 30); + public void giveVendingMachineItem(Room room, RoomAvatar roomAvatar) { + roomAvatar.giveEffect(this.getBaseItem().getRandomVendingItem(), 30); } @Override @@ -31,7 +32,7 @@ public class InteractionEffectVendingMachineNoSides extends InteractionVendingMa THashSet tiles = new THashSet<>(); for(int x = -1; x <= 1; x++) { for(int y = -1; y <= 1; y++) { - RoomTile tile = room.getLayout().getTile((short)(this.getX() + x), (short)(this.getY() + y)); + RoomTile tile = room.getLayout().getTile((short)(this.getCurrentPosition().getX() + x), (short)(this.getCurrentPosition().getY() + y)); if(tile != null) { tiles.add(tile); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionExternalImage.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionExternalImage.java index f6fa36e8..b5c5e429 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionExternalImage.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionExternalImage.java @@ -3,20 +3,21 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionExternalImage extends HabboItem { +public class InteractionExternalImage extends RoomItem { public InteractionExternalImage(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionExternalImage(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionExternalImage(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -37,7 +38,7 @@ public class InteractionExternalImage extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java index daf5ab50..9ebe2cb2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFXBox.java @@ -4,8 +4,9 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; @@ -18,15 +19,15 @@ public class InteractionFXBox extends InteractionDefault { // this.setExtradata("0"); } - public InteractionFXBox(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionFXBox(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); // this.setExtradata("0"); } @Override public void onClick(GameClient client, Room room, Object[] objects) { - if (client != null && this.getUserId() == client.getHabbo().getHabboInfo().getId()) { - if(this.getExtradata().equals("1")) + if (client != null && this.getOwnerInfo().getId() == client.getHabbo().getHabboInfo().getId()) { + if (this.getExtraData().equals("1")) return; int effectId = -1; @@ -43,23 +44,23 @@ public class InteractionFXBox extends InteractionDefault { } } - if(effectId < 0) + if (effectId < 0) return; - if(client.getHabbo().getInventory().getEffectsComponent().ownsEffect(effectId)) + if (client.getHabbo().getInventory().getEffectsComponent().ownsEffect(effectId)) return; client.getHabbo().getInventory().getEffectsComponent().createEffect(effectId, 0); client.getHabbo().getInventory().getEffectsComponent().enableEffect(effectId); - this.setExtradata("1"); + this.setExtraData("1"); room.updateItemState(this); - room.removeHabboItem(this); - HabboItem item = this; + room.getRoomItemManager().removeRoomItem(this); + RoomItem item = this; Emulator.getThreading().run(() -> { new QueryDeleteHabboItem(item.getId()).run(); room.sendComposer(new RemoveFloorItemComposer(item).compose()); - room.updateTile(room.getLayout().getTile(this.getX(), this.getY())); + room.updateTile(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); }, 500); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java index 22f4071d..b4763a98 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionFireworks.java @@ -7,8 +7,9 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import lombok.extern.slf4j.Slf4j; @@ -30,8 +31,8 @@ public class InteractionFireworks extends InteractionDefault { super(set, baseItem); } - public InteractionFireworks(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionFireworks(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -53,10 +54,10 @@ public class InteractionFireworks extends InteractionDefault { // Wireds can always detonate fireworks if charged if (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE) { - if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) { + if (this.getExtraData().equalsIgnoreCase(STATE_CHARGED)) { super.onClick(client, room, objects); - if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION)) { + if (this.getExtraData().equalsIgnoreCase(STATE_EXPLOSION)) { this.reCharge(room); } } @@ -70,13 +71,13 @@ public class InteractionFireworks extends InteractionDefault { // Habbos without rights have to walk to an adjecent tile to be able to detonate the fireworks if (!this.canToggle(client.getHabbo(), room)) { RoomTile closestTile = null; - for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) { - if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))) { + for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()))) { + if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentPosition()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentPosition()))) { closestTile = tile; } } - if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) { + if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentPosition())) { List onSuccess = new ArrayList<>(); onSuccess.add(() -> { try { @@ -86,15 +87,15 @@ public class InteractionFireworks extends InteractionDefault { } }); - client.getHabbo().getRoomUnit().setGoalLocation(closestTile); + client.getHabbo().getRoomUnit().walkTo(closestTile); Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>())); } } - if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) { + if (this.getExtraData().equalsIgnoreCase(STATE_CHARGED)) { super.onClick(client, room, objects); - if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION)) + if (this.getExtraData().equalsIgnoreCase(STATE_EXPLOSION)) { this.reCharge(room); AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger")); @@ -110,14 +111,14 @@ public class InteractionFireworks extends InteractionDefault { @Override public void onPlace(Room room) { super.onPlace(room); - this.setExtradata(STATE_CHARGED); + this.setExtraData(STATE_CHARGED); } @Override public boolean canToggle(Habbo habbo, Room room) { - return room.hasRights(habbo) || RoomLayout.tilesAdjecent( - room.getLayout().getTile(this.getX(), this.getY()), - habbo.getRoomUnit().getCurrentLocation() + return room.getRoomRightsManager().hasRights(habbo) || RoomLayout.tilesAdjecent( + room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), + habbo.getRoomUnit().getCurrentPosition() ); } @@ -133,8 +134,8 @@ public class InteractionFireworks extends InteractionDefault { } Emulator.getThreading().run(() -> { - this.setExtradata(STATE_CHARGED); - this.needsUpdate(true); + this.setExtraData(STATE_CHARGED); + this.setSqlUpdateNeeded(true); room.updateItemState(this); }, explodeDuration); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java index 9646940b..abb1fabf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGate.java @@ -4,27 +4,28 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionGate extends HabboItem { +public class InteractionGate extends RoomItem { public InteractionGate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -34,28 +35,27 @@ public class InteractionGate extends HabboItem { } public boolean isWalkable() { - return this.getExtradata().equals("1"); + return this.getExtraData().equals("1"); } @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { boolean executedByWired = (objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE); - if (client != null && !room.hasRights(client.getHabbo()) && !executedByWired) - return; + if (client != null && !room.getRoomRightsManager().hasRights(client.getHabbo()) && !executedByWired) return; // If a Habbo is standing on a tile occupied by the gate, the gate shouldn't open/close - for (RoomTile tile : room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) - if (room.hasHabbosAt(tile.getX(), tile.getY())) + for (RoomTile tile : room.getLayout().getTilesAt(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) + if (room.getRoomUnitManager().hasHabbosAt(tile)) return; // Gate closed = 0, open = 1 - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) + this.setExtraData("0"); - this.setExtradata((Integer.parseInt(this.getExtradata()) + 1) % 2 + ""); - room.updateTile(room.getLayout().getTile(this.getX(), this.getY())); - this.needsUpdate(true); + this.setExtraData((Integer.parseInt(this.getExtraData()) + 1) % 2 + ""); + room.updateTile(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); + this.setSqlUpdateNeeded(true); room.updateItemState(this); super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"}); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGift.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGift.java index 712c6c4d..5498893e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGift.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGift.java @@ -4,18 +4,19 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.HashSet; @Slf4j -public class InteractionGift extends HabboItem { +public class InteractionGift extends RoomItem { public boolean explode = false; private int[] itemId; @Getter @@ -37,8 +38,8 @@ public class InteractionGift extends HabboItem { } } - public InteractionGift(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGift(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); try { this.loadData(); @@ -91,8 +92,8 @@ public class InteractionGift extends HabboItem { private void loadData() throws NumberFormatException { String[] data = null; - if (this.getExtradata().contains("\t")) - data = this.getExtradata().split("\t"); + if (this.getExtraData().contains("\t")) + data = this.getExtraData().split("\t"); if (data != null && data.length >= 5) { int count = Integer.parseInt(data[0]); @@ -121,8 +122,8 @@ public class InteractionGift extends HabboItem { } } - public THashSet loadItems() { - THashSet items = new THashSet<>(); + public HashSet loadItems() { + HashSet items = new HashSet<>(); for (int anItemId : this.itemId) { if (anItemId == 0) continue; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupEffectTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupEffectTile.java index 721f252f..9e74799c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupEffectTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupEffectTile.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,8 +11,8 @@ public class InteractionGroupEffectTile extends InteractionEffectTile { super(set, baseItem); } - public InteractionGroupEffectTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGroupEffectTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupPressurePlate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupPressurePlate.java index 6aae5d31..7e1082b7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupPressurePlate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGroupPressurePlate.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,8 +11,8 @@ public class InteractionGroupPressurePlate extends InteractionPressurePlate { super(set, baseItem); } - public InteractionGroupPressurePlate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGroupPressurePlate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java index 3ba1afc6..8646cead 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildFurni.java @@ -4,7 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -23,8 +24,8 @@ public class InteractionGuildFurni extends InteractionDefault { this.guildId = set.getInt("guild_id"); } - public InteractionGuildFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGuildFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.guildId = 0; } @@ -43,14 +44,14 @@ public class InteractionGuildFurni extends InteractionDefault { if (guild != null) { serverMessage.appendInt(2 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(5); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); serverMessage.appendString(guild.getId() + ""); serverMessage.appendString(guild.getBadge()); serverMessage.appendString(Emulator.getGameEnvironment().getGuildManager().getSymbolColor(guild.getColorOne()).getValueA()); serverMessage.appendString(Emulator.getGameEnvironment().getGuildManager().getBackgroundColor(guild.getColorTwo()).getValueA()); } else { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); } if (this.isLimited()) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java index 7e836dab..048c837a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGuildGate.java @@ -7,8 +7,9 @@ import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate; 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.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.CloseGate; import java.sql.ResultSet; @@ -17,12 +18,12 @@ import java.sql.SQLException; public class InteractionGuildGate extends InteractionGuildFurni implements ConditionalGate { public InteractionGuildGate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionGuildGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionGuildGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -35,9 +36,9 @@ public class InteractionGuildGate extends InteractionGuildFurni implements Condi if (roomUnit == null) return false; - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); - return habbo != null && (habbo.getHabboStats().hasGuild(super.getGuildId()) || habbo.hasRight(Permission.ACC_GUILDGATE)); + return habbo != null && (habbo.getHabboStats().hasGuild(super.getGuildId()) || habbo.hasPermissionRight(Permission.ACC_GUILDGATE)); } @Override @@ -45,7 +46,7 @@ public class InteractionGuildGate extends InteractionGuildFurni implements Condi super.onWalkOn(roomUnit, room, objects); if (this.canWalkOn(roomUnit, room, objects)) { - this.setExtradata("1"); + this.setExtraData("1"); room.updateItemState(this); } } @@ -59,7 +60,7 @@ public class InteractionGuildGate extends InteractionGuildFurni implements Condi @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { - this.setExtradata("0"); + this.setExtraData("0"); room.updateItemState(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGymEquipment.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGymEquipment.java index 008b4279..d6a51125 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGymEquipment.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionGymEquipment.java @@ -2,13 +2,18 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; -import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +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.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -21,13 +26,13 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC super(set, baseItem); } - public InteractionGymEquipment(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGymEquipment(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return this.roomUnitId == -1 && super.canWalkOn(roomUnit, room, objects) && (roomUnit.getRoomUnitType().equals(RoomUnitType.USER) || roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)); + return this.roomUnitId == -1 && super.canWalkOn(roomUnit, room, objects) && (roomUnit.getRoomUnitType().equals(RoomUnitType.HABBO) || roomUnit.getRoomUnitType().equals(RoomUnitType.BOT)); } @Override @@ -40,13 +45,13 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC super.onWalkOn(roomUnit, room, objects); if (this.forceRotation()) { - roomUnit.setRotation(RoomUserRotation.fromValue(this.getRotation())); + roomUnit.setRotation(RoomRotation.fromValue(this.getRotation())); roomUnit.setCanRotate(false); } - this.roomUnitId = roomUnit.getId(); + this.roomUnitId = roomUnit.getVirtualId(); - if (roomUnit.getRoomUnitType() == RoomUnitType.USER) { - Habbo habbo = room.getHabbo(roomUnit); + if (roomUnit.getRoomUnitType() == RoomUnitType.HABBO) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { this.startTime = Emulator.getIntUnixTimestamp(); @@ -62,9 +67,9 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC this.reset(room); - if (roomUnit != null) { - Habbo habbo = room.getHabbo(roomUnit); - HabboItem topItem = room.getTopItemAt(roomUnit.getCurrentLocation().getX(), roomUnit.getCurrentLocation().getY()); + if (roomUnit instanceof RoomAvatar roomAvatar) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(roomAvatar.getCurrentPosition().getX(), roomAvatar.getCurrentPosition().getY()); int nextEffectM = 0; int nextEffectF = 0; int nextEffectDuration = -1; @@ -72,23 +77,23 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC if (topItem != null) { nextEffectM = topItem.getBaseItem().getEffectM(); nextEffectF = topItem.getBaseItem().getEffectF(); - } else if (roomUnit.getPreviousEffectId() > 0) { - nextEffectF = roomUnit.getPreviousEffectId(); - nextEffectM = roomUnit.getPreviousEffectId(); - nextEffectDuration = roomUnit.getPreviousEffectEndTimestamp(); + } else if (roomAvatar.getPreviousEffectId() > 0) { + nextEffectF = roomAvatar.getPreviousEffectId(); + nextEffectM = roomAvatar.getPreviousEffectId(); + nextEffectDuration = roomAvatar.getPreviousEffectEndTimestamp(); } if (this.forceRotation()) { - roomUnit.setCanRotate(true); + roomAvatar.setCanRotate(true); } if (habbo.getHabboInfo().getGender().equals(HabboGender.M)) { - room.giveEffect(habbo, nextEffectM, nextEffectDuration, true); + roomAvatar.giveEffect(nextEffectM, nextEffectDuration, true); return; } if (habbo.getHabboInfo().getGender().equals(HabboGender.F)) { - room.giveEffect(habbo, nextEffectF, nextEffectDuration, true); + roomAvatar.giveEffect(nextEffectF, nextEffectDuration, true); } } } @@ -104,7 +109,7 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC @Override public void cycle(Room room) { if (this.roomUnitId != -1) { - Habbo habbo = room.getHabboByRoomUnitId(this.roomUnitId); + Habbo habbo = room.getRoomUnitManager().getHabboByVirtualId(this.roomUnitId); if (habbo != null) { int timestamp = Emulator.getIntUnixTimestamp(); @@ -126,12 +131,12 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC super.setRotation(rotation); if (this.forceRotation() && this.roomUnitId != -1) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = this.getRoom(); if (room != null) { RoomUnit roomUnit = this.getCurrentRoomUnit(room); if (roomUnit != null) { - roomUnit.setRotation(RoomUserRotation.fromValue(rotation)); + roomUnit.setRotation(RoomRotation.fromValue(rotation)); room.updateRoomUnit(roomUnit); } } @@ -161,27 +166,21 @@ public class InteractionGymEquipment extends InteractionEffectTile implements IC private void setEffect(Room room, int effectId) { if (this.roomUnitId == -1) return; - room.giveEffect(this.getCurrentRoomUnit(room), effectId, -1); + RoomUnit roomUnit = this.getCurrentRoomUnit(room); + + if(roomUnit instanceof RoomAvatar roomAvatar) { + roomAvatar.giveEffect(effectId, -1); + } } private void reset(Room room) { this.roomUnitId = -1; this.startTime = 0; - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); } private RoomUnit getCurrentRoomUnit(Room room) { - Habbo habbo = room.getHabboByRoomUnitId(this.roomUnitId); - if (habbo != null) { - return habbo.getRoomUnit(); - } else { - Bot bot = room.getBotByRoomUnitId(this.roomUnitId); - if (bot != null) { - return bot.getRoomUnit(); - } - } - - return null; + return room.getRoomUnitManager().getCurrentRoomUnits().get(this.roomUnitId); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditem.java index 7c7599f0..77ec9e26 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditem.java @@ -5,8 +5,11 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +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.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.messages.outgoing.rooms.users.CarryObjectMessageComposer; import java.sql.ResultSet; import java.sql.SQLException; @@ -16,34 +19,39 @@ public class InteractionHanditem extends InteractionDefault { super(set, baseItem); } - public InteractionHanditem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionHanditem(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentLocation(), room.getLayout().getTile(this.getX(), this.getY())) || - (client.getHabbo().getRoomUnit().getCurrentLocation().getX() == this.getX() && client.getHabbo().getRoomUnit().getCurrentLocation().getY() == this.getY())) { + if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentPosition(), room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())) || + (client.getHabbo().getRoomUnit().getCurrentPosition().getX() == this.getCurrentPosition().getX() && client.getHabbo().getRoomUnit().getCurrentPosition().getY() == this.getCurrentPosition().getY())) { this.handle(room, client.getHabbo().getRoomUnit()); } } protected void handle(Room room, RoomUnit roomUnit) { - if (this.getExtradata().isEmpty()) this.setExtradata("0"); + if (this.getExtraData().isEmpty()) this.setExtraData("0"); - if (!this.getExtradata().equals("0")) return; + if (!this.getExtraData().equals("0")) return; - HabboItem instance = this; - room.giveHandItem(roomUnit, this.getBaseItem().getRandomVendingItem()); + if(!(roomUnit instanceof RoomAvatar roomAvatar)) { + return; + } + + RoomItem instance = this; + roomAvatar.setHandItem(this.getBaseItem().getRandomVendingItem()); + room.sendComposer(new CarryObjectMessageComposer(roomAvatar).compose()); if (this.getBaseItem().getStateCount() > 1) { - this.setExtradata("1"); + this.setExtraData("1"); room.updateItem(this); Emulator.getThreading().run(() -> { - InteractionHanditem.this.setExtradata("0"); + InteractionHanditem.this.setExtraData("0"); room.updateItem(instance); }, 500); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditemTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditemTile.java index aa1eb152..bf8c2bd0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditemTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHanditemTile.java @@ -3,7 +3,8 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,15 +14,15 @@ public class InteractionHanditemTile extends InteractionHanditem { super(set, baseItem); } - public InteractionHanditemTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionHanditemTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { InteractionHanditemTile instance = this; Emulator.getThreading().run(() -> { - if (roomUnit.getCurrentLocation().getX() == instance.getX() && roomUnit.getCurrentLocation().getY() == instance.getY()) { + if (roomUnit.getCurrentPosition().getX() == instance.getCurrentPosition().getX() && roomUnit.getCurrentPosition().getY() == instance.getCurrentPosition().getY()) { instance.handle(room, roomUnit); } }, 3000); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHopper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHopper.java index f20c26d6..717cbc3c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHopper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHopper.java @@ -5,29 +5,30 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.hopper.HopperActionOne; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionHopper extends HabboItem { +public class InteractionHopper extends RoomItem { public InteractionHopper(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionHopper(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionHopper(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -52,16 +53,16 @@ public class InteractionHopper extends HabboItem { super.onClick(client, room, objects); if (room != null) { - RoomTile loc = HabboItem.getSquareInFront(room.getLayout(), this); + RoomTile loc = RoomItem.getSquareInFront(room.getLayout(), this); if (loc != null) { if (this.canUseTeleport(client, loc, room)) { client.getHabbo().getRoomUnit().setTeleporting(true); - this.setExtradata("1"); + this.setExtraData("1"); room.updateItemState(this); Emulator.getThreading().run(new HopperActionOne(this, room, client), 500); } else { - client.getHabbo().getRoomUnit().setGoalLocation(loc); + client.getHabbo().getRoomUnit().walkTo(loc); } } } @@ -69,15 +70,15 @@ public class InteractionHopper extends HabboItem { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } @Override public void run() { - if (!this.getExtradata().equals("0")) { - this.setExtradata("0"); + if (!this.getExtraData().equals("0")) { + this.setExtraData("0"); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = this.getRoom(); if (room != null) { room.updateItemState(this); } @@ -86,18 +87,24 @@ public class InteractionHopper extends HabboItem { } protected boolean canUseTeleport(GameClient client, RoomTile front, Room room) { - if (client.getHabbo().getRoomUnit().getX() != front.getX()) + if (client.getHabbo().getRoomUnit().getCurrentPosition().getX() != front.getX()) return false; - if (client.getHabbo().getRoomUnit().getY() != front.getY()) + if (client.getHabbo().getRoomUnit().getCurrentPosition().getY() != front.getY()) return false; if (client.getHabbo().getRoomUnit().isTeleporting()) return false; - if (!room.getHabbosAt(this.getX(), this.getY()).isEmpty()) + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + + if(tile == null) { + return false; + } + + if (room.getRoomUnitManager().hasHabbosAt(tile)) return false; - return this.getExtradata().equals("0"); + return this.getExtraData().equals("0"); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java index d8e5fa5c..2a508003 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionInformationTerminal.java @@ -2,8 +2,9 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.habboway.nux.InClientLinkMessageComposer; import gnu.trove.map.hash.THashMap; @@ -22,8 +23,8 @@ public class InteractionInformationTerminal extends InteractionCustomValues { super(set, baseItem, defaultValues); } - public InteractionInformationTerminal(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, defaultValues); + public InteractionInformationTerminal(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, defaultValues); } @Override @@ -40,7 +41,7 @@ public class InteractionInformationTerminal extends InteractionCustomValues { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null && this.values.containsKey("internalLink")) { habbo.getClient().sendResponse(new InClientLinkMessageComposer(this.values.get("internalLink"))); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionJukeBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionJukeBox.java index dec7b52a..f97e02cc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionJukeBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionJukeBox.java @@ -3,26 +3,27 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionJukeBox extends HabboItem { +public class InteractionJukeBox extends RoomItem { public InteractionJukeBox(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionJukeBox(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionJukeBox(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -48,10 +49,10 @@ public class InteractionJukeBox extends HabboItem { if (client != null && objects.length == 1) { if ((Integer) objects[0] == 0) { - if (room.getTraxManager().isPlaying()) { - room.getTraxManager().stop(); + if (room.getRoomTraxManager().isPlaying()) { + room.getRoomTraxManager().stop(); } else { - room.getTraxManager().play(0, client.getHabbo()); + room.getRoomTraxManager().play(0, client.getHabbo()); } } } @@ -60,16 +61,16 @@ public class InteractionJukeBox extends HabboItem { @Override public void onPickUp(Room room) { super.onPickUp(room); - this.setExtradata("0"); - room.getTraxManager().removeTraxOnRoom(this); + this.setExtraData("0"); + room.getRoomTraxManager().removeTraxOnRoom(this); } @Override public void onPlace(Room room) { super.onPlace(room); - room.getTraxManager().addTraxOnRoom(this); - if (room.getTraxManager().isPlaying()) { - this.setExtradata("1"); + room.getRoomTraxManager().addTraxOnRoom(this); + if (room.getRoomTraxManager().isPlaying()) { + this.setExtraData("1"); } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionLoveLock.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionLoveLock.java index 2369b288..a0db0e72 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionLoveLock.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionLoveLock.java @@ -6,9 +6,10 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.lovelock.FriendFurniStartConfirmationMessageComposer; @@ -16,7 +17,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Calendar; -public class InteractionLoveLock extends HabboItem { +public class InteractionLoveLock extends RoomItem { public int userOneId; public int userTwoId; @@ -24,8 +25,8 @@ public class InteractionLoveLock extends HabboItem { super(set, baseItem); } - public InteractionLoveLock(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionLoveLock(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -33,7 +34,7 @@ public class InteractionLoveLock extends HabboItem { serverMessage.appendInt(2 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(6); - String[] data = this.getExtradata().split("\t"); + String[] data = this.getExtraData().split("\t"); if (data.length == 6) { serverMessage.appendString("1"); @@ -71,19 +72,19 @@ public class InteractionLoveLock extends HabboItem { @Override public void onClick(GameClient client, Room room, Object[] objects) { - if (this.getExtradata().contains("\t")) + if (this.getExtraData().contains("\t")) return; if (client == null) return; - if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentLocation(), room.getLayout().getTile(this.getX(), this.getY()))) { + if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentPosition(), room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()))) { if (this.userOneId == 0) { this.userOneId = client.getHabbo().getHabboInfo().getId(); client.sendResponse(new FriendFurniStartConfirmationMessageComposer(this)); } else { if (this.userOneId != client.getHabbo().getHabboInfo().getId()) { - Habbo habbo = room.getHabbo(this.userOneId); + Habbo habbo = room.getRoomUnitManager().getRoomHabboById(this.userOneId); if (habbo != null) { this.userTwoId = client.getHabbo().getHabboInfo().getId(); @@ -95,8 +96,8 @@ public class InteractionLoveLock extends HabboItem { } public boolean lock(Habbo userOne, Habbo userTwo, Room room) { - RoomTile tile = room.getLayout().getTile(this.getX(), this.getY()); - if (RoomLayout.tilesAdjecent(userOne.getRoomUnit().getCurrentLocation(), tile) && RoomLayout.tilesAdjecent(userTwo.getRoomUnit().getCurrentLocation(), tile)) { + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + if (RoomLayout.tilesAdjecent(userOne.getRoomUnit().getCurrentPosition(), tile) && RoomLayout.tilesAdjecent(userTwo.getRoomUnit().getCurrentPosition(), tile)) { String data = "1"; data += "\t"; data += userOne.getHabboInfo().getUsername(); @@ -109,8 +110,8 @@ public class InteractionLoveLock extends HabboItem { data += "\t"; data += Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + "-" + (Calendar.getInstance().get(Calendar.MONTH) + 1) + "-" + Calendar.getInstance().get(Calendar.YEAR); - this.setExtradata(data); - this.needsUpdate(true); + this.setExtraData(data); + this.setSqlUpdateNeeded(true); Emulator.getThreading().run(this); room.updateItem(this); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java index 84adbbb1..af830c07 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMannequin.java @@ -4,8 +4,9 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.users.clothingvalidation.ClothingValidationManager; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.users.UserChangeMessageComposer; @@ -14,13 +15,13 @@ import com.eu.habbo.messages.outgoing.users.UserObjectComposer; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionMannequin extends HabboItem { +public class InteractionMannequin extends RoomItem { public InteractionMannequin(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionMannequin(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionMannequin(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -32,8 +33,8 @@ public class InteractionMannequin extends HabboItem { public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(3); - if (this.getExtradata().split(":").length >= 2) { - String[] data = this.getExtradata().split(":"); + if (this.getExtraData().split(":").length >= 2) { + String[] data = this.getExtraData().split(":"); serverMessage.appendString("GENDER"); serverMessage.appendString(data[0].toLowerCase()); serverMessage.appendString("FIGURE"); @@ -47,8 +48,8 @@ public class InteractionMannequin extends HabboItem { serverMessage.appendString(""); serverMessage.appendString("OUTFIT_NAME"); serverMessage.appendString("My Look"); - this.setExtradata("m: :My look"); - this.needsUpdate(true); + this.setExtraData("m: :My look"); + this.setSqlUpdateNeeded(true); Emulator.getThreading().run(this); } super.serializeExtradata(serverMessage); @@ -66,7 +67,7 @@ public class InteractionMannequin extends HabboItem { @Override public void onClick(GameClient client, Room room, Object[] objects) { - String[] data = this.getExtradata().split(":"); + String[] data = this.getExtraData().split(":"); if(data.length < 2) return; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMonsterCrackable.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMonsterCrackable.java index 44f024db..1d79a5e4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMonsterCrackable.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMonsterCrackable.java @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -18,8 +19,8 @@ public class InteractionMonsterCrackable extends InteractionCrackable implements super(set, baseItem); } - public InteractionMonsterCrackable(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionMonsterCrackable(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -33,7 +34,7 @@ public class InteractionMonsterCrackable extends InteractionCrackable implements @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - if (room.isPublicRoom()) this.respawn = true; + if (room.getRoomInfo().isPublicRoom()) this.respawn = true; super.onClick(client, room, objects); } @@ -46,9 +47,10 @@ public class InteractionMonsterCrackable extends InteractionCrackable implements @Override public void reset(Room room) { RoomTile tile = room.getRandomWalkableTile(); - this.setX(tile.getX()); - this.setY(tile.getY()); - this.setZ(room.getStackHeight(tile.getX(), tile.getY(), false)); + + this.setCurrentPosition(tile); + this.setCurrentZ(room.getStackHeight(tile.getX(), tile.getY(), false)); + super.reset(room); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMoodLight.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMoodLight.java index 0830cad5..7c16ea07 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMoodLight.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMoodLight.java @@ -4,26 +4,28 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomMoodlightData; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; +import gnu.trove.map.TIntObjectMap; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionMoodLight extends HabboItem { +public class InteractionMoodLight extends RoomItem { public InteractionMoodLight(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionMoodLight(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionMoodLight(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -46,10 +48,10 @@ public class InteractionMoodLight extends HabboItem { @Override public void onPlace(Room room) { if (room != null) { - for (RoomMoodlightData data : room.getMoodlightData().valueCollection()) { + for (RoomMoodlightData data : ((TIntObjectMap) room.getRoomInfo().getMoodLightData()).valueCollection()) { if (data.isEnabled()) { - this.setExtradata(data.toString()); - this.needsUpdate(true); + this.setExtraData(data.toString()); + this.setSqlUpdateNeeded(true); room.updateItem(this); Emulator.getThreading().run(this); } 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 ddce7f99..5b9ee060 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 @@ -2,10 +2,12 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -14,9 +16,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; -public class InteractionMultiHeight extends HabboItem { - public InteractionMultiHeight(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); +public class InteractionMultiHeight extends RoomItem { + public InteractionMultiHeight(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public InteractionMultiHeight(ResultSet set, Item baseItem) throws SQLException { @@ -26,7 +28,7 @@ public class InteractionMultiHeight extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -45,50 +47,53 @@ public class InteractionMultiHeight extends HabboItem { public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if (client != null && !room.hasRights(client.getHabbo()) && !(objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE)) + if (client != null && !room.getRoomRightsManager().hasRights(client.getHabbo()) && !(objects.length >= 2 && objects[1] instanceof WiredEffectType && objects[1] == WiredEffectType.TOGGLE_STATE)) { return; + } - if (objects.length <= 0) { + if (objects.length == 0) { return; } if (objects[0] instanceof Integer && room != null) { - HabboItem topItem = room.getTopItemAt(this.getX(), this.getY()); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + if (topItem != null && !topItem.equals(this)) { // multiheight items cannot change height even if there is a stackable item on top - no items allowed on top return; } - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) { + this.setExtraData("0"); + } if (this.getBaseItem().getMultiHeights().length > 0) { - this.setExtradata("" + (Integer.parseInt(this.getExtradata()) + 1) % (this.getBaseItem().getMultiHeights().length)); - this.needsUpdate(true); - room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())); + this.setExtraData(String.valueOf((Integer.parseInt(this.getExtraData()) + 1) % (this.getBaseItem().getMultiHeights().length))); + this.setSqlUpdateNeeded(true); + room.updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())); room.updateItemState(this); } } } public void updateUnitsOnItem(Room room) { - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(this.getX(), this.getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); for(RoomTile tile : occupiedTiles) { - Collection unitsOnItem = room.getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY())); + Collection unitsOnItem = room.getRoomUnitManager().getRoomUnitsAt(room.getLayout().getTile(tile.getX(), tile.getY())); for (RoomUnit unit : unitsOnItem) { - if (unit.hasStatus(RoomUnitStatus.MOVE) && unit.getGoalLocation() != tile) - continue; + if (unit.hasStatus(RoomUnitStatus.MOVE)) { + if (unit.getTargetPosition() != tile) { + continue; + } + } if (this.getBaseItem().allowSit() || unit.hasStatus(RoomUnitStatus.SIT)) { - unit.setSitUpdate(true); - unit.statusUpdate(true); + unit.setStatusUpdateNeeded(true); } else { - unit.setZ(unit.getCurrentLocation().getStackHeight()); - unit.setPreviousLocationZ(unit.getZ()); - unit.statusUpdate(true); + unit.setCurrentZ(unit.getCurrentPosition().getStackHeight()); } } } @@ -102,45 +107,11 @@ public class InteractionMultiHeight extends HabboItem { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - - if (roomUnit != null - && (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) - && roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { - room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1); - return; - } - - if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { - room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1); - } - } - } } @Override public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - - if (roomUnit != null - && (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) - && roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) { - room.giveEffect(habbo, 0, -1); - return; - } - - if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) { - room.giveEffect(habbo, 0, -1); - } - } - } } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMusicDisc.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMusicDisc.java index 39eb0b27..3cb5277f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMusicDisc.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMusicDisc.java @@ -2,8 +2,9 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import lombok.extern.slf4j.Slf4j; @@ -11,14 +12,14 @@ import java.sql.ResultSet; import java.sql.SQLException; @Slf4j -public class InteractionMusicDisc extends HabboItem { +public class InteractionMusicDisc extends RoomItem { private int songId; public InteractionMusicDisc(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - String[] stuff = this.getExtradata().split("\n"); + String[] stuff = this.getExtraData().split("\n"); if (stuff.length >= 7 && !stuff[6].isEmpty()) { try { @@ -29,10 +30,10 @@ public class InteractionMusicDisc extends HabboItem { } } - public InteractionMusicDisc(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionMusicDisc(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); - String[] stuff = this.getExtradata().split("\n"); + String[] stuff = this.getExtraData().split("\n"); if (stuff.length >= 7 && !stuff[6].isEmpty()) { try { @@ -46,7 +47,7 @@ public class InteractionMusicDisc extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -74,13 +75,13 @@ public class InteractionMusicDisc extends HabboItem { public void onPlace(Room room) { super.onPlace(room); - room.getTraxManager().sendUpdatedSongList(); + room.getRoomTraxManager().sendUpdatedSongList(); } @Override public void onPickUp(Room room) { super.onPickUp(room); - room.getTraxManager().sendUpdatedSongList(); + room.getRoomTraxManager().sendUpdatedSongList(); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java index e5fbd80b..9ff89f85 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionMuteArea.java @@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTileState; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.outgoing.rooms.items.ObjectDataUpdateMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.ObjectsMessageComposer; @@ -39,8 +40,8 @@ public class InteractionMuteArea extends InteractionCustomValues { tiles = new THashSet<>(); } - public InteractionMuteArea(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, defaultValues); + public InteractionMuteArea(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, defaultValues); tiles = new THashSet<>(); } @@ -48,7 +49,7 @@ public class InteractionMuteArea extends InteractionCustomValues { public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if((objects.length >= 2 && objects[1] instanceof WiredEffectType) || (client != null && room.hasRights(client.getHabbo()))) { + if((objects.length >= 2 && objects[1] instanceof WiredEffectType) || (client != null && room.getRoomRightsManager().hasRights(client.getHabbo()))) { this.values.put("state", this.values.get("state").equals("0") ? "1" : "0"); room.sendComposer(new ObjectDataUpdateMessageComposer(this).compose()); } @@ -73,7 +74,7 @@ public class InteractionMuteArea extends InteractionCustomValues { } public boolean inSquare(RoomTile location) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = this.getRoom(); if(!this.values.get("state").equals("1")) return false; @@ -96,10 +97,10 @@ public class InteractionMuteArea extends InteractionCustomValues { } private void regenAffectedTiles(Room room) { - int minX = Math.max(0, this.getX() - Integer.parseInt(this.values.get("tilesBack"))); - int minY = Math.max(0, this.getY() - Integer.parseInt(this.values.get("tilesRight"))); - int maxX = Math.min(room.getLayout().getMapSizeX(), this.getX() + Integer.parseInt(this.values.get("tilesFront"))); - int maxY = Math.min(room.getLayout().getMapSizeY(), this.getY() + Integer.parseInt(this.values.get("tilesLeft"))); + int minX = Math.max(0, this.getCurrentPosition().getX() - Integer.parseInt(this.values.get("tilesBack"))); + int minY = Math.max(0, this.getCurrentPosition().getY() - Integer.parseInt(this.values.get("tilesRight"))); + int maxX = Math.min(room.getLayout().getMapSizeX(), this.getCurrentPosition().getX() + Integer.parseInt(this.values.get("tilesFront"))); + int maxY = Math.min(room.getLayout().getMapSizeY(), this.getCurrentPosition().getY() + Integer.parseInt(this.values.get("tilesLeft"))); this.tiles.clear(); @@ -124,21 +125,21 @@ public class InteractionMuteArea extends InteractionCustomValues { if(effectItem != null) { TIntObjectMap ownerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); ownerNames.put(-1, "System"); - THashSet items = new THashSet<>(); + THashSet items = new THashSet<>(); int id = 0; for(RoomTile tile : this.tiles) { id--; - HabboItem item = new InteractionDefault(id, -1, effectItem, "1", 0, 0); - item.setX(tile.getX()); - item.setY(tile.getY()); - item.setZ(tile.relativeHeight()); + RoomItem item = new InteractionDefault(id, null, effectItem, "1", 0, 0); + + item.setCurrentPosition(tile); + item.setCurrentZ(tile.relativeHeight()); items.add(item); } client.sendResponse(new ObjectsMessageComposer(ownerNames, items)); Emulator.getThreading().run(() -> { - for(HabboItem item : items) { + for(RoomItem item : items) { client.sendResponse(new RemoveFloorItemComposer(item, true)); } }, 3000); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNoSidesVendingMachine.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNoSidesVendingMachine.java index f31560db..b8516dda 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNoSidesVendingMachine.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionNoSidesVendingMachine.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; @@ -13,8 +14,8 @@ public class InteractionNoSidesVendingMachine extends InteractionVendingMachine super(set, baseItem); } - public InteractionNoSidesVendingMachine(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionNoSidesVendingMachine(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -23,7 +24,7 @@ public class InteractionNoSidesVendingMachine extends InteractionVendingMachine THashSet tiles = new THashSet<>(); for(int x = -1; x <= 1; x++) { for(int y = -1; y <= 1; y++) { - RoomTile tile = room.getLayout().getTile((short)(this.getX() + x), (short)(this.getY() + y)); + RoomTile tile = room.getLayout().getTile((short)(this.getCurrentPosition().getX() + x), (short)(this.getCurrentPosition().getY() + y)); if(tile != null) { tiles.add(tile); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java index a782efd5..d3546bc1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionObstacle.java @@ -5,9 +5,15 @@ import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.pets.HorsePet; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +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.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; @@ -15,26 +21,26 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Objects; -public class InteractionObstacle extends HabboItem implements ICycleable { +public class InteractionObstacle extends RoomItem implements ICycleable { private final THashSet middleTiles; public InteractionObstacle(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); this.middleTiles = new THashSet<>(); } - public InteractionObstacle(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionObstacle(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); this.middleTiles = new THashSet<>(); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -88,24 +94,24 @@ public class InteractionObstacle extends HabboItem implements ICycleable { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo == null) { - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet instanceof HorsePet && ((HorsePet) pet).getRider() != null) { if (roomUnit.getBodyRotation().getValue() % 2 == 0) { if (this.getRotation() == 2) { - if (roomUnit.getBodyRotation().equals(RoomUserRotation.WEST)) { - ((HorsePet) pet).getRider().getRoomUnit().setGoalLocation(room.getLayout().getTile((short) (roomUnit.getX() - 3), roomUnit.getY())); - } else if (roomUnit.getBodyRotation().equals(RoomUserRotation.EAST)) { - ((HorsePet) pet).getRider().getRoomUnit().setGoalLocation(room.getLayout().getTile((short) (roomUnit.getX() + 3), roomUnit.getY())); + if (roomUnit.getBodyRotation().equals(RoomRotation.WEST)) { + ((HorsePet) pet).getRider().getRoomUnit().walkTo(room.getLayout().getTile((short) (roomUnit.getCurrentPosition().getX() - 3), roomUnit.getCurrentPosition().getY())); + } else if (roomUnit.getBodyRotation().equals(RoomRotation.EAST)) { + ((HorsePet) pet).getRider().getRoomUnit().walkTo(room.getLayout().getTile((short) (roomUnit.getCurrentPosition().getX() + 3), roomUnit.getCurrentPosition().getY())); } } else if (this.getRotation() == 4) { - if (roomUnit.getBodyRotation().equals(RoomUserRotation.NORTH)) { - ((HorsePet) pet).getRider().getRoomUnit().setGoalLocation(room.getLayout().getTile(roomUnit.getX(), (short) (roomUnit.getY() - 3))); - } else if (roomUnit.getBodyRotation().equals(RoomUserRotation.SOUTH)) { - ((HorsePet) pet).getRider().getRoomUnit().setGoalLocation(room.getLayout().getTile(roomUnit.getX(), (short) (roomUnit.getY() + 3))); + if (roomUnit.getBodyRotation().equals(RoomRotation.NORTH)) { + ((HorsePet) pet).getRider().getRoomUnit().walkTo(room.getLayout().getTile(roomUnit.getCurrentPosition().getX(), (short) (roomUnit.getCurrentPosition().getY() - 3))); + } else if (roomUnit.getBodyRotation().equals(RoomRotation.SOUTH)) { + ((HorsePet) pet).getRider().getRoomUnit().walkTo(room.getLayout().getTile(roomUnit.getCurrentPosition().getX(), (short) (roomUnit.getCurrentPosition().getY() + 3))); } } } @@ -117,10 +123,10 @@ public class InteractionObstacle extends HabboItem implements ICycleable { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo == null) { - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet instanceof HorsePet && ((HorsePet) pet).getRider() != null) { pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); @@ -150,12 +156,12 @@ public class InteractionObstacle extends HabboItem implements ICycleable { middleTiles.clear(); if(this.getRotation() == 2) { - middleTiles.add(room.getLayout().getTile((short)(this.getX() + 1), this.getY())); - middleTiles.add(room.getLayout().getTile((short)(this.getX() + 1), (short)(this.getY() + 1))); + middleTiles.add(room.getLayout().getTile((short)(this.getCurrentPosition().getX() + 1), this.getCurrentPosition().getY())); + middleTiles.add(room.getLayout().getTile((short)(this.getCurrentPosition().getX() + 1), (short)(this.getCurrentPosition().getY() + 1))); } else if(this.getRotation() == 4) { - middleTiles.add(room.getLayout().getTile(this.getX(), (short)(this.getY() + 1))); - middleTiles.add(room.getLayout().getTile((short)(this.getX() + 1), (short)(this.getY() + 1))); + middleTiles.add(room.getLayout().getTile(this.getCurrentPosition().getX(), (short)(this.getCurrentPosition().getY() + 1))); + middleTiles.add(room.getLayout().getTile((short)(this.getCurrentPosition().getX() + 1), (short)(this.getCurrentPosition().getY() + 1))); } } @@ -174,19 +180,23 @@ public class InteractionObstacle extends HabboItem implements ICycleable { } for(RoomTile tile : this.middleTiles) { - for(RoomUnit unit : tile.getUnits()) { - if(unit.getPath().size() == 0 && !unit.hasStatus(RoomUnitStatus.MOVE)) { - if(unit.getBodyRotation().getValue() != this.getRotation() && Objects.requireNonNull(unit.getBodyRotation().getOpposite()).getValue() != this.getRotation()) + for(RoomUnit roomUnit : room.getRoomUnitManager().getRoomUnitsAt(tile)) { + if(roomUnit == null) { + continue; + } + + if(roomUnit.getPath().size() == 0 && !roomUnit.hasStatus(RoomUnitStatus.MOVE)) { + if(roomUnit.getBodyRotation().getValue() != this.getRotation() && Objects.requireNonNull(roomUnit.getBodyRotation().getOpposite()).getValue() != this.getRotation()) continue; - RoomTile tileInfront = room.getLayout().getTileInFront(unit.getCurrentLocation(), unit.getBodyRotation().getValue()); - if(tileInfront.getState() != RoomTileState.INVALID && tileInfront.getState() != RoomTileState.BLOCKED && room.getRoomUnitsAt(tileInfront).size() == 0) { - unit.setGoalLocation(tileInfront); + RoomTile tileInfront = room.getLayout().getTileInFront(roomUnit.getCurrentPosition(), roomUnit.getBodyRotation().getValue()); + if(tileInfront.getState() != RoomTileState.INVALID && tileInfront.getState() != RoomTileState.BLOCKED && room.getRoomUnitManager().getRoomUnitsAt(tileInfront).size() == 0) { + roomUnit.walkTo(tileInfront); } else { - RoomTile tileBehind = room.getLayout().getTileInFront(unit.getCurrentLocation(), Objects.requireNonNull(unit.getBodyRotation().getOpposite()).getValue()); - if(tileBehind.getState() != RoomTileState.INVALID && tileBehind.getState() != RoomTileState.BLOCKED && room.getRoomUnitsAt(tileBehind).size() == 0) { - unit.setGoalLocation(tileBehind); + RoomTile tileBehind = room.getLayout().getTileInFront(roomUnit.getCurrentPosition(), Objects.requireNonNull(roomUnit.getBodyRotation().getOpposite()).getValue()); + if(tileBehind.getState() != RoomTileState.INVALID && tileBehind.getState() != RoomTileState.BLOCKED && room.getRoomUnitManager().getRoomUnitsAt(tileBehind).size() == 0) { + roomUnit.walkTo(tileBehind); } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java index d2f559cb..084affc3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionOneWayGate.java @@ -5,8 +5,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ServerMessage; @@ -18,17 +19,17 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class InteractionOneWayGate extends HabboItem { +public class InteractionOneWayGate extends RoomItem { private boolean walkable = false; public InteractionOneWayGate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionOneWayGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionOneWayGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -48,13 +49,13 @@ public class InteractionOneWayGate extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { - if (this.getExtradata().length() == 0) { - this.setExtradata("0"); - this.needsUpdate(true); + if (this.getExtraData().length() == 0) { + this.setExtraData("0"); + this.setSqlUpdateNeeded(true); } serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -64,11 +65,11 @@ public class InteractionOneWayGate extends HabboItem { super.onClick(client, room, objects); if (client != null) { - RoomTile tileInfront = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation()); + RoomTile tileInfront = room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), this.getRotation()); if (tileInfront == null) return; - RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY()); + RoomTile currentLocation = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); if (currentLocation == null) return; @@ -76,62 +77,60 @@ public class InteractionOneWayGate extends HabboItem { if (unit == null) return; - if (tileInfront.getX() == unit.getX() && tileInfront.getY() == unit.getY()) { - if (!currentLocation.hasUnits()) { - List onSuccess = new ArrayList<>(); - List onFail = new ArrayList<>(); + if (tileInfront.equals(unit.getCurrentPosition()) && !room.getRoomUnitManager().areRoomUnitsAt(currentLocation)) { + List onSuccess = new ArrayList<>(); + List onFail = new ArrayList<>(); - onSuccess.add(() -> { - unit.setCanLeaveRoomByDoor(false); - walkable = this.getBaseItem().allowWalk(); - RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), this.getRotation() + 4); - unit.setGoalLocation(tile); - Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onFail, onFail)); + onSuccess.add(() -> { + unit.setCanLeaveRoomByDoor(false); + walkable = this.getBaseItem().allowWalk(); + RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), this.getRotation() + 4); + unit.walkTo(tile); + Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onFail, onFail)); - Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.WALKS_ON_FURNI, unit, room, new Object[]{this}), 500); - }); + Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.WALKS_ON_FURNI, unit, room, new Object[]{this}), 500); + }); - onFail.add(() -> { - unit.setCanLeaveRoomByDoor(true); - walkable = this.getBaseItem().allowWalk(); - room.updateTile(currentLocation); - room.sendComposer(new DiceValueMessageComposer(this.getId(), 0).compose()); - unit.removeOverrideTile(currentLocation); - }); - - walkable = true; + onFail.add(() -> { + unit.setCanLeaveRoomByDoor(true); + walkable = this.getBaseItem().allowWalk(); room.updateTile(currentLocation); - unit.addOverrideTile(currentLocation); - unit.setGoalLocation(currentLocation); - Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); - room.sendComposer(new DiceValueMessageComposer(this.getId(), 1).compose()); + room.sendComposer(new DiceValueMessageComposer(this.getId(), 0).compose()); + unit.removeOverrideTile(currentLocation); + }); - /* - room.scheduledTasks.add(new Runnable() + walkable = true; + room.updateTile(currentLocation); + unit.addOverrideTile(currentLocation); + unit.walkTo(currentLocation); + Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); + room.sendComposer(new DiceValueMessageComposer(this.getId(), 1).compose()); + + /* + room.scheduledTasks.add(new Runnable() + { + @Override + public void run() { - @Override - public void run() - { - gate.roomUnitID = client.getHabbo().getRoomUnit().getId(); - room.updateTile(gatePosition); - client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(InteractionOneWayGate.this.getX(), InteractionOneWayGate.this.getY()), InteractionOneWayGate.this.getRotation() + 4)); - } - }); - */ - } + gate.roomUnitID = client.getHabbo().getRoomUnit().getId(); + room.updateTile(gatePosition); + client.getHabbo().getRoomUnit().setGoalLocation(room.getLayout().getTileInFront(room.getLayout().getTile(InteractionOneWayGate.this.getX(), InteractionOneWayGate.this.getY()), InteractionOneWayGate.this.getRotation() + 4)); + } + }); + */ } } } private void refresh(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); room.sendComposer(new DiceValueMessageComposer(this.getId(), 0).compose()); - room.updateTile(room.getLayout().getTile(this.getX(), this.getY())); + room.updateTile(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); this.refresh(room); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPostIt.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPostIt.java index ae9b8872..f9a31eb7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPostIt.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPostIt.java @@ -2,22 +2,23 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionPostIt extends HabboItem { +public class InteractionPostIt extends RoomItem { public static String STICKYPOLE_PREFIX_TEXT = ""; public InteractionPostIt(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionPostIt(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPostIt(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -38,7 +39,7 @@ public class InteractionPostIt extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata().replace(((char) 9) + "", "")); + serverMessage.appendString(this.getExtraData().replace(((char) 9) + "", "")); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPoster.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPoster.java index bdb3afd4..2b5d2180 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPoster.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPoster.java @@ -2,16 +2,17 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionPoster extends HabboItem { - public InteractionPoster(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); +public class InteractionPoster extends RoomItem { + public InteractionPoster(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public InteractionPoster(ResultSet set, Item baseItem) throws SQLException { @@ -36,7 +37,7 @@ public class InteractionPoster extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java index 04491166..6af9943d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPressurePlate.java @@ -5,21 +5,23 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.HashSet; public class InteractionPressurePlate extends InteractionDefault { public InteractionPressurePlate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionPressurePlate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionPressurePlate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -65,7 +67,7 @@ public class InteractionPressurePlate extends InteractionDefault { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } public void updateState(Room room) { @@ -73,7 +75,7 @@ public class InteractionPressurePlate extends InteractionDefault { if (room == null || room.getLayout() == null || this.getBaseItem() == null) return; - RoomTile tileAtItem = room.getLayout().getTile(this.getX(), this.getY()); + RoomTile tileAtItem = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); if (tileAtItem == null) return; @@ -82,7 +84,8 @@ public class InteractionPressurePlate extends InteractionDefault { if (tiles == null) return; for (RoomTile tile : tiles) { - THashSet tileHasHabboOrBot = room.getHabbosAndBotsAt(tile.getX(), tile.getY()); + HashSet tileHasHabboOrBot = (HashSet) room.getRoomUnitManager().getAvatarsAt(tile); + if (tileHasHabboOrBot.isEmpty() && this.requiresAllTilesOccupied()) { occupied = false; break; @@ -93,7 +96,7 @@ public class InteractionPressurePlate extends InteractionDefault { } } - this.setExtradata(occupied ? "1" : "0"); + this.setExtraData(occupied ? "1" : "0"); room.updateItemState(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java index 008370b8..ab19efe7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPushable.java @@ -3,7 +3,12 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.KickBallAction; import java.sql.ResultSet; @@ -17,12 +22,12 @@ public abstract class InteractionPushable extends InteractionDefault { public InteractionPushable(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionPushable(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionPushable(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -43,7 +48,7 @@ public abstract class InteractionPushable extends InteractionDefault { return; int velocity = this.getWalkOffVelocity(roomUnit, room); - RoomUserRotation direction = this.getWalkOffDirection(roomUnit, room); + RoomRotation direction = this.getWalkOffDirection(roomUnit, room); this.onKick(room, roomUnit, velocity, direction); if (velocity > 0) { @@ -60,9 +65,9 @@ public abstract class InteractionPushable extends InteractionDefault { super.onClick(client, room, objects); if (client == null) return; - if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentLocation(), room.getLayout().getTile(this.getX(), this.getY()))) { + if (RoomLayout.tilesAdjecent(client.getHabbo().getRoomUnit().getCurrentPosition(), room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()))) { int velocity = this.getTackleVelocity(client.getHabbo().getRoomUnit(), room); - RoomUserRotation direction = this.getWalkOnDirection(client.getHabbo().getRoomUnit(), room); + RoomRotation direction = this.getWalkOnDirection(client.getHabbo().getRoomUnit(), room); this.onTackle(room, client.getHabbo().getRoomUnit(), velocity, direction); if (velocity > 0) { @@ -81,9 +86,9 @@ public abstract class InteractionPushable extends InteractionDefault { int velocity; boolean isDrag = false; - RoomUserRotation direction; + RoomRotation direction; - if (this.getX() == roomUnit.getGoalLocation().getX() && this.getY() == roomUnit.getGoalLocation().getY()) //User clicked on the tile the ball is on, they want to kick it + if (this.getCurrentPosition().getX() == roomUnit.getTargetPosition().getX() && this.getCurrentPosition().getY() == roomUnit.getTargetPosition().getY()) //User clicked on the tile the ball is on, they want to kick it { velocity = this.getWalkOnVelocity(roomUnit, room); direction = this.getWalkOnDirection(roomUnit, room); @@ -109,54 +114,54 @@ public abstract class InteractionPushable extends InteractionDefault { public abstract int getWalkOnVelocity(RoomUnit roomUnit, Room room); - public abstract RoomUserRotation getWalkOnDirection(RoomUnit roomUnit, Room room); + public abstract RoomRotation getWalkOnDirection(RoomUnit roomUnit, Room room); public abstract int getWalkOffVelocity(RoomUnit roomUnit, Room room); - public abstract RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room); + public abstract RoomRotation getWalkOffDirection(RoomUnit roomUnit, Room room); public abstract int getDragVelocity(RoomUnit roomUnit, Room room); - public abstract RoomUserRotation getDragDirection(RoomUnit roomUnit, Room room); + public abstract RoomRotation getDragDirection(RoomUnit roomUnit, Room room); public abstract int getTackleVelocity(RoomUnit roomUnit, Room room); - public abstract RoomUserRotation getTackleDirection(RoomUnit roomUnit, Room room); + public abstract RoomRotation getTackleDirection(RoomUnit roomUnit, Room room); public abstract int getNextRollDelay(int currentStep, int totalSteps); //The length in milliseconds when the ball should next roll - public abstract RoomUserRotation getBounceDirection(Room room, RoomUserRotation currentDirection); //Returns the new direction to move the ball when the ball cannot move + public abstract RoomRotation getBounceDirection(Room room, RoomRotation currentDirection); //Returns the new direction to move the ball when the ball cannot move public abstract boolean validMove(Room room, RoomTile from, RoomTile to); //Checks if the next move is valid - public abstract void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction); + public abstract void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction); - public abstract void onKick(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction); + public abstract void onKick(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction); - public abstract void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction); + public abstract void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction); - public abstract void onMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps); + public abstract void onMove(Room room, RoomTile from, RoomTile to, RoomRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps); - public abstract void onBounce(Room room, RoomUserRotation oldDirection, RoomUserRotation newDirection, RoomUnit kicker); + public abstract void onBounce(Room room, RoomRotation oldDirection, RoomRotation newDirection, RoomUnit kicker); public abstract void onStop(Room room, RoomUnit kicker, int currentStep, int totalSteps); - public abstract boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps); + public abstract boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps); } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java index 36250f87..1087cbbd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java @@ -2,81 +2,92 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +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.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionPuzzleBox extends HabboItem { +public class InteractionPuzzleBox extends RoomItem { public InteractionPuzzleBox(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionPuzzleBox(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPuzzleBox(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - RoomTile boxLocation = room.getLayout().getTile(this.getX(), this.getY()); - RoomUserRotation rotation = null; + RoomTile boxLocation = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + RoomRotation rotation = null; - if (this.getX() == client.getHabbo().getRoomUnit().getX()) { - if (this.getY() == client.getHabbo().getRoomUnit().getY() + 1) { - rotation = RoomUserRotation.SOUTH; - } else if (this.getY() == client.getHabbo().getRoomUnit().getY() - 1) { - rotation = RoomUserRotation.NORTH; + if (this.getCurrentPosition().getX() == client.getHabbo().getRoomUnit().getCurrentPosition().getX()) { + if (this.getCurrentPosition().getY() == client.getHabbo().getRoomUnit().getCurrentPosition().getY() + 1) { + rotation = RoomRotation.SOUTH; + } else { + if (this.getCurrentPosition().getY() == client.getHabbo().getRoomUnit().getCurrentPosition().getY() - 1) { + rotation = RoomRotation.NORTH; + } } - } else if (this.getY() == client.getHabbo().getRoomUnit().getY()) { - if (this.getX() == client.getHabbo().getRoomUnit().getX() + 1) { - rotation = RoomUserRotation.EAST; - } else if (this.getX() == client.getHabbo().getRoomUnit().getX() - 1) { - rotation = RoomUserRotation.WEST; + } else { + if (this.getCurrentPosition().getY() == client.getHabbo().getRoomUnit().getCurrentPosition().getY()) { + if (this.getCurrentPosition().getX() == client.getHabbo().getRoomUnit().getCurrentPosition().getX() + 1) { + rotation = RoomRotation.EAST; + } else if (this.getCurrentPosition().getX() == client.getHabbo().getRoomUnit().getCurrentPosition().getX() - 1) { + rotation = RoomRotation.WEST; + } } } if (rotation == null) { - RoomTile nearestTile = client.getHabbo().getRoomUnit().getClosestAdjacentTile(this.getX(), this.getY(), false); + RoomTile nearestTile = client.getHabbo().getRoomUnit().getClosestAdjacentTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY(), false); - if (nearestTile != null) client.getHabbo().getRoomUnit().setGoalLocation(nearestTile); + if (nearestTile != null) client.getHabbo().getRoomUnit().walkTo(nearestTile); return; } super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"}); - RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), rotation.getValue()); + RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), rotation.getValue()); - if (tile == null || tile.getState() == RoomTileState.INVALID || room.hasHabbosAt(tile.getX(), tile.getY())) { + if (tile == null || tile.getState() == RoomTileState.INVALID || room.getRoomUnitManager().hasHabbosAt(tile)) { return; } - if (!boxLocation.equals(room.getLayout().getTileInFront(client.getHabbo().getRoomUnit().getCurrentLocation(), rotation.getValue()))) + if (!boxLocation.equals(room.getLayout().getTileInFront(client.getHabbo().getRoomUnit().getCurrentPosition(), rotation.getValue()))) return; - HabboItem item = room.getTopItemAt(tile.getX(), tile.getY()); + RoomItem item = room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY()); - if (item != null && !room.getTopItemAt(tile.getX(), tile.getY()).getBaseItem().allowStack()) return; + if (item != null && !room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY()).getBaseItem().allowStack()) + return; + + this.setCurrentZ(room.getStackHeight(tile.getX(), tile.getY(), false)); + this.setSqlUpdateNeeded(true); - this.setZ(room.getStackHeight(tile.getX(), tile.getY(), false)); - this.needsUpdate(true); room.updateItem(this); room.scheduledComposers.add(new FloorItemOnRollerComposer(this, null, tile, 0, room).compose()); room.scheduledTasks.add(() -> { - client.getHabbo().getRoomUnit().setGoalLocation(boxLocation); + client.getHabbo().getRoomUnit().walkTo(boxLocation); - room.scheduledTasks.add(() -> client.getHabbo().getRoomUnit().setGoalLocation(boxLocation)); + room.scheduledTasks.add(() -> client.getHabbo().getRoomUnit().walkTo(boxLocation)); }); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPyramid.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPyramid.java index 0ec3ce19..150c90ef 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPyramid.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPyramid.java @@ -4,6 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -15,20 +17,26 @@ public class InteractionPyramid extends InteractionGate { super(set, baseItem); } - public InteractionPyramid(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPyramid(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public void change(Room room) { - if (!(this.getExtradata().equals("0") || this.getExtradata().equals("1"))) - this.setExtradata("0"); + if (!(this.getExtraData().equals("0") || this.getExtraData().equals("1"))) + this.setExtraData("0"); if (room != null) { - if (room.getHabbosAt(this.getX(), this.getY()).isEmpty()) { - int state = Integer.parseInt(this.getExtradata()); + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + + if(tile == null) { + return; + } + + if (!room.getRoomUnitManager().hasHabbosAt(tile)) { + int state = Integer.parseInt(this.getExtraData()); state = Math.abs(state - 1); - this.setExtradata(state + ""); + this.setExtraData(state + ""); room.updateItemState(this); this.nextChange = Emulator.getIntUnixTimestamp() + 1 + (Emulator.getRandom().nextInt(Emulator.getConfig().getInt("pyramids.max.delay"))); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRandomState.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRandomState.java index 2178ccef..7a4e42c2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRandomState.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRandomState.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.RandomStateParams; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,28 +14,28 @@ public class InteractionRandomState extends InteractionDefault { super(set, baseItem); } - public InteractionRandomState(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionRandomState(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onPlace(Room room) { super.onPlace(room); - this.setExtradata(""); + this.setExtraData(""); room.updateItemState(this); } public void onRandomStateClick(Room room) throws Exception { RandomStateParams params = new RandomStateParams(this.getBaseItem().getCustomParams()); - this.setExtradata(""); + this.setExtraData(""); room.updateItemState(this); int randomState = Emulator.getRandom().nextInt(params.getStates()) + 1; Emulator.getThreading().run(() -> { - this.setExtradata(randomState + ""); + this.setExtraData(randomState + ""); room.updateItemState(this); }, params.getDelay()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java index 250d7504..95c2f938 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRedeemableSubscriptionBox.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,8 +11,8 @@ public class InteractionRedeemableSubscriptionBox extends InteractionCrackable { super(set, baseItem); } - public InteractionRedeemableSubscriptionBox(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionRedeemableSubscriptionBox(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public boolean userRequiredToBeAdjacent() { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRentableSpace.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRentableSpace.java index 73e4053c..99af029c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRentableSpace.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRentableSpace.java @@ -5,9 +5,10 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.rentablespaces.RentableSpaceStatusMessageComposer; import com.eu.habbo.threading.runnables.ClearRentedSpace; @@ -21,7 +22,7 @@ import java.sql.ResultSet; import java.sql.SQLException; @Slf4j -public class InteractionRentableSpace extends HabboItem { +public class InteractionRentableSpace extends RoomItem { private int renterId; private String renterName; @@ -57,8 +58,8 @@ public class InteractionRentableSpace extends HabboItem { } } } else { - if (this.getRoomId() > 0) { - Emulator.getThreading().run(new ClearRentedSpace(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()))); + if (this.getRoom() != null) { + Emulator.getThreading().run(new ClearRentedSpace(this, Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()))); this.renterId = 0; } } @@ -66,23 +67,23 @@ public class InteractionRentableSpace extends HabboItem { } } - public InteractionRentableSpace(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionRentableSpace(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.renterName = ""; } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - if (this.getExtradata().isEmpty()) + if (this.getExtraData().isEmpty()) return false; - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo == null) return true; - if (habbo.getHabboInfo().getId() == room.getId()) + if (habbo.getHabboInfo().getId() == room.getRoomInfo().getId()) return true; if (this.endTimestamp > Emulator.getIntUnixTimestamp()) { @@ -109,8 +110,8 @@ public class InteractionRentableSpace extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { - if (this.getExtradata().isEmpty()) - this.setExtradata("0:0"); + if (this.getExtraData().isEmpty()) + this.setExtraData("0:0"); serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0)); @@ -144,30 +145,30 @@ public class InteractionRentableSpace extends HabboItem { habbo.getHabboStats().setRentedItemId(this.getId()); habbo.getHabboStats().setRentedTimeEnd(this.endTimestamp); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); this.run(); } public void endRent() { this.setEndTimestamp(0); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = this.getRoom(); if (room == null) return; - Rectangle rect = RoomLayout.getRectangle(this.getX(), this.getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); + Rectangle rect = RoomLayout.getRectangle(this.getCurrentPosition().getX(), this.getCurrentPosition().getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); - THashSet items = new THashSet<>(); + THashSet items = new THashSet<>(); for (int i = rect.x; i < rect.x + rect.getWidth(); i++) { for (int j = rect.y; j < rect.y + rect.getHeight(); j++) { - items.addAll(room.getItemsAt(i, j, this.getZ())); + items.addAll(room.getRoomItemManager().getItemsAt(i, j, this.getCurrentZ())); } } - for (HabboItem item : items) { - if (item.getUserId() == this.renterId) { - room.pickUpItem(item, null); + for (RoomItem item : items) { + if (item.getOwnerInfo().getId() == this.renterId) { + room.getRoomItemManager().pickUpItem(item, null); } } @@ -191,12 +192,12 @@ public class InteractionRentableSpace extends HabboItem { this.setRenterId(0); this.setRenterName(""); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); this.run(); } @Override - public String getExtradata() { + public String getExtraData() { return this.renterId + ":" + this.endTimestamp; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoller.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoller.java index c2e7ea41..d146d843 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoller.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoller.java @@ -4,8 +4,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import org.apache.commons.math3.util.Pair; @@ -14,24 +15,24 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -public class InteractionRoller extends HabboItem { +public class InteractionRoller extends RoomItem { public static boolean NO_RULES = false; public static final int DELAY = 400; public InteractionRoller(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionRoller(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionRoller(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -68,11 +69,11 @@ public class InteractionRoller extends HabboItem { @Override - public boolean canStackAt(Room room, List>> itemsAtLocation) { + public boolean canStackAt(List>> itemsAtLocation) { if (NO_RULES) return true; if (itemsAtLocation.isEmpty()) return false; - for (Pair> set : itemsAtLocation) { + for (Pair> set : itemsAtLocation) { if (set.getValue() != null && !set.getValue().isEmpty()) { if (set.getValue().size() > 1) { return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java index 3a977194..3b6329ea 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomAds.java @@ -2,7 +2,8 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.map.hash.THashMap; import java.sql.ResultSet; @@ -22,8 +23,8 @@ public class InteractionRoomAds extends InteractionCustomValues { super(set, baseItem, defaultValues); } - public InteractionRoomAds(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, defaultValues); + public InteractionRoomAds(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, defaultValues); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubGate.java similarity index 73% rename from src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java rename to src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubGate.java index fe76c514..808f26a1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubGate.java @@ -5,23 +5,24 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.interfaces.ConditionalGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.generic.alerts.CustomUserNotificationMessageComposer; import com.eu.habbo.threading.runnables.CloseGate; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionHabboClubGate extends InteractionDefault implements ConditionalGate { - public InteractionHabboClubGate(ResultSet set, Item baseItem) throws SQLException { +public class InteractionRoomClubGate extends InteractionDefault implements ConditionalGate { + public InteractionRoomClubGate(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionHabboClubGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionRoomClubGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -31,7 +32,7 @@ public class InteractionHabboClubGate extends InteractionDefault implements Cond @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); return habbo != null && habbo.getHabboStats().hasActiveClub(); } @@ -41,7 +42,7 @@ public class InteractionHabboClubGate extends InteractionDefault implements Cond super.onWalkOn(roomUnit, room, objects); if (this.canWalkOn(roomUnit, room, objects)) { - this.setExtradata("1"); + this.setExtraData("1"); room.updateItemState(this); } } @@ -69,7 +70,7 @@ public class InteractionHabboClubGate extends InteractionDefault implements Cond if (roomUnit == null || room == null) return; - room.getHabbo(roomUnit).getClient().sendResponse( + room.getRoomUnitManager().getHabboByRoomUnit(roomUnit).getClient().sendResponse( new CustomUserNotificationMessageComposer(CustomUserNotificationMessageComposer.GATE_NO_HC) ); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubHopper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubHopper.java similarity index 71% rename from src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubHopper.java rename to src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubHopper.java index e4b03e71..0ebcc7e7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubHopper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubHopper.java @@ -4,18 +4,19 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.generic.alerts.CustomUserNotificationMessageComposer; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionHabboClubHopper extends InteractionHopper { - public InteractionHabboClubHopper(ResultSet set, Item baseItem) throws SQLException { +public class InteractionRoomClubHopper extends InteractionHopper { + public InteractionRoomClubHopper(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionHabboClubHopper(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionRoomClubHopper(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubTeleportTile.java similarity index 56% rename from src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java rename to src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubTeleportTile.java index 9d1bfb1b..e6e940b6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionHabboClubTeleportTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomClubTeleportTile.java @@ -3,24 +3,25 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionHabboClubTeleportTile extends InteractionTeleportTile { - public InteractionHabboClubTeleportTile(ResultSet set, Item baseItem) throws SQLException { +public class InteractionRoomClubTeleportTile extends InteractionTeleportTile { + public InteractionRoomClubTeleportTile(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionHabboClubTeleportTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionRoomClubTeleportTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { return habbo.getHabboStats().hasActiveClub(); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomOMatic.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomOMatic.java index 8384d916..65f58760 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomOMatic.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionRoomOMatic.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.navigator.NoOwnedRoomsAlertMessageComposer; import java.sql.ResultSet; @@ -13,8 +14,8 @@ public class InteractionRoomOMatic extends InteractionDefault { super(set, baseItem); } - public InteractionRoomOMatic(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionRoomOMatic(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSnowboardSlope.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSnowboardSlope.java index 987bea3a..fe64e06e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSnowboardSlope.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSnowboardSlope.java @@ -7,9 +7,10 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import java.awt.*; @@ -17,8 +18,8 @@ import java.sql.ResultSet; import java.sql.SQLException; public class InteractionSnowboardSlope extends InteractionMultiHeight { - public InteractionSnowboardSlope(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionSnowboardSlope(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public InteractionSnowboardSlope(ResultSet set, Item baseItem) throws SQLException { @@ -26,42 +27,38 @@ public class InteractionSnowboardSlope extends InteractionMultiHeight { } @Override - public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - room.giveEffect(roomUnit, 97, -1); + public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { + super.onWalkOn(roomUnit, room, objects); } @Override public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - - if (roomUnit.getEffectId() == 97) { - room.giveEffect(roomUnit, 0, -1); - } } @Override public void onPlace(Room room) { super.onPlace(room); - THashSet items = room.getRoomSpecialTypes().getItemsOfType(InteractionSnowboardSlope.class); + THashSet items = room.getRoomSpecialTypes().getItemsOfType(InteractionSnowboardSlope.class); Achievement snowboardBuild = Emulator.getGameEnvironment().getAchievementManager().getAchievement("snowBoardBuild"); if (snowboardBuild == null) return; int progress; - Habbo habbo = room.getHabbo(room.getOwnerId()); + Habbo habbo = room.getRoomUnitManager().getRoomHabboById(room.getRoomInfo().getOwnerInfo().getId()); if (habbo != null) { progress = habbo.getHabboStats().getAchievementProgress(snowboardBuild); } else { - progress = AchievementManager.getAchievementProgressForHabbo(room.getOwnerId(), snowboardBuild); + progress = AchievementManager.getAchievementProgressForHabbo(room.getRoomInfo().getOwnerInfo().getId(), snowboardBuild); } progress = Math.max(items.size() - progress, 0); if (progress > 0) { - AchievementManager.progressAchievement(room.getOwnerId(), snowboardBuild); + AchievementManager.progressAchievement(room.getRoomInfo().getOwnerInfo().getId(), snowboardBuild); } } @@ -69,7 +66,7 @@ public class InteractionSnowboardSlope extends InteractionMultiHeight { public void onPickUp(Room room) { for (Habbo habbo : room.getHabbosOnItem(this)) { if (habbo.getRoomUnit().getEffectId() == 97) { - room.giveEffect(habbo, 0, -1); + habbo.getRoomUnit().giveEffect(0, -1); } } } @@ -79,8 +76,8 @@ public class InteractionSnowboardSlope extends InteractionMultiHeight { Rectangle newRect = RoomLayout.getRectangle(newLocation.getX(), newLocation.getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); for (Habbo habbo : room.getHabbosOnItem(this)) { - if (habbo.getRoomUnit().getEffectId() == 97 && !newRect.contains(habbo.getRoomUnit().getCurrentLocation().getX(), habbo.getRoomUnit().getCurrentLocation().getY())) { - room.giveEffect(habbo, 0, -1); + if (habbo.getRoomUnit().getEffectId() == 97 && !newRect.contains(habbo.getRoomUnit().getCurrentPosition().getX(), habbo.getRoomUnit().getCurrentPosition().getY())) { + habbo.getRoomUnit().giveEffect(0, -1); } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java index e3e62bbb..e1e21051 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSpinningBottle.java @@ -5,8 +5,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.plugin.events.furniture.FurnitureDiceRolledEvent; import com.eu.habbo.threading.runnables.RandomSpinningBottleNumber; @@ -14,9 +15,9 @@ import com.eu.habbo.threading.runnables.RandomSpinningBottleNumber; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionSpinningBottle extends HabboItem { - public InteractionSpinningBottle(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); +public class InteractionSpinningBottle extends RoomItem { + public InteractionSpinningBottle(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public InteractionSpinningBottle(ResultSet set, Item baseItem) throws SQLException { @@ -26,7 +27,7 @@ public class InteractionSpinningBottle extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -46,14 +47,14 @@ public class InteractionSpinningBottle extends HabboItem { super.onClick(client, room, objects); if (client != null) { - if (RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), client.getHabbo().getRoomUnit().getCurrentLocation())) { - if (!this.getExtradata().equalsIgnoreCase("-1")) { + if (RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), client.getHabbo().getRoomUnit().getCurrentPosition())) { + if (!this.getExtraData().equalsIgnoreCase("-1")) { FurnitureDiceRolledEvent event = Emulator.getPluginManager().fireEvent(new FurnitureDiceRolledEvent(this, client.getHabbo(), -1)); if (event.isCancelled()) return; - this.setExtradata("-1"); + this.setExtraData("-1"); room.updateItemState(this); Emulator.getThreading().run(this); @@ -74,7 +75,7 @@ public class InteractionSpinningBottle extends HabboItem { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStackHelper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStackHelper.java index 669a5a69..71557ba1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStackHelper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStackHelper.java @@ -2,20 +2,21 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionStackHelper extends HabboItem { +public class InteractionStackHelper extends RoomItem { public InteractionStackHelper(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionStackHelper(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionStackHelper(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -36,7 +37,7 @@ public class InteractionStackHelper extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStickyPole.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStickyPole.java index cd434e5f..96024d2f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStickyPole.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionStickyPole.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,7 +11,7 @@ public class InteractionStickyPole extends InteractionDefault { super(set, baseItem); } - public InteractionStickyPole(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionStickyPole(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java index e1761878..8fb08d3d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitch.java @@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import java.sql.ResultSet; @@ -19,13 +20,13 @@ public class InteractionSwitch extends InteractionDefault { super(set, baseItem); } - public InteractionSwitch(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionSwitch(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean canToggle(Habbo habbo, Room room) { - return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation()); + return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), habbo.getRoomUnit().getCurrentPosition()); } @Override @@ -45,13 +46,13 @@ public class InteractionSwitch extends InteractionDefault { if (!this.canToggle(client.getHabbo(), room)) { RoomTile closestTile = null; - for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) { - if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))) { + for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()))) { + if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentPosition()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentPosition()))) { closestTile = tile; } } - if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) { + if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentPosition())) { List onSuccess = new ArrayList<>(); onSuccess.add(() -> { try { @@ -61,7 +62,7 @@ public class InteractionSwitch extends InteractionDefault { } }); - client.getHabbo().getRoomUnit().setGoalLocation(closestTile); + client.getHabbo().getRoomUnit().walkTo(closestTile); Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>())); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java index 37fbce36..3a013ce7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionSwitchRemoteControl.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; @@ -16,13 +17,13 @@ public class InteractionSwitchRemoteControl extends InteractionDefault { super(set, baseItem); } - public InteractionSwitchRemoteControl(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionSwitchRemoteControl(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean canToggle(Habbo habbo, Room room) { - return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation()); + return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), habbo.getRoomUnit().getCurrentPosition()); } @Override @@ -40,20 +41,20 @@ public class InteractionSwitchRemoteControl extends InteractionDefault { if (room != null) { super.onClick(client, room, objects); - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) + this.setExtraData("0"); if (this.getBaseItem().getStateCount() > 0) { int currentState = 0; try { - currentState = Integer.parseInt(this.getExtradata()); + currentState = Integer.parseInt(this.getExtraData()); } catch (NumberFormatException e) { - log.error("Incorrect extradata (" + this.getExtradata() + ") for item ID (" + this.getId() + ") of type (" + this.getBaseItem().getName() + ")"); + log.error("Incorrect extradata (" + this.getExtraData() + ") for item ID (" + this.getId() + ") of type (" + this.getBaseItem().getName() + ")"); } - this.setExtradata("" + (currentState + 1) % this.getBaseItem().getStateCount()); - this.needsUpdate(true); + this.setExtraData("" + (currentState + 1) % this.getBaseItem().getStateCount()); + this.setSqlUpdateNeeded(true); room.updateItemState(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTalkingFurniture.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTalkingFurniture.java index c958a9d4..6d7be0ce 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTalkingFurniture.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTalkingFurniture.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,7 +11,7 @@ public class InteractionTalkingFurniture extends InteractionDefault { super(set, baseItem); } - public InteractionTalkingFurniture(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTalkingFurniture(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java index 5e152373..b4313254 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleport.java @@ -5,9 +5,11 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +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.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import com.eu.habbo.threading.runnables.teleport.TeleportActionOne; @@ -17,7 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class InteractionTeleport extends HabboItem { +public class InteractionTeleport extends RoomItem { private int targetId; private int targetRoomId; private int roomUnitID = -1; @@ -26,26 +28,26 @@ public class InteractionTeleport extends HabboItem { public InteractionTeleport(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); walkable = baseItem.allowWalk(); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionTeleport(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTeleport(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); walkable = item.allowWalk(); - this.setExtradata("0"); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return this.getBaseItem().allowWalk() || roomUnit.getId() == this.roomUnitID; + return this.getBaseItem().allowWalk() || roomUnit.getVirtualId() == this.roomUnitID; } @Override @@ -62,67 +64,73 @@ public class InteractionTeleport extends HabboItem { Habbo habbo = client.getHabbo(); - if (habbo == null) + if (habbo == null) { return; + } - RoomUnit unit = habbo.getRoomUnit(); + RoomHabbo roomHabbo = habbo.getRoomUnit(); - if (unit == null) + if (roomHabbo == null) { return; + } - RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY()); + RoomTile currentItemLocation = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); - if (currentLocation == null) + if (currentItemLocation == null) { return; + } - RoomTile infrontTile = room.getLayout().getTileInFront(currentLocation, this.getRotation()); + RoomTile inFrontTile = room.getLayout().getTileInFront(currentItemLocation, this.getRotation()); - if (!canUseTeleport(client, room)) + if (!canUseTeleport(client, room)) { return; + } - if (this.roomUnitID == unit.getId() && unit.getCurrentLocation().equals(currentLocation)) { - startTeleport(room, habbo); - walkable = true; + if (this.roomUnitID == roomHabbo.getVirtualId() && roomHabbo.getCurrentPosition().equals(currentItemLocation)) { + this.startTeleport(room, habbo); + this.walkable = true; try { super.onClick(client, room, new Object[]{"TOGGLE_OVERRIDE"}); } catch (Exception e) { e.printStackTrace(); } - } else if (unit.getCurrentLocation().equals(currentLocation) || unit.getCurrentLocation().equals(infrontTile)) { + } else if (roomHabbo.getCurrentPosition().equals(currentItemLocation) || roomHabbo.getCurrentPosition().equals(inFrontTile)) { // set state 1 and walk on item - this.roomUnitID = unit.getId(); - this.setExtradata("1"); + this.roomUnitID = roomHabbo.getVirtualId(); + this.setExtraData("1"); room.updateItemState(this); - unit.setGoalLocation(infrontTile); + roomHabbo.walkTo(inFrontTile); List onSuccess = new ArrayList<>(); List onFail = new ArrayList<>(); onSuccess.add(() -> { - room.updateTile(currentLocation); - tryTeleport(client, room); - unit.removeOverrideTile(currentLocation); - unit.setCanLeaveRoomByDoor(true); - walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentItemLocation); + this.tryTeleport(client, room); + roomHabbo.removeOverrideTile(currentItemLocation); + roomHabbo.setCanLeaveRoomByDoor(true); + this.walkable = this.getBaseItem().allowWalk(); }); onFail.add(() -> { - walkable = this.getBaseItem().allowWalk(); - room.updateTile(currentLocation); - this.setExtradata("0"); + this.walkable = this.getBaseItem().allowWalk(); + room.updateTile(currentItemLocation); + this.setExtraData("0"); room.updateItemState(this); this.roomUnitID = -1; - unit.removeOverrideTile(currentLocation); - unit.setCanLeaveRoomByDoor(true); + roomHabbo.removeOverrideTile(currentItemLocation); + roomHabbo.setCanLeaveRoomByDoor(true); }); - walkable = true; - room.updateTile(currentLocation); - unit.addOverrideTile(currentLocation); - unit.setGoalLocation(currentLocation); - unit.setCanLeaveRoomByDoor(false); - Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); + this.walkable = true; + + room.updateTile(currentItemLocation); + roomHabbo.addOverrideTile(currentItemLocation); + roomHabbo.walkTo(currentItemLocation); + roomHabbo.setCanLeaveRoomByDoor(false); + + Emulator.getThreading().run(new RoomUnitWalkToLocation(roomHabbo, currentItemLocation, room, onSuccess, onFail)); } else { // walk to teleport and interact List onSuccess = new ArrayList<>(); @@ -130,8 +138,8 @@ public class InteractionTeleport extends HabboItem { onSuccess.add(() -> tryTeleport(client, room)); - unit.setGoalLocation(infrontTile); - Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, infrontTile, room, onSuccess, onFail)); + roomHabbo.walkTo(inFrontTile); + Emulator.getThreading().run(new RoomUnitWalkToLocation(roomHabbo, inFrontTile, room, onSuccess, onFail)); } } @@ -148,10 +156,10 @@ public class InteractionTeleport extends HabboItem { @Override public void run() { - if (!this.getExtradata().equals("0")) { - this.setExtradata("0"); + if (!this.getExtraData().equals("0")) { + this.setExtraData("0"); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room != null) { room.updateItem(this); } @@ -164,7 +172,7 @@ public class InteractionTeleport extends HabboItem { this.targetId = 0; this.targetRoomId = 0; this.roomUnitID = -1; - this.setExtradata("0"); + this.setExtraData("0"); } public int getTargetId() { @@ -192,15 +200,17 @@ public class InteractionTeleport extends HabboItem { Habbo habbo = client.getHabbo(); - if (habbo == null) + if (habbo == null) { return false; + } - RoomUnit unit = habbo.getRoomUnit(); + RoomHabbo roomHabbo = habbo.getRoomUnit(); - if (unit == null) + if (roomHabbo == null) { return false; + } - return habbo.getHabboInfo().getRiding() == null; + return !roomHabbo.isRiding(); } public void startTeleport(Room room, Habbo habbo) { @@ -209,7 +219,7 @@ public class InteractionTeleport extends HabboItem { public void startTeleport(Room room, Habbo habbo, int delay) { if (habbo.getRoomUnit().isTeleporting()) { - walkable = this.getBaseItem().allowWalk(); + this.walkable = this.getBaseItem().allowWalk(); return; } @@ -222,9 +232,4 @@ public class InteractionTeleport extends HabboItem { public boolean isUsable() { return true; } - - @Override - public boolean invalidatesToRoomKick() { - return true; - } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java index e8b90bbf..74aaed4f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTeleportTile.java @@ -2,8 +2,9 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,8 +14,8 @@ public class InteractionTeleportTile extends InteractionTeleport { super(set, baseItem); } - public InteractionTeleportTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTeleportTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -30,14 +31,14 @@ public class InteractionTeleportTile extends InteractionTeleport { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { if (roomUnit != null && this.canWalkOn(roomUnit, room, objects)) { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { if (!canUseTeleport(habbo.getClient(), room)) return; if (!habbo.getRoomUnit().isTeleporting()) { - habbo.getRoomUnit().setGoalLocation(habbo.getRoomUnit().getCurrentLocation()); + habbo.getRoomUnit().walkTo(habbo.getRoomUnit().getCurrentPosition()); this.startTeleport(room, habbo, 1000); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTent.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTent.java index e295e4b2..fb2653ba 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTent.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTent.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -12,8 +13,8 @@ public class InteractionTent extends InteractionDefault { super(set, baseItem); } - public InteractionTent(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTent(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileEffectProvider.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileEffectProvider.java index b8c1d313..f6cc49e0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileEffectProvider.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTileEffectProvider.java @@ -3,7 +3,9 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.map.hash.THashMap; import java.sql.ResultSet; @@ -19,8 +21,8 @@ public class InteractionTileEffectProvider extends InteractionCustomValues { super(set, baseItem, defaultValues); } - public InteractionTileEffectProvider(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, defaultValues); + public InteractionTileEffectProvider(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, defaultValues); } @Override @@ -37,9 +39,13 @@ public class InteractionTileEffectProvider extends InteractionCustomValues { public void onWalkOn(RoomUnit roomUnit, final Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); + if(!(roomUnit instanceof RoomHabbo roomHabbo)) { + return; + } + int effectId = Integer.parseInt(this.values.get("effectId")); - if (roomUnit.getEffectId() == effectId) { + if (roomHabbo.getEffectId() == effectId) { effectId = 0; } @@ -52,6 +58,6 @@ public class InteractionTileEffectProvider extends InteractionCustomValues { room.updateItem(proxy); }, 500); - room.giveEffect(roomUnit, effectId, -1); + roomHabbo.giveEffect(effectId, -1); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrap.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrap.java index 1ea1eb16..66bac372 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrap.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrap.java @@ -3,10 +3,11 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUnitType; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -16,15 +17,15 @@ public class InteractionTrap extends InteractionDefault { super(set, baseItem); } - public InteractionTrap(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTrap(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - if (this.getExtradata().equals("0") || roomUnit == null || room.getHabbo(roomUnit) == null) return; + if (this.getExtraData().equals("0") || roomUnit == null || room.getRoomUnitManager().getHabboByRoomUnit(roomUnit) == null) return; - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); int effect = habbo.getClient().getHabbo().getRoomUnit().getEffectId(); roomUnit.stopWalking(); super.onWalkOn(roomUnit, room, objects); @@ -35,24 +36,24 @@ public class InteractionTrap extends InteractionDefault { } if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { - if (roomUnit.getRoomUnitType().equals(RoomUnitType.USER)) { + if (roomUnit instanceof RoomHabbo roomHabbo) { - if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { - room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1); + if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0 && roomHabbo.getEffectId() != this.getBaseItem().getEffectM()) { + roomHabbo.giveEffect(this.getBaseItem().getEffectM(), -1); return; } - if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { - room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1); + if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0 && roomHabbo.getEffectId() != this.getBaseItem().getEffectF()) { + roomHabbo.giveEffect(this.getBaseItem().getEffectF(), -1); return; } - roomUnit.setCanWalk(false); + roomHabbo.setCanWalk(false); Emulator.getThreading().run(() -> { - room.giveEffect(roomUnit, 0, -1); + roomHabbo.giveEffect(0, -1); roomUnit.setCanWalk(true); - room.giveEffect(roomUnit, effect, -1); + roomHabbo.giveEffect(effect, -1); }, delay); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java index 80f2c39c..6a9f93c4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionTrophy.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,8 +11,8 @@ public class InteractionTrophy extends InteractionDefault { super(set, baseItem); } - public InteractionTrophy(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTrophy(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java index 6bccfc83..72c7d8f9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVendingMachine.java @@ -3,9 +3,16 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +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.types.RoomAvatar; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; @@ -17,15 +24,15 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class InteractionVendingMachine extends HabboItem { +public class InteractionVendingMachine extends RoomItem { public InteractionVendingMachine(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionVendingMachine(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionVendingMachine(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } public THashSet getActivatorTiles(Room room) { @@ -35,14 +42,14 @@ public class InteractionVendingMachine extends HabboItem { if (tileInFront != null) tiles.add(tileInFront); - tiles.add(room.getLayout().getTile(this.getX(), this.getY())); + tiles.add(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); return tiles; } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -56,7 +63,7 @@ public class InteractionVendingMachine extends HabboItem { boolean inActivatorSpace = false; for(RoomTile ignored : activatorTiles) { - if(unit.getCurrentLocation().is(unit.getX(), unit.getY())) { + if(unit.getCurrentPosition().is(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY())) { inActivatorSpace = true; } } @@ -67,7 +74,11 @@ public class InteractionVendingMachine extends HabboItem { } private void useVendingMachine(GameClient client, Room room, RoomUnit unit) { - this.setExtradata("1"); + if(!(unit instanceof RoomAvatar roomAvatar)) { + return; + } + + this.setExtraData("1"); room.updateItem(this); try { @@ -76,25 +87,25 @@ public class InteractionVendingMachine extends HabboItem { e.printStackTrace(); } - if(!unit.isWalking() && !unit.hasStatus(RoomUnitStatus.SIT) && !unit.hasStatus(RoomUnitStatus.LAY)) { - this.rotateToMachine(unit); + if(!roomAvatar.isWalking() && !roomAvatar.hasStatus(RoomUnitStatus.SIT) && !roomAvatar.hasStatus(RoomUnitStatus.LAY)) { + this.rotateToMachine(roomAvatar); } Emulator.getThreading().run(() -> { - giveVendingMachineItem(room, unit); + giveVendingMachineItem(room, roomAvatar); if (this.getBaseItem().getEffectM() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.M) - room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectM(), -1); + client.getHabbo().getRoomUnit().giveEffect(this.getBaseItem().getEffectM(), -1); if (this.getBaseItem().getEffectF() > 0 && client.getHabbo().getHabboInfo().getGender() == HabboGender.F) - room.giveEffect(client.getHabbo(), this.getBaseItem().getEffectF(), -1); + client.getHabbo().getRoomUnit().giveEffect(this.getBaseItem().getEffectF(), -1); Emulator.getThreading().run(this, 500); }, 1500); } - public void giveVendingMachineItem(Room room, RoomUnit unit) { - Emulator.getThreading().run(new RoomUnitGiveHanditem(unit, room, this.getBaseItem().getRandomVendingItem())); + public void giveVendingMachineItem(Room room, RoomAvatar roomAvatar) { + Emulator.getThreading().run(new RoomUnitGiveHanditem(roomAvatar, room, this.getBaseItem().getRandomVendingItem())); } @Override @@ -113,7 +124,7 @@ public class InteractionVendingMachine extends HabboItem { boolean inActivatorSpace = false; for(RoomTile tile : activatorTiles) { - if(unit.getCurrentLocation().is(tile.getX(), tile.getY())) { + if(unit.getCurrentPosition().is(tile.getX(), tile.getY())) { inActivatorSpace = true; } } @@ -121,7 +132,7 @@ public class InteractionVendingMachine extends HabboItem { if(!inActivatorSpace) { RoomTile tileToWalkTo = null; for(RoomTile tile : activatorTiles) { - if((tile.getState() == RoomTileState.OPEN || tile.getState() == RoomTileState.SIT) && (tileToWalkTo == null || tileToWalkTo.distance(unit.getCurrentLocation()) > tile.distance(unit.getCurrentLocation()))) { + if((tile.getState() == RoomTileState.OPEN || tile.getState() == RoomTileState.SIT) && (tileToWalkTo == null || tileToWalkTo.distance(unit.getCurrentPosition()) > tile.distance(unit.getCurrentPosition()))) { tileToWalkTo = tile; } } @@ -132,7 +143,7 @@ public class InteractionVendingMachine extends HabboItem { onSuccess.add(() -> tryInteract(client, room, unit)); - unit.setGoalLocation(tileToWalkTo); + unit.walkTo(tileToWalkTo); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tileToWalkTo, room, onSuccess, onFail)); } } @@ -149,9 +160,9 @@ public class InteractionVendingMachine extends HabboItem { @Override public void run() { super.run(); - if (this.getExtradata().equals("1")) { - this.setExtradata("0"); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + if (this.getExtraData().equals("1")) { + this.setExtraData("0"); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room != null) { room.updateItem(this); } @@ -174,11 +185,11 @@ public class InteractionVendingMachine extends HabboItem { } private void rotateToMachine(RoomUnit unit) { - RoomUserRotation rotation = RoomUserRotation.values()[Rotation.Calculate(unit.getX(), unit.getY(), this.getX(), this.getY())]; + RoomRotation rotation = RoomRotation.values()[Rotation.Calculate(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY(), this.getCurrentPosition().getX(), this.getCurrentPosition().getY())]; if(Math.abs(unit.getBodyRotation().getValue() - rotation.getValue()) > 1) { unit.setRotation(rotation); - unit.statusUpdate(true); + unit.setStatusUpdateNeeded(true); } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVikingCotie.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVikingCotie.java index b79a675b..43b095e9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVikingCotie.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVikingCotie.java @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,23 +15,23 @@ public class InteractionVikingCotie extends InteractionDefault { super(set, baseItem); } - public InteractionVikingCotie(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionVikingCotie(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onClick(GameClient client, Room room, Object[] objects) { - if (this.getExtradata().isEmpty()) { - this.setExtradata("0"); + if (this.getExtraData().isEmpty()) { + this.setExtraData("0"); } - if (client != null && client.getHabbo().getHabboInfo().getId() == this.getUserId()) { + if (client != null && client.getHabbo().getHabboInfo().getId() == this.getOwnerInfo().getId()) { if (client.getHabbo().getRoomUnit().getEffectId() == 172 || client.getHabbo().getRoomUnit().getEffectId() == 173) { - int state = Integer.parseInt(this.getExtradata()); + int state = Integer.parseInt(this.getExtraData()); if (state < 5) { state++; - this.setExtradata(state + ""); + this.setExtraData(state + ""); room.updateItem(this); if (state == 5) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java index a28b30b4..71fa2071 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionVoteCounter.java @@ -3,8 +3,9 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.messages.ServerMessage; @@ -13,7 +14,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class InteractionVoteCounter extends HabboItem { +public class InteractionVoteCounter extends RoomItem { private boolean frozen; private int votes; @@ -21,18 +22,18 @@ public class InteractionVoteCounter extends HabboItem { public InteractionVoteCounter(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - if(!this.getExtradata().contains(",")) { - this.setExtradata("1,0"); // frozen,votes + if(!this.getExtraData().contains(",")) { + this.setExtraData("1,0"); // frozen,votes } - String[] bits = this.getExtradata().split(","); + String[] bits = this.getExtraData().split(","); frozen = bits[0].equals("1"); votes = Integer.parseInt(bits[1]); votedUsers = new ArrayList<>(); } - public InteractionVoteCounter(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionVoteCounter(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); if(!extradata.contains(",")) { extradata = "1,0"; @@ -63,12 +64,12 @@ public class InteractionVoteCounter extends HabboItem { } private void updateExtradata() { - this.setExtradata((this.frozen ? "1" : "0") + "," + this.votes); + this.setExtraData((this.frozen ? "1" : "0") + "," + this.votes); } @Override public void onClick(GameClient client, Room room, Object[] objects) { - if (room == null || !((client != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) + if (room == null || !((client != null && room.getRoomRightsManager().hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) return; this.frozen = !this.frozen; @@ -79,7 +80,7 @@ public class InteractionVoteCounter extends HabboItem { } updateExtradata(); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); room.updateItem(this); } @@ -99,7 +100,7 @@ public class InteractionVoteCounter extends HabboItem { votes += vote; updateExtradata(); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); room.updateItem(this); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java index 062e4034..eb779f16 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWater.java @@ -3,9 +3,15 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +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.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import org.apache.commons.math3.util.Pair; @@ -27,8 +33,8 @@ public class InteractionWater extends InteractionDefault { this.isInRoom = this.getRoomId() != 0; } - public InteractionWater(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionWater(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.isDeepWater = false; this.isInRoom = this.getRoomId() != 0; } @@ -78,13 +84,13 @@ public class InteractionWater extends InteractionDefault { if(roomUnit == null) return; roomUnit.setSwimming(true); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet == null) return; if (!pet.getRoomUnit().hasStatus(RoomUnitStatus.SWIM) && pet.getPetData().isCanSwim()) { - pet.getRoomUnit().setStatus(RoomUnitStatus.SWIM, ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.SWIM, ""); } } @@ -95,7 +101,7 @@ public class InteractionWater extends InteractionDefault { super.onWalkOff(roomUnit, room, objects); if ( roomUnit.getRoomUnitType() != RoomUnitType.PET) return; - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet == null) return; @@ -113,22 +119,22 @@ public class InteractionWater extends InteractionDefault { } @Override - public boolean canStackAt(Room room, List>> itemsAtLocation) { - for (Pair> set : itemsAtLocation) { - for (HabboItem item : set.getValue()) { + public boolean canStackAt(List>> itemsAtLocation) { + for (Pair> set : itemsAtLocation) { + for (RoomItem item : set.getValue()) { if(item != this) return false; } } - return super.canStackAt(room, itemsAtLocation); + return super.canStackAt(itemsAtLocation); } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { if (!super.canWalkOn(roomUnit, room, objects)) return false; - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); return pet == null || pet.getPetData().isCanSwim(); } @@ -151,7 +157,7 @@ public class InteractionWater extends InteractionDefault { } // Update neighbouring water. - for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWater.class)) { + for (RoomItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWater.class)) { // We already updated ourself. if (item == this) { continue; @@ -168,7 +174,7 @@ public class InteractionWater extends InteractionDefault { // Update water items we might have missed in the old location. if (targetOld != null) { - for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWaterItem.class)) { + for (RoomItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWaterItem.class)) { if (targetOld.intersects(item.getRectangle())) { ((InteractionWaterItem) item).update(); } @@ -180,7 +186,7 @@ public class InteractionWater extends InteractionDefault { Rectangle target = this.getRectangle(); // Only update water item furnis that are intersecting with us. - for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWaterItem.class)) { + for (RoomItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionWaterItem.class)) { if (target.intersects(item.getRectangle())) { ((InteractionWaterItem) item).update(); } @@ -201,55 +207,63 @@ public class InteractionWater extends InteractionDefault { byte _12 = 0; // Check if we are touching a water tile. - if (this.isValidForMask(room, this.getX() - 1, this.getY() - 1, this.getZ(), true)) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() - 1, this.getCurrentPosition().getY() - 1, this.getCurrentZ(), true)) { _1 = 1; } - if (this.isValidForMask(room, this.getX(), this.getY() - 1, this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX(), this.getCurrentPosition().getY() - 1, this.getCurrentZ())) { _2 = 1; } - if (this.isValidForMask(room, this.getX() + 1, this.getY() - 1, this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() + 1, this.getCurrentPosition().getY() - 1, this.getCurrentZ())) { _3 = 1; } - if (this.isValidForMask(room, this.getX() + 2, this.getY() - 1, this.getZ(), true)) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() + 2, this.getCurrentPosition().getY() - 1, this.getCurrentZ(), true)) { _4 = 1; } - if (this.isValidForMask(room, this.getX() - 1, this.getY(), this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() - 1, this.getCurrentPosition().getY(), this.getCurrentZ())) { _5 = 1; } - if (this.isValidForMask(room, this.getX() + 2, this.getY(), this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() + 2, this.getCurrentPosition().getY(), this.getCurrentZ())) { _6 = 1; } - if (this.isValidForMask(room, this.getX() - 1, this.getY() + 1, this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() - 1, this.getCurrentPosition().getY() + 1, this.getCurrentZ())) { _7 = 1; } - if (this.isValidForMask(room, this.getX() + 2, this.getY() + 1, this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() + 2, this.getCurrentPosition().getY() + 1, this.getCurrentZ())) { _8 = 1; } - if (this.isValidForMask(room, this.getX() - 1, this.getY() + 2, this.getZ(), true)) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() - 1, this.getCurrentPosition().getY() + 2, this.getCurrentZ(), true)) { _9 = 1; } - if (this.isValidForMask(room, this.getX(), this.getY() + 2, this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX(), this.getCurrentPosition().getY() + 2, this.getCurrentZ())) { _10 = 1; } - if (this.isValidForMask(room, this.getX() + 1, this.getY() + 2, this.getZ())) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() + 1, this.getCurrentPosition().getY() + 2, this.getCurrentZ())) { _11 = 1; } - if (this.isValidForMask(room, this.getX() + 2, this.getY() + 2, this.getZ(), true)) { + if (this.isValidForMask(room, this.getCurrentPosition().getX() + 2, this.getCurrentPosition().getY() + 2, this.getCurrentZ(), true)) { _12 = 1; } // Check if we are touching invalid tiles. // if (_1 == 0 && room.getLayout().isVoidTile((short)(this.getX() -1), (short) (this.getY() -1))) _1 = 1; - if (_2 == 0 && room.getLayout().isVoidTile(this.getX(), (short) (this.getY() - 1))) _2 = 1; - if (_3 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 1), (short) (this.getY() - 1))) _3 = 1; + if (_2 == 0 && room.getLayout().isVoidTile(this.getCurrentPosition().getX(), (short) (this.getCurrentPosition().getY() - 1))) + _2 = 1; + if (_3 == 0 && room.getLayout().isVoidTile((short) (this.getCurrentPosition().getX() + 1), (short) (this.getCurrentPosition().getY() - 1))) + _3 = 1; // if (_4 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), (short) (this.getY() - 1))) _4 = 1; - if (_5 == 0 && room.getLayout().isVoidTile((short) (this.getX() - 1), this.getY())) _5 = 1; - if (_6 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), this.getY())) _6 = 1; - if (_7 == 0 && room.getLayout().isVoidTile((short) (this.getX() - 1), (short) (this.getY() + 1))) _7 = 1; - if (_8 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), (short) (this.getY() + 1))) _8 = 1; + if (_5 == 0 && room.getLayout().isVoidTile((short) (this.getCurrentPosition().getX() - 1), this.getCurrentPosition().getY())) + _5 = 1; + if (_6 == 0 && room.getLayout().isVoidTile((short) (this.getCurrentPosition().getX() + 2), this.getCurrentPosition().getY())) + _6 = 1; + if (_7 == 0 && room.getLayout().isVoidTile((short) (this.getCurrentPosition().getX() - 1), (short) (this.getCurrentPosition().getY() + 1))) + _7 = 1; + if (_8 == 0 && room.getLayout().isVoidTile((short) (this.getCurrentPosition().getX() + 2), (short) (this.getCurrentPosition().getY() + 1))) + _8 = 1; // if (_9 == 0 && room.getLayout().isVoidTile((short)(this.getX() -1), (short) (this.getY() + 2))) _9 = 1; - if (_10 == 0 && room.getLayout().isVoidTile(this.getX(), (short) (this.getY() + 2))) _10 = 1; - if (_11 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 1), (short) (this.getY() + 2))) _11 = 1; + if (_10 == 0 && room.getLayout().isVoidTile(this.getCurrentPosition().getX(), (short) (this.getCurrentPosition().getY() + 2))) + _10 = 1; + if (_11 == 0 && room.getLayout().isVoidTile((short) (this.getCurrentPosition().getX() + 1), (short) (this.getCurrentPosition().getY() + 2))) + _11 = 1; // if (_12 == 0 && room.getLayout().isVoidTile((short) (this.getX() + 2), (short) (this.getY() + 2))) _12 = 1; // Update water. @@ -268,9 +282,9 @@ public class InteractionWater extends InteractionDefault { String updatedData = String.valueOf(result); - if (!this.getExtradata().equals(updatedData)) { - this.setExtradata(updatedData); - this.needsUpdate(true); + if (!this.getExtraData().equals(updatedData)) { + this.setExtraData(updatedData); + this.setSqlUpdateNeeded(true); room.updateItem(this); } } @@ -280,7 +294,7 @@ public class InteractionWater extends InteractionDefault { } private boolean isValidForMask(Room room, int x, int y, double z, boolean corner) { - for (HabboItem item : room.getItemsAt(x, y, z)) { + for (RoomItem item : room.getRoomItemManager().getItemsAt(x, y, z)) { if (item instanceof InteractionWater water) { // Take out picked up water from the recalculation. diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java index 404e1f32..95c6c138 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWaterItem.java @@ -5,7 +5,8 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import java.awt.*; @@ -17,8 +18,8 @@ public class InteractionWaterItem extends InteractionMultiHeight { super(set, baseItem); } - public InteractionWaterItem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionWaterItem(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -30,8 +31,8 @@ public class InteractionWaterItem extends InteractionMultiHeight { @Override public void onPickUp(Room room) { super.onPickUp(room); - this.setExtradata("0"); - this.needsUpdate(true); + this.setExtraData("0"); + this.setSqlUpdateNeeded(true); } @Override @@ -46,7 +47,7 @@ public class InteractionWaterItem extends InteractionMultiHeight { } public void update() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room == null) { return; @@ -60,9 +61,10 @@ public class InteractionWaterItem extends InteractionMultiHeight { for (short x = (short) rectangle.x; x < rectangle.getWidth() + rectangle.x && foundWater; x++) { for (short y = (short) rectangle.y; y < rectangle.getHeight() + rectangle.y && foundWater; y++) { boolean tile = false; - THashSet items = room.getItemsAt(room.getLayout().getTile(x, y)); + RoomTile tile1 = room.getLayout().getTile(x, y); + THashSet items = room.getRoomItemManager().getItemsAt(tile1); - for (HabboItem item : items) { + for (RoomItem item : items) { if (item instanceof InteractionWater) { tile = true; break; @@ -78,9 +80,9 @@ public class InteractionWaterItem extends InteractionMultiHeight { // Update data if changed. String updatedData = foundWater ? "1" : "0"; - if (!this.getExtradata().equals(updatedData)) { - this.setExtradata(updatedData); - this.needsUpdate(true); + if (!this.getExtraData().equals(updatedData)) { + this.setExtraData(updatedData); + this.setSqlUpdateNeeded(true); room.updateItemState(this); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java index 84838123..c0680ef6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWired.java @@ -1,50 +1,160 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredInteraction; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; -import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.OneWayDoorStatusMessageComposer; +import com.eu.habbo.messages.outgoing.wired.WiredConditionDataComposer; +import com.eu.habbo.messages.outgoing.wired.WiredEffectDataComposer; +import com.eu.habbo.messages.outgoing.wired.WiredTriggerDataComposer; +import com.fasterxml.jackson.core.JsonProcessingException; import gnu.trove.map.hash.TLongLongHashMap; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; @Slf4j -public abstract class InteractionWired extends InteractionDefault { +public abstract class InteractionWired extends InteractionDefault implements IWiredInteraction { + @Getter + @Setter + private WiredSettings wiredSettings; private long cooldown; private final TLongLongHashMap userExecutionCache = new TLongLongHashMap(3); - InteractionWired(ResultSet set, Item baseItem) throws SQLException { + public InteractionWired(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.wiredSettings = new WiredSettings(); + this.setExtraData("0"); } - InteractionWired(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + InteractionWired(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.wiredSettings = new WiredSettings(); + this.setExtraData("0"); } public abstract boolean execute(RoomUnit roomUnit, Room room, Object[] stuff); - public abstract String getWiredData(); + /** + * On Room Loading run this, get Wired Data from Database and save it into the item + * + * @param set + * @throws SQLException + */ + public void loadWiredSettings(ResultSet set) throws SQLException, JsonProcessingException { + String wiredData = set.getString("wired_data"); + this.wiredSettings = new WiredSettings(); - public abstract void serializeWiredData(ServerMessage message, Room room); + if(wiredData.startsWith("{")) { + this.wiredSettings = WiredHandler.getObjectMapper().readValue(wiredData, WiredSettings.class); + } + } - public abstract void loadWiredData(ResultSet set, Room room) throws SQLException; + /** + * + * When double-clicking into the wired, verify items first and load its default parameters + * then create a composer based on it's Wired Settings + * + * @param client + * @param room + * @param objects + * @throws Exception + */ + @Override + public void onClick(GameClient client, Room room, Object[] objects) throws Exception { + this.wiredSettings.getItems(room); + if (client != null) { + if (room.getRoomRightsManager().hasRights(client.getHabbo())) { + MessageComposer composer = null; + if(this instanceof InteractionWiredEffect) { + composer = new WiredEffectDataComposer((InteractionWiredEffect) this, room); + } else if(this instanceof InteractionWiredCondition) { + composer = new WiredConditionDataComposer((InteractionWiredCondition) this, room); + } else if(this instanceof InteractionWiredTrigger) { + composer = new WiredTriggerDataComposer((InteractionWiredTrigger) this, room); + } + + client.sendResponse(composer); + this.activateBox(room); + } + } + } + + /** + * When click save changes on the wired this executes, reads all the packet + * And updates wired current Wired Settings + * + * @param packet + */ + public void saveWiredSettings(ClientMessage packet, Room room) { + int intParamCount = packet.readInt(); + List integerParams = new ArrayList<>(); + + for(int i = 0; i < intParamCount; i++) + { + integerParams.add(packet.readInt()); + } + + this.wiredSettings.setIntegerParams(integerParams); + this.wiredSettings.setStringParam(packet.readString()); + + int itemCount = packet.readInt(); + List itemIds = new ArrayList<>(); + + for(int i = 0; i < itemCount; i++) + { + itemIds.add(packet.readInt()); + } + + this.wiredSettings.setItemIds(itemIds); + + if(this instanceof InteractionWiredEffect) { + this.wiredSettings.setDelay(packet.readInt()); + } + + this.wiredSettings.setSelectionType(packet.readInt()); + + saveAdditionalData(room); + } + + /** + * This is executed on 3 different situations + * When finishing executing: `saveWiredSettings`, when placing this item on floor, and when picking it up. + * This what it does is converts Wired Settings into a JSON string + * and updates wired_data in the database + */ @Override public void run() { - if (this.needsUpdate()) { - String wiredData = this.getWiredData(); + if (this.isSqlUpdateNeeded()) { + //TODO HERE IS WHERE WIRED_SAVE_EXCEPTION WILL BE THROWN + //EXAMPLE: if StringParam should be number, throw error here, maybe activating a flag in wiredSettings that string params are numbers + this.loadDefaultIntegerParams(); - if (wiredData == null) { + String wiredData; + + try { + wiredData = WiredHandler.getObjectMapper().writeValueAsString(this.wiredSettings); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + + if(wiredData.equalsIgnoreCase("{}")) { wiredData = ""; } @@ -63,22 +173,28 @@ public abstract class InteractionWired extends InteractionDefault { super.run(); } + /** + * When picking up the wired, all its settings are erased and updated in database + * + * @param room + */ @Override public void onPickUp(Room room) { - this.onPickUp(); + this.wiredSettings.dispose(); } - public abstract void onPickUp(); + public void loadDefaultIntegerParams() {} + public void saveAdditionalData(Room room) {} public void activateBox(Room room) { this.activateBox(room, null, 0L); } public void activateBox(Room room, RoomUnit roomUnit, long millis) { - this.setExtradata(this.getExtradata().equals("1") ? "0" : "1"); + this.setExtraData(this.getExtraData().equals("1") ? "0" : "1"); room.sendComposer(new OneWayDoorStatusMessageComposer(this).compose()); if (roomUnit != null) { - this.addUserExecutionCache(roomUnit.getId(), millis); + this.addUserExecutionCache(roomUnit.getVirtualId(), millis); } } @@ -86,7 +202,6 @@ public abstract class InteractionWired extends InteractionDefault { return 50L; } - public boolean canExecute(long newMillis) { return newMillis - this.cooldown >= this.requiredCooldown(); } @@ -111,7 +226,6 @@ public abstract class InteractionWired extends InteractionDefault { long lastTimestamp = this.userExecutionCache.get(roomUnitId); return timestamp - lastTimestamp >= 100L; } - } return true; } @@ -123,36 +237,4 @@ public abstract class InteractionWired extends InteractionDefault { public void addUserExecutionCache(int roomUnitId, long timestamp) { this.userExecutionCache.put(roomUnitId, timestamp); } - - public static WiredSettings readSettings(ClientMessage packet, boolean isEffect) - { - int intParamCount = packet.readInt(); - int[] intParams = new int[intParamCount]; - - for(int i = 0; i < intParamCount; i++) - { - intParams[i] = packet.readInt(); - } - - String stringParam = packet.readString(); - - int itemCount = packet.readInt(); - int[] itemIds = new int[itemCount]; - - for(int i = 0; i < itemCount; i++) - { - itemIds[i] = packet.readInt(); - } - - WiredSettings settings = new WiredSettings(intParams, stringParam, itemIds, -1); - - if(isEffect) - { - settings.setDelay(packet.readInt()); - } - - settings.setStuffTypeSelectionCode(packet.readInt()); - return settings; - } - } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java index df4fbd0d..fe6bef8f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredCondition.java @@ -1,13 +1,9 @@ package com.eu.habbo.habbohotel.items.interactions; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionOperator; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.messages.outgoing.wired.WiredConditionDataComposer; import java.sql.ResultSet; import java.sql.SQLException; @@ -17,36 +13,13 @@ public abstract class InteractionWiredCondition extends InteractionWired { super(set, baseItem); } - public InteractionWiredCondition(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return true; - } - - @Override - public boolean isWalkable() { - return true; - } - - @Override - public void onClick(GameClient client, Room room, Object[] objects) { - if (client != null) { - if (room.hasRights(client.getHabbo())) { - client.sendResponse(new WiredConditionDataComposer(this, room)); - this.activateBox(room); - } - } + public InteractionWiredCondition(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public abstract WiredConditionType getType(); - public abstract boolean saveData(WiredSettings settings); - public WiredConditionOperator operator() { return WiredConditionOperator.AND; } - } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java index e58e3659..68981e6c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredEffect.java @@ -1,61 +1,49 @@ package com.eu.habbo.habbohotel.items.interactions; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredEffectInteraction; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import com.eu.habbo.messages.outgoing.wired.WiredEffectDataComposer; +import gnu.trove.set.hash.THashSet; +import lombok.Getter; +import lombok.Setter; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; -public abstract class InteractionWiredEffect extends InteractionWired { - private int delay; +public abstract class InteractionWiredEffect extends InteractionWired implements IWiredEffectInteraction { + @Getter + @Setter + private List blockedTriggers; + + @Getter + @Setter + private WiredEffectType type; public InteractionWiredEffect(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionWiredEffect(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionWiredEffect(int id, HabboInfo ownerInfo, Item item, String extraData, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extraData, limitedStack, limitedSells); } - @Override - public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return true; - } + public List getBlockedTriggers(Room room) { + List blockedTriggers = new ArrayList<>(); + THashSet triggers = room.getRoomSpecialTypes().getTriggers(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); - @Override - public boolean isWalkable() { - return true; - } - - @Override - public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - if (client != null) { - if (room.hasRights(client.getHabbo())) { - client.sendResponse(new WiredEffectDataComposer(this, room)); - this.activateBox(room); + for(InteractionWiredTrigger trigger : triggers) { + if(!trigger.isTriggeredByRoomUnit()) { + blockedTriggers.add(trigger.getBaseItem().getSpriteId()); } } + + return blockedTriggers; } - public abstract boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException; - - public int getDelay() { - return this.delay; - } - - protected void setDelay(int value) { - this.delay = value; - } - - public abstract WiredEffectType getType(); - - public boolean requiresTriggeringUser() { return false; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredExtra.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredExtra.java index c29cf0a6..c0bae61a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredExtra.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredExtra.java @@ -3,7 +3,8 @@ package com.eu.habbo.habbohotel.items.interactions; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,14 +14,14 @@ public abstract class InteractionWiredExtra extends InteractionWired { super(set, baseItem); } - protected InteractionWiredExtra(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + protected InteractionWiredExtra(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onClick(GameClient client, Room room, Object[] objects) { if (client != null) { - if (room.hasRights(client.getHabbo())) { + if (room.getRoomRightsManager().hasRights(client.getHabbo())) { this.activateBox(room); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java index d8b3a9dc..f75c8e58 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredHighscore.java @@ -4,8 +4,9 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -20,7 +21,7 @@ import java.sql.SQLException; import java.util.List; @Slf4j -public class InteractionWiredHighscore extends HabboItem { +public class InteractionWiredHighscore extends RoomItem { public WiredHighscoreScoreType scoreType; @@ -46,8 +47,8 @@ public class InteractionWiredHighscore extends HabboItem { this.reloadData(); } - public InteractionWiredHighscore(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionWiredHighscore(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.scoreType = WiredHighscoreScoreType.CLASSIC; this.clearType = WiredHighscoreClearType.ALLTIME; @@ -81,16 +82,16 @@ public class InteractionWiredHighscore extends HabboItem { @Override public void onClick(GameClient client, Room room, Object[] objects) { - if (room == null || !((client != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) + if (room == null || !((client != null && room.getRoomRightsManager().hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) return; - if (this.getExtradata() == null || this.getExtradata().isEmpty() || this.getExtradata().length() == 0) { - this.setExtradata("0"); + if (this.getExtraData() == null || this.getExtraData().isEmpty() || this.getExtraData().length() == 0) { + this.setExtraData("0"); } try { - int state = Integer.parseInt(this.getExtradata()); - this.setExtradata(Math.abs(state - 1) + ""); + int state = Integer.parseInt(this.getExtraData()); + this.setExtraData(Math.abs(state - 1) + ""); room.updateItem(this); } catch (Exception e) { log.error("Caught exception", e); @@ -105,7 +106,7 @@ public class InteractionWiredHighscore extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt(6); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); serverMessage.appendInt(this.scoreType.getType()); serverMessage.appendInt(this.clearType.getType()); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java index db67dd84..86e1108f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionWiredTrigger.java @@ -1,61 +1,50 @@ package com.eu.habbo.habbohotel.items.interactions; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredTriggerInteraction; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.outgoing.wired.WiredTriggerDataComposer; +import gnu.trove.set.hash.THashSet; +import lombok.Getter; +import lombok.Setter; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; -public abstract class InteractionWiredTrigger extends InteractionWired { - private int delay; +public abstract class InteractionWiredTrigger extends InteractionWired implements IWiredTriggerInteraction { + @Getter + @Setter + private List blockedEffects; + + @Getter + @Setter + private WiredTriggerType type; protected InteractionWiredTrigger(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - protected InteractionWiredTrigger(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + protected InteractionWiredTrigger(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } - @Override - public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return true; - } + public List getBlockedEffects(Room room) { + List blockedEffects = new ArrayList<>(); + THashSet effects = room.getRoomSpecialTypes().getEffects(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); - @Override - public boolean isWalkable() { - return true; - } - - @Override - public void onClick(GameClient client, Room room, Object[] objects) { - if (client != null) { - if (room.hasRights(client.getHabbo())) { - client.sendResponse(new WiredTriggerDataComposer(this, room)); - this.activateBox(room); + for(InteractionWiredEffect effect : effects) { + if (!effect.requiresTriggeringUser()) { + blockedEffects.add(effect.getBaseItem().getSpriteId()); } } - } - public abstract WiredTriggerType getType(); - - public abstract boolean saveData(WiredSettings settings); - - protected int getDelay() { - return this.delay; - } - - protected void setDelay(int value) { - this.delay = value; + return blockedEffects; } public boolean isTriggeredByRoomUnit() { return false; } - } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionYoutubeTV.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionYoutubeTV.java index 4da6bb8f..e341d276 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionYoutubeTV.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionYoutubeTV.java @@ -5,17 +5,17 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.YoutubeManager; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.items.youtube.YoutubeDisplayVideoMessageComposer; -import com.eu.habbo.threading.runnables.YoutubeAdvanceVideo; import java.sql.ResultSet; import java.sql.SQLException; import java.util.concurrent.ScheduledFuture; -public class InteractionYoutubeTV extends HabboItem { +public class InteractionYoutubeTV extends RoomItem { public YoutubeManager.YoutubePlaylist currentPlaylist = null; public YoutubeManager.YoutubeVideo currentVideo = null; public int startedWatchingAt = 0; @@ -27,8 +27,8 @@ public class InteractionYoutubeTV extends HabboItem { super(set, baseItem); } - public InteractionYoutubeTV(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionYoutubeTV(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -48,8 +48,8 @@ public class InteractionYoutubeTV extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { - if (this.getExtradata().length() == 0) - this.setExtradata(""); + if (this.getExtraData().length() == 0) + this.setExtraData(""); serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(1); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java index b56491bd..47d768bf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameGate.java @@ -4,7 +4,8 @@ import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; @@ -13,17 +14,17 @@ import java.sql.SQLException; public abstract class InteractionGameGate extends InteractionGameTeamItem { public InteractionGameGate(ResultSet set, Item baseItem, GameTeamColors teamColor) throws SQLException { super(set, baseItem, teamColor); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionGameGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); - this.setExtradata("0"); + public InteractionGameGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); + this.setExtraData("0"); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } @Override @@ -34,7 +35,7 @@ public abstract class InteractionGameGate extends InteractionGameTeamItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -49,7 +50,7 @@ public abstract class InteractionGameGate extends InteractionGameTeamItem { if (memberCount > maxPlayers) { memberCount = maxPlayers; } - this.setExtradata(memberCount + ""); + this.setExtraData(memberCount + ""); game.getRoom().updateItem(this); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameScoreboard.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameScoreboard.java index eb416b80..cf81f3fd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameScoreboard.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameScoreboard.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.items.interactions.games; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; @@ -11,24 +12,24 @@ import java.sql.SQLException; public abstract class InteractionGameScoreboard extends InteractionGameTeamItem { protected InteractionGameScoreboard(ResultSet set, Item baseItem, GameTeamColors teamColor) throws SQLException { super(set, baseItem, teamColor); - this.setExtradata("0"); + this.setExtraData("0"); } - protected InteractionGameScoreboard(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); - this.setExtradata("0"); + protected InteractionGameScoreboard(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTeamItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTeamItem.java index f52ff6b8..583040bb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTeamItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTeamItem.java @@ -2,12 +2,13 @@ package com.eu.habbo.habbohotel.items.interactions.games; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; -public abstract class InteractionGameTeamItem extends HabboItem { +public abstract class InteractionGameTeamItem extends RoomItem { public final GameTeamColors teamColor; protected InteractionGameTeamItem(ResultSet set, Item baseItem, GameTeamColors teamColor) throws SQLException { @@ -16,8 +17,8 @@ public abstract class InteractionGameTeamItem extends HabboItem { this.teamColor = teamColor; } - protected InteractionGameTeamItem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells); + protected InteractionGameTeamItem(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.teamColor = teamColor; } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java index 161cea9b..a822f2ff 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/InteractionGameTimer.java @@ -8,8 +8,9 @@ import com.eu.habbo.habbohotel.games.wired.WiredGame; 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.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -24,7 +25,7 @@ import java.sql.SQLException; import java.util.Arrays; @Slf4j -public class InteractionGameTimer extends HabboItem implements Runnable { +public class InteractionGameTimer extends RoomItem implements Runnable { private int[] TIMER_INTERVAL_STEPS = new int[] { 30, 60, 120, 180, 300, 600 }; @@ -76,7 +77,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { } if (data.length >= 1) { - this.setExtradata(data[0] + "\t0"); + this.setExtraData(data[0] + "\t0"); } } catch (Exception e) { @@ -85,8 +86,8 @@ public class InteractionGameTimer extends HabboItem implements Runnable { } } - public InteractionGameTimer(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionGameTimer(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); parseCustomParams(item); } @@ -154,7 +155,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { @Override public void run() { - if (this.needsUpdate() || this.needsDelete()) { + if (this.isSqlUpdateNeeded() || this.isSqlDeleteNeeded()) { super.run(); } } @@ -163,8 +164,8 @@ public class InteractionGameTimer extends HabboItem implements Runnable { public void onPickUp(Room room) { this.endGame(room); - this.setExtradata(this.baseTime + "\t" + this.baseTime); - this.needsUpdate(true); + this.setExtraData(this.baseTime + "\t" + this.baseTime); + this.setSqlUpdateNeeded(true); } @Override @@ -175,9 +176,9 @@ public class InteractionGameTimer extends HabboItem implements Runnable { this.timeNow = this.baseTime; - this.setExtradata(this.timeNow + "\t" + this.baseTime); + this.setExtraData(this.timeNow + "\t" + this.baseTime); room.updateItem(this); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); super.onPlace(room); } @@ -202,8 +203,8 @@ public class InteractionGameTimer extends HabboItem implements Runnable { @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - if (this.getExtradata().isEmpty()) { - this.setExtradata("0\t" + this.TIMER_INTERVAL_STEPS[0]); + if (this.getExtraData().isEmpty()) { + this.setExtraData("0\t" + this.TIMER_INTERVAL_STEPS[0]); } // if wired triggered it @@ -232,7 +233,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { Emulator.getThreading().run(new GameTimer(this), 1000); } } else if (client != null) { - if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER))) + if (!(room.getRoomRightsManager().hasRights(client.getHabbo()) || client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER))) return; InteractionGameTimerAction state = InteractionGameTimerAction.START_STOP; @@ -313,16 +314,11 @@ public class InteractionGameTimer extends HabboItem implements Runnable { } this.baseTime = baseTime; - this.setExtradata(this.timeNow + "\t" + this.baseTime); + this.setExtraData(this.timeNow + "\t" + this.baseTime); this.timeNow = this.baseTime; room.updateItem(this); - this.needsUpdate(true); - } - - @Override - public String getDatabaseExtraData() { - return this.getExtradata(); + this.setSqlUpdateNeeded(true); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java index 0882cb0b..b0002330 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiPuck.java @@ -5,9 +5,14 @@ import com.eu.habbo.habbohotel.games.GameTeam; import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionPushable; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +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.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -17,8 +22,8 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { super(set, baseItem); } - public InteractionBattleBanzaiPuck(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionBattleBanzaiPuck(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -27,7 +32,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public RoomUserRotation getWalkOnDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getWalkOnDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } @@ -37,7 +42,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getWalkOffDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } @@ -47,7 +52,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public RoomUserRotation getDragDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getDragDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } @@ -57,7 +62,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public RoomUserRotation getTackleDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getTackleDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } @@ -67,52 +72,52 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public RoomUserRotation getBounceDirection(Room room, RoomUserRotation currentDirection) { + public RoomRotation getBounceDirection(Room room, RoomRotation currentDirection) { switch (currentDirection) { default: case NORTH: - return RoomUserRotation.SOUTH; + return RoomRotation.SOUTH; case NORTH_EAST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_WEST.getValue()))) - return RoomUserRotation.NORTH_WEST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_EAST.getValue()))) - return RoomUserRotation.SOUTH_EAST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_WEST.getValue()))) + return RoomRotation.NORTH_WEST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_EAST.getValue()))) + return RoomRotation.SOUTH_EAST; else - return RoomUserRotation.SOUTH_WEST; + return RoomRotation.SOUTH_WEST; case EAST: - return RoomUserRotation.WEST; + return RoomRotation.WEST; case SOUTH_EAST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_WEST.getValue()))) - return RoomUserRotation.SOUTH_WEST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_EAST.getValue()))) - return RoomUserRotation.NORTH_EAST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_WEST.getValue()))) + return RoomRotation.SOUTH_WEST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_EAST.getValue()))) + return RoomRotation.NORTH_EAST; else - return RoomUserRotation.NORTH_WEST; + return RoomRotation.NORTH_WEST; case SOUTH: - return RoomUserRotation.NORTH; + return RoomRotation.NORTH; case SOUTH_WEST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_EAST.getValue()))) - return RoomUserRotation.SOUTH_EAST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_WEST.getValue()))) - return RoomUserRotation.NORTH_WEST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_EAST.getValue()))) + return RoomRotation.SOUTH_EAST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_WEST.getValue()))) + return RoomRotation.NORTH_WEST; else - return RoomUserRotation.NORTH_EAST; + return RoomRotation.NORTH_EAST; case WEST: - return RoomUserRotation.EAST; + return RoomRotation.EAST; case NORTH_WEST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_EAST.getValue()))) - return RoomUserRotation.NORTH_EAST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_WEST.getValue()))) - return RoomUserRotation.SOUTH_WEST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_EAST.getValue()))) + return RoomRotation.NORTH_EAST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_WEST.getValue()))) + return RoomRotation.SOUTH_WEST; else - return RoomUserRotation.SOUTH_EAST; + return RoomRotation.SOUTH_EAST; } } @@ -123,44 +128,47 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { @Override public boolean validMove(Room room, RoomTile from, RoomTile to) { - if (to == null) return false; - HabboItem topItem = room.getTopItemAt(to.getX(), to.getY(), this); - return !(!room.getLayout().tileWalkable(to.getX(), to.getY()) || (topItem != null && (!topItem.getBaseItem().allowStack() || topItem.getBaseItem().allowSit() || topItem.getBaseItem().allowLay()))); - - //return !(!room.getLayout().tileWalkable(to.x, to.y) || (topItem != null && (!topItem.getBaseItem().setAllowStack() || topItem.getBaseItem().allowSit() || topItem.getBaseItem().allowLay()))); + if (to == null) { + return false; + } + + RoomItem topItem = room.getRoomItemManager().getTopItemAt(to.getX(), to.getY(), this); + + return !(!room.getLayout().tileWalkable(to) || (topItem != null && (!topItem.getBaseItem().allowStack() || topItem.getBaseItem().allowSit() || topItem.getBaseItem().allowLay()))); + //return !(!room.getLayout().tileWalkable(to.x, to.y) || (topItem != null && (!topItem.getBaseItem().setAllowStack() || topItem.getBaseItem().allowSit() || topItem.getBaseItem().allowLay()))); } @Override - public void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction) { + public void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction) { } @Override - public void onKick(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction) { + public void onKick(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction) { } @Override - public void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction) { + public void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction) { } @Override - public void onMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { - Habbo habbo = room.getHabbo(kicker); + public void onMove(Room room, RoomTile from, RoomTile to, RoomRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(kicker); if (habbo != null) { BattleBanzaiGame game = (BattleBanzaiGame) room.getGame(BattleBanzaiGame.class); if (game != null) { GameTeam team = game.getTeamForHabbo(habbo); if (team != null) { - HabboItem item = room.getTopItemAt(to.getX(), to.getY()); + RoomItem item = room.getRoomItemManager().getTopItemAt(to.getX(), to.getY()); try { item.onWalkOn(kicker, room, null); } catch (Exception e) { return; } - this.setExtradata(team.teamColor.type + ""); + this.setExtraData(team.teamColor.type + ""); room.updateItemState(this); } } @@ -169,7 +177,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public void onBounce(Room room, RoomUserRotation oldDirection, RoomUserRotation newDirection, RoomUnit kicker) { + public void onBounce(Room room, RoomRotation oldDirection, RoomRotation newDirection, RoomUnit kicker) { } @@ -179,7 +187,7 @@ public class InteractionBattleBanzaiPuck extends InteractionPushable { } @Override - public boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { + public boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { return to.getState() == RoomTileState.OPEN && to.isWalkable(); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiSphere.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiSphere.java index 77954520..a518ca52 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiSphere.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiSphere.java @@ -2,28 +2,29 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionBattleBanzaiSphere extends HabboItem { +public class InteractionBattleBanzaiSphere extends RoomItem { public InteractionBattleBanzaiSphere(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionBattleBanzaiSphere(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionBattleBanzaiSphere(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java index 5b7580a7..859593de 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTeleporter.java @@ -4,30 +4,31 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.BanzaiRandomTeleport; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionBattleBanzaiTeleporter extends HabboItem { +public class InteractionBattleBanzaiTeleporter extends RoomItem { public InteractionBattleBanzaiTeleporter(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionBattleBanzaiTeleporter(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionBattleBanzaiTeleporter(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -57,13 +58,13 @@ public class InteractionBattleBanzaiTeleporter extends HabboItem { super.onWalkOn(roomUnit, room, objects); if(objects.length < 3) { - HabboItem target = room.getRoomSpecialTypes().getRandomTeleporter(null, this); + RoomItem target = room.getRoomSpecialTypes().getRandomTeleporter(null, this); if (target == null) return; - this.setExtradata("1"); + this.setExtraData("1"); room.updateItemState(this); roomUnit.removeStatus(RoomUnitStatus.MOVE); - roomUnit.setGoalLocation(roomUnit.getCurrentLocation()); + roomUnit.walkTo(roomUnit.getCurrentPosition()); roomUnit.setCanWalk(false); Emulator.getThreading().run(new BanzaiRandomTeleport(this, target, roomUnit, room), 500); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTile.java index d2583d9e..b336d2aa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/InteractionBattleBanzaiTile.java @@ -5,9 +5,10 @@ import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import org.apache.commons.math3.util.Pair; @@ -16,21 +17,21 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -public class InteractionBattleBanzaiTile extends HabboItem { +public class InteractionBattleBanzaiTile extends RoomItem { public InteractionBattleBanzaiTile(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionBattleBanzaiTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionBattleBanzaiTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -54,15 +55,15 @@ public class InteractionBattleBanzaiTile extends HabboItem { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - if (this.getExtradata().isEmpty()) - this.setExtradata("0"); + if (this.getExtraData().isEmpty()) + this.setExtraData("0"); - int state = Integer.parseInt(this.getExtradata()); + int state = Integer.parseInt(this.getExtraData()); if (state % 3 == 2) return; - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo == null) return; @@ -85,26 +86,26 @@ public class InteractionBattleBanzaiTile extends HabboItem { } public boolean isLocked() { - if (this.getExtradata().isEmpty()) + if (this.getExtraData().isEmpty()) return false; - return Integer.parseInt(this.getExtradata()) % 3 == 2; + return Integer.parseInt(this.getExtraData()) % 3 == 2; } @Override - public boolean canStackAt(Room room, List>> itemsAtLocation) { - for (Pair> set : itemsAtLocation) { + public boolean canStackAt(List>> itemsAtLocation) { + for (Pair> set : itemsAtLocation) { if (set.getValue() != null && !set.getValue().isEmpty()) return false; } - return super.canStackAt(room, itemsAtLocation); + return super.canStackAt(itemsAtLocation); } @Override public void onPickUp(Room room) { super.onPickUp(room); - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); } @@ -115,7 +116,7 @@ public class InteractionBattleBanzaiTile extends HabboItem { BattleBanzaiGame game = (BattleBanzaiGame) room.getGame(BattleBanzaiGame.class); if (game != null && game.getState() != GameState.IDLE) { - this.setExtradata("1"); + this.setExtraData("1"); } } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java index cbc343df..04c1b7d9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGate.java @@ -9,7 +9,8 @@ import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -19,8 +20,8 @@ public class InteractionBattleBanzaiGate extends InteractionGameGate { super(set, baseItem, teamColor); } - public InteractionBattleBanzaiGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + public InteractionBattleBanzaiGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); } @Override @@ -35,7 +36,7 @@ public class InteractionBattleBanzaiGate extends InteractionGameGate { @Override public boolean isWalkable() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room == null) return false; @@ -54,12 +55,12 @@ public class InteractionBattleBanzaiGate extends InteractionGameGate { room.addGame(game); } - GameTeam team = game.getTeamForHabbo(room.getHabbo(roomUnit)); + GameTeam team = game.getTeamForHabbo(room.getRoomUnitManager().getHabboByRoomUnit(roomUnit)); if (team != null) { - game.removeHabbo(room.getHabbo(roomUnit)); + game.removeHabbo(room.getRoomUnitManager().getHabboByRoomUnit(roomUnit)); } else { - game.addHabbo(room.getHabbo(roomUnit), this.teamColor); + game.addHabbo(room.getRoomUnitManager().getHabboByRoomUnit(roomUnit), this.teamColor); } updateState(game, 5); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateBlue.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateBlue.java index 206bd98b..6596d2e0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateBlue.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateBlue.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiGateBlue extends InteractionBattleBanzaiGate super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiGateBlue(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiGateBlue(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateGreen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateGreen.java index ee488fba..54052d44 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateGreen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateGreen.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiGateGreen extends InteractionBattleBanzaiGat super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiGateGreen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiGateGreen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateRed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateRed.java index ceeca701..6b6f1c24 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateRed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateRed.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiGateRed extends InteractionBattleBanzaiGate super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiGateRed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiGateRed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateYellow.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateYellow.java index ec6609e4..770a1fe8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateYellow.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/gates/InteractionBattleBanzaiGateYellow.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiGateYellow extends InteractionBattleBanzaiGa super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiGateYellow(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiGateYellow(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboard.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboard.java index f34584b4..2198418b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboard.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboard.java @@ -4,7 +4,8 @@ import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,8 +15,8 @@ public class InteractionBattleBanzaiScoreboard extends InteractionGameScoreboard super(set, baseItem, teamColor); } - public InteractionBattleBanzaiScoreboard(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + public InteractionBattleBanzaiScoreboard(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardBlue.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardBlue.java index a5452738..af47fe4e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardBlue.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardBlue.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.scoreboard import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiScoreboardBlue extends InteractionBattleBanz super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiScoreboardBlue(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiScoreboardBlue(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardGreen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardGreen.java index a42332f9..1f57ffac 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardGreen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardGreen.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.scoreboard import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiScoreboardGreen extends InteractionBattleBan super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiScoreboardGreen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiScoreboardGreen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardRed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardRed.java index 9abf0aad..431c6290 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardRed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardRed.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.scoreboard import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiScoreboardRed extends InteractionBattleBanza super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiScoreboardRed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiScoreboardRed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardYellow.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardYellow.java index 6b4b8950..36d80166 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardYellow.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/battlebanzai/scoreboards/InteractionBattleBanzaiScoreboardYellow.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.scoreboard import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionBattleBanzaiScoreboardYellow extends InteractionBattleBa super(set, baseItem, TEAM_COLOR); } - public InteractionBattleBanzaiScoreboardYellow(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionBattleBanzaiScoreboardYellow(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java index 09a45a03..bb205a17 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootball.java @@ -6,8 +6,13 @@ import com.eu.habbo.habbohotel.games.football.FootballGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionPushable; import com.eu.habbo.habbohotel.items.interactions.games.football.goals.InteractionFootballGoal; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +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.users.HabboInfo; import com.eu.habbo.messages.outgoing.rooms.items.OneWayDoorStatusMessageComposer; import com.eu.habbo.util.pathfinding.Rotation; @@ -22,17 +27,17 @@ public class InteractionFootball extends InteractionPushable { super(set, baseItem); } - public InteractionFootball(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionFootball(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public int getWalkOnVelocity(RoomUnit roomUnit, Room room) { - if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 2 && this.getExtradata().equals("1")) + if (roomUnit.getPath().isEmpty() && roomUnit.getTilesMoved() == 2 && this.getExtraData().equals("1")) return 0; - if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 1) + if (roomUnit.getPath().isEmpty() && roomUnit.getTilesMoved() == 1) return 6; return 1; @@ -40,7 +45,7 @@ public class InteractionFootball extends InteractionPushable { @Override public int getWalkOffVelocity(RoomUnit roomUnit, Room room) { - if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 0) + if (roomUnit.getPath().isEmpty() && roomUnit.getTilesMoved() == 0) return 6; return 1; @@ -48,7 +53,7 @@ public class InteractionFootball extends InteractionPushable { @Override public int getDragVelocity(RoomUnit roomUnit, Room room) { - if (roomUnit.getPath().isEmpty() && roomUnit.tilesWalked() == 2) + if (roomUnit.getPath().isEmpty() && roomUnit.getTilesMoved() == 2) return 0; return 1; @@ -61,22 +66,27 @@ public class InteractionFootball extends InteractionPushable { @Override - public RoomUserRotation getWalkOnDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getWalkOnDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } @Override - public RoomUserRotation getWalkOffDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getWalkOffDirection(RoomUnit roomUnit, Room room) { RoomTile peek = roomUnit.getPath().peek(); - RoomTile nextWalkTile = peek != null ? room.getLayout().getTile(peek.getX(), peek.getY()) : roomUnit.getGoalLocation(); - return RoomUserRotation.values()[(RoomUserRotation.values().length + Rotation.Calculate(roomUnit.getX(), roomUnit.getY(), nextWalkTile.getX(), nextWalkTile.getY()) + 4) % 8]; + RoomTile nextWalkTile; + if (peek != null) { + nextWalkTile = room.getLayout().getTile(peek.getX(), peek.getY()); + } else { + nextWalkTile = roomUnit.getTargetPosition(); + } + return RoomRotation.values()[(RoomRotation.values().length + Rotation.Calculate(roomUnit.getCurrentPosition().getX(), roomUnit.getCurrentPosition().getY(), nextWalkTile.getX(), nextWalkTile.getY()) + 4) % 8]; } - public RoomUserRotation getDragDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getDragDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } - public RoomUserRotation getTackleDirection(RoomUnit roomUnit, Room room) { + public RoomRotation getTackleDirection(RoomUnit roomUnit, Room room) { return roomUnit.getBodyRotation(); } @@ -92,52 +102,52 @@ public class InteractionFootball extends InteractionPushable { } @Override - public RoomUserRotation getBounceDirection(Room room, RoomUserRotation currentDirection) { + public RoomRotation getBounceDirection(Room room, RoomRotation currentDirection) { switch (currentDirection) { default: case NORTH: - return RoomUserRotation.SOUTH; + return RoomRotation.SOUTH; case NORTH_EAST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_WEST.getValue()))) - return RoomUserRotation.NORTH_WEST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_EAST.getValue()))) - return RoomUserRotation.SOUTH_EAST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_WEST.getValue()))) + return RoomRotation.NORTH_WEST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_EAST.getValue()))) + return RoomRotation.SOUTH_EAST; else - return RoomUserRotation.SOUTH_WEST; + return RoomRotation.SOUTH_WEST; case EAST: - return RoomUserRotation.WEST; + return RoomRotation.WEST; case SOUTH_EAST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_WEST.getValue()))) - return RoomUserRotation.SOUTH_WEST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_EAST.getValue()))) - return RoomUserRotation.NORTH_EAST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_WEST.getValue()))) + return RoomRotation.SOUTH_WEST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_EAST.getValue()))) + return RoomRotation.NORTH_EAST; else - return RoomUserRotation.NORTH_WEST; + return RoomRotation.NORTH_WEST; case SOUTH: - return RoomUserRotation.NORTH; + return RoomRotation.NORTH; case SOUTH_WEST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_EAST.getValue()))) - return RoomUserRotation.SOUTH_EAST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_WEST.getValue()))) - return RoomUserRotation.NORTH_WEST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_EAST.getValue()))) + return RoomRotation.SOUTH_EAST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_WEST.getValue()))) + return RoomRotation.NORTH_WEST; else - return RoomUserRotation.NORTH_EAST; + return RoomRotation.NORTH_EAST; case WEST: - return RoomUserRotation.EAST; + return RoomRotation.EAST; case NORTH_WEST: - if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH_EAST.getValue()))) - return RoomUserRotation.NORTH_EAST; - else if (this.validMove(room, room.getLayout().getTile(this.getX(), this.getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH_WEST.getValue()))) - return RoomUserRotation.SOUTH_WEST; + if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.NORTH_EAST.getValue()))) + return RoomRotation.NORTH_EAST; + else if (this.validMove(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), room.getLayout().getTileInFront(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), RoomRotation.SOUTH_WEST.getValue()))) + return RoomRotation.SOUTH_WEST; else - return RoomUserRotation.SOUTH_EAST; + return RoomRotation.SOUTH_EAST; } } @@ -145,7 +155,7 @@ public class InteractionFootball extends InteractionPushable { @Override public boolean validMove(Room room, RoomTile from, RoomTile to) { if (to == null || to.getState() == RoomTileState.INVALID) return false; - HabboItem topItem = room.getTopItemAt(to.getX(), to.getY(), this); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(to.getX(), to.getY(), this); // Move is valid if there isnt any furni yet if (topItem == null) { @@ -153,13 +163,13 @@ public class InteractionFootball extends InteractionPushable { } // If any furni on tile is not stackable, move is invalid (tested on 22-03-2022) - if (room.getItemsAt(to).stream().anyMatch(x -> !x.getBaseItem().allowStack())) { + if (room.getRoomItemManager().getItemsAt(to).stream().anyMatch(x -> !x.getBaseItem().allowStack())) { return false; } // Ball can only go up by 1.65 according to Habbo (tested using stack tile on 22-03-2022) - BigDecimal topItemHeight = BigDecimal.valueOf(topItem.getZ() + topItem.getBaseItem().getHeight()); - BigDecimal ballHeight = BigDecimal.valueOf(this.getZ()); + BigDecimal topItemHeight = BigDecimal.valueOf(topItem.getCurrentZ() + topItem.getBaseItem().getHeight()); + BigDecimal ballHeight = BigDecimal.valueOf(this.getCurrentZ()); if (topItemHeight.subtract(ballHeight).compareTo(BigDecimal.valueOf(1.65)) > 0) { return false; @@ -186,22 +196,22 @@ public class InteractionFootball extends InteractionPushable { //Events @Override - public void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction) { + public void onDrag(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction) { } @Override - public void onKick(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction) { + public void onKick(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction) { } @Override - public void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomUserRotation direction) { + public void onTackle(Room room, RoomUnit roomUnit, int velocity, RoomRotation direction) { } @Override - public void onMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { + public void onMove(Room room, RoomTile from, RoomTile to, RoomRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { FootballGame game = (FootballGame) room.getGame(FootballGame.class); if (game == null) { try { @@ -211,37 +221,37 @@ public class InteractionFootball extends InteractionPushable { return; } } - HabboItem currentTopItem = room.getTopItemAt(from.getX(), from.getY(), this); - HabboItem topItem = room.getTopItemAt(to.getX(), to.getY(), this); + RoomItem currentTopItem = room.getRoomItemManager().getTopItemAt(from.getX(), from.getY(), this); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(to.getX(), to.getY(), this); if ((topItem != null) && ((currentTopItem == null) || (currentTopItem.getId() != topItem.getId())) && topItem instanceof InteractionFootballGoal interactionFootballGoal) { GameTeamColors color = interactionFootballGoal.teamColor; game.onScore(kicker, color); } - this.setExtradata(Math.abs(currentStep - (totalSteps + 1)) + ""); + this.setExtraData(Math.abs(currentStep - (totalSteps + 1)) + ""); room.sendComposer(new OneWayDoorStatusMessageComposer(this).compose()); } @Override - public void onBounce(Room room, RoomUserRotation oldDirection, RoomUserRotation newDirection, RoomUnit kicker) { + public void onBounce(Room room, RoomRotation oldDirection, RoomRotation newDirection, RoomUnit kicker) { } @Override public void onStop(Room room, RoomUnit kicker, int currentStep, int totalSteps) { - this.setExtradata("0"); + this.setExtraData("0"); room.sendComposer(new OneWayDoorStatusMessageComposer(this).compose()); } @Override - public boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomUserRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { - HabboItem topItem = room.getTopItemAt(from.getX(), from.getY(), this); - return !((Emulator.getRandom().nextInt(10) >= 3 && room.hasHabbosAt(to.getX(), to.getY())) || (topItem != null && topItem.getBaseItem().getName().startsWith("fball_goal_") && currentStep != 1)); + public boolean canStillMove(Room room, RoomTile from, RoomTile to, RoomRotation direction, RoomUnit kicker, int nextRoll, int currentStep, int totalSteps) { + RoomItem topItem = room.getRoomItemManager().getTopItemAt(from.getX(), from.getY(), this); + return !((Emulator.getRandom().nextInt(10) >= 3 && room.getRoomUnitManager().hasHabbosAt(to)) || (topItem != null && topItem.getBaseItem().getName().startsWith("fball_goal_") && currentStep != 1)); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java index 50a232ec..c1b6bf32 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/InteractionFootballGate.java @@ -3,10 +3,11 @@ package com.eu.habbo.habbohotel.items.interactions.games.football; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.users.clothingvalidation.ClothingValidationManager; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.users.UserChangeMessageComposer; @@ -20,7 +21,7 @@ import com.eu.habbo.util.figure.FigureUtil; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionFootballGate extends HabboItem { +public class InteractionFootballGate extends RoomItem { private static final String CACHE_KEY = "fball_gate_look"; private String figureM; private String figureF; @@ -33,8 +34,8 @@ public class InteractionFootballGate extends HabboItem { this.figureF = bits.length > 1 ? bits[1] : ""; } - public InteractionFootballGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionFootballGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); String[] bits = extradata.split(";"); this.figureM = bits.length > 0 ? bits[0] : ""; @@ -67,8 +68,8 @@ public class InteractionFootballGate extends HabboItem { habbo.getHabboInfo().setLook((String) habbo.getHabboStats().getCache().get(CACHE_KEY)); habbo.getHabboStats().getCache().remove(CACHE_KEY); habbo.getClient().sendResponse(new FigureUpdateComposer(habbo)); - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); } } } @@ -76,16 +77,16 @@ public class InteractionFootballGate extends HabboItem { public void setFigureM(String look) { this.figureM = look; - this.setExtradata(this.figureM + ";" + this.figureF); - this.needsUpdate(true); + this.setExtraData(this.figureM + ";" + this.figureF); + this.setSqlUpdateNeeded(true); Emulator.getThreading().run(this); } public void setFigureF(String look) { this.figureF = look; - this.setExtradata(this.figureM + ";" + this.figureF); - this.needsUpdate(true); + this.setExtraData(this.figureM + ";" + this.figureF); + this.setSqlUpdateNeeded(true); Emulator.getThreading().run(this); } @@ -113,7 +114,7 @@ public class InteractionFootballGate extends HabboItem { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { if (habbo.getHabboStats().getCache().containsKey(CACHE_KEY)) { String oldlook = (String) habbo.getHabboStats().getCache().get(CACHE_KEY); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java index 443bb720..a87c770c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoal.java @@ -4,7 +4,8 @@ import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTeamItem; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; @@ -15,8 +16,8 @@ public class InteractionFootballGoal extends InteractionGameTeamItem { super(set, baseItem, teamColor); } - public InteractionFootballGoal(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + public InteractionFootballGoal(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); } @Override @@ -37,7 +38,7 @@ public class InteractionFootballGoal extends InteractionGameTeamItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalBlue.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalBlue.java index 34d2b52f..1e600210 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalBlue.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalBlue.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.goals; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballGoalBlue extends InteractionFootballGoal { super(set, baseItem, GameTeamColors.BLUE); } - public InteractionFootballGoalBlue(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.BLUE); + public InteractionFootballGoalBlue(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.BLUE); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalGreen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalGreen.java index 42276c9e..da40f7be 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalGreen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalGreen.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.goals; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballGoalGreen extends InteractionFootballGoal { super(set, baseItem, GameTeamColors.GREEN); } - public InteractionFootballGoalGreen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.GREEN); + public InteractionFootballGoalGreen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.GREEN); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalRed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalRed.java index b4d9b5d4..945a0227 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalRed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalRed.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.goals; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballGoalRed extends InteractionFootballGoal { super(set, baseItem, GameTeamColors.RED); } - public InteractionFootballGoalRed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.RED); + public InteractionFootballGoalRed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.RED); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalYellow.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalYellow.java index ba725033..252cc98a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalYellow.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/goals/InteractionFootballGoalYellow.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.goals; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballGoalYellow extends InteractionFootballGoal { super(set, baseItem, GameTeamColors.YELLOW); } - public InteractionFootballGoalYellow(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.YELLOW); + public InteractionFootballGoalYellow(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.YELLOW); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboard.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboard.java index dba5f039..16338413 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboard.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboard.java @@ -6,7 +6,8 @@ import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import java.sql.ResultSet; @@ -20,14 +21,14 @@ public class InteractionFootballScoreboard extends InteractionGameScoreboard { super(set, baseItem, teamColor); try { - this.score = Integer.parseInt(this.getExtradata()); + this.score = Integer.parseInt(this.getExtraData()); } catch (Exception e) { this.score = 0; } } - public InteractionFootballScoreboard(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + public InteractionFootballScoreboard(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); try { this.score = Integer.parseInt(extradata); @@ -58,10 +59,10 @@ public class InteractionFootballScoreboard extends InteractionGameScoreboard { this.score = 99; } - this.setExtradata(this.score + ""); - this.needsUpdate(true); + this.setExtraData(this.score + ""); + this.setSqlUpdateNeeded(true); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room != null) { room.updateItem(this); } @@ -84,10 +85,10 @@ public class InteractionFootballScoreboard extends InteractionGameScoreboard { this.score = 99; } - this.setExtradata(this.score + ""); - this.needsUpdate(true); + this.setExtraData(this.score + ""); + this.setSqlUpdateNeeded(true); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room != null) { room.updateItem(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardBlue.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardBlue.java index 1a4cd219..912e0f22 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardBlue.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardBlue.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballScoreboardBlue extends InteractionFootballScoreb super(set, baseItem, GameTeamColors.BLUE); } - public InteractionFootballScoreboardBlue(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.BLUE); + public InteractionFootballScoreboardBlue(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.BLUE); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardGreen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardGreen.java index 1f785c0c..f9522567 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardGreen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardGreen.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballScoreboardGreen extends InteractionFootballScore super(set, baseItem, GameTeamColors.GREEN); } - public InteractionFootballScoreboardGreen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.GREEN); + public InteractionFootballScoreboardGreen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.GREEN); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardRed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardRed.java index 6d65b7ea..bf40c6a0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardRed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardRed.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballScoreboardRed extends InteractionFootballScorebo super(set, baseItem, GameTeamColors.RED); } - public InteractionFootballScoreboardRed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.RED); + public InteractionFootballScoreboardRed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.RED); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardYellow.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardYellow.java index 731a9e82..93d4498b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardYellow.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/football/scoreboards/InteractionFootballScoreboardYellow.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.football.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionFootballScoreboardYellow extends InteractionFootballScor super(set, baseItem, GameTeamColors.YELLOW); } - public InteractionFootballScoreboardYellow(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, GameTeamColors.YELLOW); + public InteractionFootballScoreboardYellow(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, GameTeamColors.YELLOW); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java index 673e6e83..2df02776 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeBlock.java @@ -8,24 +8,26 @@ import com.eu.habbo.habbohotel.games.freeze.FreezeGame; import com.eu.habbo.habbohotel.games.freeze.FreezeGamePlayer; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionFreezeBlock extends HabboItem { +public class InteractionFreezeBlock extends RoomItem { public InteractionFreezeBlock(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionFreezeBlock(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionFreezeBlock(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -33,12 +35,13 @@ public class InteractionFreezeBlock extends HabboItem { if (client == null) return; - HabboItem item = null; - THashSet items = room.getItemsAt(room.getLayout().getTile(this.getX(), this.getY())); + RoomItem item = null; + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + THashSet items = room.getRoomItemManager().getItemsAt(tile); - for (HabboItem i : items) { + for (RoomItem i : items) { if (i instanceof InteractionFreezeTile) { - if (item == null || i.getZ() <= item.getZ()) { + if (item == null || i.getCurrentZ() <= item.getCurrentZ()) { item = i; } } @@ -56,11 +59,11 @@ public class InteractionFreezeBlock extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { - if (this.getExtradata().length() == 0) { - this.setExtradata("0"); + if (this.getExtraData().length() == 0) { + this.setExtraData("0"); } serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -72,7 +75,7 @@ public class InteractionFreezeBlock extends HabboItem { @Override public boolean isWalkable() { - return !this.getExtradata().isEmpty() && !this.getExtradata().equals("0"); + return !this.getExtraData().isEmpty() && !this.getExtraData().equals("0"); } @Override @@ -84,14 +87,14 @@ public class InteractionFreezeBlock extends HabboItem { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - if (this.getExtradata().isEmpty() || this.getExtradata().equalsIgnoreCase("0")) + if (this.getExtraData().isEmpty() || this.getExtraData().equalsIgnoreCase("0")) return; FreezeGame game = (FreezeGame) room.getGame(FreezeGame.class); if (game == null || !game.state.equals(GameState.RUNNING)) return; - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo == null || habbo.getHabboInfo().getCurrentGame() != FreezeGame.class) return; @@ -103,7 +106,7 @@ public class InteractionFreezeBlock extends HabboItem { int powerUp; try { - powerUp = Integer.parseInt(this.getExtradata()) / 1000; + powerUp = Integer.parseInt(this.getExtraData()) / 1000; } catch (NumberFormatException e) { powerUp = 0; } @@ -112,7 +115,7 @@ public class InteractionFreezeBlock extends HabboItem { if (powerUp == 6 && !player.canPickupLife()) return; - this.setExtradata((powerUp + 10) * 1000 + ""); + this.setExtraData((powerUp + 10) * 1000 + ""); room.updateItem(this); @@ -124,6 +127,6 @@ public class InteractionFreezeBlock extends HabboItem { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeExitTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeExitTile.java index de76eeef..62652f27 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeExitTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeExitTile.java @@ -2,27 +2,28 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionFreezeExitTile extends HabboItem { +public class InteractionFreezeExitTile extends RoomItem { public InteractionFreezeExitTile(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionFreezeExitTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionFreezeExitTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } @Override @@ -43,7 +44,7 @@ public class InteractionFreezeExitTile extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeTile.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeTile.java index d46b3c82..1df899dd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/InteractionFreezeTile.java @@ -5,8 +5,9 @@ import com.eu.habbo.habbohotel.games.freeze.FreezeGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import org.apache.commons.math3.util.Pair; @@ -15,15 +16,15 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -public class InteractionFreezeTile extends HabboItem { +public class InteractionFreezeTile extends RoomItem { public InteractionFreezeTile(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionFreezeTile(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionFreezeTile(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -41,7 +42,7 @@ public class InteractionFreezeTile extends HabboItem { if (client == null) return; - if (client.getHabbo().getRoomUnit().getCurrentLocation().getX() == this.getX() && client.getHabbo().getRoomUnit().getCurrentLocation().getY() == this.getY()) { + if (client.getHabbo().getRoomUnit().getCurrentPosition().getX() == this.getCurrentPosition().getX() && client.getHabbo().getRoomUnit().getCurrentPosition().getY() == this.getCurrentPosition().getY()) { FreezeGame game = (FreezeGame) room.getGame(FreezeGame.class); if (game != null) @@ -57,14 +58,14 @@ public class InteractionFreezeTile extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } @Override @@ -74,11 +75,11 @@ public class InteractionFreezeTile extends HabboItem { @Override - public boolean canStackAt(Room room, List>> itemsAtLocation) { - for (Pair> set : itemsAtLocation) { + public boolean canStackAt(List>> itemsAtLocation) { + for (Pair> set : itemsAtLocation) { if (set.getValue() != null && !set.getValue().isEmpty()) return false; } - return super.canStackAt(room, itemsAtLocation); + return super.canStackAt(itemsAtLocation); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java index e135e7d1..1bf54566 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGate.java @@ -9,7 +9,8 @@ import com.eu.habbo.habbohotel.games.freeze.FreezeGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -19,8 +20,8 @@ public class InteractionFreezeGate extends InteractionGameGate { super(set, baseItem, teamColor); } - public InteractionFreezeGate(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + public InteractionFreezeGate(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); } @Override @@ -34,7 +35,7 @@ public class InteractionFreezeGate extends InteractionGameGate { @Override public boolean isWalkable() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room == null) return false; @@ -52,12 +53,12 @@ public class InteractionFreezeGate extends InteractionGameGate { room.addGame(game); } - GameTeam team = game.getTeamForHabbo(room.getHabbo(roomUnit)); + GameTeam team = game.getTeamForHabbo(room.getRoomUnitManager().getHabboByRoomUnit(roomUnit)); if (team != null) { - game.removeHabbo(room.getHabbo(roomUnit)); + game.removeHabbo(room.getRoomUnitManager().getHabboByRoomUnit(roomUnit)); } else { - game.addHabbo(room.getHabbo(roomUnit), this.teamColor); + game.addHabbo(room.getRoomUnitManager().getHabboByRoomUnit(roomUnit), this.teamColor); } updateState(game, 5); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateBlue.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateBlue.java index 90040250..22d10c07 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateBlue.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateBlue.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeGateBlue extends InteractionFreezeGate { super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeGateBlue(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeGateBlue(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateGreen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateGreen.java index dd62a2eb..f99c02ff 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateGreen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateGreen.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeGateGreen extends InteractionFreezeGate { super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeGateGreen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeGateGreen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateRed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateRed.java index 7f502050..0d28f833 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateRed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateRed.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeGateRed extends InteractionFreezeGate { super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeGateRed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeGateRed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateYellow.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateYellow.java index 418ce0ed..8b5c3add 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateYellow.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/gates/InteractionFreezeGateYellow.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.gates; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeGateYellow extends InteractionFreezeGate { super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeGateYellow(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeGateYellow(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboard.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboard.java index 5f8d510d..d90ca07c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboard.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboard.java @@ -4,7 +4,8 @@ import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,8 +15,8 @@ public class InteractionFreezeScoreboard extends InteractionGameScoreboard { super(set, baseItem, teamColor); } - InteractionFreezeScoreboard(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { - super(id, userId, item, extradata, limitedStack, limitedSells, teamColor); + InteractionFreezeScoreboard(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, GameTeamColors teamColor) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, teamColor); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardBlue.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardBlue.java index 9c005626..b9fda992 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardBlue.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardBlue.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeScoreboardBlue extends InteractionFreezeScoreboard super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeScoreboardBlue(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeScoreboardBlue(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardGreen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardGreen.java index 3ce66539..9aa9ebca 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardGreen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardGreen.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeScoreboardGreen extends InteractionFreezeScoreboar super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeScoreboardGreen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeScoreboardGreen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardRed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardRed.java index 9846fa55..719299bd 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardRed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardRed.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeScoreboardRed extends InteractionFreezeScoreboard super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeScoreboardRed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeScoreboardRed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardYellow.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardYellow.java index 1c9d94e0..59b2d384 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardYellow.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/freeze/scoreboards/InteractionFreezeScoreboardYellow.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.freeze.scoreboards; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +14,7 @@ public class InteractionFreezeScoreboardYellow extends InteractionFreezeScoreboa super(set, baseItem, TEAM_COLOR); } - public InteractionFreezeScoreboardYellow(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, TEAM_COLOR); + public InteractionFreezeScoreboardYellow(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, TEAM_COLOR); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagField.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagField.java index 53c8dd7b..dce84c97 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagField.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagField.java @@ -4,15 +4,16 @@ import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.tag.TagGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public abstract class InteractionTagField extends HabboItem { +public abstract class InteractionTagField extends RoomItem { public Class gameClazz; public InteractionTagField(ResultSet set, Item baseItem, Class gameClazz) throws SQLException { @@ -21,15 +22,15 @@ public abstract class InteractionTagField extends HabboItem { this.gameClazz = gameClazz; } - public InteractionTagField(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells, Class gameClazz) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTagField(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells, Class gameClazz) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.gameClazz = gameClazz; } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { return habbo.getHabboInfo().getCurrentGame() == null || habbo.getHabboInfo().getCurrentGame() == this.gameClazz; @@ -50,7 +51,7 @@ public abstract class InteractionTagField extends HabboItem { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { if (habbo.getHabboInfo().getCurrentGame() == null) { @@ -75,7 +76,7 @@ public abstract class InteractionTagField extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagPole.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagPole.java index d9aa71c6..e07f0388 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagPole.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/InteractionTagPole.java @@ -2,20 +2,21 @@ package com.eu.habbo.habbohotel.items.interactions.games.tag; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionTagPole extends HabboItem { +public class InteractionTagPole extends RoomItem { public InteractionTagPole(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionTagPole(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTagPole(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -36,13 +37,13 @@ public class InteractionTagPole extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunField.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunField.java index df20b8d3..bd902eb8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunField.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunField.java @@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -16,15 +17,15 @@ public class InteractionBunnyrunField extends InteractionTagField { super(set, baseItem, BunnyrunGame.class); } - public InteractionBunnyrunField(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, BunnyrunGame.class); + public InteractionBunnyrunField(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, BunnyrunGame.class); } @Override public void onPlace(Room room) { super.onPlace(room); - Habbo itemOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId()); + Habbo itemOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getOwnerInfo().getId()); if (itemOwner != null) { AchievementManager.progressAchievement(itemOwner, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RbBunnyTag")); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunPole.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunPole.java index 9c0ae732..1573f4e5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunPole.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/bunnyrun/InteractionBunnyrunPole.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.tag.bunnyrun; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionBunnyrunPole extends InteractionTagPole { super(set, baseItem); } - public InteractionBunnyrunPole(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionBunnyrunPole(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagField.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagField.java index 75d25b2b..34901520 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagField.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagField.java @@ -6,8 +6,9 @@ import com.eu.habbo.habbohotel.games.tag.IceTagGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -20,15 +21,15 @@ public class InteractionIceTagField extends InteractionTagField { super(set, baseItem, IceTagGame.class); } - public InteractionIceTagField(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, IceTagGame.class); + public InteractionIceTagField(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, IceTagGame.class); } @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) this.stepTimes.put(habbo, Emulator.getIntUnixTimestamp()); } @@ -37,7 +38,7 @@ public class InteractionIceTagField extends InteractionTagField { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null && this.stepTimes.containsKey(habbo)) { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("TagC"), (Emulator.getIntUnixTimestamp() - this.stepTimes.get(habbo)) / 60); this.stepTimes.remove(habbo); @@ -48,7 +49,7 @@ public class InteractionIceTagField extends InteractionTagField { public void onPlace(Room room) { super.onPlace(room); - Habbo itemOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId()); + Habbo itemOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getOwnerInfo().getId()); if (itemOwner != null) { AchievementManager.progressAchievement(itemOwner, Emulator.getGameEnvironment().getAchievementManager().getAchievement("TagA")); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagPole.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagPole.java index b2fe44c0..78a1c4f9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagPole.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/icetag/InteractionIceTagPole.java @@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.items.interactions.games.tag.icetag; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -11,7 +12,7 @@ public class InteractionIceTagPole extends InteractionTagPole { super(set, baseItem); } - public InteractionIceTagPole(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionIceTagPole(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/rollerskate/InteractionRollerskateField.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/rollerskate/InteractionRollerskateField.java index c25374c9..0511e567 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/rollerskate/InteractionRollerskateField.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/games/tag/rollerskate/InteractionRollerskateField.java @@ -6,8 +6,9 @@ import com.eu.habbo.habbohotel.games.tag.RollerskateGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -20,15 +21,15 @@ public class InteractionRollerskateField extends InteractionTagField { super(set, baseItem, RollerskateGame.class); } - public InteractionRollerskateField(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells, RollerskateGame.class); + public InteractionRollerskateField(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells, RollerskateGame.class); } @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) this.stepTimes.put(habbo, Emulator.getIntUnixTimestamp()); } @@ -37,7 +38,7 @@ public class InteractionRollerskateField extends InteractionTagField { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null && this.stepTimes.containsKey(habbo)) { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RbTagC"), (Emulator.getIntUnixTimestamp() - this.stepTimes.get(habbo)) / 60); this.stepTimes.remove(habbo); @@ -48,7 +49,7 @@ public class InteractionRollerskateField extends InteractionTagField { public void onPlace(Room room) { super.onPlace(room); - Habbo itemOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getUserId()); + Habbo itemOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.getOwnerInfo().getId()); if (itemOwner != null) { AchievementManager.progressAchievement(itemOwner, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RbTagA")); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java index 58eea046..6672f7ee 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/interfaces/ConditionalGate.java @@ -1,7 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions.interfaces; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; public interface ConditionalGate { void onRejected(RoomUnit roomUnit, Room room, Object[] objects); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionMonsterPlantSeed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionMonsterPlantSeed.java index b92511cd..40d0f0b0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionMonsterPlantSeed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionMonsterPlantSeed.java @@ -4,29 +4,30 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionMonsterPlantSeed extends HabboItem { +public class InteractionMonsterPlantSeed extends RoomItem { public InteractionMonsterPlantSeed(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - if (this.getExtradata().isEmpty()) { - this.setExtradata("" + randomRarityLevel()); - this.needsUpdate(true); + if (this.getExtraData().isEmpty()) { + this.setExtraData("" + randomRarityLevel()); + this.setSqlUpdateNeeded(true); } } - public InteractionMonsterPlantSeed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionMonsterPlantSeed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); - if (this.getExtradata().isEmpty()) { - this.setExtradata("" + randomRarityLevel()); - this.needsUpdate(true); + if (this.getExtraData().isEmpty()) { + this.setExtraData("" + randomRarityLevel()); + this.setSqlUpdateNeeded(true); } } @@ -78,7 +79,7 @@ public class InteractionMonsterPlantSeed extends HabboItem { serverMessage.appendInt(1 + (this.isLimited() ? 256 : 0)); serverMessage.appendInt(1); serverMessage.appendString("rarity"); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionNest.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionNest.java index 9cd0adf5..d4fea6d8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionNest.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionNest.java @@ -6,28 +6,29 @@ import com.eu.habbo.habbohotel.pets.Pet; 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.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionNest extends HabboItem { +public class InteractionNest extends RoomItem { public InteractionNest(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public InteractionNest(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionNest(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -56,7 +57,7 @@ public class InteractionNest extends HabboItem { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet == null) return; @@ -71,10 +72,10 @@ public class InteractionNest extends HabboItem { return; pet.setTask(PetTasks.NEST); - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().walkTo(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); + pet.getRoomUnit().clearStatuses(); pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE); - pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, room.getStackHeight(this.getX(), this.getY(), false) + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.LAY, room.getStackHeight(this.getCurrentPosition().getX(), this.getCurrentPosition().getY(), false) + ""); room.sendComposer(new UserUpdateComposer(roomUnit).compose()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java index 87eabfe3..68d56385 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetBreedingNest.java @@ -7,9 +7,10 @@ import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetManager; import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.pets.PerkAllowancesComposer; import com.eu.habbo.messages.outgoing.rooms.pets.breeding.ConfirmBreedingRequestComposer; @@ -19,7 +20,7 @@ import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; import java.sql.ResultSet; import java.sql.SQLException; -public class InteractionPetBreedingNest extends HabboItem { +public class InteractionPetBreedingNest extends RoomItem { private Pet petOne = null; private Pet petTwo = null; @@ -27,13 +28,13 @@ public class InteractionPetBreedingNest extends HabboItem { super(set, baseItem); } - public InteractionPetBreedingNest(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPetBreedingNest(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - return room.getPet(roomUnit) != null && !this.boxFull(); + return room.getRoomUnitManager().getPetByRoomUnit(roomUnit) != null && !this.boxFull(); } @Override @@ -45,7 +46,7 @@ public class InteractionPetBreedingNest extends HabboItem { @Override public void serializeExtradata(ServerMessage serverMessage) { serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); + serverMessage.appendString(this.getExtraData()); super.serializeExtradata(serverMessage); } @@ -57,18 +58,18 @@ public class InteractionPetBreedingNest extends HabboItem { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet != null && !this.boxFull()) { this.addPet(pet); if (this.boxFull()) { - Habbo ownerPetOne = room.getHabbo(this.petOne.getUserId()); - Habbo ownerPetTwo = room.getHabbo(this.petTwo.getUserId()); + Habbo ownerPetOne = room.getRoomUnitManager().getRoomHabboById(this.petOne.getUserId()); + Habbo ownerPetTwo = room.getRoomUnitManager().getRoomHabboById(this.petTwo.getUserId()); if (ownerPetOne != null && ownerPetTwo != null && this.petOne.getPetData().getType() == this.petTwo.getPetData().getType() && this.petOne.getPetData().getOffspringType() != -1) { ownerPetTwo.getClient().sendResponse(new ConfirmBreedingRequestComposer(this.getId(), this.petOne.getPetData().getOffspringType(), this.petOne, ownerPetOne.getHabboInfo().getUsername(), this.petTwo, ownerPetTwo.getHabboInfo().getUsername())); - this.setExtradata("1"); + this.setExtraData("1"); room.updateItem(this); } } @@ -98,7 +99,7 @@ public class InteractionPetBreedingNest extends HabboItem { if (this.petOne != null && this.petOne.getRoomUnit() == roomUnit) this.petOne = null; if (this.petTwo != null && this.petTwo.getRoomUnit() == roomUnit) this.petTwo = null; - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); } @@ -108,14 +109,14 @@ public class InteractionPetBreedingNest extends HabboItem { } public void stopBreeding(Habbo habbo) { - this.setExtradata("0"); - habbo.getHabboInfo().getCurrentRoom().updateItem(this); + this.setExtraData("0"); + habbo.getRoomUnit().getRoom().updateItem(this); if (this.petOne != null) { habbo.getClient().sendResponse(new PerkAllowancesComposer(this.getId(), PerkAllowancesComposer.CLOSE_WIDGET, "")); } if (this.petTwo.getUserId() != habbo.getHabboInfo().getId()) { - Habbo owner = this.petTwo.getRoom().getHabbo(this.petTwo.getUserId()); + Habbo owner = this.petTwo.getRoom().getRoomUnitManager().getRoomHabboById(this.petTwo.getUserId()); if (owner != null) { owner.getClient().sendResponse(new PerkAllowancesComposer(this.getId(), PerkAllowancesComposer.CLOSE_WIDGET, "")); } @@ -142,19 +143,20 @@ public class InteractionPetBreedingNest extends HabboItem { public void breed(Habbo habbo, String name) { Emulator.getThreading().run(new QueryDeleteHabboItem(this.getId())); - this.setExtradata("2"); - habbo.getHabboInfo().getCurrentRoom().updateItem(this); + this.setExtraData("2"); + habbo.getRoomUnit().getRoom().updateItem(this); - HabboItem box = this; + RoomItem box = this; Emulator.getThreading().run(() -> { Pet offspring = Emulator.getGameEnvironment().getPetManager().createPet(petOne.getPetData().getOffspringType(), (int) Math.min(Math.round(Math.max(1d, PetManager.getNormalDistributionForBreeding(petOne.getLevel(), petTwo.getLevel()).sample())), 20), name, habbo.getClient()); - habbo.getHabboInfo().getCurrentRoom().placePet(offspring, box.getX(), box.getY(), box.getZ()); - offspring.setNeedsUpdate(true); + + habbo.getRoomUnit().getRoom().getRoomUnitManager().placePet(offspring, habbo.getRoomUnit().getRoom(), box.getCurrentPosition().getX(), box.getCurrentPosition().getY(), box.getCurrentZ()); + offspring.setSqlUpdateNeeded(true); offspring.run(); InteractionPetBreedingNest.this.freePets(); - habbo.getHabboInfo().getCurrentRoom().removeHabboItem(box); + habbo.getRoomUnit().getRoom().getRoomItemManager().removeRoomItem(box); habbo.getClient().sendResponse(new NestBreedingSuccessComposer(offspring.getId(), Emulator.getGameEnvironment().getPetManager().getRarityForOffspring(offspring))); if (box.getBaseItem().getName().startsWith("pet_breeding_")) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java index 96a0932e..88cbd152 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetDrink.java @@ -6,8 +6,14 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.PetClearPosture; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import org.slf4j.Logger; @@ -26,13 +32,13 @@ public class InteractionPetDrink extends InteractionDefault { super(set, baseItem); } - public InteractionPetDrink(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPetDrink(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean canToggle(Habbo habbo, Room room) { - return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getX(), this.getY()), habbo.getRoomUnit().getCurrentLocation()); + return RoomLayout.tilesAdjecent(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()), habbo.getRoomUnit().getCurrentPosition()); } @Override @@ -42,17 +48,17 @@ public class InteractionPetDrink extends InteractionDefault { if (!this.canToggle(client.getHabbo(), room)) { RoomTile closestTile = null; - for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getX(), this.getY()))) { - if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))) { + for (RoomTile tile : room.getLayout().getTilesAround(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()))) { + if (tile.isWalkable() && (closestTile == null || closestTile.distance(client.getHabbo().getRoomUnit().getCurrentPosition()) > tile.distance(client.getHabbo().getRoomUnit().getCurrentPosition()))) { closestTile = tile; } } - if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) { + if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentPosition())) { List onSuccess = new ArrayList<>(); onSuccess.add(() -> this.change(room, this.getBaseItem().getStateCount() - 1)); - client.getHabbo().getRoomUnit().setGoalLocation(closestTile); + client.getHabbo().getRoomUnit().walkTo(closestTile); Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>())); } } @@ -63,23 +69,23 @@ public class InteractionPetDrink extends InteractionDefault { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - if (this.getExtradata() == null || this.getExtradata().isEmpty()) - this.setExtradata("0"); + if (this.getExtraData() == null || this.getExtraData().isEmpty()) + this.setExtraData("0"); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet != null && pet.getPetData().haveDrinkItem(this) && pet.levelThirst >= 35) { pet.clearPosture(); - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().walkTo(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); + pet.getRoomUnit().setRotation(RoomRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatuses(); + pet.getRoomUnit().addStatus(RoomUnitStatus.EAT, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); pet.setPacketUpdate(true); Emulator.getThreading().run(() -> { pet.addThirst(-75); this.change(room, -1); - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().clearStatuses(); new PetClearPosture(pet, RoomUnitStatus.EAT, null, true); pet.setPacketUpdate(true); }, 1000); @@ -97,12 +103,12 @@ public class InteractionPetDrink extends InteractionDefault { private void change(Room room, int amount) { int state = 0; - if (this.getExtradata() == null || this.getExtradata().isEmpty()) { - this.setExtradata("0"); + if (this.getExtraData() == null || this.getExtraData().isEmpty()) { + this.setExtraData("0"); } try { - state = Integer.parseInt(this.getExtradata()); + state = Integer.parseInt(this.getExtraData()); } catch (Exception e) { LOGGER.error("Caught exception", e); } @@ -116,8 +122,8 @@ public class InteractionPetDrink extends InteractionDefault { state = 0; } - this.setExtradata(state + ""); - this.needsUpdate(true); + this.setExtraData(state + ""); + this.setSqlUpdateNeeded(true); room.updateItemState(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetFood.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetFood.java index 92bf9bc3..5e606bcf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetFood.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetFood.java @@ -6,9 +6,10 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import com.eu.habbo.threading.runnables.PetEatAction; @@ -20,28 +21,28 @@ public class InteractionPetFood extends InteractionDefault { super(set, baseItem); } - public InteractionPetFood(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPetFood(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - if (this.getExtradata().length() == 0) - this.setExtradata("0"); + if (this.getExtraData().length() == 0) + this.setExtraData("0"); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet != null) { if (pet.getPetData().haveFoodItem(this)) { if (pet.levelHunger >= 35) { pet.setTask(PetTasks.EAT); - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().walkTo(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); + pet.getRoomUnit().setRotation(RoomRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatuses(); pet.getRoomUnit().removeStatus(RoomUnitStatus.MOVE); - pet.getRoomUnit().setStatus(RoomUnitStatus.EAT, "0"); + pet.getRoomUnit().addStatus(RoomUnitStatus.EAT, "0"); room.sendComposer(new UserUpdateComposer(roomUnit).compose()); Emulator.getThreading().run(new PetEatAction(pet, this)); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java index fef842ea..4a13ee51 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetToy.java @@ -6,8 +6,14 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetTasks; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +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.users.HabboInfo; import com.eu.habbo.threading.runnables.PetClearPosture; import java.sql.ResultSet; @@ -16,32 +22,32 @@ import java.sql.SQLException; public class InteractionPetToy extends InteractionDefault { public InteractionPetToy(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionPetToy(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionPetToy(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override public void onClick(GameClient client, Room room, Object[] objects) {} @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); - for (Pet pet : room.getPetsAt(oldLocation)) { - pet.getRoomUnit().clearStatus(); + for (Pet pet : room.getRoomUnitManager().getPetsAt(oldLocation)) { + pet.getRoomUnit().clearStatuses(); pet.setPacketUpdate(true); } } @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); for (Pet pet : room.getPetsOnItem(this)) { - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().clearStatuses(); pet.setPacketUpdate(true); } } @@ -50,30 +56,32 @@ public class InteractionPetToy extends InteractionDefault { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); - if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) { - if (pet.getEnergy() <= 35) { - return; - } + if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem())) { + if (this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getTargetPosition())) { + if (pet.getEnergy() <= 35) { + return; + } - pet.setTask(PetTasks.PLAY); - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(this.getX(), this.getY())); - pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().setStatus(RoomUnitStatus.PLAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); - pet.setPacketUpdate(true); - HabboItem item = this; - Emulator.getThreading().run(() -> { - pet.addHappiness(25); - item.setExtradata("0"); - room.updateItem(item); - pet.getRoomUnit().clearStatus(); - new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run(); + pet.setTask(PetTasks.PLAY); + pet.getRoomUnit().walkTo(room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); + pet.getRoomUnit().setRotation(RoomRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatuses(); + pet.getRoomUnit().addStatus(RoomUnitStatus.PLAY, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); pet.setPacketUpdate(true); - }, ((long)(Emulator.getRandom().nextInt(20) * 500) + 2500)); - this.setExtradata("1"); - room.updateItemState(this); + RoomItem item = this; + Emulator.getThreading().run(() -> { + pet.addHappiness(25); + item.setExtraData("0"); + room.updateItem(item); + pet.getRoomUnit().clearStatuses(); + new PetClearPosture(pet, RoomUnitStatus.PLAY, null, true).run(); + pet.setPacketUpdate(true); + }, ((long) (Emulator.getRandom().nextInt(20) * 500) + 2500)); + this.setExtraData("1"); + room.updateItemState(this); + } } } @@ -81,19 +89,19 @@ public class InteractionPetToy extends InteractionDefault { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet != null) { - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().clearStatuses(); pet.setPacketUpdate(true); } } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); return roomUnit.getRoomUnitType() == RoomUnitType.PET && pet != null && pet.getPetData().haveToyItem(this.getBaseItem()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java index 9c16421f..acc70222 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTrampoline.java @@ -6,7 +6,12 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetTasks; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.PetClearPosture; import java.sql.ResultSet; @@ -15,12 +20,12 @@ import java.sql.SQLException; public class InteractionPetTrampoline extends InteractionDefault { public InteractionPetTrampoline(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.setExtradata("0"); + this.setExtraData("0"); } - public InteractionPetTrampoline(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.setExtradata("0"); + public InteractionPetTrampoline(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.setExtraData("0"); } @Override @@ -28,10 +33,10 @@ public class InteractionPetTrampoline extends InteractionDefault { @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); - for (Pet pet : room.getPetsAt(oldLocation)) { + for (Pet pet : room.getRoomUnitManager().getPetsAt(oldLocation)) { pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); pet.setPacketUpdate(true); } @@ -39,7 +44,7 @@ public class InteractionPetTrampoline extends InteractionDefault { @Override public void onPickUp(Room room) { - this.setExtradata("0"); + this.setExtraData("0"); for (Pet pet : room.getPetsOnItem(this)) { pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); @@ -51,26 +56,28 @@ public class InteractionPetTrampoline extends InteractionDefault { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); - if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) { - if (pet.getEnergy() <= 35) { - return; - } + if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem())) { + if (this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getTargetPosition())) { + if (pet.getEnergy() <= 35) { + return; + } - pet.clearPosture(); - pet.setTask(PetTasks.JUMP); - pet.getRoomUnit().setStatus(RoomUnitStatus.JUMP, ""); - Emulator.getThreading().run(() -> { - new PetClearPosture(pet, RoomUnitStatus.JUMP, null, false); - pet.getRoomUnit().setGoalLocation(room.getRandomWalkableTile()); - this.setExtradata("0"); + pet.clearPosture(); + pet.setTask(PetTasks.JUMP); + pet.getRoomUnit().addStatus(RoomUnitStatus.JUMP, ""); + Emulator.getThreading().run(() -> { + new PetClearPosture(pet, RoomUnitStatus.JUMP, null, false); + pet.getRoomUnit().walkTo(room.getRandomWalkableTile()); + this.setExtraData("0"); + room.updateItemState(this); + }, 4000); + pet.addHappiness(25); + + this.setExtraData("1"); room.updateItemState(this); - }, 4000); - pet.addHappiness(25); - - this.setExtradata("1"); - room.updateItemState(this); + } } } @@ -78,10 +85,10 @@ public class InteractionPetTrampoline extends InteractionDefault { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet != null) { - this.setExtradata("0"); + this.setExtraData("0"); room.updateItem(this); pet.getRoomUnit().removeStatus(RoomUnitStatus.JUMP); pet.setPacketUpdate(true); @@ -90,7 +97,7 @@ public class InteractionPetTrampoline extends InteractionDefault { @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); return roomUnit.getRoomUnitType() == RoomUnitType.PET && pet != null && pet.getPetData().haveToyItem(this.getBaseItem()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java index 7ff78077..1b381e01 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/pets/InteractionPetTree.java @@ -4,7 +4,13 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.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.RoomUnitType; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.threading.runnables.PetClearPosture; import java.sql.ResultSet; @@ -15,21 +21,21 @@ public class InteractionPetTree extends InteractionDefault { super(set, baseItem); } - public InteractionPetTree(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionPetTree(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { - for (Pet pet : room.getPetsAt(oldLocation)) { - pet.getRoomUnit().clearStatus(); + for (Pet pet : room.getRoomUnitManager().getPetsAt(oldLocation)) { + pet.getRoomUnit().clearStatuses(); pet.setPacketUpdate(true); } } @Override public void onPickUp(Room room) { for (Pet pet : room.getPetsOnItem(this)) { - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().clearStatuses(); pet.setPacketUpdate(true); } } @@ -38,39 +44,41 @@ public class InteractionPetTree extends InteractionDefault { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); - if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem()) && this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getGoalLocation())) { - RoomUnitStatus task = switch (pet.getTask()) { - case RING_OF_FIRE -> RoomUnitStatus.RINGOFFIRE; - case SWING -> RoomUnitStatus.SWING; - case ROLL -> RoomUnitStatus.ROLL; - default -> RoomUnitStatus.HANG; - }; - if (pet.getEnergy() >= 35 && task != RoomUnitStatus.HANG) { + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); + if (pet != null && pet.getPetData().haveToyItem(this.getBaseItem())) { + if (this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getTargetPosition())) { + RoomUnitStatus task = switch (pet.getTask()) { + case RING_OF_FIRE -> RoomUnitStatus.RINGOFFIRE; + case SWING -> RoomUnitStatus.SWING; + case ROLL -> RoomUnitStatus.ROLL; + default -> RoomUnitStatus.HANG; + }; + if (pet.getEnergy() >= 35 && task != RoomUnitStatus.HANG) { - pet.getRoomUnit().setCanWalk(false); - pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().setStatus(task, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); - pet.setPacketUpdate(true); - RoomUnitStatus finalTask = task; - Emulator.getThreading().run(() -> { - pet.addHappiness(25); - pet.getRoomUnit().clearStatus(); - new PetClearPosture(pet, finalTask, null, true); - if (this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getCurrentLocation())) { - pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); - } else { - pet.clearPosture(); - } - pet.getRoomUnit().setCanWalk(true); - pet.setPacketUpdate(true); - }, (long) 2500 + (Emulator.getRandom().nextInt(20) * 500)); - } else { - pet.getRoomUnit().setRotation(RoomUserRotation.values()[this.getRotation()]); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); - pet.setPacketUpdate(true); + pet.getRoomUnit().setCanWalk(false); + pet.getRoomUnit().setRotation(RoomRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatuses(); + pet.getRoomUnit().addStatus(task, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); + pet.setPacketUpdate(true); + RoomUnitStatus finalTask = task; + Emulator.getThreading().run(() -> { + pet.addHappiness(25); + pet.getRoomUnit().clearStatuses(); + new PetClearPosture(pet, finalTask, null, true); + if (this.getOccupyingTiles(room.getLayout()).contains(pet.getRoomUnit().getCurrentPosition())) { + pet.getRoomUnit().addStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); + } else { + pet.clearPosture(); + } + pet.getRoomUnit().setCanWalk(true); + pet.setPacketUpdate(true); + }, (long) 2500 + (Emulator.getRandom().nextInt(20) * 500)); + } else { + pet.getRoomUnit().setRotation(RoomRotation.values()[this.getRotation()]); + pet.getRoomUnit().clearStatuses(); + pet.getRoomUnit().addStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); + pet.setPacketUpdate(true); + } } } } @@ -79,17 +87,17 @@ public class InteractionPetTree extends InteractionDefault { public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOff(roomUnit, room, objects); - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); if (pet != null) { - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().clearStatuses(); pet.setPacketUpdate(true); } } @Override public boolean canWalkOn(RoomUnit roomUnit, Room room, Object[] objects) { - Pet pet = room.getPet(roomUnit); + Pet pet = room.getRoomUnitManager().getPetByRoomUnit(roomUnit); return roomUnit.getRoomUnitType() == RoomUnitType.PET && pet != null && pet.getPetData().haveToyItem(this.getBaseItem()); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java index a016a1a2..19cadf05 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemHead.java @@ -5,7 +5,8 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import java.sql.ResultSet; @@ -17,14 +18,14 @@ public class InteractionTotemHead extends InteractionDefault { super(set, baseItem); } - public InteractionTotemHead(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTotemHead(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public TotemType getTotemType() { int extraData; try { - extraData = Integer.parseInt(this.getExtradata()); + extraData = Integer.parseInt(this.getExtraData()); } catch(NumberFormatException ex) { extraData = 0; } @@ -37,7 +38,7 @@ public class InteractionTotemHead extends InteractionDefault { public TotemColor getTotemColor() { int extraData; try { - extraData = Integer.parseInt(this.getExtradata()); + extraData = Integer.parseInt(this.getExtraData()); }catch(NumberFormatException ex) { extraData = 0; } @@ -50,31 +51,32 @@ public class InteractionTotemHead extends InteractionDefault { private void update(Room room, RoomTile tile) { InteractionTotemLegs legs = null; - for(HabboItem item : room.getItemsAt(tile)) { - if(item instanceof InteractionTotemLegs && item.getZ() < this.getZ()) - legs = (InteractionTotemLegs)item; + for(RoomItem item : room.getRoomItemManager().getItemsAt(tile)) { + if(item instanceof InteractionTotemLegs) { + if (item.getCurrentZ() < this.getCurrentZ()) legs = (InteractionTotemLegs) item; + } } if(legs == null) return; - this.setExtradata(((4 * this.getTotemType().getType()) + legs.getTotemColor().getColor()) - 1 + ""); + this.setExtraData(((4 * this.getTotemType().getType()) + legs.getTotemColor().getColor()) - 1 + ""); } public void updateTotemState(Room room) { - updateTotemState(room, room.getLayout().getTile(this.getX(), this.getY())); + updateTotemState(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); } public void updateTotemState(Room room, RoomTile tile) { - this.setExtradata(getTotemType().getType() - 1 + ""); + this.setExtraData(getTotemType().getType() - 1 + ""); update(room, tile); - this.needsUpdate(true); + this.setSqlUpdateNeeded(true); room.updateItem(this); } @Override public void onClick(GameClient client, Room room, Object[] objects) { - if (!((client != null && room != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) + if (!((client != null && room != null && room.getRoomRightsManager().hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) return; TotemType newType = TotemType.fromInt(getTotemType().getType() + 1); @@ -82,7 +84,7 @@ public class InteractionTotemHead extends InteractionDefault { newType = TotemType.TROLL; } - this.setExtradata(newType.getType() - 1 + ""); + this.setExtraData(newType.getType() - 1 + ""); updateTotemState(room); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java index f12a5193..db588c04 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemLegs.java @@ -5,7 +5,8 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import java.sql.ResultSet; @@ -16,14 +17,14 @@ public class InteractionTotemLegs extends InteractionDefault { super(set, baseItem); } - public InteractionTotemLegs(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTotemLegs(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public TotemType getTotemType() { int extraData; try { - extraData = Integer.parseInt(this.getExtradata()); + extraData = Integer.parseInt(this.getExtraData()); } catch(NumberFormatException ex) { extraData = 0; } @@ -33,7 +34,7 @@ public class InteractionTotemLegs extends InteractionDefault { public TotemColor getTotemColor() { int extraData; try { - extraData = Integer.parseInt(this.getExtradata()); + extraData = Integer.parseInt(this.getExtraData()); } catch(NumberFormatException ex) { extraData = 0; } @@ -41,9 +42,10 @@ public class InteractionTotemLegs extends InteractionDefault { } private void updateHead(Room room, RoomTile tile) { - for(HabboItem item : room.getItemsAt(tile)) { - if(item instanceof InteractionTotemHead && item.getZ() > this.getZ()) - ((InteractionTotemHead)item).updateTotemState(room); + for(RoomItem item : room.getRoomItemManager().getItemsAt(tile)) { + if(item instanceof InteractionTotemHead) { + if (item.getCurrentZ() > this.getCurrentZ()) ((InteractionTotemHead) item).updateTotemState(room); + } } } @@ -51,10 +53,10 @@ public class InteractionTotemLegs extends InteractionDefault { public void onClick(GameClient client, Room room, Object[] objects) throws Exception { super.onClick(client, room, objects); - if (room == null || !((client != null && room.hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) + if (room == null || !((client != null && room.getRoomRightsManager().hasRights(client.getHabbo())) || (objects.length >= 2 && objects[1] instanceof WiredEffectType))) return; - updateHead(room, room.getLayout().getTile(this.getX(), this.getY())); + updateHead(room, room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY())); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java index 6c9ddb3f..fae2bab2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/totems/InteractionTotemPlanet.java @@ -4,7 +4,9 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; @@ -15,14 +17,14 @@ public class InteractionTotemPlanet extends InteractionDefault { super(set, baseItem); } - public InteractionTotemPlanet(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public InteractionTotemPlanet(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public TotemPlanetType getPlanetType() { int extraData; try { - extraData = Integer.parseInt(this.getExtradata()); + extraData = Integer.parseInt(this.getExtraData()); } catch(NumberFormatException ex) { extraData = 0; } @@ -31,7 +33,7 @@ public class InteractionTotemPlanet extends InteractionDefault { @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - if(client.getHabbo().getHabboInfo().getId() != this.getUserId()) { + if(client.getHabbo().getHabboInfo().getId() != this.getOwnerInfo().getId()) { super.onClick(client, room, objects); return; } @@ -39,11 +41,13 @@ public class InteractionTotemPlanet extends InteractionDefault { InteractionTotemLegs legs = null; InteractionTotemHead head = null; - THashSet items = room.getItemsAt(room.getLayout().getTile(this.getX(), this.getY())); + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + THashSet items = room.getRoomItemManager().getItemsAt(tile); - for(HabboItem item : items) { - if(item instanceof InteractionTotemLegs && item.getZ() < this.getZ()) - legs = (InteractionTotemLegs)item; + for(RoomItem item : items) { + if(item instanceof InteractionTotemLegs) { + if (item.getCurrentZ() < this.getCurrentZ()) legs = (InteractionTotemLegs) item; + } } if(legs == null) { @@ -51,9 +55,10 @@ public class InteractionTotemPlanet extends InteractionDefault { return; } - for(HabboItem item : items) { - if(item instanceof InteractionTotemHead && item.getZ() > legs.getZ()) - head = (InteractionTotemHead)item; + for(RoomItem item : items) { + if(item instanceof InteractionTotemHead) { + if (item.getCurrentZ() > legs.getCurrentZ()) head = (InteractionTotemHead) item; + } } if(head == null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java index b6027a06..1521880d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredSettings.java @@ -1,63 +1,88 @@ package com.eu.habbo.habbohotel.items.interactions.wired; -public class WiredSettings { - private int[] intParams; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredSettings; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +public class WiredSettings implements IWiredSettings { + @Getter + @Setter + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List integerParams; + + @Getter + @Setter + @JsonInclude(JsonInclude.Include.NON_EMPTY) private String stringParam; - private int[] furniIds; - private int stuffTypeSelectionCode; + + @Getter + @Setter + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List itemIds; + + @Getter + @Setter + @JsonInclude(JsonInclude.Include.NON_DEFAULT) private int delay; - public WiredSettings(int[] intParams, String stringParam, int[] furniIds, int stuffTypeSelectionCode, int delay) - { - this.furniIds = furniIds; - this.intParams = intParams; - this.stringParam = stringParam; - this.stuffTypeSelectionCode = stuffTypeSelectionCode; - this.delay = delay; + @Getter + @Setter + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List matchParams; + + @Getter + @Setter + @JsonIgnore + private int selectionType; + + public WiredSettings() { + this.itemIds = new ArrayList<>(); + this.integerParams = new ArrayList<>(); + this.stringParam = ""; + this.delay = 0; + this.matchParams = new ArrayList<>(); + this.selectionType = 0; } - public WiredSettings(int[] intParams, String stringParam, int[] furniIds, int stuffTypeSelectionCode) - { - this(intParams, stringParam, furniIds, stuffTypeSelectionCode, 0); + public HashSet getItems(Room room) { + HashSet items = new HashSet<>(); + + if(this.itemIds.size() == 0) { + return items; + } + + for(int i = 0; i < this.itemIds.size(); i++) { + RoomItem item = room.getRoomItemManager().getRoomItemById(this.itemIds.get(i)); + + if(item == null || item.getRoomId() == 0) { + this.itemIds.remove(i); + if(!matchParams.isEmpty()) { + this.matchParams.removeIf(setting -> setting.getItem_id() == item.getId()); + } + continue; + } + + items.add(item); + } + + return items; } - public int getStuffTypeSelectionCode() { - return stuffTypeSelectionCode; - } - - public void setStuffTypeSelectionCode(int stuffTypeSelectionCode) { - this.stuffTypeSelectionCode = stuffTypeSelectionCode; - } - - public int[] getFurniIds() { - return furniIds; - } - - public void setFurniIds(int[] furniIds) { - this.furniIds = furniIds; - } - - public String getStringParam() { - return stringParam; - } - - public void setStringParam(String stringParam) { - this.stringParam = stringParam; - } - - public int[] getIntParams() { - return intParams; - } - - public void setIntParams(int[] intParams) { - this.intParams = intParams; - } - - public int getDelay() { - return delay; - } - - public void setDelay(int delay) { - this.delay = delay; + public void dispose() { + this.integerParams.clear(); + this.itemIds.clear(); + this.stringParam = ""; + this.delay = 0; + this.matchParams.clear(); + this.selectionType = 0; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredTriggerReset.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredTriggerReset.java deleted file mode 100644 index 81dd0284..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/WiredTriggerReset.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired; - -public interface WiredTriggerReset { - void resetTimer(); -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java index 1774a6de..ab5860ef 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionDateRangeActive.java @@ -3,12 +3,10 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; @@ -18,10 +16,8 @@ import java.sql.SQLException; * a given range. */ public class WiredConditionDateRangeActive extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.DATE_RANGE; - - private int startDate; // the start of the date range - private int endDate; // the end of the date range + public final int PARAM_START_DATE = 0; + public final int PARAM_END_DATE = 1; /** * Creates a new instance of this class. @@ -36,58 +32,14 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition { /** * Creates a new instance of this class. * @param id The ID of this item. - * @param userId The ID of the user that owns this item. + * @param ownerInfo The info of the user that owns this item. * @param item The item this instance is associated with. * @param extradata Additional data associated with this item. * @param limitedStack The amount of items in this stack (if this item is stackable). * @param limitedSells The amount of items that can be sold from this stack (if this item is sellable). */ - public WiredConditionDateRangeActive(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - /** - * Returns the {@link WiredConditionType} of this object. - * @return the type of this wired condition - */ - @Override - public WiredConditionType getType() { - return type; - } - - /** - * Sends information about this wired condition to the client. - * @param message the message to send data with - * @param room the room this wired condition is in - */ - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.startDate); - message.appendInt(this.endDate); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.startDate); - message.appendInt(this.endDate); - } - - /** - * Saves the given {@link WiredSettings} object to this wired condition. - * @param settings the settings to save - * @return {@code true} if the settings were saved successfully, {@code false} otherwise - * */ - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 2) return false; - this.startDate = settings.getIntParams()[0]; - this.endDate = settings.getIntParams()[1]; - return true; + public WiredConditionDateRangeActive(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } /** @@ -101,72 +53,27 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { int time = Emulator.getIntUnixTimestamp(); - return this.startDate < time && this.endDate >= time; + + int startDate = this.getWiredSettings().getIntegerParams().get(PARAM_START_DATE); + int endDate = this.getWiredSettings().getIntegerParams().get(PARAM_END_DATE); + + return startDate < time && endDate >= time; } - /** - * Gets the wired data for this wired condition in JSON format. - * @return the wired data in JSON format - */ @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.startDate, - this.endDate - )); - } - - /** - * Loads the wired data for this wired condition from a database. - * @param set the ResultSet object to get data from - * @param room the room that this wired condition is in - * @throws SQLException if an error occurs while getting data from the ResultSet object - */ - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.startDate = data.startDate; - this.endDate = data.endDate; - } else { - String[] data = wiredData.split("\t"); - - if (data.length == 2) { - try { - this.startDate = Integer.parseInt(data[0]); - this.endDate = Integer.parseInt(data[1]); - } catch (Exception ignored) { - } - } + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); } } /** - * Called when this item is picked up. Resets the startDate and endDate member variables to 0. + * Returns the {@link WiredConditionType} of this object. + * @return the type of this wired condition */ @Override - public void onPickUp() { - this.startDate = 0; - this.endDate = 0; - } - - /** - * A nested class for storing the wired data for this wired condition in JSON format. - */ - static class JsonData { - int startDate; - int endDate; - - /** - * Creates a new instance of this class. - * @param startDate the start of the date range - * @param endDate the end of the date range - */ - public JsonData(int startDate, int endDate) { - this.startDate = startDate; - this.endDate = endDate; - } + public WiredConditionType getType() { + return WiredConditionType.DATE_RANGE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java index 752454a8..cd6e7266 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveFurni.java @@ -1,166 +1,66 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.FURNI_HAS_FURNI; - - private boolean all; - private final THashSet items; + public final int PARAM_ALL_FURNI = 0; public WiredConditionFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredConditionFurniHaveFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); + public WiredConditionFurniHaveFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.refresh(); - - if (this.items.isEmpty()) + if(this.getWiredSettings().getItemIds().isEmpty()) { return true; + } - if (this.all) { - return this.items.stream().allMatch(item -> { - double minZ = item.getZ() + Item.getCurrentHeight(item); - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + boolean allFurni = this.getWiredSettings().getIntegerParams().get(PARAM_ALL_FURNI) == 1; + + if (allFurni) { + return this.getWiredSettings().getItems(room).stream().allMatch(item -> { + double minZ = item.getCurrentZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().anyMatch(tile -> room.getRoomItemManager().getItemsAt(tile).stream().anyMatch(matchedItem -> { + if (matchedItem == item) return false; + return matchedItem.getCurrentZ() >= minZ; + })); }); } else { - return this.items.stream().anyMatch(item -> { - double minZ = item.getZ() + Item.getCurrentHeight(item); - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - return occupiedTiles.stream().anyMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + return this.getWiredSettings().getItems(room).stream().anyMatch(item -> { + double minZ = item.getCurrentZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().anyMatch(tile -> room.getRoomItemManager().getItemsAt(tile).stream().anyMatch(matchedItem -> { + if (matchedItem == item) return false; + return matchedItem.getCurrentZ() >= minZ; + })); }); } } @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.all, - this.items.stream().map(HabboItem::getId).toList() - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.all = data.all; - - data.itemIds.stream().mapToInt(id -> id).mapToObj(room::getHabboItem).filter(Objects::nonNull).forEach(this.items::add); - - } else { - String[] data = wiredData.split(":"); - - if (data.length >= 1) { - this.all = (data[0].equals("1")); - - if (data.length == 2) { - String[] itemsSplit = data[1].split(";"); - Arrays.stream(itemsSplit).map(s -> room.getHabboItem(Integer.parseInt(s))).filter(Objects::nonNull).forEach(this.items::add); - } - } + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); } } - @Override - public void onPickUp() { - this.items.clear(); - this.all = false; - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.all ? 1 : 0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if (settings.getIntParams().length < 1) return false; - - this.all = settings.getIntParams()[0] == 1; - - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - - if (item != null) - this.items.add(item); - } - - return true; - } - return false; - } - - private void refresh() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - this.items.removeIf(i -> room.getHabboItem(i.getId()) == null); - } - - static class JsonData { - boolean all; - List itemIds; - - public JsonData(boolean all, List itemIds) { - this.all = all; - this.itemIds = itemIds; - } + return WiredConditionType.FURNI_HAS_FURNI; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java deleted file mode 100644 index abae0d25..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveHabbo.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -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.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO; - protected THashSet items; - - public WiredConditionFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - this.items = new THashSet<>(); - } - - public WiredConditionFurniHaveHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public void onPickUp() { - this.items.clear(); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.refresh(); - - if (this.items.isEmpty()) - return true; - - Collection habbos = room.getHabbos(); - Collection bots = room.getCurrentBots().valueCollection(); - Collection pets = room.getCurrentPets().valueCollection(); - - return this.items.stream().allMatch(item -> { - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || - bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || - pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())); - }); - } - - @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - - for(int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(":"); - - if (data.length >= 1) { - - String[] items = data[1].split(";"); - - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - int count = settings.getFurniIds().length; - - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - - if (item != null) - this.items.add(item); - } - - return true; - } - - return false; - } - - private void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (room.getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } - } -} 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 new file mode 100644 index 00000000..498f74ff --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniHaveRoom.java @@ -0,0 +1,50 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; +import com.eu.habbo.habbohotel.pets.Pet; +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.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; +import gnu.trove.set.hash.THashSet; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; + +public class WiredConditionFurniHaveRoom extends InteractionWiredCondition { + public WiredConditionFurniHaveRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionFurniHaveRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if (this.getWiredSettings().getItemIds().isEmpty()) { + return true; + } + + 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.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentPosition())) || + bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentPosition())) || + pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentPosition())); + }); + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.FURNI_HAVE_HABBO; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java index 38b06c51..7e32cc42 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionFurniTypeMatch.java @@ -1,161 +1,44 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.STUFF_IS; - - private final THashSet items = new THashSet<>(); - public WiredConditionFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionFurniTypeMatch(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void onPickUp() { - this.items.clear(); + public WiredConditionFurniTypeMatch(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.refresh(); + if(this.getWiredSettings().getItemIds().isEmpty()) { + return true; + } - if(items.isEmpty()) - return false; + if(stuff.length == 0) { + return true; + } - if (stuff != null) { - if (stuff.length >= 1) { - if (stuff[0] instanceof HabboItem triggeringItem) { - return this.items.stream().anyMatch(item -> item == triggeringItem); - } - } + if (stuff[0] instanceof RoomItem triggeringItem) { + return this.getWiredSettings().getItems(room).stream().anyMatch(item -> item == triggeringItem); } return false; } - @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - - for(int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(";"); - - for (String s : data) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) { - this.items.add(item); - } - } - } - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); - } - } - - return true; - } - - private void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (room.getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } + return WiredConditionType.STUFF_IS; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java index d9c1d1ad..243bc2f6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionGroupMember.java @@ -2,74 +2,37 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionGroupMember extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.ACTOR_IN_GROUP; - public WiredConditionGroupMember(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionGroupMember(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionGroupMember(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (room.getGuildId() == 0) + if (room.getRoomInfo().getGuild().getId() == 0) { return false; + } - Habbo habbo = room.getHabbo(roomUnit); - - return habbo != null && habbo.getHabboStats().hasGuild(room.getGuildId()); - } - - @Override - public String getWiredData() { - return ""; - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - - } - - @Override - public void onPickUp() { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + return habbo != null && habbo.getHabboStats().hasGuild(room.getRoomInfo().getGuild().getId()); } @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - return true; + return WiredConditionType.ACTOR_IN_GROUP; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java deleted file mode 100644 index 839b7db4..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboCount.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredConditionHabboCount extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.USER_COUNT; - - private int lowerLimit = 0; - private int upperLimit = 50; - - public WiredConditionHabboCount(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionHabboCount(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - int count = room.getUserCount(); - - return count >= this.lowerLimit && count <= this.upperLimit; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.lowerLimit, - this.upperLimit - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.lowerLimit = data.lowerLimit; - this.upperLimit = data.upperLimit; - } else { - String[] data = wiredData.split(":"); - - this.lowerLimit = Integer.parseInt(data[0]); - this.upperLimit = Integer.parseInt(data[1]); - } - } - - @Override - public void onPickUp() { - this.lowerLimit = 0; - this.upperLimit = 50; - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.lowerLimit); - message.appendInt(this.upperLimit); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 2) return false; - this.lowerLimit = settings.getIntParams()[0]; - this.upperLimit = settings.getIntParams()[1]; - - return true; - } - - static class JsonData { - int lowerLimit; - int upperLimit; - - public JsonData(int lowerLimit, int upperLimit) { - this.lowerLimit = lowerLimit; - this.upperLimit = upperLimit; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java deleted file mode 100644 index 52f951f7..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasEffect.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredConditionHabboHasEffect extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_EFFECT; - - protected int effectId = 0; - - public WiredConditionHabboHasEffect(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionHabboHasEffect(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) return false; - return roomUnit.getEffectId() == this.effectId; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.effectId - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.effectId = data.effectId; - } else { - this.effectId = Integer.parseInt(wiredData); - } - } - - @Override - public void onPickUp() { - this.effectId = 0; - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(true); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.effectId + ""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.effectId = settings.getIntParams()[0]; - - return true; - } - - static class JsonData { - int effectId; - - public JsonData(int effectId) { - this.effectId = effectId; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java deleted file mode 100644 index 5f7f8b0f..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboHasHandItem.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import lombok.extern.slf4j.Slf4j; - -import java.sql.ResultSet; -import java.sql.SQLException; - -@Slf4j -public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { - - public static final WiredConditionType type = WiredConditionType.ACTOR_HAS_HANDITEM; - - private int handItem; - - public WiredConditionHabboHasHandItem(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionHabboHasHandItem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.handItem); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.handItem = settings.getIntParams()[0]; - - return true; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) return false; - return roomUnit.getHandItem() == this.handItem; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.handItem - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - try { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.handItem = data.handItemId; - } else { - this.handItem = Integer.parseInt(wiredData); - } - } catch (Exception e) { - log.error("Caught exception", e); - } - } - - @Override - public void onPickUp() { - this.handItem = 0; - } - - static class JsonData { - int handItemId; - - public JsonData(int handItemId) { - this.handItemId = handItemId; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java deleted file mode 100644 index 81831829..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionHabboWearsBadge.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboBadge; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.ACTOR_WEARS_BADGE; - - protected String badge = ""; - - public WiredConditionHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionHabboWearsBadge(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { - for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) { - if (badge.getCode().equalsIgnoreCase(this.badge)) { - return true; - } - } - } - } - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.badge - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.badge = data.badge; - } else { - this.badge = wiredData; - } - } - - @Override - public void onPickUp() { - this.badge = ""; - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.badge); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.badge = settings.getStringParam(); - - return true; - } - - static class JsonData { - String badge; - - public JsonData(String badge) { - this.badge = badge; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java index 9c75f4f3..439d7842 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionLessTimeElapsed.java @@ -3,95 +3,40 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionLessTimeElapsed extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.TIME_LESS_THAN; - - private int cycles; + public final int PARAM_CYCLE = 0; public WiredConditionLessTimeElapsed(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionLessTimeElapsed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionLessTimeElapsed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 < this.cycles; + int cycles = this.getWiredSettings().getIntegerParams().get(PARAM_CYCLE); + return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 < cycles; } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.cycles - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - try { - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.cycles = data.cycles; - } else { - if (!wiredData.equals("")) - this.cycles = Integer.parseInt(wiredData); - } - } catch (Exception ignored) { + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); } } - @Override - public void onPickUp() { - this.cycles = 0; - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.cycles); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.cycles = settings.getIntParams()[0]; - return true; - } - - static class JsonData { - int cycles; - - public JsonData(int cycles) { - this.cycles = cycles; - } + return WiredConditionType.TIME_LESS_THAN; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java index e3a68648..148fe15e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMatchStatePosition.java @@ -1,18 +1,15 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; +import lombok.Getter; import java.sql.ResultSet; import java.sql.SQLException; @@ -20,115 +17,54 @@ import java.util.ArrayList; import java.util.List; public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { - public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; - - private final THashSet settings; - - private boolean state; - private boolean position; - private boolean direction; + public final int PARAM_STATE = 0; + public final int PARAM_ROTATION = 1; + public final int PARAM_POSITION = 2; + @Getter + private List matchSettings; public WiredConditionMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.settings = new THashSet<>(); } - public WiredConditionMatchStatePosition(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.settings = new THashSet<>(); - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.settings.size()); - - for (WiredMatchFurniSetting item : this.settings) - message.appendInt(item.getItem_id()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(4); - message.appendInt(this.state ? 1 : 0); - message.appendInt(this.direction ? 1 : 0); - message.appendInt(this.position ? 1 : 0); - message.appendInt(10); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 3) return false; - this.state = settings.getIntParams()[0] == 1; - this.direction = settings.getIntParams()[1] == 1; - this.position = settings.getIntParams()[2] == 1; - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null) - return true; - - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.settings.clear(); - - for (int i = 0; i < count; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem item = room.getHabboItem(itemId); - - if (item != null) - this.settings.add(new WiredMatchFurniSetting(item.getId(), item.getExtradata(), item.getRotation(), item.getX(), item.getY())); - } - - return true; + public WiredConditionMatchStatePosition(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (this.settings.isEmpty()) + if(this.getWiredSettings().getItemIds().isEmpty() && this.getWiredSettings().getMatchParams().isEmpty()) { return true; - - THashSet s = new THashSet<>(); - - for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.getItem_id()); - - if (item != null) { - if (this.state) { - if (!item.getExtradata().equals(setting.getState())) - return false; - } - - if (this.position) { - if (!(setting.getX() == item.getX() && setting.getY() == item.getY())) - return false; - } - - if (this.direction) { - if (setting.getRotation() != item.getRotation()) - return false; - } - } else { - s.add(setting); - } } - if (!s.isEmpty()) { - for (WiredMatchFurniSetting setting : s) { - this.settings.remove(setting); + boolean state = this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; + boolean position = this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1; + boolean rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1; + this.matchSettings = this.getWiredSettings().getMatchParams(); + + for(RoomItem item : this.getWiredSettings().getItems(room)) { + WiredMatchFurniSetting furniSettings = this.matchSettings.stream().filter(settings -> settings.getItem_id() == item.getId()).findAny().orElse(null); + + if(furniSettings == null) { + continue; + } + + if(state) { + if(!item.getExtraData().equals(furniSettings.getState())) { + return false; + } + } + + if(position) { + if (!(furniSettings.getX() == item.getCurrentPosition().getX() && furniSettings.getY() == item.getCurrentPosition().getY())) { + return false; + } + } + + if(rotation) { + if (furniSettings.getRotation() != item.getRotation()) { + return false; + } } } @@ -136,103 +72,43 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.state, - this.position, - this.direction, - new ArrayList<>(this.settings) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.state = data.state; - this.position = data.position; - this.direction = data.direction; - this.settings.addAll(data.settings); - } else { - String[] data = wiredData.split(":"); - - int itemCount = Integer.parseInt(data[0]); - - String[] items = data[1].split(";"); - - for (int i = 0; i < itemCount; i++) { - String[] stuff = items[i].split("-"); - - if (stuff.length >= 5) - this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4]))); - } - - this.state = data[2].equals("1"); - this.direction = data[3].equals("1"); - this.position = data[4].equals("1"); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); } } @Override - public void onPickUp() { - this.settings.clear(); - this.direction = false; - this.position = false; - this.state = false; - } + public void saveAdditionalData(Room room) { + List matchSettings = new ArrayList<>(); - private void refresh() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - THashSet remove = new THashSet<>(); - - for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.getItem_id()); - if (item == null) { - remove.add(setting); - } - } - - for (WiredMatchFurniSetting setting : remove) { - this.settings.remove(setting); - } + for (RoomItem item : this.getWiredSettings().getItems(room)) { + WiredMatchFurniSetting settings = new WiredMatchFurniSetting(item.getId(), item.getExtraData(), item.getRotation(), item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + matchSettings.add(settings); } - } - @Override - public THashSet getMatchFurniSettings() { - return this.settings; + this.getWiredSettings().setMatchParams(matchSettings); } @Override public boolean shouldMatchState() { - return this.state; + return this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; } @Override public boolean shouldMatchRotation() { - return this.direction; + return this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1; } @Override public boolean shouldMatchPosition() { - return this.position; + return this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1; } - static class JsonData { - boolean state; - boolean position; - boolean direction; - List settings; - - public JsonData(boolean state, boolean position, boolean direction, List settings) { - this.state = state; - this.position = position; - this.direction = direction; - this.settings = settings; - } + @Override + public WiredConditionType getType() { + return WiredConditionType.MATCH_SSHOT; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java index ea0b85f8..4b968654 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionMoreTimeElapsed.java @@ -3,95 +3,40 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition { - private static final WiredConditionType type = WiredConditionType.TIME_MORE_THAN; - - private int cycles; + public final int PARAM_CYCLE = 0; public WiredConditionMoreTimeElapsed(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionMoreTimeElapsed(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionMoreTimeElapsed(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 > this.cycles; + int cycles = this.getWiredSettings().getIntegerParams().get(PARAM_CYCLE); + return (Emulator.getIntUnixTimestamp() - room.getLastTimerReset()) / 0.5 > cycles; } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.cycles - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - try { - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.cycles = data.cycles; - } else { - if (!wiredData.equals("")) - this.cycles = Integer.parseInt(wiredData); - } - } catch (Exception ignored) { + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); } } - @Override - public void onPickUp() { - this.cycles = 0; - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.cycles); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.cycles = settings.getIntParams()[0]; - return true; - } - - static class JsonData { - int cycles; - - public JsonData(int cycles) { - this.cycles = cycles; - } + return WiredConditionType.TIME_MORE_THAN; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java index 05feda6b..7d6c9d76 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveFurni.java @@ -1,182 +1,69 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionOperator; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_FURNI; - - private boolean all; - private final THashSet items; + public final int PARAM_ALL_FURNI = 0; public WiredConditionNotFurniHaveFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredConditionNotFurniHaveFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); + public WiredConditionNotFurniHaveFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.refresh(); - - if (this.items.isEmpty()) + if(this.getWiredSettings().getItemIds().isEmpty()) { return true; + } - if(this.all) { - return this.items.stream().allMatch(item -> { - double minZ = item.getZ() + Item.getCurrentHeight(item); - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + boolean allFurni = this.getWiredSettings().getIntegerParams().get(PARAM_ALL_FURNI) == 1; + + if(allFurni) { + return this.getWiredSettings().getItems(room).stream().allMatch(item -> { + double minZ = item.getCurrentZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().noneMatch(tile -> room.getRoomItemManager().getItemsAt(tile).stream().anyMatch(matchedItem -> { + if (matchedItem == item) return false; + return matchedItem.getCurrentZ() >= minZ; + })); }); } else { - return this.items.stream().anyMatch(item -> { - double minZ = item.getZ() + Item.getCurrentHeight(item); - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - return occupiedTiles.stream().noneMatch(tile -> room.getItemsAt(tile).stream().anyMatch(matchedItem -> matchedItem != item && matchedItem.getZ() >= minZ)); + return this.getWiredSettings().getItems(room).stream().anyMatch(item -> { + double minZ = item.getCurrentZ() + Item.getCurrentHeight(item); + THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return occupiedTiles.stream().noneMatch(tile -> room.getRoomItemManager().getItemsAt(tile).stream().anyMatch(matchedItem -> { + if (matchedItem == item) return false; + return matchedItem.getCurrentZ() >= minZ; + })); }); } } @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.all, - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.all = data.all; - - for (int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(":"); - - if (data.length >= 1) { - this.all = (data[0].equals("1")); - - if (data.length == 2) { - String[] items = data[1].split(";"); - - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); } } - @Override - public void onPickUp() { - this.all = false; - this.items.clear(); - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.all ? 1 : 0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.all = settings.getIntParams()[0] == 1; - - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - - if (item != null) - this.items.add(item); - } - - return true; - } - return false; - } - - private void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (room.getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } + return WiredConditionType.NOT_FURNI_HAVE_FURNI; } @Override @@ -185,14 +72,4 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { //return this.all ? WiredConditionOperator.AND : WiredConditionOperator.OR; return WiredConditionOperator.AND; } - - static class JsonData { - boolean all; - List itemIds; - - public JsonData(boolean all, List itemIds) { - this.all = all; - this.itemIds = itemIds; - } - } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java deleted file mode 100644 index 4410a39c..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveHabbo.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -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.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO; - - protected THashSet items; - - public WiredConditionNotFurniHaveHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - this.items = new THashSet<>(); - } - - public WiredConditionNotFurniHaveHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public void onPickUp() { - this.items.clear(); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.refresh(); - - if (this.items.isEmpty()) - return true; - - Collection habbos = room.getHabbos(); - Collection bots = room.getCurrentBots().valueCollection(); - Collection pets = room.getCurrentPets().valueCollection(); - - return this.items.stream().noneMatch(item -> { - THashSet occupiedTiles = room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || - bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())) || - pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentLocation())); - }); - } - - @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - WiredConditionFurniHaveHabbo.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class); - - for(int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(":"); - - if (data.length >= 1) { - String[] items = data[1].split(";"); - - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - - if (item != null) - this.items.add(item); - } - - return true; - } - - return false; - } - - private void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (room.getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } - } -} 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 new file mode 100644 index 00000000..bd60b14a --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniHaveRoom.java @@ -0,0 +1,50 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; +import com.eu.habbo.habbohotel.pets.Pet; +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.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; +import gnu.trove.set.hash.THashSet; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; + +public class WiredConditionNotFurniHaveRoom extends InteractionWiredCondition { + public WiredConditionNotFurniHaveRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionNotFurniHaveRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getItemIds().isEmpty()) { + return true; + } + + 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.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + return habbos.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentPosition())) || + bots.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentPosition())) || + pets.stream().anyMatch(character -> occupiedTiles.contains(character.getRoomUnit().getCurrentPosition())); + }); + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.NOT_FURNI_HAVE_HABBO; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java index 36966574..932842aa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotFurniTypeMatch.java @@ -1,161 +1,48 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS; - - private final THashSet items = new THashSet<>(); + private final THashSet items = new THashSet<>(); public WiredConditionNotFurniTypeMatch(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionNotFurniTypeMatch(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionNotFurniTypeMatch(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.refresh(); - - if(items.isEmpty()) + if(this.getWiredSettings().getItemIds().isEmpty()) { return true; - - if (stuff != null) { - if (stuff.length >= 1) { - if (stuff[0] instanceof HabboItem triggeringItem) { - return this.items.stream().noneMatch(item -> item == triggeringItem); - } - } } - return true; - } - - @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class); - - for(int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = set.getString("wired_data").split(";"); - - for (String s : data) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) { - this.items.add(item); - } - } + if(stuff.length == 0) { + return true; } - } - @Override - public void onPickUp() { - this.items.clear(); + if (stuff[0] instanceof RoomItem triggeringItem) { + return this.getWiredSettings().getItems(room).stream().noneMatch(item -> item == triggeringItem); + } + + return false; } @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); - } - } - - return true; - } - - private void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (room.getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } + return WiredConditionType.NOT_STUFF_IS; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java deleted file mode 100644 index d9fe194c..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboCount.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredConditionNotHabboCount extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.NOT_USER_COUNT; - - private int lowerLimit = 10; - private int upperLimit = 20; - - public WiredConditionNotHabboCount(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionNotHabboCount(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - int count = room.getUserCount(); - - return count < this.lowerLimit || count > this.upperLimit; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.lowerLimit, - this.upperLimit - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - WiredConditionHabboCount.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionHabboCount.JsonData.class); - this.lowerLimit = data.lowerLimit; - this.upperLimit = data.upperLimit; - } else { - String[] data = wiredData.split(":"); - this.lowerLimit = Integer.parseInt(data[0]); - this.upperLimit = Integer.parseInt(data[1]); - } - } - - @Override - public void onPickUp() { - this.upperLimit = 0; - this.lowerLimit = 20; - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.lowerLimit); - message.appendInt(this.upperLimit); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 2) return false; - this.lowerLimit = settings.getIntParams()[0]; - this.upperLimit = settings.getIntParams()[1]; - - return true; - } - - static class JsonData { - int lowerLimit; - int upperLimit; - - public JsonData(int lowerLimit, int upperLimit) { - this.lowerLimit = lowerLimit; - this.upperLimit = upperLimit; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java deleted file mode 100644 index 749245f8..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboHasEffect.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { - private static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_EFFECT; - - protected int effectId; - - public WiredConditionNotHabboHasEffect(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionNotHabboHasEffect(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) return false; - return roomUnit.getEffectId() != this.effectId; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.effectId - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.effectId = data.effectId; - } else { - this.effectId = Integer.parseInt(wiredData); - } - } - - @Override - public void onPickUp() { - this.effectId = 0; - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.effectId + ""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.effectId = settings.getIntParams()[0]; - - return true; - } - - static class JsonData { - int effectId; - - public JsonData(int effectId) { - this.effectId = effectId; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java deleted file mode 100644 index 96d293ce..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotHabboWearsBadge.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.conditions; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboBadge; -import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_BADGE; - - protected String badge = ""; - - public WiredConditionNotHabboWearsBadge(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredConditionNotHabboWearsBadge(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { - for (HabboBadge b : habbo.getInventory().getBadgesComponent().getWearingBadges()) { - if (b.getCode().equalsIgnoreCase(this.badge)) - return false; - } - } - return true; - } - - return true; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.badge - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.badge = data.badge; - } else { - this.badge = wiredData; - } - } - - @Override - public void onPickUp() { - this.badge = ""; - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.badge); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.badge = settings.getStringParam(); - - return true; - } - - static class JsonData { - String badge; - - public JsonData(String badge) { - this.badge = badge; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java index 2a6a0458..1b4450a1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInGroup.java @@ -2,74 +2,36 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionNotInGroup extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_GROUP; - public WiredConditionNotInGroup(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionNotInGroup(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionNotInGroup(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (room.getGuildId() == 0) + if (room.getRoomInfo().getGuild().getId() == 0) return false; - Habbo habbo = room.getHabbo(roomUnit); - - return habbo == null || !habbo.getHabboStats().hasGuild(room.getGuildId()); - } - - @Override - public String getWiredData() { - return ""; - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - - } - - @Override - public void onPickUp() { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + return habbo == null || !habbo.getHabboStats().hasGuild(room.getRoomInfo().getGuild().getId()); } @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - return true; + return WiredConditionType.NOT_ACTOR_IN_GROUP; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java index fdd025cf..e8ada995 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotInTeam.java @@ -3,104 +3,57 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionNotInTeam extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_IN_TEAM; - - private GameTeamColors teamColor = GameTeamColors.RED; + public final int PARAM_TEAM = 0; + private final GameTeamColors DEFAULT_TEAM = GameTeamColors.RED; public WiredConditionNotInTeam(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionNotInTeam(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionNotInTeam(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM); + + if(teamValue < 1 || teamValue > 4) { + return false; + } + + GameTeamColors teamColor = GameTeamColors.values()[teamValue]; + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { - return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); // user is not part of any team + return habbo.getHabboInfo().getGamePlayer() == null || !habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(teamColor); } return true; } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.teamColor - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - try { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.teamColor = data.teamColor; - } else { - if (!wiredData.equals("")) - this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)]; - } - } catch (Exception e) { - this.teamColor = GameTeamColors.RED; + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(DEFAULT_TEAM.type); } } - @Override - public void onPickUp() { - this.teamColor = GameTeamColors.RED; - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.teamColor.type); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]]; - - return true; - } - - static class JsonData { - GameTeamColors teamColor; - - public JsonData(GameTeamColors teamColor) { - this.teamColor = teamColor; - } + return WiredConditionType.NOT_ACTOR_IN_TEAM; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java index d6b11988..b708916e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotMatchStatePosition.java @@ -2,21 +2,20 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStatePosition { - public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT; - public WiredConditionNotMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionNotMatchStatePosition(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionNotMatchStatePosition(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -26,6 +25,6 @@ public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStat @Override public WiredConditionType getType() { - return type; + return WiredConditionType.NOT_MATCH_SSHOT; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomCount.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomCount.java new file mode 100644 index 00000000..6c9260c4 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomCount.java @@ -0,0 +1,30 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredConditionNotRoomCount extends WiredConditionRoomCount { + public WiredConditionNotRoomCount(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionNotRoomCount(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + return !super.execute(roomUnit, room, stuff); + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.NOT_USER_COUNT; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomHasEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomHasEffect.java new file mode 100644 index 00000000..185eff52 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomHasEffect.java @@ -0,0 +1,30 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredConditionNotRoomHasEffect extends WiredConditionRoomHasEffect { + public WiredConditionNotRoomHasEffect(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionNotRoomHasEffect(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + return !super.execute(roomUnit, room, stuff); + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.NOT_ACTOR_WEARS_EFFECT; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomWearsBadge.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomWearsBadge.java new file mode 100644 index 00000000..c58c97c2 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotRoomWearsBadge.java @@ -0,0 +1,34 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredConditionNotRoomWearsBadge extends WiredConditionRoomWearsBadge { + public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_WEARS_BADGE; + + protected String badge = ""; + + public WiredConditionNotRoomWearsBadge(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionNotRoomWearsBadge(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + return !super.execute(roomUnit, room, stuff); + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.NOT_ACTOR_WEARS_BADGE; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java index 21ea027e..322a82d9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionNotTriggerOnFurni.java @@ -2,7 +2,8 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; import java.sql.ResultSet; @@ -15,21 +16,13 @@ public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurn super(set, baseItem); } - public WiredConditionNotTriggerOnFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionNotTriggerOnFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) - return false; - - this.refresh(); - - if (this.items.isEmpty()) - return true; - - return !triggerOnFurni(roomUnit, room); + return !super.execute(roomUnit, room, stuff); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomCount.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomCount.java new file mode 100644 index 00000000..bd80c4a8 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomCount.java @@ -0,0 +1,46 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredConditionRoomCount extends InteractionWiredCondition { + public final int PARAM_LOWER_LIMIT = 0; + public final int PARAM_UPPER_LIMIT = 1; + + public WiredConditionRoomCount(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionRoomCount(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + int lowerLimit = this.getWiredSettings().getIntegerParams().get(PARAM_LOWER_LIMIT); + int upperLimit = this.getWiredSettings().getIntegerParams().get(PARAM_UPPER_LIMIT); + int userCount = room.getRoomUnitManager().getRoomHabbosCount(); + + return userCount >= lowerLimit && userCount <= upperLimit; + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); + } + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.USER_COUNT; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomHasEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomHasEffect.java new file mode 100644 index 00000000..63d97b87 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomHasEffect.java @@ -0,0 +1,47 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredConditionRoomHasEffect extends InteractionWiredCondition { + public final int PARAM_EFFECT_ID = 0; + + public WiredConditionRoomHasEffect(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionRoomHasEffect(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if (roomUnit == null || !(roomUnit instanceof RoomAvatar roomAvatar)) { + return false; + } + + int effectId = this.getWiredSettings().getIntegerParams().get(PARAM_EFFECT_ID); + + return roomAvatar.getEffectId() == effectId; + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + } + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.ACTOR_WEARS_EFFECT; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomHasHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomHasHandItem.java new file mode 100644 index 00000000..7cbcd262 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomHasHandItem.java @@ -0,0 +1,49 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; +import lombok.extern.slf4j.Slf4j; + +import java.sql.ResultSet; +import java.sql.SQLException; + +@Slf4j +public class WiredConditionRoomHasHandItem extends InteractionWiredCondition { + public final int PARAM_HAND_ITEM_ID = 0; + + public WiredConditionRoomHasHandItem(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionRoomHasHandItem(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if (!(roomUnit instanceof RoomAvatar roomAvatar)) { + return false; + } + + int handItemId = this.getWiredSettings().getIntegerParams().get(PARAM_HAND_ITEM_ID); + + return roomAvatar.getHandItem() == handItemId; + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + } + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.ACTOR_HAS_HANDITEM; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomWearsBadge.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomWearsBadge.java new file mode 100644 index 00000000..415a4c3e --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionRoomWearsBadge.java @@ -0,0 +1,52 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.conditions; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboBadge; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredConditionType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredConditionRoomWearsBadge extends InteractionWiredCondition { + public WiredConditionRoomWearsBadge(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredConditionRoomWearsBadge(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getStringParam().isEmpty()) { + return true; + } + + String badgeCode = this.getWiredSettings().getStringParam(); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if(habbo == null) { + return false; + } + + synchronized (habbo.getInventory().getBadgesComponent().getWearingBadges()) { + for (HabboBadge badge : habbo.getInventory().getBadgesComponent().getWearingBadges()) { + if (badge.getCode().equalsIgnoreCase(badgeCode)) { + return true; + } + } + } + + return false; + } + + @Override + public WiredConditionType getType() { + return WiredConditionType.ACTOR_WEARS_BADGE; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java index d78a616b..fe4763a2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTeamMember.java @@ -3,37 +3,42 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredConditionTeamMember extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.ACTOR_IN_TEAM; - - private GameTeamColors teamColor = GameTeamColors.RED; + public final int PARAM_TEAM = 0; + private final GameTeamColors DEFAULT_TEAM = GameTeamColors.RED; public WiredConditionTeamMember(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionTeamMember(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionTeamMember(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM); + + if(teamValue < 1 || teamValue > 4) { + return false; + } + + GameTeamColors teamColor = GameTeamColors.values()[teamValue]; + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { if (habbo.getHabboInfo().getGamePlayer() != null) { - return habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(this.teamColor); + return habbo.getHabboInfo().getGamePlayer().getTeamColor().equals(teamColor); } } @@ -41,68 +46,16 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.teamColor - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - try { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.teamColor = data.teamColor; - } else { - if (!wiredData.equals("")) - this.teamColor = GameTeamColors.values()[Integer.parseInt(wiredData)]; - } - } catch (Exception e) { - this.teamColor = GameTeamColors.RED; + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(DEFAULT_TEAM.type); } } - @Override - public void onPickUp() { - this.teamColor = GameTeamColors.RED; - } - @Override public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.teamColor.type); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.teamColor = GameTeamColors.values()[settings.getIntParams()[0]]; - - return true; - } - - static class JsonData { - GameTeamColors teamColor; - - public JsonData(GameTeamColors teamColor) { - this.teamColor = teamColor; - } + return WiredConditionType.ACTOR_IN_TEAM; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java index a8d9aae7..92a564a3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java @@ -1,157 +1,39 @@ package com.eu.habbo.habbohotel.items.interactions.wired.conditions; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredConditionOperator; import com.eu.habbo.habbohotel.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { - public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI; - - protected THashSet items = new THashSet<>(); - public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredConditionTriggerOnFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredConditionTriggerOnFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) + if(this.getWiredSettings().getItemIds().isEmpty()) { + return true; + } + + if(roomUnit == null) { return false; - - this.refresh(); - - if (this.items.isEmpty()) - return false; - - return triggerOnFurni(roomUnit, room); - } - - protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) { - THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); - return this.items.stream().anyMatch(itemsAtUser::contains); - } - - @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - - for(int id : data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(";"); - - for (String s : data) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) { - this.items.add(item); - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - } - - @Override - public WiredConditionType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.items.clear(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null) { - for (int i = 0; i < count; i++) { - HabboItem item = room.getHabboItem(settings.getFurniIds()[i]); - - if (item != null) { - this.items.add(item); - } - } } - return true; - } - - protected void refresh() { - THashSet items = new THashSet<>(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (item.getRoomId() != room.getId()) - items.add(item); - } - } - - this.items.removeAll(items); + THashSet itemsAtUser = room.getRoomItemManager().getItemsAt(roomUnit.getCurrentPosition()); + return this.getWiredSettings().getItems(room).stream().anyMatch(itemsAtUser::contains); } @Override @@ -159,11 +41,8 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { return WiredConditionOperator.AND; } - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } + @Override + public WiredConditionType getType() { + return WiredConditionType.TRIGGER_ON_FURNI; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java index 14e83480..7455518f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectAlert.java @@ -3,8 +3,9 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,16 +15,16 @@ public class WiredEffectAlert extends WiredEffectWhisper { super(set, baseItem); } - public WiredEffectAlert(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectAlert(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { - habbo.alert(this.message + habbo.alert(this.getWiredSettings().getStringParam() .replace("%online%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "") .replace("%username%", habbo.getHabboInfo().getUsername()) .replace("%roomsloaded%", Emulator.getGameEnvironment().getRoomManager().loadedRoomsCount() + "")); 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 b0e1ff48..cef31e8d 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 @@ -2,152 +2,47 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import java.util.regex.Pattern; public class WiredEffectBotClothes extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_CLOTHES; - - private String botName = ""; - private String botLook = ""; - public WiredEffectBotClothes(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectBotClothes(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectBotClothes(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName + ((char) 9) + "" + this.botLook); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + String[] stringParams = this.getWiredSettings().getStringParam().split("\t"); - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - String dataString = settings.getStringParam(); - int delay = settings.getDelay(); + String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + String botLook = stringParams[1]; - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); + List bots = room.getRoomUnitManager().getBotsByName(botName); - String splitBy = "\t"; - if(!dataString.contains(splitBy)) - throw new WiredSaveException("Malformed data string"); + if(bots.size() == 0) { + return false; + } - String[] data = dataString.split(Pattern.quote(splitBy)); - - if (data.length != 2) - throw new WiredSaveException("Malformed data string. Invalid data length"); - - this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.botLook = data[1]; - this.setDelay(delay); + Bot bot = bots.get(0); + bot.setFigure(botLook); return true; } @Override public WiredEffectType getType() { - return type; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - List bots = room.getBots(this.botName); - - if (bots.size() == 1) { - Bot bot = bots.get(0); - bot.setFigure(this.botLook); - } - - return true; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.botLook, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.botName = data.bot_name; - this.botLook = data.look; - } - else { - String[] data = wiredData.split(((char) 9) + ""); - - if (data.length >= 3) { - this.setDelay(Integer.parseInt(data[0])); - this.botName = data[1]; - this.botLook = data[2]; - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.botLook = ""; - this.botName = ""; - this.setDelay(0); - } - - public String getBotName() { - return this.botName; - } - - public void setBotName(String botName) { - this.botName = botName; - } - - public String getBotLook() { - return this.botLook; - } - - public void setBotLook(String botLook) { - this.botLook = botLook; - } - - static class JsonData { - String bot_name; - String look; - int delay; - - public JsonData(String bot_name, String look, int delay) { - this.bot_name = bot_name; - this.look = look; - this.delay = delay; - } + return WiredEffectType.BOT_CLOTHES; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java deleted file mode 100644 index 5d8d17c9..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.effects; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_FOLLOW_AVATAR; - - private String botName = ""; - private int mode = 0; - - public WiredEffectBotFollowHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredEffectBotFollowHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName); - message.appendInt(1); - message.appendInt(this.mode); - message.appendInt(1); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Mode is invalid"); - - int mode = settings.getIntParams()[0]; - - if(mode != 0 && mode != 1) - throw new WiredSaveException("Mode is invalid"); - - String botName = settings.getStringParam().replace("\t", ""); - botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.botName = botName; - this.mode = mode; - this.setDelay(delay); - - return true; - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - List bots = room.getBots(this.botName); - - if (habbo != null && bots.size() == 1) { - Bot bot = bots.get(0); - - if (this.mode == 1) { - bot.startFollowingHabbo(habbo); - } else { - bot.stopFollowingHabbo(); - } - - return true; - } - - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.mode = data.mode; - this.botName = data.bot_name; - } - else { - String[] data = wiredData.split(((char) 9) + ""); - - if (data.length == 3) { - this.setDelay(Integer.parseInt(data[0])); - this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0); - this.botName = data[2]; - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.botName = ""; - this.mode = 0; - this.setDelay(0); - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - String bot_name; - int mode; - int delay; - - public JsonData(String bot_name, int mode, int delay) { - this.bot_name = bot_name; - this.mode = mode; - this.delay = delay; - } - } -} 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 new file mode 100644 index 00000000..f7f29026 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowRoom.java @@ -0,0 +1,61 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.effects; + +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.InteractionWiredEffect; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.threading.runnables.BotFollowHabbo; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class WiredEffectBotFollowRoom extends InteractionWiredEffect { + public final int PARAM_MODE = 0; + + public WiredEffectBotFollowRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredEffectBotFollowRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + List bots = room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()); + + if (habbo != null && bots.size() == 1) { + Bot bot = bots.get(0); + + if (this.getWiredSettings().getIntegerParams().get(PARAM_MODE) == 1) { + bot.setFollowingHabboId(habbo.getHabboInfo().getId()); + Emulator.getThreading().run(new BotFollowHabbo(bot, habbo, habbo.getRoomUnit().getRoom())); + } else { + bot.setFollowingHabboId(0); + } + + return true; + } + + return false; + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + } + } + + @Override + public WiredEffectType getType() { + return WiredEffectType.BOT_FOLLOW_AVATAR; + } +} 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 c82b0eda..9fd302a5 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 @@ -2,19 +2,17 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.threading.runnables.RoomUnitGiveHanditem; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; @@ -24,102 +22,46 @@ import java.util.ArrayList; import java.util.List; public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_GIVE_HANDITEM; - - private String botName = ""; - private int itemId; - + public final int PARAM_ITEM_ID = 0; public WiredEffectBotGiveHandItem(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectBotGiveHandItem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName); - message.appendInt(1); - message.appendInt(this.itemId); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Missing item id"); - - int itemId = settings.getIntParams()[0]; - - if(itemId < 0) - itemId = 0; - - String botName = settings.getStringParam(); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.itemId = itemId; - this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.setDelay(delay); - - return true; - } - - @Override - public WiredEffectType getType() { - return type; + public WiredEffectBotGiveHandItem(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - List bots = room.getBots(this.botName); + if(!(roomUnit instanceof RoomAvatar roomAvatar)) { + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar); + List bots = room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()); + int itemId = this.getWiredSettings().getIntegerParams().get(PARAM_ITEM_ID); if (habbo != null && bots.size() == 1) { Bot bot = bots.get(0); List tasks = new ArrayList<>(); - tasks.add(new RoomUnitGiveHanditem(roomUnit, room, this.itemId)); + tasks.add(new RoomUnitGiveHanditem(roomAvatar, room, itemId)); tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0)); tasks.add(() -> { - if(roomUnit.getRoom() != null && roomUnit.getRoom().getId() == room.getId() && roomUnit.getCurrentLocation().distance(bot.getRoomUnit().getCurrentLocation()) < 2) { - WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{}); + if(roomAvatar.getRoom() != null) { + if (roomAvatar.getRoom().getRoomInfo().getId() == room.getRoomInfo().getId() && roomAvatar.getCurrentPosition().distance(bot.getRoomUnit().getCurrentPosition()) < 2) { + WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{}); + } } }); - RoomTile tile = bot.getRoomUnit().getClosestAdjacentTile(roomUnit.getX(), roomUnit.getY(), true); + RoomTile tile = bot.getRoomUnit().getClosestAdjacentTile(roomAvatar.getCurrentPosition().getX(), roomAvatar.getCurrentPosition().getY(), true); if(tile != null) { - bot.getRoomUnit().setGoalLocation(tile); + bot.getRoomUnit().walkTo(tile); } - Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId)); + Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, itemId)); Emulator.getThreading().run(new RoomUnitWalkToLocation(bot.getRoomUnit(), tile, room, tasks, tasks)); return true; @@ -129,54 +71,14 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.itemId, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.itemId = data.item_id; - this.botName = data.bot_name; - } - else { - String[] data = wiredData.split(((char) 9) + ""); - - if (data.length == 3) { - this.setDelay(Integer.parseInt(data[0])); - this.itemId = Integer.parseInt(data[1]); - this.botName = data[2]; - } - - this.needsUpdate(true); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); } } @Override - public void onPickUp() { - this.botName = ""; - this.itemId = 0; - this.setDelay(0); - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - String bot_name; - int item_id; - int delay; - - public JsonData(String bot_name, int item_id, int delay) { - this.bot_name = bot_name; - this.item_id = item_id; - this.delay = delay; - } + public WiredEffectType getType() { + return WiredEffectType.BOT_GIVE_HANDITEM; } } 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 11681d45..8377b39c 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 @@ -2,117 +2,59 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import java.util.regex.Pattern; public class WiredEffectBotTalk extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_TALK; - - private int mode; - private String botName = ""; - private String message = ""; + public final int PARAM_MODE = 0; public WiredEffectBotTalk(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectBotTalk(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName + "" + ((char) 9) + "" + this.message); - message.appendInt(1); - message.appendInt(this.mode); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Mode is invalid"); - int mode = settings.getIntParams()[0]; - - if(mode != 0 && mode != 1) - throw new WiredSaveException("Mode is invalid"); - - String dataString = settings.getStringParam(); - - String splitBy = "\t"; - if(!dataString.contains(splitBy)) - throw new WiredSaveException("Malformed data string"); - - String[] data = dataString.split(Pattern.quote(splitBy)); - - if (data.length != 2) - throw new WiredSaveException("Malformed data string. Invalid data length"); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.setDelay(delay); - this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.mode = mode; - - return true; - } - - @Override - public WiredEffectType getType() { - return type; + public WiredEffectBotTalk(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - String message = this.message; + String[] stringParams = this.getWiredSettings().getStringParam().split("\t"); - Habbo habbo = room.getHabbo(roomUnit); + String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + String message = stringParams[1].substring(0, Math.min(stringParams[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { message = message.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername()) .replace(Emulator.getTexts().getValue("wired.variable.credits", "%credits%"), habbo.getHabboInfo().getCredits() + "") .replace(Emulator.getTexts().getValue("wired.variable.pixels", "%pixels%"), habbo.getHabboInfo().getPixels() + "") .replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "") - .replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getOwnerName()) - .replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.itemCount() + "") - .replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.botName) - .replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getName()) - .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getUserCount() + ""); + .replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getRoomInfo().getOwnerInfo().getUsername()) + .replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.getRoomItemManager().getCurrentItems().size() + "") + .replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), botName) + .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.getBots(this.botName); + List bots = room.getRoomUnitManager().getBotsByName(botName); if (bots.size() == 1) { Bot bot = bots.get(0); if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) { - if (this.mode == 1) { + if (this.getWiredSettings().getIntegerParams().get(PARAM_MODE) == 1) { bot.shout(message); } else { bot.talk(message); @@ -124,83 +66,19 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.mode = data.mode; - this.botName = data.bot_name; - this.message = data.message; - } - else { - String[] data = wiredData.split(((char) 9) + ""); - - if (data.length == 4) { - this.setDelay(Integer.parseInt(data[0])); - this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0; - this.botName = data[2]; - this.message = data[3]; - } - - this.needsUpdate(true); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(0); } } @Override - public void onPickUp() { - this.mode = 0; - this.botName = ""; - this.message = ""; - this.setDelay(0); - } - - public int getMode() { - return this.mode; - } - - public void setMode(int mode) { - this.mode = mode; - } - - public String getBotName() { - return this.botName; - } - - public void setBotName(String botName) { - this.botName = botName; - } - - public String getMessage() { - return this.message; - } - - public void setMessage(String message) { - this.message = message; + public WiredEffectType getType() { + return WiredEffectType.BOT_TALK; } @Override protected long requiredCooldown() { return 500; } - - static class JsonData { - String bot_name; - int mode; - String message; - int delay; - - public JsonData(String bot_name, int mode, String message, int delay) { - this.bot_name = bot_name; - this.mode = mode; - this.message = message; - this.delay = delay; - } - } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java deleted file mode 100644 index 2c3b0698..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.effects; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_TALK_TO_AVATAR; - - private int mode; - private String botName = ""; - private String message = ""; - - public WiredEffectBotTalkToHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredEffectBotTalkToHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName + "" + ((char) 9) + "" + this.message); - message.appendInt(1); - message.appendInt(this.mode); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("Missing mode"); - int mode = settings.getIntParams()[0]; - - if(mode != 0 && mode != 1) - throw new WiredSaveException("Mode is invalid"); - - String dataString = settings.getStringParam(); - String splitBy = "\t"; - if(!dataString.contains(splitBy)) - throw new WiredSaveException("Malformed data string"); - - String[] data = dataString.split(Pattern.quote(splitBy)); - - if (data.length != 2) - throw new WiredSaveException("Malformed data string. Invalid data length"); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.botName = data[0].substring(0, Math.min(data[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.message = data[1].substring(0, Math.min(data[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.mode = mode; - this.setDelay(delay); - - return true; - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - String m = this.message; - m = m.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername()) - .replace(Emulator.getTexts().getValue("wired.variable.credits", "%credits%"), habbo.getHabboInfo().getCredits() + "") - .replace(Emulator.getTexts().getValue("wired.variable.pixels", "%pixels%"), habbo.getHabboInfo().getPixels() + "") - .replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "") - .replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getOwnerName()) - .replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.itemCount() + "") - .replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.botName) - .replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), room.getName()) - .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), room.getUserCount() + ""); - - List bots = room.getBots(this.botName); - - if (bots.size() != 1) { - return false; - } - - Bot bot = bots.get(0); - - if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ m })) { - if (this.mode == 1) { - bot.whisper(m, habbo); - } else { - bot.talk(habbo.getHabboInfo().getUsername() + ": " + m); - } - } - - return true; - } - - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.mode = data.mode; - this.botName = data.bot_name; - this.message = data.message; - } - else { - String[] data = wiredData.split(((char) 9) + ""); - - if (data.length == 4) { - this.setDelay(Integer.parseInt(data[0])); - this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0; - this.botName = data[2]; - this.message = data[3]; - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.botName = ""; - this.message = ""; - this.mode = 0; - this.setDelay(0); - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - String bot_name; - int mode; - String message; - int delay; - - public JsonData(String bot_name, int mode, String message, int delay) { - this.bot_name = bot_name; - this.mode = mode; - this.message = message; - this.delay = delay; - } - } -} 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 new file mode 100644 index 00000000..a74dd952 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToRoom.java @@ -0,0 +1,83 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.effects; + +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.InteractionWiredEffect; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class WiredEffectBotTalkToRoom extends InteractionWiredEffect { + public final int PARAM_MODE = 0; + + public WiredEffectBotTalkToRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredEffectBotTalkToRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + String[] stringParams = this.getWiredSettings().getStringParam().split("\t"); + + String botName = stringParams[0].substring(0, Math.min(stringParams[0].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + String message = stringParams[1].substring(0, Math.min(stringParams[1].length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo != null) { + message = message.replace(Emulator.getTexts().getValue("wired.variable.username", "%username%"), habbo.getHabboInfo().getUsername()) + .replace(Emulator.getTexts().getValue("wired.variable.credits", "%credits%"), habbo.getHabboInfo().getCredits() + "") + .replace(Emulator.getTexts().getValue("wired.variable.pixels", "%pixels%"), habbo.getHabboInfo().getPixels() + "") + .replace(Emulator.getTexts().getValue("wired.variable.points", "%points%"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "") + .replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), room.getRoomInfo().getOwnerInfo().getUsername()) + .replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), room.getRoomItemManager().getCurrentItems().size() + "") + .replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), botName) + .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); + + if (bots.size() != 1) { + return false; + } + + Bot bot = bots.get(0); + + if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, bot.getRoomUnit(), room, new Object[]{ message })) { + if (this.getWiredSettings().getIntegerParams().get(PARAM_MODE) == 1) { + bot.whisper(message, habbo); + } else { + bot.talk(habbo.getHabboInfo().getUsername() + ": " + message); + } + } + + return true; + } + + return false; + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(0); + } + } + + @Override + public WiredEffectType getType() { + return WiredEffectType.BOT_TALK_TO_AVATAR; + } +} 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 69be9e5e..7c2d7607 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 @@ -2,63 +2,84 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTileState; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +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.types.RoomBot; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer; import com.eu.habbo.threading.runnables.RoomUnitTeleport; import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; public class WiredEffectBotTeleport extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_TELEPORT; - - private THashSet items; - private String botName = ""; - public WiredEffectBotTeleport(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredEffectBotTeleport(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); + public WiredEffectBotTeleport(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; + } + + String botName = this.getWiredSettings().getStringParam(); + List bots = room.getRoomUnitManager().getBotsByName(botName); + + if (bots.size() == 0) { + return false; + } + + Bot bot = bots.get(0); + + int i = Emulator.getRandom().nextInt(this.getWiredSettings().getItemIds().size()) + 1; + int j = 1; + + for (RoomItem item : this.getWiredSettings().getItems(room)) { + if (item.getRoomId() != 0) { + Room room1 = bot.getRoomUnit().getRoom(); + if (item.getRoomId() == room1.getRoomInfo().getId()) { + if (i == j) { + teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); + return true; + } else { + j++; + } + } + } + } + + return true; } public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) { - if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting()) + if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting() || !(roomUnit instanceof RoomBot roomBot)) return; - Room room = roomUnit.getRoom(); + Room room = roomBot.getRoom(); if (room == null) { return; } - // makes a temporary effect + room.sendComposer(new AvatarEffectMessageComposer(roomBot, 4).compose()); + Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomBot), (long) WiredHandler.TELEPORT_DELAY + 1000); - roomUnit.getRoom().unIdle(roomUnit.getRoom().getHabbo(roomUnit)); - room.sendComposer(new AvatarEffectMessageComposer(roomUnit, 4).compose()); - Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), (long) WiredHandler.TELEPORT_DELAY + 1000); - - if (tile == roomUnit.getCurrentLocation()) { + if (tile == roomBot.getCurrentPosition()) { return; } @@ -79,180 +100,12 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { } } - Emulator.getThreading().run(() -> roomUnit.setWiredTeleporting(true), Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); - Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - String botName = settings.getStringParam(); - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.setDelay(delay); - - return true; + Emulator.getThreading().run(() -> roomBot.setWiredTeleporting(true), Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); + Emulator.getThreading().run(new RoomUnitTeleport(roomBot, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomBot.getEffectId()), WiredHandler.TELEPORT_DELAY); } @Override public WiredEffectType getType() { - return type; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (this.items.isEmpty()) - return false; - - List bots = room.getBots(this.botName); - - if (bots.size() != 1) { - return false; - } - - Bot bot = bots.get(0); - - int i = Emulator.getRandom().nextInt(this.items.size()) + 1; - int j = 1; - - for (HabboItem item : this.items) { - if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) { - if (i == j) { - teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY())); - return true; - } else { - j++; - } - } - } - - return true; - } - - @Override - public String getWiredData() { - ArrayList itemIds = new ArrayList<>(); - - if (this.items != null) { - for (HabboItem item : this.items) { - if (item.getRoomId() != 0) { - itemIds.add(item.getId()); - } - } - } - - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new THashSet<>(); - - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.botName = data.bot_name; - - for(int itemId : data.items) { - HabboItem item = room.getHabboItem(itemId); - - if (item != null) - this.items.add(item); - } - } - else { - String[] wiredDataSplit = set.getString("wired_data").split("\t"); - - if (wiredDataSplit.length >= 2) { - this.setDelay(Integer.parseInt(wiredDataSplit[0])); - String[] data = wiredDataSplit[1].split(";"); - - if (data.length > 1) { - this.botName = data[0]; - - for (int i = 1; i < data.length; i++) { - HabboItem item = room.getHabboItem(Integer.parseInt(data[i])); - - if (item != null) - this.items.add(item); - } - } - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.botName = ""; - this.items.clear(); - this.setDelay(0); - } - - static class JsonData { - String bot_name; - List items; - int delay; - - public JsonData(String bot_name, List items, int delay) { - this.bot_name = bot_name; - this.items = items; - this.delay = delay; - } + return WiredEffectType.BOT_TELEPORT; } } 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 c1b4da34..07f50e2c 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 @@ -2,209 +2,70 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.BOT_MOVE; - - private List items; - private String botName = ""; - public WiredEffectBotWalkToFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new ArrayList<>(); } - public WiredEffectBotWalkToFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new ArrayList<>(); + public WiredEffectBotWalkToFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; } - for (HabboItem item : items) { - this.items.remove(item); + String botName = this.getWiredSettings().getStringParam(); + List bots = room.getRoomUnitManager().getBotsByName(botName); + + if (bots.size() == 0) { + return false; } - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); + Bot bot = bots.get(0); + this.getWiredSettings().getItems(room).removeIf(item -> { + if (item == null || item.getRoomId() != this.getRoomId()) return true; + Room room1 = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); + return room1.getRoomItemManager().getRoomItemById(item.getId()) == null; + }); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } + // Bots shouldn't walk to the tile they are already standing on + List possibleItems = this.getWiredSettings().getItems(room).stream() + .filter(item -> !room.getBotsOnItem(item).contains(bot)) + .collect(Collectors.toList()); - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - String botName = settings.getStringParam(); - int itemsCount = settings.getFurniIds().length; + // Get a random tile of possible tiles to walk to + if (possibleItems.size() > 0) { + RoomItem item = possibleItems.get(Emulator.getRandom().nextInt(possibleItems.size())); - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); + if (item.getRoomId() != 0) { + Room room1 = bot.getRoomUnit().getRoom(); + if (item.getRoomId() == room1.getRoomInfo().getId()) { + bot.getRoomUnit().walkTo(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); + } + } } - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.botName = botName.substring(0, Math.min(botName.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.setDelay(delay); - return true; } @Override public WiredEffectType getType() { - return type; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - List bots = room.getBots(this.botName); - - if (this.items.isEmpty() || bots.size() != 1) { - return true; - } - - Bot bot = bots.get(0); - this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); - - // Bots shouldn't walk to the tile they are already standing on - List possibleItems = this.items.stream() - .filter(item -> !room.getBotsOnItem(item).contains(bot)) - .collect(Collectors.toList()); - - // Get a random tile of possible tiles to walk to - if (possibleItems.size() > 0) { - HabboItem item = possibleItems.get(Emulator.getRandom().nextInt(possibleItems.size())); - - if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) { - bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY())); - } - } - - return true; - } - - @Override - public String getWiredData() { - ArrayList itemIds = new ArrayList<>(); - - if (this.items != null) { - for (HabboItem item : this.items) { - if (item.getRoomId() != 0) { - itemIds.add(item.getId()); - } - } - } - - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new ArrayList<>(); - - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.botName = data.bot_name; - - for(int itemId : data.items) { - HabboItem item = room.getHabboItem(itemId); - - if (item != null) - this.items.add(item); - } - } - else { - String[] wiredDataSplit = set.getString("wired_data").split("\t"); - - if (wiredDataSplit.length >= 2) { - this.setDelay(Integer.parseInt(wiredDataSplit[0])); - String[] data = wiredDataSplit[1].split(";"); - - if (data.length > 1) { - this.botName = data[0]; - - for (int i = 1; i < data.length; i++) { - HabboItem item = room.getHabboItem(Integer.parseInt(data[i])); - - if (item != null) - this.items.add(item); - } - } - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.botName = ""; - this.setDelay(0); - } - - static class JsonData { - String bot_name; - List items; - int delay; - - public JsonData(String bot_name, List items, int delay) { - this.bot_name = bot_name; - this.items = items; - this.delay = delay; - } + return WiredEffectType.BOT_MOVE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index c0383efb..91e4b76a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -1,29 +1,30 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +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.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; -import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.HashMap; public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { + public final int PARAM_START_DIRECTION = 0; + public final int PARAM_BLOCKED_ACTION = 1; public static final int ACTION_WAIT = 0; public static final int ACTION_TURN_RIGHT_45 = 1; public static final int ACTION_TURN_RIGHT_90 = 2; @@ -32,83 +33,102 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { public static final int ACTION_TURN_BACK = 5; public static final int ACTION_TURN_RANDOM = 6; - public static final WiredEffectType type = WiredEffectType.MOVE_DIRECTION; + private int defaultDirectionValue; - private final THashMap items = new THashMap<>(0); - private RoomUserRotation startRotation = RoomUserRotation.NORTH; - private int blockedAction = 0; + private int defaultBlockActionValue; + + private boolean requiresUpdate = false; + private final HashMap itemsSettings; public WiredEffectChangeFurniDirection(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); + this.itemsSettings = new HashMap<>(); } - public WiredEffectChangeFurniDirection(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectChangeFurniDirection(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + this.itemsSettings = new HashMap<>(); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items.keySet()) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; } - for (HabboItem item : items) { - this.items.remove(item); + int startDirectionValue = this.getWiredSettings().getIntegerParams().get(PARAM_START_DIRECTION); + int blockActionValue = this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION); + + if(startDirectionValue < 0 || startDirectionValue > 7 || (startDirectionValue % 2) != 0) { + return false; } - if (this.items.isEmpty()) return false; + if(blockActionValue < 0 || blockActionValue > 6) { + return false; + } - for (Map.Entry entry : this.items.entrySet()) { - HabboItem item = entry.getKey(); - RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().getDirection().getValue()); + if(this.defaultDirectionValue != startDirectionValue) { + this.defaultDirectionValue = startDirectionValue; + this.requiresUpdate = true; + } + RoomRotation startDirection = RoomRotation.fromValue(startDirectionValue); + + if(this.requiresUpdate) { + for (WiredChangeDirectionSetting setting : this.itemsSettings.values()) { + setting.setDirection(startDirection); + } + this.requiresUpdate = false; + } + + for(RoomItem item : this.getWiredSettings().getItems(room)) { + WiredChangeDirectionSetting setting = this.itemsSettings.computeIfAbsent(item, k -> + new WiredChangeDirectionSetting(item.getId(), item.getRotation(), startDirection) + ); + + RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), setting.getDirection().getValue()); int count = 1; - while ((targetTile == null || targetTile.getState() == RoomTileState.INVALID || room.furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) { - entry.getValue().setDirection(this.nextRotation(entry.getValue().getDirection())); + while ((targetTile == null || targetTile.getState() == RoomTileState.INVALID || !room.getLayout().tileWalkable(targetTile) || room.getRoomItemManager().furnitureFitsAt(targetTile, item, item.getRotation(), false) != FurnitureMovementError.NONE) && count < 8) { + setting.setDirection(this.nextDirection(setting.getDirection())); - RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), entry.getValue().getDirection().getValue()); + RoomTile tile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), setting.getDirection().getValue()); if (tile != null && tile.getState() != RoomTileState.INVALID) { targetTile = tile; } count++; } - } - for (Map.Entry entry : this.items.entrySet()) { - HabboItem item = entry.getKey(); - int newDirection = entry.getValue().getDirection().getValue(); + int newDirectionValue = setting.getDirection().getValue(); - RoomTile targetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), newDirection); + RoomTile newTargetTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), newDirectionValue); - if(item.getRotation() != entry.getValue().getRotation()) { - if(room.furnitureFitsAt(targetTile, item, entry.getValue().getRotation(), false) != FurnitureMovementError.NONE) + if(item.getRotation() != setting.getRotation()) { + if(room.getRoomItemManager().furnitureFitsAt(newTargetTile, item, setting.getRotation(), false) != FurnitureMovementError.NONE) continue; - room.moveFurniTo(entry.getKey(), targetTile, entry.getValue().getRotation(), null, true); + room.getRoomItemManager().moveItemTo(item, newTargetTile, setting.getRotation(), null, true, true); } boolean hasRoomUnits = false; - THashSet newOccupiedTiles = room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + + THashSet newOccupiedTiles = room.getLayout().getTilesAt(newTargetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); for(RoomTile tile : newOccupiedTiles) { - for (RoomUnit _roomUnit : room.getRoomUnits(tile)) { + for (RoomUnit _roomUnit : room.getRoomUnitManager().getRoomUnitsAt(tile)) { hasRoomUnits = true; - if(_roomUnit.getCurrentLocation() == targetTile) { - Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{entry.getKey()})); + if(_roomUnit.getCurrentPosition() == newTargetTile) { + Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, _roomUnit, room, new Object[]{item})); break; } } } - if (targetTile != null && targetTile.getState() != RoomTileState.INVALID && room.furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) { + if (newTargetTile != null && newTargetTile.getState() != RoomTileState.INVALID && room.getRoomItemManager().furnitureFitsAt(targetTile, item, item.getRotation(), false) == FurnitureMovementError.NONE) { if (!hasRoomUnits) { - RoomTile oldLocation = room.getLayout().getTile(entry.getKey().getX(), entry.getKey().getY()); - double oldZ = entry.getKey().getZ(); - if(room.moveFurniTo(entry.getKey(), targetTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) { - room.sendComposer(new FloorItemOnRollerComposer(entry.getKey(), null, oldLocation, oldZ, targetTile, entry.getKey().getZ(), 0, room).compose()); + RoomTile oldLocation = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + double oldZ = item.getCurrentZ(); + if (room.getRoomItemManager().moveItemTo(item, newTargetTile, item.getRotation(), null, false, true) == FurnitureMovementError.NONE) { + room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, targetTile, item.getCurrentZ(), 0, room).compose()); } } } @@ -118,161 +138,23 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { } @Override - public String getWiredData() { - ArrayList settings = new ArrayList<>(this.items.values()); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - - this.items.clear(); - - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.startRotation = data.start_direction; - this.blockedAction = data.blocked_action; - - for(WiredChangeDirectionSetting setting : data.items) { - HabboItem item = room.getHabboItem(setting.getItem_id()); - - if (item != null) { - this.items.put(item, setting); - } - } - } - else { - String[] data = wiredData.split("\t"); - - if (data.length >= 4) { - this.setDelay(Integer.parseInt(data[0])); - this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1])); - this.blockedAction = Integer.parseInt(data[2]); - - int itemCount = Integer.parseInt(data[3]); - - if (itemCount > 0) { - for (int i = 4; i < data.length; i++) { - String[] subData = data[i].split(":"); - - if (subData.length >= 2) { - HabboItem item = room.getHabboItem(Integer.parseInt(subData[0])); - - if (item != null) { - int rotation = item.getRotation(); - - if (subData.length > 2) { - rotation = Integer.parseInt(subData[2]); - } - - this.items.put(item, new WiredChangeDirectionSetting(item.getId(), rotation, RoomUserRotation.fromValue(Integer.parseInt(subData[1])))); - } - } - } - } - } - - this.needsUpdate(true); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); } } - @Override - public void onPickUp() { - this.setDelay(0); - this.items.clear(); - this.blockedAction = 0; - this.startRotation = RoomUserRotation.NORTH; - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (Map.Entry item : this.items.entrySet()) { - message.appendInt(item.getKey().getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.startRotation != null ? this.startRotation.getValue() : 0); - message.appendInt(this.blockedAction); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 2) throw new WiredSaveException("Invalid data"); - - int startDirectionInt = settings.getIntParams()[0]; - - if(startDirectionInt < 0 || startDirectionInt > 7 || (startDirectionInt % 2) != 0) { - throw new WiredSaveException("Start direction is invalid"); - } - - RoomUserRotation startDirection = RoomUserRotation.fromValue(startDirectionInt); - - int blockedActionInt = settings.getIntParams()[1]; - - if(blockedActionInt < 0 || blockedActionInt > 6) { - throw new WiredSaveException("Blocked action is invalid"); - } - - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - THashMap newItems = new THashMap<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.put(it, new WiredChangeDirectionSetting(it.getId(), it.getRotation(), startDirection)); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.putAll(newItems); - this.startRotation = startDirection; - this.blockedAction = blockedActionInt; - this.setDelay(delay); - - return true; - } - - private RoomUserRotation nextRotation(RoomUserRotation currentRotation) { - return switch (this.blockedAction) { - case ACTION_TURN_BACK -> RoomUserRotation.fromValue(currentRotation.getValue()).getOpposite(); - case ACTION_TURN_LEFT_45 -> RoomUserRotation.counterClockwise(currentRotation); - case ACTION_TURN_LEFT_90 -> - RoomUserRotation.counterClockwise(RoomUserRotation.counterClockwise(currentRotation)); - case ACTION_TURN_RIGHT_45 -> RoomUserRotation.clockwise(currentRotation); - case ACTION_TURN_RIGHT_90 -> RoomUserRotation.clockwise(RoomUserRotation.clockwise(currentRotation)); - case ACTION_TURN_RANDOM -> RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8)); - case ACTION_WAIT -> currentRotation; - default -> currentRotation; + private RoomRotation nextDirection(RoomRotation currentDirection) { + return switch (this.getWiredSettings().getIntegerParams().get(PARAM_BLOCKED_ACTION)) { + case ACTION_TURN_BACK -> RoomRotation.fromValue(currentDirection.getValue()).getOpposite(); + case ACTION_TURN_LEFT_45 -> RoomRotation.counterClockwise(currentDirection); + case ACTION_TURN_LEFT_90 -> RoomRotation.counterClockwise(RoomRotation.counterClockwise(currentDirection)); + case ACTION_TURN_RIGHT_45 -> RoomRotation.clockwise(currentDirection); + case ACTION_TURN_RIGHT_90 -> RoomRotation.clockwise(RoomRotation.clockwise(currentDirection)); + case ACTION_TURN_RANDOM -> RoomRotation.fromValue(Emulator.getRandom().nextInt(8)); + case ACTION_WAIT -> currentDirection; + default -> currentDirection; }; } @@ -281,17 +163,8 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { return 495; } - static class JsonData { - RoomUserRotation start_direction; - int blocked_action; - List items; - int delay; - - public JsonData(RoomUserRotation start_direction, int blocked_action, List items, int delay) { - this.start_direction = start_direction; - this.blocked_action = blocked_action; - this.items = items; - this.delay = delay; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.MOVE_DIRECTION; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java index 71345755..bbf01674 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveEffect.java @@ -2,7 +2,9 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -12,23 +14,29 @@ public class WiredEffectGiveEffect extends WiredEffectWhisper { super(set, baseItem); } - public WiredEffectGiveEffect(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectGiveEffect(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getStringParam().isEmpty()) { + return false; + } + int effectId; try { - effectId = Integer.parseInt(this.message); + effectId = Integer.parseInt(this.getWiredSettings().getStringParam()); } catch (Exception e) { return false; } - if (effectId >= 0) { - room.giveEffect(roomUnit, effectId, Integer.MAX_VALUE); - return true; + if(roomUnit instanceof RoomAvatar roomAvatar) { + if (effectId >= 0) { + roomAvatar.giveEffect(effectId, Integer.MAX_VALUE); + return true; + } } return false; diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java index df98240e..52992a2d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHandItem.java @@ -2,8 +2,10 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.messages.outgoing.rooms.users.CarryObjectMessageComposer; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,19 +15,24 @@ public class WiredEffectGiveHandItem extends WiredEffectWhisper { super(set, baseItem); } - public WiredEffectGiveHandItem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectGiveHandItem(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - try { - int itemId = Integer.parseInt(this.message); + if(this.getWiredSettings().getStringParam().isEmpty()) { + return false; + } - Habbo habbo = room.getHabbo(roomUnit); + try { + int itemId = Integer.parseInt(this.getWiredSettings().getStringParam()); + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { - room.giveHandItem(habbo, itemId); + habbo.getRoomUnit().setHandItem(itemId); + room.sendComposer(new CarryObjectMessageComposer(habbo.getRoomUnit()).compose()); } } catch (Exception ignored) { } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java index 5ba1cda4..89052f26 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java @@ -1,143 +1,50 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.hotelview.BonusRareInfoMessageComposer; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; - - private int amount = 0; +public class WiredEffectGiveHotelviewBonusRarePoints extends WiredEffectWhisper { public WiredEffectGiveHotelviewBonusRarePoints(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectGiveHotelviewBonusRarePoints(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.amount + ""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(type.getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) { - try { - this.amount = Integer.parseInt(settings.getStringParam()); - } catch (Exception e) { - return false; - } - - this.setDelay(settings.getDelay()); - - return true; - } - - @Override - public WiredEffectType getType() { - return type; + public WiredEffectGiveHotelviewBonusRarePoints(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo == null) + if(this.getWiredSettings().getStringParam().isEmpty()) { return false; + } - if (this.amount > 0) { - habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), this.amount); + int amount; + + try { + amount = Integer.parseInt(this.getWiredSettings().getStringParam()); + } catch (Exception e) { + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo == null) { + return false; + } + + if (amount > 0) { + habbo.givePoints(Emulator.getConfig().getInt("hotelview.promotional.points.type"), amount); habbo.getClient().sendResponse(new BonusRareInfoMessageComposer(habbo)); } return true; } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay(), this.amount)); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - this.amount = 0; - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.amount = data.amount; - } else { - if (wiredData.split("\t").length >= 2) { - super.setDelay(Integer.parseInt(wiredData.split("\t")[0])); - - try { - this.amount = Integer.parseInt(wiredData.split("\t")[1]); - } catch (Exception ignored) { - } - } - } - } - - @Override - public void onPickUp() { - this.amount = 0; - this.setDelay(0); - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - int delay; - int amount; - - public JsonData(int delay, int amount) { - this.delay = delay; - this.amount = amount; - } - } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java index f518cd0c..8e7db2a9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java @@ -1,92 +1,48 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; - - private int amount = 0; - public WiredEffectGiveHotelviewHofPoints(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectGiveHotelviewHofPoints(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.amount + ""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(type.getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) { - try { - this.amount = Integer.parseInt(settings.getStringParam()); - } catch (Exception e) { - return false; - } - - this.setDelay(settings.getDelay()); - - return true; - } - - @Override - public WiredEffectType getType() { - return type; + public WiredEffectGiveHotelviewHofPoints(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo == null) + if(this.getWiredSettings().getStringParam().isEmpty()) { return false; + } - if (this.amount > 0) { - habbo.getHabboStats().hofPoints += this.amount; + int amount; + + try { + amount = Integer.parseInt(this.getWiredSettings().getStringParam()); + } catch (Exception e) { + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo == null) { + return false; + } + + if (amount > 0) { + habbo.getHabboStats().hofPoints += amount; Emulator.getThreading().run(habbo.getHabboStats()); } @@ -94,53 +50,7 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.amount = data.amount; - this.setDelay(data.delay); - } - else { - this.amount = 0; - - if (wiredData.split("\t").length >= 2) { - super.setDelay(Integer.parseInt(wiredData.split("\t")[0])); - - try { - this.amount = Integer.parseInt(this.getWiredData().split("\t")[1]); - } catch (Exception ignored) { - } - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.amount = 0; - this.setDelay(0); - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - int amount; - int delay; - - public JsonData(int amount, int delay) { - this.amount = amount; - this.delay = delay; - } + public WiredEffectType getType() { + return WiredEffectType.SHOW_MESSAGE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java index 9d80cc4d..28d42cfe 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java @@ -2,145 +2,53 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredEffectGiveRespect extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; - - private int respects = 0; - public WiredEffectGiveRespect(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectGiveRespect(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectGiveRespect(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.respects + ""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(type.getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) { - try { - this.respects = Integer.parseInt(settings.getStringParam()); - } catch (Exception e) { - return false; - } - - this.setDelay(settings.getDelay()); - - return true; - } - @Override public WiredEffectType getType() { - return type; + return WiredEffectType.SHOW_MESSAGE; } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo == null) + if(this.getWiredSettings().getStringParam().isEmpty()) { return false; + } + + int respects; + + try { + respects = Integer.parseInt(this.getWiredSettings().getStringParam()); + } catch (Exception e) { + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo == null) { + return false; + } habbo.getHabboStats().increaseRespectPointsReceived(respects); - AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned"), this.respects); + AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned"), respects); return true; } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.respects, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.respects = data.amount; - this.setDelay(data.delay); - } - else { - String[] data = wiredData.split("\t"); - this.respects = 0; - - if (data.length >= 2) { - super.setDelay(Integer.parseInt(data[0])); - - try { - this.respects = Integer.parseInt(data[1]); - } catch (Exception ignored) { - } - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.respects = 0; - this.setDelay(0); - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - int amount; - int delay; - - public JsonData(int amount, int delay) { - this.amount = amount; - this.delay = delay; - } - } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java index da0c9b36..96b552bc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java @@ -1,28 +1,19 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredGiveRewardItem; import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import com.eu.habbo.messages.outgoing.generic.alerts.WiredValidationErrorComposer; import gnu.trove.set.hash.THashSet; import lombok.Getter; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; @Getter public class WiredEffectGiveReward extends InteractionWiredEffect { @@ -30,190 +21,66 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { public final static int LIMIT_N_DAY = 1; public final static int LIMIT_N_HOURS = 2; public final static int LIMIT_N_MINUTES = 3; - - private final static WiredEffectType type = WiredEffectType.GIVE_REWARD; - private int limit; - private int limitationInterval; + public final int PARAM_REWARD_LIMIT = 0; + public final int PARAM_UNIQUE_REWARD = 1; + public final int PARAM_LIMIT = 2; + public final int PARAM_LIMITATION_INTERVAL = 3; + public THashSet rewardItems = new THashSet<>(); private int given; - private int rewardTime; - private boolean uniqueRewards; - - private final THashSet rewardItems = new THashSet<>(); public WiredEffectGiveReward(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectGiveReward(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectGiveReward(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + int rewardTime = this.getWiredSettings().getIntegerParams().get(PARAM_REWARD_LIMIT); + boolean uniqueRewards = this.getWiredSettings().getIntegerParams().get(PARAM_UNIQUE_REWARD) == 1; + int limit = this.getWiredSettings().getIntegerParams().get(PARAM_LIMIT); + int limitationInterval = this.getWiredSettings().getIntegerParams().get(PARAM_LIMITATION_INTERVAL); + + String data = this.getWiredSettings().getStringParam(); + + String[] items = data.split(";"); + + int i = 1; + + for(String item : items) { + String[] d = item.split(","); + + if(d.length == 3) { + if(!(d[1].contains(":") || d[1].contains(";"))) { + this.rewardItems.add(new WiredGiveRewardItem(i, d[0].equalsIgnoreCase("0"), d[1], Integer.valueOf(d[2]))); + continue; + } + } + + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); return habbo != null && WiredHandler.getReward(habbo, this); } - @Override - public String getWiredData() { - - ArrayList rewards = new ArrayList<>(this.rewardItems); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay())); + public int getLimit() { + return this.getWiredSettings().getIntegerParams().get(PARAM_LIMIT); } - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.limit = data.limit; - this.given = data.given; - this.rewardTime = data.reward_time; - this.uniqueRewards = data.unique_rewards; - this.limitationInterval = data.limit_interval; - this.rewardItems.clear(); - this.rewardItems.addAll(data.rewards); - } else { - String[] data = wiredData.split(":"); - if (data.length > 0) { - this.limit = Integer.parseInt(data[0]); - this.given = Integer.parseInt(data[1]); - this.rewardTime = Integer.parseInt(data[2]); - this.uniqueRewards = data[3].equals("1"); - this.limitationInterval = Integer.parseInt(data[4]); - this.setDelay(Integer.parseInt(data[5])); - - if (data.length > 6) { - if (!data[6].equalsIgnoreCase("\t")) { - String[] items = data[6].split(";"); - - this.rewardItems.clear(); - - for (String s : items) { - try { - this.rewardItems.add(new WiredGiveRewardItem(s)); - } catch (Exception ignored) { - } - } - } - } - - this.needsUpdate(true); - } - } + public int getRewardTime() { + return this.getWiredSettings().getIntegerParams().get(PARAM_REWARD_LIMIT); } - @Override - public void onPickUp() { - this.limit = 0; - this.limitationInterval = 0; - this.given = 0; - this.rewardTime = 0; - this.uniqueRewards = false; - this.rewardItems.clear(); - this.setDelay(0); + public boolean isUniqueRewards() { + return this.getWiredSettings().getIntegerParams().get(PARAM_UNIQUE_REWARD) == 1; } - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - super.onClick(client, room, objects); - - if (client.getHabbo().hasRight(Permission.ACC_SUPERWIRED)) { - client.getHabbo().whisper(Emulator.getTexts().getValue("hotel.wired.superwired.info"), RoomChatMessageBubbles.BOT); - } - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(this.rewardItems.size()); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - StringBuilder s = new StringBuilder(); - - for (WiredGiveRewardItem item : this.rewardItems) { - s.append(item.wiredString()).append(";"); - } - message.appendString(s.toString()); - message.appendInt(4); - message.appendInt(this.rewardTime); - message.appendInt(this.uniqueRewards); - message.appendInt(this.limit); - message.appendInt(this.limitationInterval); - message.appendInt(this.limit > 0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if (gameClient.getHabbo().hasRight(Permission.ACC_SUPERWIRED)) { - if (settings.getIntParams().length < 4) throw new WiredSaveException("Invalid data"); - this.rewardTime = settings.getIntParams()[0]; - this.uniqueRewards = settings.getIntParams()[1] == 1; - this.limit = settings.getIntParams()[2]; - this.limitationInterval = settings.getIntParams()[3]; - this.given = 0; - - String data = settings.getStringParam(); - - String[] items = data.split(";"); - - this.rewardItems.clear(); - - int i = 1; - for (String s : items) { - String[] d = s.split(","); - - if (d.length == 3) { - if (!(d[1].contains(":") || d[1].contains(";"))) { - this.rewardItems.add(new WiredGiveRewardItem(i, d[0].equalsIgnoreCase("0"), d[1], Integer.parseInt(d[2]))); - continue; - } - } - - gameClient.sendResponse(new WiredValidationErrorComposer(Emulator.getTexts().getValue("alert.superwired.invalid"))); - return false; - } - - this.setDelay(settings.getDelay()); - - WiredHandler.dropRewards(this.getId()); - return true; - } - - gameClient.getHabbo().whisper("U cannot do this.", RoomChatMessageBubbles.ALERT); - return false; - } - - @Override - public boolean requiresTriggeringUser() { - return true; + public int getLimitationInterval() { + return this.getWiredSettings().getIntegerParams().get(PARAM_LIMITATION_INTERVAL); } @Override @@ -222,28 +89,11 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { } public void incrementGiven() { - given++; + this.given++; } - static class JsonData { - int limit; - int given; - int reward_time; - boolean unique_rewards; - int limit_interval; - List rewards; - int delay; - - public JsonData(int limit, int given, int reward_time, boolean unique_rewards, int limit_interval, List rewards, int delay) { - this.limit = limit; - this.given = given; - this.reward_time = reward_time; - this.unique_rewards = unique_rewards; - this.limit_interval = limit_interval; - this.rewards = rewards; - this.delay = delay; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.GIVE_REWARD; } - - -} +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java index ef253238..47f4b591 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java @@ -1,18 +1,13 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.iterator.TObjectIntIterator; import gnu.trove.map.TObjectIntMap; import gnu.trove.map.hash.TObjectIntHashMap; @@ -20,29 +15,35 @@ import gnu.trove.map.hash.TObjectIntHashMap; import java.sql.ResultSet; import java.sql.SQLException; import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; import java.util.Map; public class WiredEffectGiveScore extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.GIVE_SCORE; - - private int score; - private int count; - + public final int PARAM_SCORE = 0; + public final int PARAM_TIMES_PER_GAME = 1; private final TObjectIntMap> data = new TObjectIntHashMap<>(); public WiredEffectGiveScore(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectGiveScore(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectGiveScore(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + int score = this.getWiredSettings().getIntegerParams().get(PARAM_SCORE); + int timesPerGame = this.getWiredSettings().getIntegerParams().get(PARAM_TIMES_PER_GAME); + + if(score < 1 || score > 100) { + return false; + } + + if(timesPerGame < 1 || timesPerGame > 10) { + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null && habbo.getHabboInfo().getCurrentGame() != null) { Game game = room.getGame(habbo.getHabboInfo().getCurrentGame()); @@ -63,10 +64,10 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { if (map.getValue() == habbo.getHabboInfo().getId()) { if (map.getKey() == gameStartTime) { - if (iterator.value() < this.count) { + if (iterator.value() < timesPerGame) { iterator.setValue(iterator.value() + 1); - habbo.getHabboInfo().getGamePlayer().addScore(this.score, true); + habbo.getHabboInfo().getGamePlayer().addScore(score, true); return true; } @@ -85,7 +86,7 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { if (habbo.getHabboInfo().getGamePlayer() != null) { - habbo.getHabboInfo().getGamePlayer().addScore(this.score, true); + habbo.getHabboInfo().getGamePlayer().addScore(score, true); } return true; @@ -95,117 +96,15 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.score, this.count, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.score = data.score; - this.count = data.count; - this.setDelay(data.delay); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(1); } - else { - String[] data = wiredData.split(";"); - - if (data.length == 3) { - this.score = Integer.parseInt(data[0]); - this.count = Integer.parseInt(data[1]); - this.setDelay(Integer.parseInt(data[2])); - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.score = 0; - this.count = 0; - this.setDelay(0); } @Override public WiredEffectType getType() { - return WiredEffectGiveScore.type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.score); - message.appendInt(this.count); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 2) throw new WiredSaveException("Invalid data"); - - int score = settings.getIntParams()[0]; - - if(score < 1 || score > 100) - throw new WiredSaveException("Score is invalid"); - - int timesPerGame = settings.getIntParams()[1]; - - if(timesPerGame < 1 || timesPerGame > 10) - throw new WiredSaveException("Times per game is invalid"); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.score = score; - this.count = timesPerGame; - this.setDelay(delay); - - return true; - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - int score; - int count; - int delay; - - public JsonData(int score, int count, int delay) { - this.score = score; - this.count = count; - this.delay = delay; - } + return WiredEffectType.GIVE_SCORE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java index 00b483f0..7507c887 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java @@ -1,36 +1,30 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameState; import com.eu.habbo.habbohotel.games.GameTeam; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.map.hash.TIntIntHashMap; import java.sql.ResultSet; import java.sql.SQLException; public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.GIVE_SCORE_TEAM; - - private int points; - private int count; - private GameTeamColors teamColor = GameTeamColors.RED; - + public final int PARAM_SCORE = 0; + public final int PARAM_TIMES_PER_GAME = 1; + public final int PARAM_TEAM = 2; private final TIntIntHashMap startTimes = new TIntIntHashMap(); - public WiredEffectGiveScoreToTeam(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + private final GameTeamColors DEFAULT_TEAM = GameTeamColors.RED; + + public WiredEffectGiveScoreToTeam(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } public WiredEffectGiveScoreToTeam(ResultSet set, Item baseItem) throws SQLException { @@ -39,16 +33,33 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + int score = this.getWiredSettings().getIntegerParams().get(PARAM_SCORE); + int timesPerGame = this.getWiredSettings().getIntegerParams().get(PARAM_TIMES_PER_GAME); + int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM); + + if(score < 1 || score > 100) { + return false; + } + + if(timesPerGame < 1 || timesPerGame > 10) { + return false; + } + + if(teamValue < 1 || teamValue > 4) { + return false; + } + + GameTeamColors teamColor = GameTeamColors.values()[teamValue]; + for (Game game : room.getGames()) { if (game != null && game.state.equals(GameState.RUNNING)) { int c = this.startTimes.get(game.getStartTime()); - if (c < this.count) { - GameTeam team = game.getTeam(this.teamColor); + if (c < timesPerGame) { + GameTeam team = game.getTeam(teamColor); if (team != null) { - team.addTeamScore(this.points); - + team.addTeamScore(score); this.startTimes.put(game.getStartTime(), c + 1); } } @@ -59,110 +70,16 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.points, this.count, this.teamColor, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.points = data.score; - this.count = data.count; - this.teamColor = data.team; - this.setDelay(data.delay); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(1); + this.getWiredSettings().getIntegerParams().add(DEFAULT_TEAM.type); } - else { - String[] data = set.getString("wired_data").split(";"); - - if (data.length == 4) { - this.points = Integer.parseInt(data[0]); - this.count = Integer.parseInt(data[1]); - this.teamColor = GameTeamColors.values()[Integer.parseInt(data[2])]; - this.setDelay(Integer.parseInt(data[3])); - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.startTimes.clear(); - this.points = 0; - this.count = 0; - this.teamColor = GameTeamColors.RED; - this.setDelay(0); } @Override public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(3); - message.appendInt(this.points); - message.appendInt(this.count); - message.appendInt(this.teamColor.type); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data"); - - int points = settings.getIntParams()[0]; - - if(points < 1 || points > 100) - throw new WiredSaveException("Points is invalid"); - - int timesPerGame = settings.getIntParams()[1]; - - if(timesPerGame < 1 || timesPerGame > 10) - throw new WiredSaveException("Times per game is invalid"); - - int team = settings.getIntParams()[2]; - - if(team < 1 || team > 4) - throw new WiredSaveException("Team is invalid"); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.points = points; - this.count = timesPerGame; - this.teamColor = GameTeamColors.values()[team]; - this.setDelay(delay); - - return true; - } - - static class JsonData { - int score; - int count; - GameTeamColors team; - int delay; - - public JsonData(int score, int count, GameTeamColors team, int delay) { - this.score = score; - this.count = count; - this.team = team; - this.delay = delay; - } + return WiredEffectType.GIVE_SCORE_TEAM; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java index e83fa361..3b0c7695 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java @@ -1,54 +1,53 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredEffectJoinTeam extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.JOIN_TEAM; - - private GameTeamColors teamColor = GameTeamColors.RED; + public final int PARAM_TEAM = 0; + private GameTeamColors DEFAULT_TEAM = GameTeamColors.RED; public WiredEffectJoinTeam(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectJoinTeam(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectJoinTeam(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + int teamValue = this.getWiredSettings().getIntegerParams().get(PARAM_TEAM); + + if(teamValue < 1 || teamValue > 4) { + return false; + } + + GameTeamColors teamColor = GameTeamColors.values()[teamValue]; + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { WiredGame game = (WiredGame) room.getGameOrCreate(WiredGame.class); - if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getCurrentGame() != null && (habbo.getHabboInfo().getCurrentGame() != WiredGame.class || (habbo.getHabboInfo().getCurrentGame() == WiredGame.class && habbo.getHabboInfo().getGamePlayer().getTeamColor() != this.teamColor))) { - // remove from current game + if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getCurrentGame() != null && (habbo.getHabboInfo().getCurrentGame() != WiredGame.class || (habbo.getHabboInfo().getCurrentGame() == WiredGame.class && habbo.getHabboInfo().getGamePlayer().getTeamColor() != teamColor))) { Game currentGame = room.getGame(habbo.getHabboInfo().getCurrentGame()); currentGame.removeHabbo(habbo); } if(habbo.getHabboInfo().getGamePlayer() == null) { - game.addHabbo(habbo, this.teamColor); + game.addHabbo(habbo, teamColor); } return true; @@ -58,108 +57,14 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.teamColor, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.teamColor = data.team; + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(DEFAULT_TEAM.type); } - else { - String[] data = set.getString("wired_data").split("\t"); - - if (data.length >= 1) { - this.setDelay(Integer.parseInt(data[0])); - - if (data.length >= 2) { - this.teamColor = GameTeamColors.values()[Integer.parseInt(data[1])]; - } - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.teamColor = GameTeamColors.RED; - this.setDelay(0); } @Override public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.teamColor.type); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("invalid data"); - - int team = settings.getIntParams()[0]; - - if(team < 1 || team > 4) - throw new WiredSaveException("Team is invalid"); - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.teamColor = GameTeamColors.values()[team]; - this.setDelay(delay); - - return true; - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - GameTeamColors team; - int delay; - - public JsonData(GameTeamColors team, int delay) { - this.team = team; - this.delay = delay; - } + return WiredEffectType.JOIN_TEAM; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java deleted file mode 100644 index 180b15e1..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.effects; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomChatMessage; -import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer; -import com.eu.habbo.threading.runnables.RoomUnitKick; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class WiredEffectKickHabbo extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.KICK_USER; - - private String message = ""; - - public WiredEffectKickHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredEffectKickHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (room == null) - return false; - - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - if (habbo.hasRight(Permission.ACC_UNKICKABLE)) { - habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.unkickable")); - return true; - } - - if (habbo.getHabboInfo().getId() == room.getOwnerId()) { - habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.owner")); - return true; - } - - room.giveEffect(habbo, 4, 2); - - if (!this.message.isEmpty()) - habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.message, habbo, habbo, RoomChatMessageBubbles.ALERT))); - - Emulator.getThreading().run(new RoomUnitKick(habbo, room, true), 2000); - - return true; - } - - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.message = data.message; - } - else { - try { - String[] data = set.getString("wired_data").split("\t"); - - if (data.length >= 1) { - this.setDelay(Integer.parseInt(data[0])); - - if (data.length >= 2) { - this.message = data[1]; - } - } - } catch (Exception e) { - this.message = ""; - this.setDelay(0); - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.message = ""; - this.setDelay(0); - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.message); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - String message = settings.getStringParam(); - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - this.setDelay(delay); - - return true; - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - String message; - int delay; - - public JsonData(String message, int delay) { - this.message = message; - this.delay = delay; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickRoom.java new file mode 100644 index 00000000..fd258d8e --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickRoom.java @@ -0,0 +1,65 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.effects; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; +import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomChatMessage; +import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer; +import com.eu.habbo.threading.runnables.RoomUnitKick; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredEffectKickRoom extends InteractionWiredEffect { + public WiredEffectKickRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredEffectKickRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if (room == null) + return false; + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo != null) { + if (habbo.hasPermissionRight(Permission.ACC_UNKICKABLE)) { + habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.unkickable")); + return true; + } + + if (habbo.getHabboInfo().getId() == room.getRoomInfo().getOwnerInfo().getId()) { + habbo.whisper(Emulator.getTexts().getValue("hotel.wired.kickexception.owner")); + return true; + } + + habbo.getRoomUnit().giveEffect(4, 2); + + if (!this.getWiredSettings().getStringParam().isEmpty()) { + habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.getWiredSettings().getStringParam(), habbo, habbo, RoomChatMessageBubbles.ALERT))); + } + + Emulator.getThreading().run(new RoomUnitKick(habbo, room, true), 2000); + + return true; + } + + return false; + } + + @Override + public WiredEffectType getType() { + return WiredEffectType.KICK_USER; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java index 9265a125..40d38583 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java @@ -1,39 +1,30 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.wired.WiredGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredEffectLeaveTeam extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.LEAVE_TEAM; - public WiredEffectLeaveTeam(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectLeaveTeam(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectLeaveTeam(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { if (habbo.getHabboInfo().getCurrentGame() != null) { @@ -52,80 +43,8 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { return false; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - } - else { - this.setDelay(Integer.parseInt(wiredData)); - } - } - - @Override - public void onPickUp() { - this.setDelay(0); - } - @Override public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.setDelay(delay); - return true; - } - - static class JsonData { - int delay; - - public JsonData(int delay) { - this.delay = delay; - } + return WiredEffectType.LEAVE_TEAM; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java index ab995a51..2d6b44d5 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMatchFurni.java @@ -1,86 +1,89 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; -import gnu.trove.set.hash.THashSet; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.regex.Pattern; @Slf4j public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings { - - private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT; private final boolean checkForWiredResetPermission = true; - private final THashSet settings; - private boolean state = false; - private boolean direction = false; - private boolean position = false; + public final int PARAM_STATE = 0; + public final int PARAM_ROTATION = 1; + public final int PARAM_POSITION = 2; + @Getter + private List matchSettings; public WiredEffectMatchFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.settings = new THashSet<>(0); } - public WiredEffectMatchFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.settings = new THashSet<>(0); + public WiredEffectMatchFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - - if(this.settings.isEmpty()) + if(this.getWiredSettings().getItemIds().isEmpty() && this.getWiredSettings().getMatchParams().isEmpty()) { return true; + } - for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.getItem_id()); - if (item != null) { - if (this.state && (this.checkForWiredResetPermission && item.allowWiredResetState())) { - if (!setting.getState().equals(" ") && !item.getExtradata().equals(setting.getState())) { - item.setExtradata(setting.getState()); - room.updateItemState(item); - } + boolean state = this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; + boolean position = this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1; + boolean rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1; + this.matchSettings = this.getWiredSettings().getMatchParams(); + + for(RoomItem item : this.getWiredSettings().getItems(room)) { + WiredMatchFurniSetting furniSettings = this.matchSettings.stream().filter(settings -> settings.getItem_id() == item.getId()).findAny().orElse(null); + + if(furniSettings == null) { + continue; + } + + if (state && (this.checkForWiredResetPermission && item.allowWiredResetState())) { + if (!furniSettings.getState().equals(" ") && !item.getExtraData().equals(furniSettings.getState())) { + item.setExtraData(furniSettings.getState()); + room.updateItemState(item); } + } - RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY()); - double oldZ = item.getZ(); + RoomTile oldLocation = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + double oldZ = item.getCurrentZ(); - if(this.direction && !this.position) { - if(item.getRotation() != setting.getRotation() && room.furnitureFitsAt(oldLocation, item, setting.getRotation(), false) == FurnitureMovementError.NONE) { - room.moveFurniTo(item, oldLocation, setting.getRotation(), null, true); - } + if(rotation && !position) { + if (item.getRotation() != furniSettings.getRotation() && room.getRoomItemManager().furnitureFitsAt(oldLocation, item, furniSettings.getRotation(), false) == FurnitureMovementError.NONE) { + room.getRoomItemManager().moveItemTo(item, oldLocation, furniSettings.getRotation(), null, true, true); } - else if(this.position) { - boolean slideAnimation = !this.direction || item.getRotation() == setting.getRotation(); - RoomTile newLocation = room.getLayout().getTile((short) setting.getX(), (short) setting.getY()); - int newRotation = this.direction ? setting.getRotation() : item.getRotation(); + } + else if(position) { + boolean slideAnimation = !rotation || item.getRotation() == furniSettings.getRotation(); + RoomTile newLocation = room.getLayout().getTile((short) furniSettings.getX(), (short) furniSettings.getY()); + int newRotation = rotation ? furniSettings.getRotation() : item.getRotation(); - if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && room.furnitureFitsAt(newLocation, item, newRotation, true) == FurnitureMovementError.NONE) { - if(room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) { - if(slideAnimation) { - room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose()); - } + if (newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && room.getRoomItemManager().furnitureFitsAt(newLocation, item, newRotation, true) == FurnitureMovementError.NONE) { + boolean sendUpdates = !slideAnimation; + if (room.getRoomItemManager().moveItemTo(item, newLocation, newRotation, null, sendUpdates, true) == FurnitureMovementError.NONE) { + if (slideAnimation) { + room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getCurrentZ(), 0, room).compose()); } } } - } } @@ -88,189 +91,43 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int } @Override - public String getWiredData() { - this.refresh(); - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList<>(this.settings), this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.state = data.state; - this.direction = data.direction; - this.position = data.position; - this.settings.clear(); - this.settings.addAll(data.items); - } - else { - String[] data = set.getString("wired_data").split(":"); - - int itemCount = Integer.parseInt(data[0]); - - String[] items = data[1].split(Pattern.quote(";")); - - for (String item : items) { - try { - - String[] stuff = item.split(Pattern.quote("-")); - - if (stuff.length >= 5) { - this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4]))); - } - - } catch (Exception e) { - log.error("Caught exception", e); - } - } - - this.state = data[2].equals("1"); - this.direction = data[3].equals("1"); - this.position = data[4].equals("1"); - this.setDelay(Integer.parseInt(data[5])); - this.needsUpdate(true); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); } } @Override - public void onPickUp() { - this.settings.clear(); - this.state = false; - this.direction = false; - this.position = false; - this.setDelay(0); - } + public void saveAdditionalData(Room room) { + List matchSettings = new ArrayList<>(); - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - this.refresh(); - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.settings.size()); - - for (WiredMatchFurniSetting item : this.settings) - message.appendInt(item.getItem_id()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(3); - message.appendInt(this.state ? 1 : 0); - message.appendInt(this.direction ? 1 : 0); - message.appendInt(this.position ? 1 : 0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 3) throw new WiredSaveException("Invalid data"); - boolean setState = settings.getIntParams()[0] == 1; - boolean setDirection = settings.getIntParams()[1] == 1; - boolean setPosition = settings.getIntParams()[2] == 1; - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null) - throw new WiredSaveException("Trying to save wired in unloaded room"); - - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); + for (RoomItem item : this.getWiredSettings().getItems(room)) { + WiredMatchFurniSetting settings = new WiredMatchFurniSetting(item.getId(), this.checkForWiredResetPermission && item.allowWiredResetState() ? item.getExtraData() : " ", item.getRotation(), item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + matchSettings.add(settings); } - List newSettings = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newSettings.add(new WiredMatchFurniSetting(it.getId(), this.checkForWiredResetPermission && it.allowWiredResetState() ? it.getExtradata() : " ", it.getRotation(), it.getX(), it.getY())); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.state = setState; - this.direction = setDirection; - this.position = setPosition; - this.settings.clear(); - this.settings.addAll(newSettings); - this.setDelay(delay); - - return true; - } - - private void refresh() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room != null && room.isLoaded()) { - THashSet remove = new THashSet<>(); - - for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.getItem_id()); - if (item == null) { - remove.add(setting); - } - } - - for (WiredMatchFurniSetting setting : remove) { - this.settings.remove(setting); - } - - } - } - - @Override - public THashSet getMatchFurniSettings() { - return this.settings; + this.getWiredSettings().setMatchParams(matchSettings); } @Override public boolean shouldMatchState() { - return this.state; + return this.getWiredSettings().getIntegerParams().get(PARAM_STATE) == 1; } @Override public boolean shouldMatchRotation() { - return this.direction; + return this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION) == 1; } @Override public boolean shouldMatchPosition() { - return this.position; + return this.getWiredSettings().getIntegerParams().get(PARAM_POSITION) == 1; } - static class JsonData { - boolean state; - boolean direction; - boolean position; - List items; - int delay; - - public JsonData(boolean state, boolean direction, boolean position, List items, int delay) { - this.state = state; - this.direction = direction; - this.position = position; - this.items = items; - this.delay = delay; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.MATCH_SSHOT; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java index cec31bf6..0863a048 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniAway.java @@ -1,58 +1,42 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; public class WiredEffectMoveFurniAway extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.FLEE; - - private THashSet items = new THashSet<>(); - public WiredEffectMoveFurniAway(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectMoveFurniAway(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectMoveFurniAway(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - THashSet items = new THashSet<>(); + for (RoomItem item : this.getWiredSettings().getItems(room)) { + RoomTile t = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); - for (HabboItem item : this.items) { - if (item.getRoomId() == 0) - items.add(item); - } - - this.items.removeAll(items); - - for (HabboItem item : this.items) { - RoomTile t = room.getLayout().getTile(item.getX(), item.getY()); - - RoomUnit target = room.getRoomUnits().stream().min(Comparator.comparingDouble(a -> a.getCurrentLocation().distance(t))).orElse(null); + RoomUnit target = room.getRoomUnitManager().getCurrentRoomUnits().values().stream().min(Comparator.comparingDouble(a -> a.getCurrentPosition().distance(t))).orElse(null); if (target != null) { - if (target.getCurrentLocation().distance(t) <= 1) { + if (target.getCurrentPosition().distance(t) <= 1) { Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.COLLISION, target, room, new Object[]{item}), 500); continue; } @@ -60,35 +44,39 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { int x = 0; int y = 0; - if (target.getX() == item.getX()) { - if (item.getY() < target.getY()) + if (target.getCurrentPosition().getX() == item.getCurrentPosition().getX()) { + if (item.getCurrentPosition().getY() < target.getCurrentPosition().getY()) y--; else y++; - } else if (target.getY() == item.getY()) { - if (item.getX() < target.getX()) - x--; - else - x++; - } else if (target.getX() - item.getX() > target.getY() - item.getY()) { - if (target.getX() - item.getX() > 0) - x--; - else - x++; } else { - if (target.getY() - item.getY() > 0) - y--; - else - y++; + if (target.getCurrentPosition().getY() == item.getCurrentPosition().getY()) { + if (item.getCurrentPosition().getX() < target.getCurrentPosition().getX()) + x--; + else + x++; + } else { + if (target.getCurrentPosition().getX() - item.getCurrentPosition().getX() > target.getCurrentPosition().getY() - item.getCurrentPosition().getY()) { + if (target.getCurrentPosition().getX() - item.getCurrentPosition().getX() > 0) + x--; + else + x++; + } else { + if (target.getCurrentPosition().getY() - item.getCurrentPosition().getY() > 0) + y--; + else + y++; + } + } } - RoomTile newLocation = room.getLayout().getTile((short) (item.getX() + x), (short) (item.getY() + y)); - RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY()); - double oldZ = item.getZ(); + RoomTile newLocation = room.getLayout().getTile((short) (item.getCurrentPosition().getX() + x), (short) (item.getCurrentPosition().getY() + y)); + RoomTile oldLocation = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + double oldZ = item.getCurrentZ(); - if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && newLocation != oldLocation && room.furnitureFitsAt(newLocation, item, item.getRotation(), true) == FurnitureMovementError.NONE) { - if(room.moveFurniTo(item, newLocation, item.getRotation(), null, false) == FurnitureMovementError.NONE) { - room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose()); + if (newLocation != null && newLocation.getState() != RoomTileState.INVALID && newLocation != oldLocation && room.getRoomItemManager().furnitureFitsAt(newLocation, item, item.getRotation(), true) == FurnitureMovementError.NONE) { + if (room.getRoomItemManager().moveItemTo(item, newLocation, item.getRotation(), null, false, true) == FurnitureMovementError.NONE) { + room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getCurrentZ(), 0, room).compose()); } } } @@ -96,130 +84,13 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { return true; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new THashSet<>(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] wiredDataOld = wiredData.split("\t"); - - if (wiredDataOld.length >= 1) { - this.setDelay(Integer.parseInt(wiredDataOld[0])); - } - if (wiredDataOld.length == 2) { - if (wiredDataOld[1].contains(";")) { - for (String s : wiredDataOld[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.setDelay(0); - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.setDelay(delay); - - return true; - } - @Override protected long requiredCooldown() { return 495; } - static class JsonData { - int delay; - List itemIds; - - public JsonData(int delay, List itemIds) { - this.delay = delay; - this.itemIds = itemIds; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.FLEE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java index cd052fe7..f1a2126a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTo.java @@ -1,118 +1,70 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; public class WiredEffectMoveFurniTo extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.MOVE_FURNI_TO; - private final List items = new ArrayList<>(); - private int direction; - private int spacing = 1; - private final Map indexOffset = new LinkedHashMap<>(); + public final int PARAM_DIRECTION = 0; + public final int PARAM_SPACING = 1; public WiredEffectMoveFurniTo(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectMoveFurniTo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null) - return false; - - this.items.clear(); - this.indexOffset.clear(); - - if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); - this.direction = settings.getIntParams()[0]; - this.spacing = settings.getIntParams()[1]; - - int count = settings.getFurniIds().length; - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); - } - - this.setDelay(settings.getDelay()); - - return true; - } - - @Override - public WiredEffectType getType() { - return type; + public WiredEffectMoveFurniTo(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - List items = new ArrayList<>(); - - for (HabboItem item : this.items) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - if (this.items.isEmpty()) + if(this.getWiredSettings().getItemIds().isEmpty()) { return false; + } - if (stuff != null && stuff.length > 0) { - for (Object object : stuff) { - if (object instanceof HabboItem) { - HabboItem targetItem = this.items.get(Emulator.getRandom().nextInt(this.items.size())); + if(stuff == null || stuff.length == 0) { + return false; + } - if (targetItem != null) { - int indexOffset = 0; - if (!this.indexOffset.containsKey(targetItem.getId())) { - this.indexOffset.put(targetItem.getId(), indexOffset); - } else { - indexOffset = this.indexOffset.get(targetItem.getId()) + this.spacing; + int direction = this.getWiredSettings().getIntegerParams().get(PARAM_DIRECTION); + int spacing = this.getWiredSettings().getIntegerParams().get(PARAM_SPACING); + + for (Object object : stuff) { + if (object instanceof RoomItem) { + int randomItemIndex = Emulator.getRandom().nextInt(this.getWiredSettings().getItemIds().size()); + + RoomItem[] items = this.getWiredSettings().getItems(room).toArray(new RoomItem[this.getWiredSettings().getItemIds().size()]); + + RoomItem randomItem = items[randomItemIndex]; + + if (randomItem != null) { + int indexOffset = 0; + + RoomTile objectTile = room.getLayout().getTile(randomItem.getCurrentPosition().getX(), randomItem.getCurrentPosition().getY()); + + if (objectTile != null) { + THashSet refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(((RoomItem) object).getCurrentPosition().getX(), ((RoomItem) object).getCurrentPosition().getY()), ((RoomItem) object).getBaseItem().getWidth(), ((RoomItem) object).getBaseItem().getLength(), ((RoomItem) object).getRotation()); + + RoomTile tile = room.getLayout().getTileInFront(objectTile, direction, indexOffset); + if (tile == null || !tile.getAllowStack()) { + indexOffset = 0; + tile = room.getLayout().getTileInFront(objectTile, direction, indexOffset); } - RoomTile objectTile = room.getLayout().getTile(targetItem.getX(), targetItem.getY()); - - if (objectTile != null) { - THashSet refreshTiles = room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation()); - - RoomTile tile = room.getLayout().getTileInFront(objectTile, this.direction, indexOffset); - if (tile == null || !tile.getAllowStack()) { - indexOffset = 0; - tile = room.getLayout().getTileInFront(objectTile, this.direction, indexOffset); - } - - room.sendComposer(new FloorItemOnRollerComposer((HabboItem) object, null, tile, tile.getStackHeight() - ((HabboItem) object).getZ(), room).compose()); - refreshTiles.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(((HabboItem) object).getX(), ((HabboItem) object).getY()), ((HabboItem) object).getBaseItem().getWidth(), ((HabboItem) object).getBaseItem().getLength(), ((HabboItem) object).getRotation())); - room.updateTiles(refreshTiles); - this.indexOffset.put(targetItem.getId(), indexOffset); - } + room.sendComposer(new FloorItemOnRollerComposer((RoomItem) object, null, tile, tile.getStackHeight() - ((RoomItem) object).getCurrentZ(), room).compose()); + refreshTiles.addAll(room.getLayout().getTilesAt(room.getLayout().getTile(((RoomItem) object).getCurrentPosition().getX(), ((RoomItem) object).getCurrentPosition().getY()), ((RoomItem) object).getBaseItem().getWidth(), ((RoomItem) object).getBaseItem().getLength(), ((RoomItem) object).getRotation())); + room.updateTiles(refreshTiles); } } } @@ -122,101 +74,11 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { } @Override - public String getWiredData() { - THashSet itemsToRemove = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - itemsToRemove.add(item); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().isEmpty()) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(1); } - - for (HabboItem item : itemsToRemove) { - this.items.remove(item); - } - - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.direction, - this.spacing, - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.direction); - message.appendInt(this.spacing); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.direction = data.direction; - this.spacing = data.spacing; - this.setDelay(data.delay); - - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split("\t"); - - if (data.length == 4) { - try { - this.direction = Integer.parseInt(data[0]); - this.spacing = Integer.parseInt(data[1]); - this.setDelay(Integer.parseInt(data[2])); - } catch (Exception ignored) { - } - - for (String s : data[3].split("\r")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - - @Override - public void onPickUp() { - this.setDelay(0); - this.items.clear(); - this.direction = 0; - this.spacing = 0; - this.indexOffset.clear(); } @Override @@ -224,17 +86,8 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { return 495; } - static class JsonData { - int direction; - int spacing; - int delay; - List itemIds; - - public JsonData(int direction, int spacing, int delay, List itemIds) { - this.direction = direction; - this.spacing = spacing; - this.delay = delay; - this.itemIds = itemIds; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.MOVE_FURNI_TO; } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java index 86400d3b..dba15814 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveFurniTowards.java @@ -1,27 +1,23 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +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.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import com.eu.habbo.threading.runnables.WiredCollissionRunnable; import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; /** * Wired effect: move to closest user @@ -30,34 +26,27 @@ import java.util.stream.Collectors; * @author Beny. */ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.CHASE; - - private THashSet items; - - private THashMap lastDirections; - - + private THashMap lastDirections; + public WiredEffectMoveFurniTowards(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); this.lastDirections = new THashMap<>(); } - public WiredEffectMoveFurniTowards(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); + public WiredEffectMoveFurniTowards(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.lastDirections = new THashMap<>(); } - public List getAvailableDirections(HabboItem item, Room room) { - List availableDirections = new ArrayList<>(); + public List getAvailableDirections(RoomItem item, Room room) { + List availableDirections = new ArrayList<>(); RoomLayout layout = room.getLayout(); - RoomTile currentTile = layout.getTile(item.getX(), item.getY()); + RoomTile currentTile = layout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); - RoomUserRotation[] rotations = new RoomUserRotation[]{RoomUserRotation.NORTH, RoomUserRotation.EAST, RoomUserRotation.SOUTH, RoomUserRotation.WEST}; + RoomRotation[] rotations = new RoomRotation[]{RoomRotation.NORTH, RoomRotation.EAST, RoomRotation.SOUTH, RoomRotation.WEST}; - for (RoomUserRotation rot : rotations) { + for (RoomRotation rot : rotations) { RoomTile tile = layout.getTileInFront(currentTile, rot.getValue()); if (tile == null || tile.getState() == RoomTileState.BLOCKED || tile.getState() == RoomTileState.INVALID) @@ -66,10 +55,10 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { if (!layout.tileExists(tile.getX(), tile.getY())) continue; - if (room.furnitureFitsAt(tile, item, item.getRotation()) == FurnitureMovementError.INVALID_MOVE) + if (room.getRoomItemManager().furnitureFitsAt(tile, item, item.getRotation(), true) == FurnitureMovementError.INVALID_MOVE) continue; - HabboItem topItem = room.getTopItemAt(tile.getX(), tile.getY()); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY()); if (topItem != null && !topItem.getBaseItem().allowStack()) continue; @@ -83,26 +72,14 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; } - for (HabboItem item : items) { - this.items.remove(item); - } - - for (HabboItem item : this.items) { - - if (item == null) - continue; - + for (RoomItem item : this.getWiredSettings().getItems(room)) { // direction the furni will move in - RoomUserRotation moveDirection = null; - RoomUserRotation lastDirection = lastDirections.get(item.getId()); + RoomRotation moveDirection = null; + RoomRotation lastDirection = lastDirections.get(item.getId()); // 1. Check if any user is within 3 tiles from the item RoomUnit target = null; // closest found user @@ -117,10 +94,10 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { if (target != null) break; - RoomUserRotation[] rotations = new RoomUserRotation[]{RoomUserRotation.NORTH, RoomUserRotation.EAST, RoomUserRotation.SOUTH, RoomUserRotation.WEST}; + RoomRotation[] rotations = new RoomRotation[]{RoomRotation.NORTH, RoomRotation.EAST, RoomRotation.SOUTH, RoomRotation.WEST}; - for (RoomUserRotation rot : rotations) { - RoomTile startTile = layout.getTile(item.getX(), item.getY()); + for (RoomRotation rot : rotations) { + RoomTile startTile = layout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); for (int ii = 0; ii <= i; ii++) { if (startTile == null) @@ -130,7 +107,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { } if (startTile != null && layout.tileExists(startTile.getX(), startTile.getY())) { - Collection roomUnitsAtTile = room.getRoomUnitsAt(startTile); + Collection roomUnitsAtTile = room.getRoomUnitManager().getRoomUnitsAt(startTile); if (roomUnitsAtTile.size() > 0) { target = roomUnitsAtTile.iterator().next(); if (i == 0) { // i = 0 means right next to it @@ -147,26 +124,30 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { continue; if (target != null) { - if (target.getX() == item.getX()) { - if (item.getY() < target.getY()) - moveDirection = RoomUserRotation.SOUTH; + if (target.getCurrentPosition().getX() == item.getCurrentPosition().getX()) { + if (item.getCurrentPosition().getY() < target.getCurrentPosition().getY()) + moveDirection = RoomRotation.SOUTH; else - moveDirection = RoomUserRotation.NORTH; - } else if (target.getY() == item.getY()) { - if (item.getX() < target.getX()) - moveDirection = RoomUserRotation.EAST; - else - moveDirection = RoomUserRotation.WEST; - } else if (target.getX() - item.getX() > target.getY() - item.getY()) { - if (target.getX() - item.getX() > 0) - moveDirection = RoomUserRotation.EAST; - else - moveDirection = RoomUserRotation.WEST; + moveDirection = RoomRotation.NORTH; } else { - if (target.getY() - item.getY() > 0) - moveDirection = RoomUserRotation.SOUTH; - else - moveDirection = RoomUserRotation.NORTH; + if (target.getCurrentPosition().getY() == item.getCurrentPosition().getY()) { + if (item.getCurrentPosition().getX() < target.getCurrentPosition().getX()) + moveDirection = RoomRotation.EAST; + else + moveDirection = RoomRotation.WEST; + } else { + if (target.getCurrentPosition().getX() - item.getCurrentPosition().getX() > target.getCurrentPosition().getY() - item.getCurrentPosition().getY()) { + if (target.getCurrentPosition().getX() - item.getCurrentPosition().getX() > 0) + moveDirection = RoomRotation.EAST; + else + moveDirection = RoomRotation.WEST; + } else { + if (target.getCurrentPosition().getY() - item.getCurrentPosition().getY() > 0) + moveDirection = RoomRotation.SOUTH; + else + moveDirection = RoomRotation.NORTH; + } + } } } @@ -182,7 +163,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { 3+ available - move in random direction, but never the opposite */ - List availableDirections = this.getAvailableDirections(item, room); + List availableDirections = this.getAvailableDirections(item, room); if (moveDirection != null && !availableDirections.contains(moveDirection)) moveDirection = null; @@ -196,7 +177,7 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { if (lastDirection == null) { moveDirection = availableDirections.get(Emulator.getRandom().nextInt(availableDirections.size())); } else { - RoomUserRotation oppositeLast = lastDirection.getOpposite(); + RoomRotation oppositeLast = lastDirection.getOpposite(); if (availableDirections.get(0) == oppositeLast) { moveDirection = availableDirections.get(1); @@ -206,23 +187,23 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { } } else { if (lastDirection != null) { - RoomUserRotation opposite = lastDirection.getOpposite(); + RoomRotation opposite = lastDirection.getOpposite(); availableDirections.remove(opposite); } moveDirection = availableDirections.get(Emulator.getRandom().nextInt(availableDirections.size())); } } - RoomTile newTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getX(), item.getY()), moveDirection.getValue()); + RoomTile newTile = room.getLayout().getTileInFront(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), moveDirection.getValue()); - RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY()); - double oldZ = item.getZ(); + RoomTile oldLocation = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + double oldZ = item.getCurrentZ(); if(newTile != null) { lastDirections.put(item.getId(), moveDirection); - if(newTile.getState() != RoomTileState.INVALID && newTile != oldLocation && room.furnitureFitsAt(newTile, item, item.getRotation(), true) == FurnitureMovementError.NONE) { - if (room.moveFurniTo(item, newTile, item.getRotation(), null, false) == FurnitureMovementError.NONE) { - room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newTile, item.getZ(), 0, room).compose()); + if (newTile.getState() != RoomTileState.INVALID && newTile != oldLocation && room.getRoomItemManager().furnitureFitsAt(newTile, item, item.getRotation(), true) == FurnitureMovementError.NONE) { + if (room.getRoomItemManager().moveItemTo(item, newTile, item.getRotation(), null, false, true) == FurnitureMovementError.NONE) { + room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newTile, item.getCurrentZ(), 0, room).compose()); } } } @@ -231,131 +212,13 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { return true; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new THashSet<>(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] wiredDataOld = wiredData.split("\t"); - - if (wiredDataOld.length >= 1) { - this.setDelay(Integer.parseInt(wiredDataOld[0])); - } - if (wiredDataOld.length == 2) { - if (wiredDataOld[1].contains(";")) { - for (String s : wiredDataOld[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.setDelay(0); - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.setDelay(delay); - - return true; - } - @Override protected long requiredCooldown() { return 495; } - static class JsonData { - int delay; - List itemIds; - - public JsonData(int delay, List itemIds) { - this.delay = delay; - this.itemIds = itemIds; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.CHASE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java index 6272bc69..d18fe1e1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMoveRotateFurni.java @@ -1,17 +1,18 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +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.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; import gnu.trove.set.hash.THashSet; import lombok.extern.slf4j.Slf4j; @@ -19,58 +20,61 @@ import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; @Slf4j public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable { - - public static final WiredEffectType type = WiredEffectType.MOVE_ROTATE; - private final THashSet items = new THashSet<>(WiredHandler.MAXIMUM_FURNI_SELECTION / 2); - private int direction; - private int rotation; - private final THashSet itemCooldowns; + public final int PARAM_DIRECTION = 0; + public final int PARAM_ROTATION = 1; public WiredEffectMoveRotateFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.itemCooldowns = new THashSet<>(); } - public WiredEffectMoveRotateFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.itemCooldowns = new THashSet<>(); + public WiredEffectMoveRotateFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(0); + this.getWiredSettings().getIntegerParams().add(0); + } } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - // remove items that are no longer in the room - this.items.removeIf(item -> Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; + } - for (HabboItem item : this.items) { - if(this.itemCooldowns.contains(item)) - continue; + int direction = this.getWiredSettings().getIntegerParams().get(PARAM_DIRECTION); + int rotation = this.getWiredSettings().getIntegerParams().get(PARAM_ROTATION); - int newRotation = this.rotation > 0 ? this.getNewRotation(item) : item.getRotation(); - RoomTile newLocation = room.getLayout().getTile(item.getX(), item.getY()); - RoomTile oldLocation = room.getLayout().getTile(item.getX(), item.getY()); - double oldZ = item.getZ(); + for (RoomItem item : this.getWiredSettings().getItems(room)) { + int newRotation = rotation > 0 ? this.getNewRotation(item, rotation) : item.getRotation(); + RoomTile newLocation = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + RoomTile oldLocation = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + double oldZ = item.getCurrentZ(); - if(this.direction > 0) { - RoomUserRotation moveDirection = this.getMovementDirection(); + if(direction > 0) { + RoomRotation moveDirection = this.getMovementDirection(direction); newLocation = room.getLayout().getTile( - (short) (item.getX() + ((moveDirection == RoomUserRotation.WEST || moveDirection == RoomUserRotation.NORTH_WEST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomUserRotation.EAST || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.NORTH_EAST) ? 1 : 0)))), - (short) (item.getY() + ((moveDirection == RoomUserRotation.NORTH || moveDirection == RoomUserRotation.NORTH_EAST || moveDirection == RoomUserRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomUserRotation.SOUTH || moveDirection == RoomUserRotation.SOUTH_EAST || moveDirection == RoomUserRotation.SOUTH_WEST) ? -1 : 0))) + (short) (item.getCurrentPosition().getX() + ((moveDirection == RoomRotation.WEST || moveDirection == RoomRotation.NORTH_WEST || moveDirection == RoomRotation.SOUTH_WEST) ? -1 : (((moveDirection == RoomRotation.EAST || moveDirection == RoomRotation.SOUTH_EAST || moveDirection == RoomRotation.NORTH_EAST) ? 1 : 0)))), + (short) (item.getCurrentPosition().getY() + ((moveDirection == RoomRotation.NORTH || moveDirection == RoomRotation.NORTH_EAST || moveDirection == RoomRotation.NORTH_WEST) ? 1 : ((moveDirection == RoomRotation.SOUTH || moveDirection == RoomRotation.SOUTH_EAST || moveDirection == RoomRotation.SOUTH_WEST) ? -1 : 0))) ); } boolean slideAnimation = item.getRotation() == newRotation; - FurnitureMovementError furniMoveTest = room.furnitureFitsAt(newLocation, item, newRotation, true); + FurnitureMovementError furniMoveTest = room.getRoomItemManager().furnitureFitsAt(newLocation, item, newRotation, true); if(newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != item.getRotation()) && (furniMoveTest == FurnitureMovementError.NONE || ((furniMoveTest == FurnitureMovementError.TILE_HAS_BOTS || furniMoveTest == FurnitureMovementError.TILE_HAS_HABBOS || furniMoveTest == FurnitureMovementError.TILE_HAS_PETS) && newLocation == oldLocation))) { - if(room.furnitureFitsAt(newLocation, item, newRotation, false) == FurnitureMovementError.NONE && room.moveFurniTo(item, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) { - this.itemCooldowns.add(item); - if(slideAnimation) { - room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getZ(), 0, room).compose()); + if(room.getRoomItemManager().furnitureFitsAt(newLocation, item, newRotation, false) == FurnitureMovementError.NONE) { + boolean sendUpdates = !slideAnimation; + if (room.getRoomItemManager().moveItemTo(item, newLocation, newRotation, null, sendUpdates, true) == FurnitureMovementError.NONE) { + if (slideAnimation) { + room.sendComposer(new FloorItemOnRollerComposer(item, null, oldLocation, oldZ, newLocation, item.getCurrentZ(), 0, room).compose()); + } } } } @@ -79,143 +83,13 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement return true; } - @Override - public String getWiredData() { - THashSet itemsToRemove = new THashSet<>(this.items.size() / 2); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || (room != null && room.getHabboItem(item.getId()) == null)) - itemsToRemove.add(item); - } - - for (HabboItem item : itemsToRemove) { - this.items.remove(item); - } - - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.direction, - this.rotation, - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.direction = data.direction; - this.rotation = data.rotation; - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split("\t"); - - if (data.length == 4) { - try { - this.direction = Integer.parseInt(data[0]); - this.rotation = Integer.parseInt(data[1]); - this.setDelay(Integer.parseInt(data[2])); - } catch (Exception e) { - System.out.println(e); - } - - for (String s : data[3].split("\r")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - - @Override - public void onPickUp() { - this.direction = 0; - this.rotation = 0; - this.items.clear(); - this.setDelay(0); - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(2); - message.appendInt(this.direction); - message.appendInt(this.rotation); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null) - return false; - - if(settings.getIntParams().length < 2) throw new WiredSaveException("invalid data"); - - this.direction = settings.getIntParams()[0]; - this.rotation = settings.getIntParams()[1]; - - int count = settings.getFurniIds().length; - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count", 5)) return false; - - this.items.clear(); - for (int i = 0; i < count; i++) { - this.items.add(room.getHabboItem(settings.getFurniIds()[i])); - } - - this.setDelay(settings.getDelay()); - - return true; - } - - /** * Returns a new rotation for an item based on the wired options * * @param item HabboItem * @return new rotation */ - private int getNewRotation(HabboItem item) { + private int getNewRotation(RoomItem item, int rotation) { if(item.getMaximumRotations() == 2) { return item.getRotation() == 0 ? 4 : 0; @@ -224,11 +98,11 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement return item.getRotation(); } else if(item.getMaximumRotations() > 4) { - if (this.rotation == 1) { + if (rotation == 1) { return item.getRotation() == item.getMaximumRotations() - 1 ? 0 : item.getRotation() + 1; - } else if (this.rotation == 2) { + } else if (rotation == 2) { return item.getRotation() > 0 ? item.getRotation() - 1 : item.getMaximumRotations() - 1; - } else if (this.rotation == 3) { //Random rotation + } else if (rotation == 3) { //Random rotation THashSet possibleRotations = new THashSet<>(); for (int i = 0; i < item.getMaximumRotations(); i++) { @@ -248,15 +122,15 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement } } else { - if (this.rotation == 1) { + if (rotation == 1) { return (item.getRotation() + 2) % 8; - } else if (this.rotation == 2) { + } else if (rotation == 2) { int rot = (item.getRotation() - 2) % 8; if(rot < 0) { rot += 8; } return rot; - } else if (this.rotation == 3) { //Random rotation + } else if (rotation == 3) { //Random rotation THashSet possibleRotations = new THashSet<>(); for (int i = 0; i < item.getMaximumRotations(); i++) { @@ -284,46 +158,35 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement * * @return direction */ - private RoomUserRotation getMovementDirection() { - RoomUserRotation movemementDirection = RoomUserRotation.NORTH; - if (this.direction == 1) { - movemementDirection = RoomUserRotation.values()[Emulator.getRandom().nextInt(RoomUserRotation.values().length / 2) * 2]; - } else if (this.direction == 2) { + private RoomRotation getMovementDirection(int direction) { + RoomRotation movemementDirection = RoomRotation.NORTH; + if (direction == 1) { + movemementDirection = RoomRotation.values()[Emulator.getRandom().nextInt(RoomRotation.values().length / 2) * 2]; + } else if (direction == 2) { if (Emulator.getRandom().nextInt(2) == 1) { - movemementDirection = RoomUserRotation.EAST; + movemementDirection = RoomRotation.EAST; } else { - movemementDirection = RoomUserRotation.WEST; + movemementDirection = RoomRotation.WEST; } - } else if (this.direction == 3) { + } else if (direction == 3) { if (Emulator.getRandom().nextInt(2) != 1) { - movemementDirection = RoomUserRotation.SOUTH; + movemementDirection = RoomRotation.SOUTH; } - } else if (this.direction == 4) { - movemementDirection = RoomUserRotation.SOUTH; - } else if (this.direction == 5) { - movemementDirection = RoomUserRotation.EAST; - } else if (this.direction == 7) { - movemementDirection = RoomUserRotation.WEST; + } else if (direction == 4) { + movemementDirection = RoomRotation.SOUTH; + } else if (direction == 5) { + movemementDirection = RoomRotation.EAST; + } else if (direction == 7) { + movemementDirection = RoomRotation.WEST; } return movemementDirection; } @Override - public void cycle(Room room) { - this.itemCooldowns.clear(); - } + public void cycle(Room room) {} - static class JsonData { - int direction; - int rotation; - int delay; - List itemIds; - - public JsonData(int direction, int rotation, int delay, List itemIds) { - this.direction = direction; - this.rotation = rotation; - this.delay = delay; - this.itemIds = itemIds; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.MOVE_ROTATE; } -} +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java deleted file mode 100644 index 34afbb2f..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteHabbo.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.effects; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomChatMessage; -import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredEffectMuteHabbo extends InteractionWiredEffect { - private static final WiredEffectType type = WiredEffectType.MUTE_TRIGGER; - - private int length = 5; - private String message = ""; - - public WiredEffectMuteHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredEffectMuteHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.message); - message.appendInt(1); - message.appendInt(this.length); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - if(settings.getIntParams().length < 1) throw new WiredSaveException("invalid data"); - - this.length = settings.getIntParams()[0]; - this.message = settings.getStringParam(); - - this.setDelay(settings.getDelay()); - - return true; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) - return true; - - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - if (room.hasRights(habbo)) - return false; - - room.muteHabbo(habbo, 60); - - habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED))); - } - - return true; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.length, - this.message - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.length = data.length; - this.message = data.message; - } else { - String[] data = wiredData.split("\t"); - - if (data.length >= 3) { - try { - this.setDelay(Integer.parseInt(data[0])); - this.length = Integer.parseInt(data[1]); - this.message = data[2]; - } catch (Exception ignored) { - } - } - } - } - - @Override - public void onPickUp() { - this.setDelay(0); - this.message = ""; - this.length = 0; - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - int delay; - int length; - String message; - - public JsonData(int delay, int length, String message) { - this.delay = delay; - this.length = length; - this.message = message; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteRoom.java new file mode 100644 index 00000000..53c1b449 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectMuteRoom.java @@ -0,0 +1,56 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.effects; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomChatMessage; +import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredEffectMuteRoom extends InteractionWiredEffect { + private final int PARAM_LENGTH = 0; + + public WiredEffectMuteRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredEffectMuteRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + int length = this.getWiredSettings().getIntegerParams().get(PARAM_LENGTH); + String message = this.getWiredSettings().getStringParam(); + + if (roomUnit == null) + return true; + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo != null) { + if (room.getRoomRightsManager().hasRights(habbo)) + return false; + + room.muteHabbo(habbo, 60); + + habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), habbo, habbo, RoomChatMessageBubbles.WIRED))); + } + + return true; + } + + + @Override + public WiredEffectType getType() { + return WiredEffectType.MUTE_TRIGGER; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java index 032471ac..3c49cab4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectResetTimers.java @@ -1,123 +1,34 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.WiredResetTimers; -import gnu.trove.procedure.TObjectProcedure; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredEffectResetTimers extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.RESET_TIMERS; - - private int delay = 0; - public WiredEffectResetTimers(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectResetTimers(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.getDelay()); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) { - this.setDelay(settings.getDelay()); - return true; + public WiredEffectResetTimers(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Emulator.getThreading().run(new WiredResetTimers(room), this.delay); - + Emulator.getThreading().run(new WiredResetTimers(room), this.getWiredSettings().getDelay()); return true; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.delay - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.delay = data.delay; - } else { - try { - if (!wiredData.equals("")) { - this.delay = Integer.parseInt(wiredData); - } - } catch (Exception ignored) { - } - } - - this.setDelay(this.delay); - } - - @Override - public void onPickUp() { - this.delay = 0; - this.setDelay(0); - } - @Override public WiredEffectType getType() { - return type; - } - - static class JsonData { - int delay; - - public JsonData(int delay) { - this.delay = delay; - } + return WiredEffectType.RESET_TIMERS; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java index 202da6dd..5172ea41 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTeleport.java @@ -1,51 +1,64 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTileState; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +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.types.RoomHabbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer; import com.eu.habbo.threading.runnables.RoomUnitTeleport; import com.eu.habbo.threading.runnables.SendRoomUnitEffectComposer; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; public class WiredEffectTeleport extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.TELEPORT; - protected List items; + protected List items; public WiredEffectTeleport(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); this.items = new ArrayList<>(); } - public WiredEffectTeleport(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredEffectTeleport(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.items = new ArrayList<>(); } + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; + } + + int randomItemIndex = Emulator.getRandom().nextInt(this.getWiredSettings().getItemIds().size()); + + RoomItem[] items = this.getWiredSettings().getItems(room).toArray(new RoomItem[this.getWiredSettings().getItemIds().size()]); + + RoomItem randomItem = items[randomItemIndex]; + + teleportUnitToTile(roomUnit, room.getLayout().getTile(randomItem.getCurrentPosition().getX(), randomItem.getCurrentPosition().getY())); + + return true; + } + public static void teleportUnitToTile(RoomUnit roomUnit, RoomTile tile) { - if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting()) + if (roomUnit == null || tile == null || roomUnit.isWiredTeleporting() || !(roomUnit instanceof RoomHabbo roomHabbo)) return; - Room room = roomUnit.getRoom(); + Room room = roomHabbo.getRoom(); if (room == null) { return; @@ -53,11 +66,11 @@ public class WiredEffectTeleport extends InteractionWiredEffect { // makes a temporary effect - roomUnit.getRoom().unIdle(roomUnit.getRoom().getHabbo(roomUnit)); - room.sendComposer(new AvatarEffectMessageComposer(roomUnit, 4).compose()); - Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomUnit), (long) WiredHandler.TELEPORT_DELAY + 1000); + roomHabbo.unIdle(); + room.sendComposer(new AvatarEffectMessageComposer(roomHabbo, 4).compose()); + Emulator.getThreading().run(new SendRoomUnitEffectComposer(room, roomHabbo), (long) WiredHandler.TELEPORT_DELAY + 1000); - if (tile == roomUnit.getCurrentLocation()) { + if (tile == roomHabbo.getCurrentPosition()) { return; } @@ -78,155 +91,8 @@ public class WiredEffectTeleport extends InteractionWiredEffect { } } - Emulator.getThreading().run(() -> { roomUnit.setWiredTeleporting(true); }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); - Emulator.getThreading().run(new RoomUnitTeleport(roomUnit, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomUnit.getEffectId()), WiredHandler.TELEPORT_DELAY); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) - message.appendInt(item.getId()); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.setDelay(delay); - - return true; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - this.items.removeIf(item -> item == null || item.getRoomId() != this.getRoomId() - || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null); - - if (!this.items.isEmpty()) { - int i = Emulator.getRandom().nextInt(this.items.size()); - HabboItem item = this.items.get(i); - - teleportUnitToTile(roomUnit, room.getLayout().getTile(item.getX(), item.getY())); - return true; - } - - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new ArrayList<>(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] wiredDataOld = wiredData.split("\t"); - - if (wiredDataOld.length >= 1) { - this.setDelay(Integer.parseInt(wiredDataOld[0])); - } - if (wiredDataOld.length == 2) { - if (wiredDataOld[1].contains(";")) { - for (String s : wiredDataOld[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.setDelay(0); - } - - @Override - public WiredEffectType getType() { - return type; - } - - @Override - public boolean requiresTriggeringUser() { - return true; + Emulator.getThreading().run(() -> { roomHabbo.setWiredTeleporting(true); }, Math.max(0, WiredHandler.TELEPORT_DELAY - 500)); + Emulator.getThreading().run(new RoomUnitTeleport(roomHabbo, room, tile.getX(), tile.getY(), tile.getStackHeight() + (tile.getState() == RoomTileState.SIT ? -0.5 : 0), roomHabbo.getEffectId()), WiredHandler.TELEPORT_DELAY); } @Override @@ -234,13 +100,8 @@ public class WiredEffectTeleport extends InteractionWiredEffect { return 50L; } - static class JsonData { - int delay; - List itemIds; - - public JsonData(int delay, List itemIds) { - this.delay = delay; - this.itemIds = itemIds; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.TELEPORT; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java index 2b623c3b..11ce95c7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleFurni.java @@ -1,7 +1,5 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; @@ -15,32 +13,22 @@ import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreeze import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; import com.eu.habbo.habbohotel.items.interactions.pets.*; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import gnu.trove.set.hash.THashSet; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Slf4j public class WiredEffectToggleFurni extends InteractionWiredEffect { - - public static final WiredEffectType type = WiredEffectType.TOGGLE_STATE; - - private final THashSet items; - - private static final List> FORBIDDEN_TYPES = new ArrayList<>() { + private static final List> FORBIDDEN_TYPES = new ArrayList<>() { { this.add(InteractionWired.class); this.add(InteractionTeleport.class); @@ -84,190 +72,54 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { public WiredEffectToggleFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredEffectToggleFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.setDelay(delay); - - return true; + public WiredEffectToggleFurni(int id, HabboInfo ownerInfo, Item item, String extraData, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extraData, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + for (RoomItem item : this.getWiredSettings().getItems(room)) { - THashSet itemsToRemove = new THashSet<>(); - for (HabboItem item : this.items) { if (item == null || item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) { - itemsToRemove.add(item); continue; } - try { - if (item.getBaseItem().getStateCount() > 1 || item instanceof InteractionGameTimer) { - int state = 0; - if (!item.getExtradata().isEmpty()) { - try { - state = Integer.parseInt(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc. - } catch (NumberFormatException ignored) { + if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) { + continue; + } + + if (item.getBaseItem().getStateCount() > 1 || item instanceof InteractionGameTimer) { + int state = 0; + + if (!item.getExtraData().isEmpty()) { + try { + state = Integer.parseInt(item.getExtraData()); // assumes that extradata is state, could be something else for trophies etc. + } catch (NumberFormatException ignored) { - } } - item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? habbo.getClient() : null, room, new Object[]{state, this.getType()}); } - } catch (Exception e) { - log.error("Caught exception", e); + + try { + item.onClick(habbo != null && !(item instanceof InteractionGameTimer) ? habbo.getClient() : null, room, new Object[]{state, this.getType()}); + } catch (Exception e) { + log.error("Caught exception", e); + } } } - this.items.removeAll(itemsToRemove); - return true; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) { - continue; - } - - if (item != null) { - this.items.add(item); - } - } - } else { - String[] wiredDataOld = wiredData.split("\t"); - - if (wiredDataOld.length >= 1) { - this.setDelay(Integer.parseInt(wiredDataOld[0])); - } - if (wiredDataOld.length == 2) { - if (wiredDataOld[1].contains(";")) { - for (String s : wiredDataOld[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) - continue; - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.setDelay(0); - } - @Override public WiredEffectType getType() { - return type; - } - - static class JsonData { - int delay; - List itemIds; - - public JsonData(int delay, List itemIds) { - this.delay = delay; - this.itemIds = itemIds; - } + return WiredEffectType.TOGGLE_STATE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java index 48c52c48..b91a3327 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectToggleRandom.java @@ -1,12 +1,10 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; -import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTile; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock; @@ -15,31 +13,21 @@ import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreeze import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; import com.eu.habbo.habbohotel.items.interactions.pets.*; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; -import gnu.trove.set.hash.THashSet; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Slf4j public class WiredEffectToggleRandom extends InteractionWiredEffect { - - public static final WiredEffectType type = WiredEffectType.TOGGLE_RANDOM; - - private final THashSet items = new THashSet<>(); - - private static final List> FORBIDDEN_TYPES = new ArrayList<>() { + private static final List> FORBIDDEN_TYPES = new ArrayList<>() { { this.add(InteractionWired.class); this.add(InteractionTeleport.class); @@ -83,98 +71,19 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { super(set, baseItem); } - public WiredEffectToggleRandom(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.setDelay(delay); - - return true; + public WiredEffectToggleRandom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - THashSet items = this.items; - - for (HabboItem item : items) { + for (RoomItem item : this.getWiredSettings().getItems(room)) { if (item.getRoomId() == 0 || FORBIDDEN_TYPES.stream().anyMatch(a -> a.isAssignableFrom(item.getClass()))) { - this.items.remove(item); continue; } try { - item.setExtradata(Emulator.getRandom().nextInt(item.getBaseItem().getStateCount() + 1) + ""); + item.setExtraData(Emulator.getRandom().nextInt(item.getBaseItem().getStateCount() + 1) + ""); room.updateItem(item); } catch (Exception e) { log.error("Caught exception", e); @@ -183,71 +92,8 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { return true; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - - if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable) - continue; - - if (item != null) - this.items.add(item); - } - } else { - String[] wiredDataOld = wiredData.split("\t"); - - if (wiredDataOld.length >= 1) { - this.setDelay(Integer.parseInt(wiredDataOld[0])); - } - if (wiredDataOld.length == 2) { - if (wiredDataOld[1].contains(";")) { - for (String s : wiredDataOld[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable) - continue; - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.setDelay(0); - } - @Override public WiredEffectType getType() { - return type; - } - - static class JsonData { - int delay; - List itemIds; - - public JsonData(int delay, List itemIds) { - this.delay = delay; - this.itemIds = itemIds; - } + return WiredEffectType.TOGGLE_RANDOM; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java index 64939ddc..30923e0f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectTriggerStacks.java @@ -1,118 +1,33 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; public class WiredEffectTriggerStacks extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.CALL_STACKS; - - private THashSet items; - public WiredEffectTriggerStacks(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredEffectTriggerStacks(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId() || Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - - for (HabboItem item : items) { - this.items.remove(item); - } - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - int itemsCount = settings.getFurniIds().length; - - if(itemsCount > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) { - throw new WiredSaveException("Too many furni selected"); - } - - List newItems = new ArrayList<>(); - - for (int i = 0; i < itemsCount; i++) { - int itemId = settings.getFurniIds()[i]; - HabboItem it = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(itemId); - - if(it == null) - throw new WiredSaveException(String.format("Item %s not found", itemId)); - - newItems.add(it); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.items.clear(); - this.items.addAll(newItems); - this.setDelay(delay); - - return true; + public WiredEffectTriggerStacks(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getItemIds().isEmpty()) { + return false; + } if (stuff == null || (stuff.length >= 1 && stuff[stuff.length - 1] instanceof WiredEffectTriggerStacks)) { return false; @@ -122,81 +37,29 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { boolean found; - for (HabboItem item : this.items) { + for (RoomItem item : this.getWiredSettings().getItems(room)) { //if(item instanceof InteractionWiredTrigger) { found = false; for (RoomTile tile : usedTiles) { - if (tile.getX() == item.getX() && tile.getY() == item.getY()) { + if (tile.getX() == item.getCurrentPosition().getX() && tile.getY() == item.getCurrentPosition().getY()) { found = true; break; } } if (!found) { - usedTiles.add(room.getLayout().getTile(item.getX(), item.getY())); + usedTiles.add(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); } } } - Object[] newStuff = new Object[stuff.length + 1]; - System.arraycopy(stuff, 0, newStuff, 0, stuff.length); - newStuff[newStuff.length - 1] = this; - WiredHandler.executeEffectsAtTiles(usedTiles, roomUnit, room, newStuff); - return true; - } + Object[] newStuff = new Object[stuff.length + 1]; + System.arraycopy(stuff, 0, newStuff, 0, stuff.length); + newStuff[newStuff.length - 1] = this; + WiredHandler.executeEffectsAtTiles(usedTiles, roomUnit, room, newStuff); - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new THashSet<>(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] wiredDataOld = wiredData.split("\t"); - - if (wiredDataOld.length >= 1) { - this.setDelay(Integer.parseInt(wiredDataOld[0])); - } - if (wiredDataOld.length == 2) { - if (wiredDataOld[1].contains(";")) { - for (String s : wiredDataOld[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.setDelay(0); - } - - @Override - public WiredEffectType getType() { - return type; + return true; } @Override @@ -204,13 +67,8 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { return 250; } - static class JsonData { - int delay; - List itemIds; - - public JsonData(int delay, List itemIds) { - this.delay = delay; - this.itemIds = itemIds; - } + @Override + public WiredEffectType getType() { + return WiredEffectType.CALL_STACKS; } } 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 3aa3543d..4afa7d97 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 @@ -1,166 +1,63 @@ package com.eu.habbo.habbohotel.items.interactions.wired.effects; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomChatMessage; import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.wired.WiredSaveException; import com.eu.habbo.messages.outgoing.rooms.users.WhisperMessageComposer; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredEffectWhisper extends InteractionWiredEffect { - public static final WiredEffectType type = WiredEffectType.SHOW_MESSAGE; - - protected String message = ""; - public WiredEffectWhisper(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredEffectWhisper(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.message); - message.appendInt(0); - message.appendInt(0); - message.appendInt(type.getCode()); - message.appendInt(this.getDelay()); - - if (this.requiresTriggeringUser()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getTriggers(this.getX(), this.getY()).forEach(object -> { - if (!object.isTriggeredByRoomUnit()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings, GameClient gameClient) throws WiredSaveException { - String message = settings.getStringParam(); - - if(gameClient.getHabbo() == null || !gameClient.getHabbo().hasRight(Permission.ACC_SUPERWIRED)) { - message = Emulator.getGameEnvironment().getWordFilter().filter(message, null); - message = message.substring(0, Math.min(message.length(), Emulator.getConfig().getInt("hotel.wired.message.max_length", 100))); - } - - int delay = settings.getDelay(); - - if(delay > Emulator.getConfig().getInt("hotel.wired.max_delay", 20)) - throw new WiredSaveException("Delay too long"); - - this.message = message; - this.setDelay(delay); - return true; + public WiredEffectWhisper(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (this.message.length() > 0) { - if (roomUnit != null) { - Habbo habbo = room.getHabbo(roomUnit); + if(this.getWiredSettings().getStringParam().isEmpty()) { + return false; + } - if (habbo != null) { - String msg = this.message.replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""); - habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED))); - Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg })); + if (roomUnit != null) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); - if (habbo.getRoomUnit().isIdle()) { - habbo.getRoomUnit().getRoom().unIdle(habbo); - } - return true; + if (habbo != null) { + String msg = this.getWiredSettings().getStringParam().replace("%user%", habbo.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""); + habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(msg, habbo, habbo, RoomChatMessageBubbles.WIRED))); + Emulator.getThreading().run(() -> WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, roomUnit, room, new Object[]{ msg })); + + if (habbo.getRoomUnit().isIdle()) { + habbo.getRoomUnit().unIdle(); } - } else { - for (Habbo h : room.getHabbos()) { - h.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(this.message.replace("%user%", h.getHabboInfo().getUsername()).replace("%online_count%", Emulator.getGameEnvironment().getHabboManager().getOnlineCount() + "").replace("%room_count%", Emulator.getGameEnvironment().getRoomManager().getActiveRooms().size() + ""), h, h, RoomChatMessageBubbles.WIRED))); - } - return true; } + } else { + 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))); + } + + return true; } + return false; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay())); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if(wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.setDelay(data.delay); - this.message = data.message; - } - else { - this.message = ""; - - if (wiredData.split("\t").length >= 2) { - super.setDelay(Integer.parseInt(wiredData.split("\t")[0])); - this.message = wiredData.split("\t")[1]; - } - - this.needsUpdate(true); - } - } - - @Override - public void onPickUp() { - this.message = ""; - this.setDelay(0); - } - @Override public WiredEffectType getType() { - return type; - } - - @Override - public boolean requiresTriggeringUser() { - return true; - } - - static class JsonData { - String message; - int delay; - - public JsonData(String message, int delay) { - this.message = message; - this.delay = delay; - } + return WiredEffectType.SHOW_MESSAGE; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java index 730abc0c..3f3f1396 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredBlob.java @@ -7,8 +7,9 @@ import com.eu.habbo.habbohotel.games.battlebanzai.BattleBanzaiGame; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionDefault; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import lombok.AllArgsConstructor; import lombok.Getter; @@ -39,8 +40,8 @@ public class WiredBlob extends InteractionDefault { this.parseCustomParams(); } - public WiredBlob(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredBlob(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); this.parseCustomParams(); } @@ -49,7 +50,7 @@ public class WiredBlob extends InteractionDefault { public void onPlace(Room room) { super.onPlace(room); - this.setExtradata(WiredBlobState.USED.getState()); + this.setExtraData(WiredBlobState.USED.getState()); room.updateItem(this); } @@ -57,9 +58,9 @@ public class WiredBlob extends InteractionDefault { public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { super.onWalkOn(roomUnit, room, objects); - if (!this.getExtradata().equals(WiredBlobState.ACTIVE.getState())) return; + if (!this.getExtraData().equals(WiredBlobState.ACTIVE.getState())) return; - Habbo habbo = room.getHabbo(roomUnit); + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (habbo != null) { GamePlayer player = habbo.getHabboInfo().getGamePlayer(); @@ -73,7 +74,7 @@ public class WiredBlob extends InteractionDefault { battleBanzaiGame.refreshCounters(habbo.getHabboInfo().getGamePlayer().getTeamColor()); } - this.setExtradata(WiredBlobState.USED.getState()); + this.setExtraData(WiredBlobState.USED.getState()); room.updateItem(this); } } @@ -82,20 +83,20 @@ public class WiredBlob extends InteractionDefault { @Override public void onClick(GameClient client, Room room, Object[] objects) { if (!this.RESETS_WITH_GAME && objects != null && objects.length == 2 && objects[1].equals(WiredEffectType.TOGGLE_STATE) && room.getGames().stream().anyMatch(game -> game.getState().equals(GameState.RUNNING) || game.getState().equals(GameState.PAUSED))) { - this.setExtradata(this.getExtradata().equals(WiredBlobState.ACTIVE.getState()) ? WiredBlobState.USED.getState() : WiredBlobState.ACTIVE.getState()); + this.setExtraData(this.getExtraData().equals(WiredBlobState.ACTIVE.getState()) ? WiredBlobState.USED.getState() : WiredBlobState.ACTIVE.getState()); room.updateItem(this); } } public void onGameStart(Room room) { if (this.RESETS_WITH_GAME) { - this.setExtradata(WiredBlobState.ACTIVE.getState()); + this.setExtraData(WiredBlobState.ACTIVE.getState()); room.updateItem(this); } } public void onGameEnd(Room room) { - this.setExtradata(WiredBlobState.USED.getState()); + this.setExtraData(WiredBlobState.USED.getState()); room.updateItem(this); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java index 55b01606..edd2321d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraRandom.java @@ -3,8 +3,8 @@ package com.eu.habbo.habbohotel.items.interactions.wired.extra; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredExtra; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import java.sql.ResultSet; import java.sql.SQLException; @@ -14,37 +14,12 @@ public class WiredExtraRandom extends InteractionWiredExtra { super(set, baseItem); } - public WiredExtraRandom(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredExtraRandom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { return false; } - - @Override - public String getWiredData() { - return null; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - - } - - @Override - public void onPickUp() { - - } - - @Override - public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) { - - } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java index b3931aa3..73b05345 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/extra/WiredExtraUnseen.java @@ -5,8 +5,8 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredExtra; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import lombok.Getter; import java.sql.ResultSet; @@ -22,8 +22,8 @@ public class WiredExtraUnseen extends InteractionWiredExtra { super(set, baseItem); } - public WiredExtraUnseen(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredExtraUnseen(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -31,31 +31,6 @@ public class WiredExtraUnseen extends InteractionWiredExtra { return false; } - @Override - public String getWiredData() { - return null; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - - } - - @Override - public void onPickUp() { - this.seenList.clear(); - } - - @Override - public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) { - - } - @Override public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { super.onMove(room, oldLocation, newLocation); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredEffectInteraction.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredEffectInteraction.java new file mode 100644 index 00000000..689532a8 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredEffectInteraction.java @@ -0,0 +1,13 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredEffectType; + +import java.util.List; + +public interface IWiredEffectInteraction { + WiredEffectType getType(); + void setType(WiredEffectType value); + List getBlockedTriggers(Room room); + void setBlockedTriggers(List value); +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredInteraction.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredInteraction.java new file mode 100644 index 00000000..2653f315 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredInteraction.java @@ -0,0 +1,10 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +public interface IWiredInteraction { + WiredSettings getWiredSettings(); + void setWiredSettings(WiredSettings value); + boolean execute(RoomUnit roomUnit, Room room, Object[] stuff); +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredPeriodical.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredPeriodical.java new file mode 100644 index 00000000..bea5fbd0 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredPeriodical.java @@ -0,0 +1,8 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import com.eu.habbo.habbohotel.rooms.RoomTile; + +public interface IWiredPeriodical { + int getInterval(); + void setInterval(int value); +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredSettings.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredSettings.java new file mode 100644 index 00000000..5bccb38a --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredSettings.java @@ -0,0 +1,19 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import lombok.Getter; +import lombok.Setter; + +import java.util.List; + +public interface IWiredSettings { + List getIntegerParams(); + void setIntegerParams(List value); + String getStringParam(); + void setStringParam(String value); + List getItemIds(); + void setItemIds(List value); + int getDelay(); + void setDelay(int value); + int getSelectionType(); + void setSelectionType(int value); +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredTriggerInteraction.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredTriggerInteraction.java new file mode 100644 index 00000000..b27a81ca --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/IWiredTriggerInteraction.java @@ -0,0 +1,13 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.util.List; + +public interface IWiredTriggerInteraction { + WiredTriggerType getType(); + void setType(WiredTriggerType value); + List getBlockedEffects(Room room); + void setBlockedEffects(List value); +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java index 9f631c9d..c0cd89fa 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java @@ -1,10 +1,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; -import gnu.trove.set.hash.THashSet; + +import java.util.List; public interface InteractionWiredMatchFurniSettings { - THashSet getMatchFurniSettings(); + List getMatchSettings(); boolean shouldMatchState(); boolean shouldMatchRotation(); boolean shouldMatchPosition(); diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/WiredTriggerReset.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/WiredTriggerReset.java new file mode 100644 index 00000000..f8c9fa03 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/WiredTriggerReset.java @@ -0,0 +1,5 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +public interface WiredTriggerReset { + void resetTimer(); +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java index d9ce1284..6b7aade0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtSetTime.java @@ -3,129 +3,50 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.WiredExecuteTask; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements WiredTriggerReset { - public final static WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME; + public final int PARAM_EXECUTE_TIME = 0; - public int executeTime; public int taskId; public WiredTriggerAtSetTime(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerAtSetTime(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerAtSetTime(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME) * 500); return true; } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.executeTime - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.executeTime = data.executeTime; - } else { - if (wiredData.length() >= 1) { - this.executeTime = (Integer.parseInt(wiredData)); - } + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(1); } - - if (this.executeTime < 500) { - this.executeTime = 20 * 500; - } - this.taskId = 1; - Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime); - } - - @Override - public void onPickUp() { - this.executeTime = 0; - this.taskId = 0; - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.executeTime / 500); - message.appendInt(1); - message.appendInt(this.getType().getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.executeTime = settings.getIntParams()[0] * 500; - - this.resetTimer(); - - return true; } @Override public void resetTimer() { this.taskId++; - - Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime); + Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME) * 500); } - static class JsonData { - int executeTime; - - public JsonData(int executeTime) { - this.executeTime = executeTime; - } + @Override + public WiredTriggerType getType() { + return WiredTriggerType.AT_GIVEN_TIME; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java index bde10d78..56ad9c57 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerAtTimeLong.java @@ -3,126 +3,50 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.WiredExecuteTask; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements WiredTriggerReset { - private static final WiredTriggerType type = WiredTriggerType.AT_GIVEN_TIME; + public final int PARAM_EXECUTE_TIME = 0; public int taskId; - private int executeTime; public WiredTriggerAtTimeLong(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerAtTimeLong(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerAtTimeLong(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - return true; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.executeTime - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.executeTime = data.executeTime; - } else { - if (wiredData.length() >= 1) { - this.executeTime = (Integer.parseInt(wiredData)); - } - } - - if (this.executeTime < 500) { - this.executeTime = 20 * 500; - } this.taskId = 1; - Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime); - } - - @Override - public void onPickUp() { - this.executeTime = 0; - this.taskId = 0; - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.executeTime / 500); - message.appendInt(1); - message.appendInt(this.getType().getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.executeTime = settings.getIntParams()[0] * 500; - + Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME)); return true; } + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(1); + } + } + @Override public void resetTimer() { this.taskId++; - - Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime); + Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId())), this.getWiredSettings().getIntegerParams().get(PARAM_EXECUTE_TIME)); } - static class JsonData { - int executeTime; - - public JsonData(int executeTime) { - this.executeTime = executeTime; - } + @Override + public WiredTriggerType getType() { + return WiredTriggerType.AT_GIVEN_TIME; } } 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 c069c39d..1776fa03 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 @@ -1,179 +1,42 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; @Slf4j public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { - - - public final static WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI; - - private final THashSet items; - private String botName = ""; - public WiredTriggerBotReachedFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredTriggerBotReachedFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()) == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName); - message.appendInt(0); - message.appendInt(0); - message.appendInt(WiredTriggerType.BOT_REACHED_STF.getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - this.botName = settings.getStringParam(); - - this.items.clear(); - - int count = settings.getFurniIds().length; - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i])); - } - - return true; + public WiredTriggerBotReachedFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (stuff.length >= 1) { - if (stuff[0] instanceof HabboItem) { - return this.items.contains(stuff[0]) && room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); - } + if(stuff.length == 0) { + return false; } + + 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 false; } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.botName, - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.botName = data.botName; - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - String[] data = wiredData.split(":"); - - if (data.length == 1) { - this.botName = data[0]; - } else if (data.length == 2) { - this.botName = data[0]; - - String[] items = data[1].split(";"); - - for (String id : items) { - try { - HabboItem item = room.getHabboItem(Integer.parseInt(id)); - - if (item != null) - this.items.add(item); - } catch (Exception e) { - log.error("Caught exception", e); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - this.botName = ""; - } - - static class JsonData { - String botName; - List itemIds; - - public JsonData(String botName, List itemIds) { - this.botName = botName; - this.itemIds = itemIds; - } + public WiredTriggerType getType() { + return WiredTriggerType.WALKS_ON_FURNI; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java deleted file mode 100644 index c303cb59..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedHabbo.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.triggers; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger { - public final static WiredTriggerType type = WiredTriggerType.BOT_REACHED_AVTR; - - private String botName = ""; - - public WiredTriggerBotReachedHabbo(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredTriggerBotReachedHabbo(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.botName); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.botName = settings.getStringParam(); - - return true; - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - return room.getBots(this.botName).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.botName - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.botName = data.botName; - } else { - this.botName = wiredData; - } - } - - @Override - public void onPickUp() { - this.botName = ""; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - String botName; - - public JsonData(String botName) { - this.botName = botName; - } - } -} 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 new file mode 100644 index 00000000..93758c00 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerBotReachedRoom.java @@ -0,0 +1,31 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.triggers; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredTriggerBotReachedRoom extends InteractionWiredTrigger { + public WiredTriggerBotReachedRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredTriggerBotReachedRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + return room.getRoomUnitManager().getBotsByName(this.getWiredSettings().getStringParam()).stream().anyMatch(bot -> bot.getRoomUnit() == roomUnit); + } + + @Override + public WiredTriggerType getType() { + return WiredTriggerType.BOT_REACHED_AVTR; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java index 317ac801..da95fec8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerCollision.java @@ -2,13 +2,11 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; @@ -20,57 +18,17 @@ public class WiredTriggerCollision extends InteractionWiredTrigger { super(set, baseItem); } - public WiredTriggerCollision(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerCollision(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - return stuff.length > 0 && stuff[0] instanceof HabboItem; - } - - @Override - public String getWiredData() { - return ""; - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - - } - - @Override - public void onPickUp() { - + return stuff.length > 0 && stuff[0] instanceof RoomItem; } @Override public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(type.getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - return true; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; + return WiredTriggerType.COLLISION; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java index 48bd083d..7d8257e8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerFurniStateToggled.java @@ -1,162 +1,41 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; -import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger { - private static final WiredTriggerType type = WiredTriggerType.STATE_CHANGED; - - private THashSet items; - public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.items = new THashSet<>(); } - public WiredTriggerFurniStateToggled(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); + public WiredTriggerFurniStateToggled(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (stuff.length >= 1) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - for (Object object : stuff) { - if (object instanceof WiredEffectType) { - return false; - } - } - - if (stuff[0] instanceof HabboItem) { - return this.items.contains(stuff[0]); - } - } + if(stuff.length == 0 || room.getRoomUnitManager().getHabboByRoomUnit(roomUnit) == null) { + return false; } + + if (stuff[0] instanceof RoomItem && !(stuff[0] instanceof WiredEffectType)) { + return this.getWiredSettings().getItems(room).contains(stuff[0]); + } + return false; } - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items = new THashSet<>(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - if (wiredData.split(":").length >= 3) { - super.setDelay(Integer.parseInt(wiredData.split(":")[0])); - - if (!wiredData.split(":")[2].equals("\t")) { - for (String s : wiredData.split(":")[2].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - } - @Override public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.items) { - if (item.getRoomId() != this.getRoomId()) { - items.add(item); - continue; - } - - if (room.getHabboItem(item.getId()) == null) { - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.items.clear(); - - int count = settings.getFurniIds().length; - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i])); - } - - return true; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } + return WiredTriggerType.STATE_CHANGED; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java index 3de40ee4..3dca0c5f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameEnds.java @@ -2,26 +2,21 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredTriggerGameEnds extends InteractionWiredTrigger { - private static final WiredTriggerType type = WiredTriggerType.GAME_ENDS; - public WiredTriggerGameEnds(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerGameEnds(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerGameEnds(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -29,56 +24,8 @@ public class WiredTriggerGameEnds extends InteractionWiredTrigger { return true; } - @Override - public String getWiredData() { - return ""; - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - } - - @Override - public void onPickUp() { - - } - @Override public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - return true; + return WiredTriggerType.GAME_ENDS; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java index 922e5f3f..d563cd1c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerGameStarts.java @@ -2,26 +2,21 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; public class WiredTriggerGameStarts extends InteractionWiredTrigger { - private static final WiredTriggerType type = WiredTriggerType.GAME_STARTS; - public WiredTriggerGameStarts(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerGameStarts(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerGameStarts(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -29,56 +24,8 @@ public class WiredTriggerGameStarts extends InteractionWiredTrigger { return true; } - @Override - public String getWiredData() { - return ""; - } - - @Override - public void loadWiredData(ResultSet set, Room room) { - } - - @Override - public void onPickUp() { - - } - @Override public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(type.getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - return true; + return WiredTriggerType.GAME_STARTS; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java deleted file mode 100644 index a6e0ae7c..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboEntersRoom.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.triggers; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger { - public static final WiredTriggerType type = WiredTriggerType.ENTER_ROOM; - - private String username = ""; - - public WiredTriggerHabboEntersRoom(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredTriggerHabboEntersRoom(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - Habbo habbo = room.getHabbo(roomUnit); - - if (habbo != null) { - if (this.username.length() > 0) { - return habbo.getHabboInfo().getUsername().equalsIgnoreCase(this.username); - } - - return true; - } - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.username - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.username = data.username; - } else { - this.username = wiredData; - } - } - - @Override - public void onPickUp() { - this.username = ""; - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.username); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.username = settings.getStringParam(); - - return true; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - String username; - - public JsonData(String username) { - this.username = username; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java deleted file mode 100644 index 0e3a04c4..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboSaysKeyword.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.triggers; - -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger { - private static final WiredTriggerType type = WiredTriggerType.SAY_SOMETHING; - - private boolean ownerOnly = false; - private String key = ""; - - public WiredTriggerHabboSaysKeyword(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - } - - public WiredTriggerHabboSaysKeyword(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (this.key.length() > 0) { - if (stuff[0] instanceof String) { - if (((String) stuff[0]).toLowerCase().contains(this.key.toLowerCase())) { - Habbo habbo = room.getHabbo(roomUnit); - return !this.ownerOnly || (habbo != null && room.getOwnerId() == habbo.getHabboInfo().getId()); - } - } - } - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.ownerOnly, - this.key - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.ownerOnly = data.ownerOnly; - this.key = data.key; - } else { - String[] data = wiredData.split("\t"); - - if (data.length == 2) { - this.ownerOnly = data[0].equalsIgnoreCase("1"); - this.key = data[1]; - } - } - } - - @Override - public void onPickUp() { - this.ownerOnly = false; - this.key = ""; - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(this.key); - message.appendInt(0); - message.appendInt(1); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.ownerOnly = settings.getIntParams()[0] == 1; - this.key = settings.getStringParam(); - - return true; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - boolean ownerOnly; - String key; - - public JsonData(boolean ownerOnly, String key) { - this.ownerOnly = ownerOnly; - this.key = key; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java deleted file mode 100644 index 02623288..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOffFurni.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.triggers; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; - -public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger { - public static final WiredTriggerType type = WiredTriggerType.WALKS_OFF_FURNI; - - private final THashSet items; - - public WiredTriggerHabboWalkOffFurni(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - this.items = new THashSet<>(); - } - - public WiredTriggerHabboWalkOffFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (stuff.length >= 1) { - if (stuff[0] instanceof HabboItem) { - return this.items.contains(stuff[0]); - } - } - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new WiredTriggerFurniStateToggled.JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - if (wiredData.split(":").length >= 3) { - super.setDelay(Integer.parseInt(wiredData.split(":")[0])); - - if (!wiredData.split(":")[2].equals("\t")) { - for (String s : wiredData.split(":")[2].split(";")) { - if (s.isEmpty()) - continue; - - try { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } catch (Exception ignored) { - } - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - if (room == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (room.getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.items.clear(); - - int count = settings.getFurniIds().length; - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i])); - } - - return true; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java deleted file mode 100644 index 4c779ca6..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerHabboWalkOnFurni.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.triggers; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.stream.Collectors; - -public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger { - public static final WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI; - - private THashSet items; - - public WiredTriggerHabboWalkOnFurni(ResultSet set, Item baseItem) throws SQLException { - super(set, baseItem); - this.items = new THashSet<>(); - } - - public WiredTriggerHabboWalkOnFurni(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); - this.items = new THashSet<>(); - } - - @Override - public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (stuff.length >= 1) { - if (stuff[0] instanceof HabboItem) { - return this.items.contains(stuff[0]); - } - } - return false; - } - - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - THashSet items = new THashSet<>(); - - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()) == null) { - items.addAll(this.items); - } else { - for (HabboItem item : this.items) { - if (Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(item.getId()) == null) - items.add(item); - } - } - - for (HabboItem item : items) { - this.items.remove(item); - } - - message.appendBoolean(false); - message.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); - message.appendInt(this.items.size()); - for (HabboItem item : this.items) { - message.appendInt(item.getId()); - } - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(0); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - this.items.clear(); - - int count = settings.getFurniIds().length; - - for (int i = 0; i < count; i++) { - this.items.add(Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()).getHabboItem(settings.getFurniIds()[i])); - } - - return true; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.items.clear(); - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - for (Integer id: data.itemIds) { - HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); - } - } - } else { - if (wiredData.split(":").length >= 3) { - super.setDelay(Integer.parseInt(wiredData.split(":")[0])); - - if (!wiredData.split(":")[2].equals("\t")) { - for (String s : wiredData.split(":")[2].split(";")) { - if (s.isEmpty()) - continue; - - try { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); - - if (item != null) - this.items.add(item); - } catch (Exception ignored) { - } - } - } - } - } - } - - @Override - public void onPickUp() { - this.items.clear(); - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - List itemIds; - - public JsonData(List itemIds) { - this.itemIds = itemIds; - } - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java index c97eaad8..a194425c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeater.java @@ -1,35 +1,33 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredPeriodical; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; +import lombok.Setter; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset { - public static final WiredTriggerType type = WiredTriggerType.PERIODICALLY; - public static final int DEFAULT_DELAY = 10 * 500; - - protected int repeatTime = DEFAULT_DELAY; +public class WiredTriggerRepeater extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset { + public final int PARAM_REPEAT_TIME = 0; protected int counter = 0; + @Setter + private int interval; public WiredTriggerRepeater(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerRepeater(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerRepeater(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -38,113 +36,53 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.repeatTime - )); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(1); + } } @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.repeatTime = data.repeatTime; - } else { - if (wiredData.length() >= 1) { - this.repeatTime = (Integer.parseInt(wiredData)); + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + if(room.getTriggersOnRoom().containsKey(oldLocation)) { + if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) { + room.getTriggersOnRoom().remove(oldLocation); } } - if (this.repeatTime < 500) { - this.repeatTime = 20 * 500; - } + super.onMove(room, oldLocation, newLocation); } @Override - public void onPickUp() { - this.repeatTime = DEFAULT_DELAY; - this.counter = 0; - } + public void onPickUp(Room room) { + RoomTile oldLocation = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.repeatTime / 500); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.repeatTime = settings.getIntParams()[0] * 500; - this.counter = 0; - - if (this.repeatTime < 500) { - this.repeatTime = 500; - } - - return true; - } - - @Override - public void cycle(Room room) { - this.counter += 500; - if (this.counter >= this.repeatTime) { - this.counter = 0; - if (this.getRoomId() != 0) { - if (room.isLoaded()) { - WiredHandler.handle(this, null, room, new Object[]{this}); - } + if(room.getTriggersOnRoom().containsKey(oldLocation)) { + if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) { + room.getTriggersOnRoom().remove(oldLocation); } } + + super.onPickUp(room); + } + + public int getInterval() { + return this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 500; } @Override public void resetTimer() { this.counter = 0; if (this.getRoomId() != 0) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room != null && room.isLoaded()) { WiredHandler.handle(this, null, room, new Object[]{this}); } } } - static class JsonData { - int repeatTime; - - public JsonData(int repeatTime) { - this.repeatTime = repeatTime; - } + @Override + public WiredTriggerType getType() { + return WiredTriggerType.PERIODICALLY; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java index 8984c313..41d05b1d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRepeaterLong.java @@ -1,34 +1,32 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.IWiredPeriodical; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; +import lombok.Setter; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements ICycleable, WiredTriggerReset { - public static final int DEFAULT_DELAY = 10 * 5000; - private static final WiredTriggerType type = WiredTriggerType.PERIODICALLY_LONG; - private int repeatTime = DEFAULT_DELAY; - private int counter = 0; +public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements IWiredPeriodical, WiredTriggerReset { + public final int PARAM_REPEAT_TIME = 0; + protected int counter = 0; + @Setter + private int interval; public WiredTriggerRepeaterLong(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerRepeaterLong(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerRepeaterLong(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -37,108 +35,53 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.repeatTime - )); + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(1); + } } @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.repeatTime = data.repeatTime; - } else { - if (wiredData.length() >= 1) { - this.repeatTime = (Integer.parseInt(wiredData)); + public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { + if(room.getTriggersOnRoom().containsKey(oldLocation)) { + if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) { + room.getTriggersOnRoom().remove(oldLocation); } } - if (this.repeatTime < 5000) { - this.repeatTime = 20 * 5000; - } + super.onMove(room, oldLocation, newLocation); } @Override - public void onPickUp() { - this.repeatTime = DEFAULT_DELAY; - } + public void onPickUp(Room room) { + RoomTile oldLocation = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); - @Override - public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.repeatTime / 5000); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - - if (!this.isTriggeredByRoomUnit()) { - List invalidTriggers = new ArrayList<>(); - room.getRoomSpecialTypes().getEffects(this.getX(), this.getY()).forEach(object -> { - if (object.requiresTriggeringUser()) { - invalidTriggers.add(object.getBaseItem().getSpriteId()); - } - return true; - }); - message.appendInt(invalidTriggers.size()); - for (Integer i : invalidTriggers) { - message.appendInt(i); - } - } else { - message.appendInt(0); - } - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.repeatTime = settings.getIntParams()[0] * 5000; - this.counter = 0; - return true; - } - - - @Override - public void cycle(Room room) { - this.counter += 500; - if (this.counter >= this.repeatTime) { - this.counter = 0; - if (this.getRoomId() != 0) { - if (room.isLoaded()) { - WiredHandler.handle(this, null, room, new Object[]{this}); - } + if(room.getTriggersOnRoom().containsKey(oldLocation)) { + if(room.getTriggersOnRoom().get(oldLocation).getId() == this.getId()) { + room.getTriggersOnRoom().remove(oldLocation); } } + + super.onPickUp(room); + } + + public int getInterval() { + return this.getWiredSettings().getIntegerParams().get(PARAM_REPEAT_TIME) * 5000; } @Override public void resetTimer() { this.counter = 0; if (this.getRoomId() != 0) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getRoomId()); if (room != null && room.isLoaded()) { WiredHandler.handle(this, null, room, new Object[]{this}); } } } - static class JsonData { - int repeatTime; - - public JsonData(int repeatTime) { - this.repeatTime = repeatTime; - } + @Override + public WiredTriggerType getType() { + return WiredTriggerType.PERIODICALLY_LONG; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomEntersRoom.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomEntersRoom.java new file mode 100644 index 00000000..9fc0b6d2 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomEntersRoom.java @@ -0,0 +1,42 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.triggers; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredTriggerRoomEntersRoom extends InteractionWiredTrigger { + public WiredTriggerRoomEntersRoom(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredTriggerRoomEntersRoom(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(this.getWiredSettings().getStringParam().isEmpty()) { + return true; + } + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + + if (habbo != null) { + return habbo.getHabboInfo().getUsername().equalsIgnoreCase(this.getWiredSettings().getStringParam()); + } + + return false; + } + + @Override + public WiredTriggerType getType() { + return WiredTriggerType.ENTER_ROOM; + } +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomSaysKeyword.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomSaysKeyword.java new file mode 100644 index 00000000..1c19b48a --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomSaysKeyword.java @@ -0,0 +1,54 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.triggers; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredTriggerRoomSaysKeyword extends InteractionWiredTrigger { + public int PARAM_OWNER_ONLY = 0; + + public WiredTriggerRoomSaysKeyword(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredTriggerRoomSaysKeyword(int id, HabboInfo ownerInfo, Item item, String extraData, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extraData, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if (this.getWiredSettings().getStringParam().isEmpty()) { + return false; + } + + boolean ownerOnly = this.getWiredSettings().getIntegerParams().get(PARAM_OWNER_ONLY) == 1; + + if (stuff[0] instanceof String) { + if (((String) stuff[0]).toLowerCase().contains(this.getWiredSettings().getStringParam().toLowerCase())) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); + return !ownerOnly || (habbo != null && room.getRoomInfo().getOwnerInfo().getId() == habbo.getHabboInfo().getId()); + } + } + + return false; + } + + @Override + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(0); + } + } + + @Override + public WiredTriggerType getType() { + return WiredTriggerType.SAY_SOMETHING; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomWalkOffFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomWalkOffFurni.java new file mode 100644 index 00000000..42af4a53 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomWalkOffFurni.java @@ -0,0 +1,40 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.triggers; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredTriggerRoomWalkOffFurni extends InteractionWiredTrigger { + public WiredTriggerRoomWalkOffFurni(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredTriggerRoomWalkOffFurni(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(stuff.length == 0) { + return false; + } + + if (stuff[0] instanceof RoomItem) { + return this.getWiredSettings().getItems(room).contains(stuff[0]); + } + + return false; + } + + @Override + public WiredTriggerType getType() { + return WiredTriggerType.WALKS_OFF_FURNI; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomWalkOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomWalkOnFurni.java new file mode 100644 index 00000000..da3b0c56 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerRoomWalkOnFurni.java @@ -0,0 +1,40 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.triggers; + +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class WiredTriggerRoomWalkOnFurni extends InteractionWiredTrigger { + public WiredTriggerRoomWalkOnFurni(ResultSet set, Item baseItem) throws SQLException { + super(set, baseItem); + } + + public WiredTriggerRoomWalkOnFurni(int id, HabboInfo ownerInfo, Item item, String extraData, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extraData, limitedStack, limitedSells); + } + + @Override + public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { + if(stuff.length == 0) { + return false; + } + + if (stuff[0] instanceof RoomItem) { + return this.getWiredSettings().getItems(room).contains(stuff[0]); + } + + return false; + } + + @Override + public WiredTriggerType getType() { + return WiredTriggerType.WALKS_ON_FURNI; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java index 449e165e..5e189abe 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerScoreAchieved.java @@ -2,26 +2,23 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; -import com.eu.habbo.messages.ServerMessage; import java.sql.ResultSet; import java.sql.SQLException; public class WiredTriggerScoreAchieved extends InteractionWiredTrigger { - private static final WiredTriggerType type = WiredTriggerType.SCORE_ACHIEVED; - private int score = 0; + public final int PARAM_SCORE = 0; public WiredTriggerScoreAchieved(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } - public WiredTriggerScoreAchieved(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerScoreAchieved(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override @@ -30,77 +27,21 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger { int points = (Integer) stuff[0]; int amountAdded = (Integer) stuff[1]; - return points - amountAdded < this.score && points >= this.score; + return points - amountAdded < this.getWiredSettings().getIntegerParams().get(PARAM_SCORE) && points >= this.getWiredSettings().getIntegerParams().get(PARAM_SCORE); } return false; } @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.score - )); - } - - @Override - public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wiredData = set.getString("wired_data"); - - if (wiredData.startsWith("{")) { - JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - this.score = data.score; - } else { - try { - this.score = Integer.parseInt(wiredData); - } catch (Exception ignored) { - } + public void loadDefaultIntegerParams() { + if(this.getWiredSettings().getIntegerParams().size() == 0) { + this.getWiredSettings().getIntegerParams().add(1); } } - @Override - public void onPickUp() { - this.score = 0; - } - @Override public WiredTriggerType getType() { - return type; - } - - @Override - public void serializeWiredData(ServerMessage message, Room room) { - message.appendBoolean(false); - message.appendInt(5); - message.appendInt(0); - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(1); - message.appendInt(this.score); - message.appendInt(0); - message.appendInt(this.getType().getCode()); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(WiredSettings settings) { - if(settings.getIntParams().length < 1) return false; - this.score = settings.getIntParams()[0]; - return true; - } - - @Override - public boolean isTriggeredByRoomUnit() { - return true; - } - - static class JsonData { - int score; - - public JsonData(int score) { - this.score = score; - } + return WiredTriggerType.SCORE_ACHIEVED; } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java index feee2674..8b5521a4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamLoses.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import java.sql.ResultSet; @@ -11,8 +12,8 @@ public class WiredTriggerTeamLoses extends WiredTriggerGameStarts { super(set, baseItem); } - public WiredTriggerTeamLoses(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerTeamLoses(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java index afe8124c..ce03c230 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/triggers/WiredTriggerTeamWins.java @@ -1,6 +1,7 @@ package com.eu.habbo.habbohotel.items.interactions.wired.triggers; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import java.sql.ResultSet; @@ -11,8 +12,8 @@ public class WiredTriggerTeamWins extends WiredTriggerGameStarts { super(set, baseItem); } - public WiredTriggerTeamWins(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { - super(id, userId, item, extradata, limitedStack, limitedSells); + public WiredTriggerTeamWins(int id, HabboInfo ownerInfo, Item item, String extradata, int limitedStack, int limitedSells) { + super(id, ownerInfo, item, extradata, limitedStack, limitedSells); } @Override diff --git a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java index 5f142514..ffbf0673 100644 --- a/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java +++ b/src/main/java/com/eu/habbo/habbohotel/messenger/Messenger.java @@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.achievements.Achievement; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.outgoing.friends.UpdateFriendComposer; import com.eu.habbo.plugin.events.users.friends.UserAcceptFriendRequestEvent; import gnu.trove.map.hash.THashMap; @@ -77,7 +76,7 @@ public class Messenger { if (user != null) { habboInfo = user.getHabboInfo(); } else { - habboInfo = HabboManager.getOfflineHabboInfo(friend); + habboInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(friend); } if (habboInfo == null) { diff --git a/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java b/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java index 05ccdc3a..aacaedbc 100644 --- a/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java +++ b/src/main/java/com/eu/habbo/habbohotel/messenger/MessengerBuddy.java @@ -57,7 +57,7 @@ public class MessengerBuddy implements Runnable, ISerialize { Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(this.username); if (habbo != null) { - this.inRoom = habbo.getHabboInfo().getCurrentRoom() != null; + this.inRoom = habbo.getRoomUnit().getRoom() != null; } } } catch (SQLException e) { @@ -98,7 +98,7 @@ public class MessengerBuddy implements Runnable, ISerialize { this.look = habbo.getHabboInfo().getLook(); this.relation = 0; this.userOne = userOne; - this.inRoom = habbo.getHabboInfo().getCurrentRoom() != null; + this.inRoom = habbo.getRoomUnit().getRoom() != null; } public void setOnline(boolean value) { diff --git a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java index a3dfbd23..b0b25d56 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolIssue.java @@ -1,7 +1,7 @@ package com.eu.habbo.habbohotel.modtool; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ISerialize; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.UpdateModToolIssue; @@ -29,7 +29,7 @@ public class ModToolIssue implements ISerialize { public int groupId = -1; public int threadId = -1; public int commentId = -1; - public HabboItem photoItem = null; + public RoomItem photoItem = null; public ModToolIssue(ResultSet set) throws SQLException { this.id = set.getInt("id"); 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 96ea6976..7eaa80ca 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -7,7 +7,6 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomState; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.outgoing.modtool.IssueCloseNotificationMessageComposer; import com.eu.habbo.messages.outgoing.modtool.IssueInfoMessageComposer; @@ -320,7 +319,7 @@ public class ModToolManager { "DESC LIMIT ?) x " + (groupUser ? "GROUP BY user_id" : "") + ";")) { - statement.setInt(1, room.getId()); + statement.setInt(1, room.getRoomInfo().getId()); if (fromTimestamp > 0) statement.setInt(2, fromTimestamp); @@ -386,7 +385,7 @@ public class ModToolManager { } public void alert(Habbo moderator, Habbo target, String message, SupportUserAlertedReason reason) { - if (!moderator.hasRight(Permission.ACC_SUPPORTTOOL)) { + if (!moderator.hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { ScripterManager.scripterDetected(moderator.getClient(), Emulator.getTexts().getValue("scripter.warning.modtools.alert").replace("%username%", moderator.getHabboInfo().getUsername()).replace("%message%", message)); return; } @@ -401,9 +400,9 @@ public class ModToolManager { } public void kick(Habbo moderator, Habbo target, String message) { - if (moderator.hasRight(Permission.ACC_SUPPORTTOOL) && !target.hasRight(Permission.ACC_UNKICKABLE)) { - if (target.getHabboInfo().getCurrentRoom() != null) { - Emulator.getGameEnvironment().getRoomManager().leaveRoom(target, target.getHabboInfo().getCurrentRoom()); + if (moderator.hasPermissionRight(Permission.ACC_SUPPORTTOOL) && !target.hasPermissionRight(Permission.ACC_UNKICKABLE)) { + if (target.getRoomUnit().getRoom() != null) { + Emulator.getGameEnvironment().getRoomManager().leaveRoom(target, target.getRoomUnit().getRoom()); } this.alert(moderator, target, message, SupportUserAlertedReason.KICKED); } @@ -415,7 +414,7 @@ public class ModToolManager { List bans = new ArrayList<>(); Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(targetUserId); - HabboInfo offlineInfo = target != null ? target.getHabboInfo() : HabboManager.getOfflineHabboInfo(targetUserId); + HabboInfo offlineInfo = target != null ? target.getHabboInfo() : Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(targetUserId); if (moderator.getHabboInfo().getPermissionGroup().getId() < offlineInfo.getPermissionGroup().getId()) { return bans; @@ -472,18 +471,19 @@ public class ModToolManager { Emulator.getPluginManager().fireEvent(roomActionEvent); if (roomActionEvent.isChangeTitle()) { - room.setName(Emulator.getTexts().getValue("hotel.room.inappropriate.title")); + String name = Emulator.getTexts().getValue("hotel.room.inappropriate.title"); + room.getRoomInfo().setName(name); room.setNeedsUpdate(true); } if (roomActionEvent.isLockDoor()) { - room.setState(RoomState.LOCKED); + room.getRoomInfo().setState(RoomState.LOCKED); room.setNeedsUpdate(true); } if (roomActionEvent.isKickUsers()) { - for (Habbo habbo : room.getHabbos()) { - if (!(habbo.hasRight(Permission.ACC_UNKICKABLE) || habbo.hasRight(Permission.ACC_SUPPORTTOOL) || room.isOwner(habbo))) { + 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/modtool/WordFilter.java b/src/main/java/com/eu/habbo/habbohotel/modtool/WordFilter.java index 8310645f..5c625d03 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/WordFilter.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/WordFilter.java @@ -125,7 +125,7 @@ public class WordFilter { public String filter(String message, Habbo habbo) { String filteredMessage = message; - if (!Emulator.getConfig().getBoolean("hotel.wordfilter.enabled", true) || (habbo != null && habbo.hasRight(Permission.ACC_CHAT_NO_FILTER))) { + if (!Emulator.getConfig().getBoolean("hotel.wordfilter.enabled", true) || (habbo != null && habbo.hasPermissionRight(Permission.ACC_CHAT_NO_FILTER))) { return message; } if (Emulator.getConfig().getBoolean("hotel.wordfilter.normalise")) { diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorHotelFilter.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorHotelFilter.java index 012cce5f..7ae56f39 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorHotelFilter.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorHotelFilter.java @@ -19,7 +19,7 @@ public class NavigatorHotelFilter extends NavigatorFilter { @Override public List getResult(Habbo habbo) { - boolean showInvisible = habbo.hasRight(Permission.ACC_ENTERANYROOM) || habbo.hasRight(Permission.ACC_ANYROOMOWNER); + boolean showInvisible = habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER); List resultLists = new ArrayList<>(); int i = 0; @@ -41,7 +41,7 @@ public class NavigatorHotelFilter extends NavigatorFilter { @Override public List getResult(Habbo habbo, NavigatorFilterField filterField, String value, int roomCategory) { - boolean showInvisible = habbo.hasRight(Permission.ACC_ENTERANYROOM) || habbo.hasRight(Permission.ACC_ANYROOMOWNER); + boolean showInvisible = habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER); if (!filterField.getDatabaseQuery().isEmpty()) { List resultLists = new ArrayList<>(); int i = 0; diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java index daccc52f..f69b33a8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorManager.java @@ -56,7 +56,7 @@ public class NavigatorManager { NavigatorPublicCategory category = this.publicCategories.get(set.getInt("public_cat_id")); if (category != null) { - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(set.getInt("room_id")); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(set.getInt("room_id")); if (room != null) { category.addRoom(room); diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicCategory.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicCategory.java index 02ae1c44..f433d227 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicCategory.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicCategory.java @@ -31,6 +31,6 @@ public class NavigatorPublicCategory { public void removeRoom(Room room) { this.rooms.remove(room); - room.preventUncaching = room.isPublicRoom(); + room.preventUncaching = room.getRoomInfo().isPublicRoom(); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicFilter.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicFilter.java index 1a50fd4a..8b2a02be 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicFilter.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorPublicFilter.java @@ -16,7 +16,7 @@ public class NavigatorPublicFilter extends NavigatorFilter { @Override public List getResult(Habbo habbo) { - boolean showInvisible = habbo.hasRight(Permission.ACC_ENTERANYROOM) || habbo.hasRight(Permission.ACC_ANYROOMOWNER); + boolean showInvisible = habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER); List resultLists = new ArrayList<>(); int i = 0; diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorRoomAdsFilter.java b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorRoomAdsFilter.java index 84baf63f..7ca46762 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorRoomAdsFilter.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/NavigatorRoomAdsFilter.java @@ -16,7 +16,7 @@ public class NavigatorRoomAdsFilter extends NavigatorFilter { @Override public List getResult(Habbo habbo) { - boolean showInvisible = habbo.hasRight(Permission.ACC_ENTERANYROOM) || habbo.hasRight(Permission.ACC_ANYROOMOWNER); + boolean showInvisible = habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER); List resultList = new ArrayList<>(); resultList.add(new SearchResultList(0, "categories", "", SearchAction.NONE, habbo.getHabboStats().getNavigatorWindowSettings().getListModeForCategory("categories", ListMode.LIST), habbo.getHabboStats().getNavigatorWindowSettings().getDisplayModeForCategory("official-root", DisplayMode.VISIBLE), Emulator.getGameEnvironment().getNavigatorManager().getRoomsForCategory("categories", habbo), false, showInvisible, DisplayOrder.ACTIVITY, 0)); return resultList; diff --git a/src/main/java/com/eu/habbo/habbohotel/navigation/SearchResultList.java b/src/main/java/com/eu/habbo/habbohotel/navigation/SearchResultList.java index 0419d7c8..511597e3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/navigation/SearchResultList.java +++ b/src/main/java/com/eu/habbo/habbohotel/navigation/SearchResultList.java @@ -38,7 +38,7 @@ public class SearchResultList implements ISerialize, Comparable toRemove = new ArrayList<>(); for (Room room : this.rooms) { - if (room.getState() == RoomState.INVISIBLE) { + if (room.getRoomInfo().getState() == RoomState.INVISIBLE) { toRemove.add(room); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionCommand.java b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionCommand.java index b0326644..15355970 100644 --- a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionCommand.java @@ -1,17 +1,17 @@ package com.eu.habbo.habbohotel.permissions; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Arrays; +@Slf4j +@Getter public class PermissionCommand { - @Getter private final String name; - private final String description; - @Getter private final String[] keys; public PermissionCommand(ResultSet set) throws SQLException { 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 60d31f09..c3e61a77 100644 --- a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionGroup.java +++ b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionGroup.java @@ -4,7 +4,10 @@ import com.eu.habbo.Emulator; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -29,12 +32,12 @@ public class PermissionGroup { private final String prefix; @Getter private final String prefixColor; - private final Map commands; - private final Map rights; + private final Map commands; + private final Map rights; @Getter final Map timers; - public PermissionGroup(ResultSet set, Map commandsAvailable) throws SQLException { + public PermissionGroup(ResultSet set, Map commandsAvailable, Map rightsAvailable) throws SQLException { this.id = set.getInt("id"); this.name = set.getString("name"); this.description = set.getString("description"); @@ -50,20 +53,26 @@ public class PermissionGroup { this.timers = new HashMap<>(); this.loadCommands(commandsAvailable); - this.loadRights(); + this.loadRights(rightsAvailable); this.loadTimers(); log.info("Loaded " + this.name + " rank with " + this.commands.size() + " commands and " + this.rights.size() + " rights!"); } private void loadCommands(Map commandsAvailable) { + this.commands.clear(); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM permission_group_commands WHERE group_id = ?")) { statement.setInt(1, this.id); try(ResultSet set = statement.executeQuery()) { while (set.next()) { String commandName = set.getString("command_name"); PermissionCommand command = commandsAvailable.values().stream().filter(commandAvailable -> commandAvailable.getName().equalsIgnoreCase(commandName)).findFirst().orElse(null); - this.commands.put(command, PermissionSetting.fromString(set.getString("setting_type"))); + + if(command != null) { + PermissionSetting setting = PermissionSetting.fromString(set.getString("setting_type")); + this.commands.put(command.getName(), setting); + } } } } catch (SQLException e) { @@ -71,13 +80,19 @@ public class PermissionGroup { } } - private void loadRights() { + private void loadRights(Map rightsAvailable) { + this.rights.clear(); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM permission_group_rights WHERE group_id = ?")) { statement.setInt(1, this.id); try(ResultSet set = statement.executeQuery()) { while (set.next()) { - PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(set.getString("name")); - this.rights.put(right, PermissionSetting.fromString(set.getString("setting_type"))); + String rightName = set.getString("right_name"); + PermissionRight right = rightsAvailable.values().stream().filter(rightAvailable -> rightAvailable.getName().equalsIgnoreCase(rightName)).findFirst().orElse(null); + + if(right != null) { + this.rights.put(right.getName(), PermissionSetting.fromString(set.getString("setting_type"))); + } } } } catch (SQLException e) { @@ -86,6 +101,8 @@ public class PermissionGroup { } private void loadTimers() { + this.timers.clear(); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM permission_group_timers WHERE group_id = ? ORDER BY id ASC")) { statement.setInt(1, this.id); try(ResultSet set = statement.executeQuery()) { @@ -99,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; @@ -111,24 +128,23 @@ public class PermissionGroup { return true; } - PermissionSetting setting = this.commands.get(command); - return setting == PermissionSetting.ALLOWED || (setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights); - } + if(this.commands.containsKey(command.getName())) { + PermissionSetting setting = this.commands.get(command.getName()); - public boolean hasCommand(String name, boolean hasRoomRights) { - PermissionCommand command = Emulator.getGameEnvironment().getPermissionsManager().getCommand(name); - if (this.commands.containsKey(command)) { - PermissionSetting setting = this.commands.get(command); - return (setting == PermissionSetting.ALLOWED || (setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights)); + if(setting == null) { + return false; + } + + return setting == PermissionSetting.ALLOWED || (setting == PermissionSetting.HAS_ROOM_RIGHTS && hasRoomRights); } + return false; } - public boolean hasRight(String name, boolean hasRoomRights) { - PermissionRight right = Emulator.getGameEnvironment().getPermissionsManager().getRight(name); - if(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; @@ -142,14 +158,14 @@ public class PermissionGroup { return 0; } - public List getCommands() { - Collection fixedCommands = Emulator.getGameEnvironment().getPermissionsManager().getFixedCommands(); - Set commands = this.commands.keySet(); + public List getCommands() { + Collection fixedCommands = Emulator.getGameEnvironment().getPermissionsManager().getFixedCommands(); + Set commands = this.commands.keySet(); return Stream.concat(fixedCommands.stream(), commands.stream()).collect(Collectors.toList()); } - public Set getRights() { + public Set getRights() { return this.rights.keySet(); } diff --git a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java index e8fca734..771a41ab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/permissions/PermissionsManager.java @@ -10,12 +10,14 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; @Slf4j public class PermissionsManager { - private final Map permissionGroups; + private final ConcurrentHashMap permissionGroups; private final Map permissionCommands; private final Map fixedCommands; private final Map permissionRights; @@ -23,7 +25,7 @@ public class PermissionsManager { public PermissionsManager() { long millis = System.currentTimeMillis(); - this.permissionGroups = new HashMap<>(); + this.permissionGroups = new ConcurrentHashMap<>(); this.permissionCommands = new HashMap<>(); this.fixedCommands = new HashMap<>(); this.permissionRights = new HashMap<>(); @@ -37,21 +39,35 @@ public class PermissionsManager { this.loadPermissionRights(); this.loadPermissionGroups(); this.loadEnables(); + log.info(this.permissionGroups.size() + " ranks, " + this.permissionCommands.size() + " commands " + this.permissionRights.size() + " rights -> Loaded!"); } + /** + * Load permission groups information, commands and rights + */ private void loadPermissionGroups() { + HashSet currentGroupIds = new HashSet<>(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM permission_groups ORDER BY id ASC")) { while (set.next()) { - PermissionGroup permissionGroup = new PermissionGroup(set, this.permissionCommands); + PermissionGroup permissionGroup = new PermissionGroup(set, this.permissionCommands, this.permissionRights); this.permissionGroups.put(permissionGroup.getId(), permissionGroup); + currentGroupIds.add(permissionGroup.getId()); } } catch (SQLException e) { log.error("Caught SQL exception", e); } + + //TODO if Group is eliminated every user that has this rank must update to lowest Rank + this.permissionGroups.entrySet().removeIf(entry -> !currentGroupIds.contains(entry.getKey())); } + /** + * Load every available command in the database + */ private void loadPermissionCommands() { + this.permissionCommands.clear(); + this.loadFixedCommands(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM permission_commands")) { @@ -62,8 +78,14 @@ public class PermissionsManager { } catch (SQLException e) { log.error("Caught SQL exception", e); } + + log.info("Loaded {} available commands!", this.permissionCommands.size()); } + /** + * Load fixed commands, any command that doesn't require a permission + * these commands are always available for any user + */ private void loadFixedCommands() { String[] fixedCommandNames = { "cmd_about", @@ -75,7 +97,8 @@ public class PermissionsManager { "cmd_mute_pets", "cmd_plugins", "cmd_sit", - "cmd_stand" + "cmd_stand", + "cmd_test" }; for(String command : fixedCommandNames) { @@ -86,11 +109,19 @@ public class PermissionsManager { } } + /** + * Add a fixed command through plugins if you want to include a fixed command + * on main source make use of `loadFixedCommands()` instead + * + * @param fixedCommand A command that will be always available to any user + */ public void addFixedCommand(PermissionCommand fixedCommand) { this.fixedCommands.put(fixedCommand.getName(), fixedCommand); } private void loadPermissionRights() { + this.permissionRights.clear(); + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); Statement statement = connection.createStatement(); ResultSet set = statement.executeQuery("SELECT * FROM permission_rights")) { while (set.next()) { PermissionRight permissionRight = new PermissionRight(set); @@ -99,6 +130,8 @@ public class PermissionsManager { } catch (SQLException e) { log.error("Caught SQL exception", e); } + + log.info("Loaded {} available rights!", this.permissionRights.size()); } private void loadEnables() { @@ -140,8 +173,8 @@ public class PermissionsManager { .orElseGet(() -> null); } - public Collection getFixedCommands() { - return this.fixedCommands.values(); + public Collection getFixedCommands() { + return this.fixedCommands.keySet(); } public boolean isFixedCommand(String name) { diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/GnomePet.java b/src/main/java/com/eu/habbo/habbohotel/pets/GnomePet.java index d4ac7222..67b628d7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/GnomePet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/GnomePet.java @@ -41,7 +41,7 @@ public class GnomePet extends Pet implements IPetLook { @Override public void run() { - if (this.isNeedsUpdate()) { + if (this.isSqlUpdateNeeded()) { super.run(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET gnome_data = ? WHERE id = ? LIMIT 1")) { diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java b/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java index c63b742c..3f814c26 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/HorsePet.java @@ -36,7 +36,7 @@ public class HorsePet extends RideablePet { @Override public void run() { - if (this.isNeedsUpdate()) { + if (this.isSqlUpdateNeeded()) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET hair_style = ?, hair_color = ?, saddle = ?, ride = ?, saddle_item_id = ? WHERE id = ?")) { statement.setInt(1, this.hairStyle); statement.setInt(2, this.hairColor); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java b/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java index daee7dab..141887b0 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/MonsterplantPet.java @@ -4,8 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; @@ -19,7 +19,6 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; @@ -120,7 +119,7 @@ public class MonsterplantPet extends Pet implements IPetLook { @Override public void run() { - if (this.isNeedsUpdate()) { + if (this.isSqlUpdateNeeded()) { super.run(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET mp_type = ?, mp_color = ?, mp_nose = ?, mp_eyes = ?, mp_mouth = ?, mp_nose_color = ?, mp_eyes_color = ?, mp_mouth_color = ?, mp_death_timestamp = ?, mp_breedable = ?, mp_allow_breed = ?, mp_is_dead = ? WHERE id = ?")) { @@ -146,26 +145,26 @@ public class MonsterplantPet extends Pet implements IPetLook { @Override public void cycle() { - if (this.room != null && this.roomUnit != null) { + if (this.room != null && this.getRoomUnit() != null) { if (this.isDead()) { - this.roomUnit.removeStatus(RoomUnitStatus.GESTURE); + this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); if (!this.hasDied) { AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantGardenOfDeath")); this.hasDied = true; - this.setNeedsUpdate(true); + this.setSqlUpdateNeeded(true); } - this.roomUnit.clearStatus(); - this.roomUnit.setStatus(RoomUnitStatus.RIP, ""); + this.getRoomUnit().clearStatuses(); + this.getRoomUnit().addStatus(RoomUnitStatus.RIP, ""); this.setPacketUpdate(true); } else { int difference = Emulator.getIntUnixTimestamp() - this.created + 1; if (difference >= GROW_TIME) { this.growthStage = 7; boolean clear = false; - for (RoomUnitStatus s : this.roomUnit.getStatus().keySet()) { + for (RoomUnitStatus s : this.getRoomUnit().getStatuses().keySet()) { if (s.equals(RoomUnitStatus.GROW)) { clear = true; break; @@ -173,7 +172,7 @@ public class MonsterplantPet extends Pet implements IPetLook { } if (clear) { - this.roomUnit.clearStatus(); + this.getRoomUnit().clearStatuses(); this.setPacketUpdate(true); } } else { @@ -181,8 +180,8 @@ public class MonsterplantPet extends Pet implements IPetLook { if (g > this.growthStage) { this.growthStage = g; - this.roomUnit.clearStatus(); - this.roomUnit.setStatus(RoomUnitStatus.fromString("grw" + this.growthStage), ""); + this.getRoomUnit().clearStatuses(); + this.getRoomUnit().addStatus(RoomUnitStatus.fromString("grw" + this.growthStage), ""); this.setPacketUpdate(true); } } @@ -306,8 +305,8 @@ public class MonsterplantPet extends Pet implements IPetLook { this.room.sendComposer(new PetStatusUpdateComposer(pet).compose()); this.room.sendComposer(new PetStatusUpdateComposer(this).compose()); - this.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "reb"); - pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "reb"); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, "reb"); + pet.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, "reb"); this.room.sendComposer(new UserUpdateComposer(this.getRoomUnit()).compose()); this.room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); @@ -315,11 +314,11 @@ public class MonsterplantPet extends Pet implements IPetLook { this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); - Habbo ownerOne = this.room.getHabbo(this.getUserId()); + Habbo ownerOne = this.room.getRoomUnitManager().getRoomHabboById(this.getUserId()); Habbo ownerTwo = null; if (this.getUserId() != pet.getUserId()) { - ownerTwo = this.room.getHabbo(pet.getUserId()); + ownerTwo = this.room.getRoomUnitManager().getRoomHabboById(pet.getUserId()); } Item seedBase; @@ -331,7 +330,7 @@ public class MonsterplantPet extends Pet implements IPetLook { } if (seedBase != null) { - HabboItem seed; + RoomItem seed; if (ownerOne != null) { AchievementManager.progressAchievement(ownerOne, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantBreeder"), 1); seed = Emulator.getGameEnvironment().getItemManager().createItem(ownerOne.getHabboInfo().getId(), seedBase, 0, 0, ""); 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 56cd7ceb..1d728066 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/Pet.java @@ -4,8 +4,10 @@ import com.eu.habbo.Emulator; import com.eu.habbo.database.DatabaseConstants; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet; +import com.eu.habbo.habbohotel.units.Unit; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ISerialize; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.pets.PetExperienceComposer; @@ -17,9 +19,13 @@ import com.eu.habbo.plugin.events.pets.PetTalkEvent; import gnu.trove.map.hash.THashMap; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.Calendar; import java.util.Map; import java.util.TimeZone; @@ -27,107 +33,39 @@ import java.util.TimeZone; import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; @Slf4j -public class Pet implements ISerialize, Runnable { - - @Getter - @Setter - public int levelThirst; - @Getter - @Setter - public int levelHunger; - - @Setter - @Getter - private boolean needsUpdate = false; - - @Setter - @Getter - private boolean packetUpdate = false; - @Getter - protected int id; - @Getter - @Setter +@Getter +@Setter +@Accessors(chain = true) +public class Pet extends Unit implements ISerialize, Runnable { + protected final int id; protected int userId; - @Getter - @Setter protected Room room; - @Getter - @Setter protected String name; - @Setter - @Getter protected PetData petData; - @Setter - @Getter protected int race; - @Getter - @Setter protected String color; - @Getter - @Setter protected int happiness; - @Getter - @Setter protected int experience; - @Setter - @Getter protected int energy; - - /** - * The respect points of the pet. - */ protected int respect; - @Getter - @Setter protected int created; - @Getter - @Setter protected int level; - @Getter - @Setter - RoomUnit roomUnit; - - /** - * The chat timeout of the pet. - */ private int chatTimeout; - - /** - * The tick timeout of the pet. - */ private int tickTimeout = Emulator.getIntUnixTimestamp(); private int happinessDelay = Emulator.getIntUnixTimestamp(); private int gestureTickTimeout = Emulator.getIntUnixTimestamp(); - - /** - * The random action tick timeout of the pet. - */ private int randomActionTickTimeout = Emulator.getIntUnixTimestamp(); - - /** - * The posture timeout of the pet. - */ private int postureTimeout = Emulator.getIntUnixTimestamp(); - @Getter - @Setter private int stayStartedAt = 0; - /** - * The number of ticks that the pet has spent idle while waiting for a command. - */ private int idleCommandTicks = 0; - - /** - * The number of ticks that the pet has spent free after completing a command. - */ private int freeCommandTicks = -1; - - @Getter - @Setter private PetTasks task = PetTasks.FREE; - - @Setter - @Getter private boolean muted = false; + private final RoomPet roomUnit; + public int levelThirst; + public int levelHunger; + private boolean sqlUpdateNeeded = false; + private boolean packetUpdate = false; /** * Creates a new pet using the given result set, which should contain data retrieved from a @@ -137,7 +75,6 @@ public class Pet implements ISerialize, Runnable { * @throws SQLException if an error occurs while reading from the result set */ public Pet(ResultSet set) throws SQLException { - super(); this.id = set.getInt("id"); this.userId = set.getInt(DatabaseConstants.USER_ID); this.room = null; @@ -157,6 +94,9 @@ public class Pet implements ISerialize, Runnable { this.levelThirst = set.getInt("thirst"); this.levelHunger = set.getInt("hunger"); this.level = PetManager.getLevel(this.experience); + + this.roomUnit = new RoomPet(); + this.roomUnit.setUnit(this); } /** @@ -189,6 +129,9 @@ public class Pet implements ISerialize, Runnable { this.levelHunger = 0; this.created = Emulator.getIntUnixTimestamp(); this.level = 1; + + this.roomUnit = new RoomPet(); + this.roomUnit.setUnit(this); } /** @@ -197,8 +140,8 @@ public class Pet implements ISerialize, Runnable { * @param message the message to be said */ protected void say(String message) { - if (this.roomUnit != null && this.room != null && !message.isEmpty()) { - RoomChatMessage chatMessage = new RoomChatMessage(message, this.roomUnit, RoomChatMessageBubbles.NORMAL); + if (this.getRoomUnit() != null && this.room != null && !message.isEmpty()) { + RoomChatMessage chatMessage = new RoomChatMessage(message, this.getRoomUnit(), RoomChatMessageBubbles.NORMAL); PetTalkEvent talkEvent = new PetTalkEvent(this, chatMessage); if (!Emulator.getPluginManager().fireEvent(talkEvent).isCancelled()) { this.room.petChat(new ChatMessageComposer(chatMessage).compose()); @@ -281,52 +224,26 @@ public class Pet implements ISerialize, Runnable { */ @Override public void run() { - if (this.isNeedsUpdate()) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { - if (this.id > 0) { - try (PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET room_id = ?, experience = ?, energy = ?, respect = ?, x = ?, y = ?, z = ?, rot = ?, hunger = ?, thirst = ?, happiness = ?, created = ? WHERE id = ?")) { - statement.setInt(1, (this.room == null ? 0 : this.room.getId())); - statement.setInt(2, this.experience); - statement.setInt(3, this.energy); - statement.setInt(4, this.respect); - statement.setInt(5, this.roomUnit != null ? this.roomUnit.getX() : 0); - statement.setInt(6, this.roomUnit != null ? this.roomUnit.getY() : 0); - statement.setDouble(7, this.roomUnit != null ? this.roomUnit.getZ() : 0.0); - statement.setInt(8, this.roomUnit != null ? this.roomUnit.getBodyRotation().getValue() : 0); - statement.setInt(9, this.levelHunger); - statement.setInt(10, this.levelThirst); - statement.setInt(11, this.happiness); - statement.setInt(12, this.created); - statement.setInt(13, this.id); - statement.execute(); - } - } else if (this.id == 0) { - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO users_pets (user_id, room_id, name, race, type, color, experience, energy, respect, created) VALUES (?, 0, ?, ?, ?, ?, 0, 0, 0, ?)", Statement.RETURN_GENERATED_KEYS)) { - statement.setInt(1, this.userId); - statement.setString(2, this.name); - statement.setInt(3, this.race); - statement.setInt(4, 0); - - if (this.petData != null) { - statement.setInt(4, this.petData.getType()); - } - - statement.setString(5, this.color); - statement.setInt(6, this.created); - statement.execute(); - - try (ResultSet set = statement.getGeneratedKeys()) { - if (set.next()) { - this.id = set.getInt(1); - } - } - } - } + if (this.sqlUpdateNeeded) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users_pets SET room_id = ?, experience = ?, energy = ?, respect = ?, x = ?, y = ?, z = ?, rot = ?, hunger = ?, thirst = ?, happiness = ?, created = ? WHERE id = ?")) { + statement.setInt(1, (this.room == null ? 0 : this.room.getRoomInfo().getId())); + statement.setInt(2, this.experience); + statement.setInt(3, this.energy); + statement.setInt(4, this.respect); + statement.setInt(5, this.getRoomUnit() != null ? this.getRoomUnit().getCurrentPosition().getX() : 0); + statement.setInt(6, this.getRoomUnit() != null ? this.getRoomUnit().getCurrentPosition().getY() : 0); + statement.setDouble(7, this.getRoomUnit() != null ? this.getRoomUnit().getCurrentZ() : 0.0); + statement.setInt(8, this.getRoomUnit() != null ? this.getRoomUnit().getBodyRotation().getValue() : 0); + statement.setInt(9, this.levelHunger); + statement.setInt(10, this.levelThirst); + statement.setInt(11, this.happiness); + statement.setInt(12, this.created); + statement.setInt(13, this.id); + statement.execute(); + this.sqlUpdateNeeded = false; } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); } - - this.setNeedsUpdate(false); } } @@ -337,16 +254,16 @@ public class Pet implements ISerialize, Runnable { public void cycle() { this.idleCommandTicks++; - int time = Emulator.getIntUnixTimestamp(); - if (this.roomUnit != null && this.task != PetTasks.RIDE) { - if (time - this.gestureTickTimeout > 5 && this.roomUnit.hasStatus(RoomUnitStatus.GESTURE)) { - this.roomUnit.removeStatus(RoomUnitStatus.GESTURE); - this.setPacketUpdate(true); + int currentTime = Emulator.getIntUnixTimestamp(); + + if (this.getRoomUnit() != null && this.task != PetTasks.RIDE) { + if (currentTime - this.gestureTickTimeout > 5 && this.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) { + this.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); } - 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) { @@ -357,12 +274,12 @@ public class Pet implements ISerialize, Runnable { } } - if (!this.roomUnit.isWalking()) { - if (this.roomUnit.getWalkTimeOut() < time && this.canWalk()) { + if (!this.getRoomUnit().isWalking()) { + if (this.getRoomUnit().getWalkTimeOut() < currentTime && this.canWalk()) { RoomTile tile = this.room.getRandomWalkableTile(); if (tile != null) { - this.roomUnit.setGoalLocation(tile); + this.getRoomUnit().walkTo(tile); } } @@ -377,12 +294,12 @@ public class Pet implements ISerialize, Runnable { this.addHappiness(1); if (this.energy == PetManager.maxEnergy(this.level)) { - this.roomUnit.removeStatus(RoomUnitStatus.LAY); - this.roomUnit.setCanWalk(true); - this.roomUnit.setGoalLocation(this.room.getRandomWalkableTile()); + this.getRoomUnit().removeStatus(RoomUnitStatus.LAY); + this.getRoomUnit().setCanWalk(true); + this.getRoomUnit().walkTo(this.room.getRandomWalkableTile()); this.task = null; - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.ENERGY.getKey()); - this.gestureTickTimeout = time; + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.ENERGY.getKey()); + this.gestureTickTimeout = currentTime; } } /* this is regeneration, add back if needed else if (this.tickTimeout >= 5) { @@ -404,7 +321,7 @@ public class Pet implements ISerialize, Runnable { this.getRoomUnit().setCanWalk(true); } } else { - this.roomUnit.setWalkTimeOut(20 + time); + this.getRoomUnit().setWalkTimeOut(20 + currentTime); if (this.energy >= 2) this.addEnergy(-1); @@ -416,20 +333,20 @@ public class Pet 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) @@ -447,7 +364,7 @@ public class Pet implements ISerialize, Runnable { } int timeOut = Emulator.getRandom().nextInt(30); - this.chatTimeout = time + (timeOut < 3 ? 30 : timeOut); + this.chatTimeout = currentTime + (timeOut < 3 ? 30 : timeOut); } } } @@ -495,26 +412,26 @@ public class Pet implements ISerialize, Runnable { public void clearPosture() { THashMap keys = new THashMap<>(); - if (this.roomUnit.hasStatus(RoomUnitStatus.MOVE)) - keys.put(RoomUnitStatus.MOVE, this.roomUnit.getStatus(RoomUnitStatus.MOVE)); + if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) + keys.put(RoomUnitStatus.MOVE, this.getRoomUnit().getStatus(RoomUnitStatus.MOVE)); - if (this.roomUnit.hasStatus(RoomUnitStatus.SIT)) - keys.put(RoomUnitStatus.SIT, this.roomUnit.getStatus(RoomUnitStatus.SIT)); + if (this.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) + keys.put(RoomUnitStatus.SIT, this.getRoomUnit().getStatus(RoomUnitStatus.SIT)); - if (this.roomUnit.hasStatus(RoomUnitStatus.LAY)) - keys.put(RoomUnitStatus.LAY, this.roomUnit.getStatus(RoomUnitStatus.LAY)); + if (this.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) + keys.put(RoomUnitStatus.LAY, this.getRoomUnit().getStatus(RoomUnitStatus.LAY)); - if (this.roomUnit.hasStatus(RoomUnitStatus.GESTURE)) - keys.put(RoomUnitStatus.GESTURE, this.roomUnit.getStatus(RoomUnitStatus.GESTURE)); + if (this.getRoomUnit().hasStatus(RoomUnitStatus.GESTURE)) + keys.put(RoomUnitStatus.GESTURE, this.getRoomUnit().getStatus(RoomUnitStatus.GESTURE)); if (this.task == null) { - boolean isDead = this.roomUnit.hasStatus(RoomUnitStatus.RIP); + boolean isDead = this.getRoomUnit().hasStatus(RoomUnitStatus.RIP); - this.roomUnit.clearStatus(); + this.getRoomUnit().clearStatuses(); - if (isDead) this.roomUnit.setStatus(RoomUnitStatus.RIP, ""); + if (isDead) this.getRoomUnit().addStatus(RoomUnitStatus.RIP, ""); for (Map.Entry entry : keys.entrySet()) { - this.roomUnit.setStatus(entry.getKey(), entry.getValue()); + this.getRoomUnit().addStatus(entry.getKey(), entry.getValue()); } if (!keys.isEmpty()) this.setPacketUpdate(true); @@ -529,26 +446,26 @@ public class Pet implements ISerialize, Runnable { public void updateGesture(int time) { this.gestureTickTimeout = time; if (this.energy < 30) { - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.TIRED.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.TIRED.getKey()); this.findNest(); } else if (this.happiness == 100) { - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.LOVE.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.LOVE.getKey()); } else if (this.happiness >= 90) { this.randomHappyAction(); - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.HAPPY.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.HAPPY.getKey()); } else if (this.happiness <= 5) { this.randomSadAction(); - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.SAD.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.SAD.getKey()); } else if (this.levelHunger > 80) { - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.HUNGRY.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.HUNGRY.getKey()); this.eat(); } else if (this.levelThirst > 80) { - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.THIRSTY.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.THIRSTY.getKey()); this.drink(); } else if (this.idleCommandTicks > 240) { this.idleCommandTicks = 0; - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, PetGestures.QUESTION.getKey()); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, PetGestures.QUESTION.getKey()); } } @@ -578,12 +495,16 @@ public class Pet implements ISerialize, Runnable { */ public void findNest() { - HabboItem item = this.petData.randomNest(this.room.getRoomSpecialTypes().getNests()); - this.roomUnit.setCanWalk(true); + RoomItem item = this.petData.randomNest(this.room.getRoomSpecialTypes().getNests()); + this.getRoomUnit().setCanWalk(true); if (item != null) { - this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + this.getRoomUnit().walkTo(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); } else { - this.roomUnit.setStatus(RoomUnitStatus.LAY, this.room.getStackHeight(this.roomUnit.getX(), this.roomUnit.getY(), false) + ""); + if(this instanceof HorsePet horsePet && horsePet.hasSaddle()) { + return; + } + + this.getRoomUnit().addStatus(RoomUnitStatus.LAY, this.room.getStackHeight(this.getRoomUnit().getCurrentPosition().getX(), this.getRoomUnit().getCurrentPosition().getY(), false) + ""); this.say(this.petData.randomVocal(PetVocalsType.SLEEPING)); this.task = PetTasks.DOWN; } @@ -593,16 +514,16 @@ public class Pet implements ISerialize, Runnable { * Makes the pet drink. */ public boolean drink() { - HabboItem item = this.petData.randomDrinkItem(this.room.getRoomSpecialTypes().getPetDrinks()); + RoomItem item = this.petData.randomDrinkItem(this.room.getRoomSpecialTypes().getPetDrinks()); if (item != null) { - this.roomUnit.setCanWalk(true); - if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { + this.getRoomUnit().setCanWalk(true); + if (this.getRoomUnit().getCurrentPosition().distance(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())) == 0) { try { item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); } catch (Exception ignored) { } } else { - this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + this.getRoomUnit().walkTo(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); } } return item != null; @@ -612,10 +533,10 @@ public class Pet implements ISerialize, Runnable { * Makes the pet eat. */ public void eat() { - HabboItem item = this.petData.randomFoodItem(this.room.getRoomSpecialTypes().getPetFoods()); + RoomItem item = this.petData.randomFoodItem(this.room.getRoomSpecialTypes().getPetFoods()); if (item != null) { - this.roomUnit.setCanWalk(true); - this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + this.getRoomUnit().setCanWalk(true); + this.getRoomUnit().walkTo(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); } } @@ -625,17 +546,17 @@ public class Pet implements ISerialize, Runnable { * @return true if a toy was found, false otherwise */ public boolean findToy() { - HabboItem item = this.petData.randomToyItem(this.room.getRoomSpecialTypes().getPetToys()); + RoomItem item = this.petData.randomToyItem(this.room.getRoomSpecialTypes().getPetToys()); if (item != null) { - this.roomUnit.setCanWalk(true); - if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { + this.getRoomUnit().setCanWalk(true); + if (this.getRoomUnit().getCurrentPosition().distance(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())) == 0) { try { item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); } catch (Exception ignored) { } return true; } - this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + this.getRoomUnit().walkTo(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); return true; } @@ -649,20 +570,20 @@ public class Pet implements ISerialize, Runnable { * @param type the type of item to search for * @return true if an item was found, false otherwise */ - public boolean findPetItem(PetTasks task, Class type) { - HabboItem item = this.petData.randomToyHabboItem(this.room.getRoomSpecialTypes().getItemsOfType(type)); + public boolean findPetItem(PetTasks task, Class type) { + RoomItem item = this.petData.randomToyHabboItem(this.room.getRoomSpecialTypes().getItemsOfType(type)); if (item != null) { - this.roomUnit.setCanWalk(true); + this.getRoomUnit().setCanWalk(true); this.setTask(task); - if (this.getRoomUnit().getCurrentLocation().distance(this.room.getLayout().getTile(item.getX(), item.getY())) == 0) { + if (this.getRoomUnit().getCurrentPosition().distance(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())) == 0) { try { item.onWalkOn(this.getRoomUnit(), this.getRoom(), null); } catch (Exception ignored) { } return true; } - this.roomUnit.setGoalLocation(this.room.getLayout().getTile(item.getX(), item.getY())); + this.getRoomUnit().walkTo(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); return true; } return false; @@ -673,7 +594,7 @@ public class Pet implements ISerialize, Runnable { */ public void randomHappyAction() { if (this.petData.getActionsHappy().length > 0) { - this.roomUnit.setStatus(RoomUnitStatus.fromString(this.petData.getActionsHappy()[Emulator.getRandom().nextInt(this.petData.getActionsHappy().length)]), ""); + this.getRoomUnit().addStatus(RoomUnitStatus.fromString(this.petData.getActionsHappy()[Emulator.getRandom().nextInt(this.petData.getActionsHappy().length)]), ""); } } @@ -682,7 +603,7 @@ public class Pet implements ISerialize, Runnable { */ public void randomSadAction() { if (this.petData.getActionsTired().length > 0) { - this.roomUnit.setStatus(RoomUnitStatus.fromString(this.petData.getActionsTired()[Emulator.getRandom().nextInt(this.petData.getActionsTired().length)]), ""); + this.getRoomUnit().addStatus(RoomUnitStatus.fromString(this.petData.getActionsTired()[Emulator.getRandom().nextInt(this.petData.getActionsTired().length)]), ""); } } @@ -691,7 +612,7 @@ public class Pet implements ISerialize, Runnable { */ public void randomAction() { if (this.petData.getActionsRandom().length > 0) { - this.roomUnit.setStatus(RoomUnitStatus.fromString(this.petData.getActionsRandom()[Emulator.getRandom().nextInt(this.petData.getActionsRandom().length)]), ""); + this.getRoomUnit().addStatus(RoomUnitStatus.fromString(this.petData.getActionsRandom()[Emulator.getRandom().nextInt(this.petData.getActionsRandom().length)]), ""); } } @@ -726,7 +647,7 @@ public class Pet implements ISerialize, Runnable { this.level++; this.say(this.petData.randomVocal(PetVocalsType.LEVEL_UP)); this.addHappiness(100); - this.roomUnit.setStatus(RoomUnitStatus.GESTURE, "exp"); + this.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, "exp"); this.gestureTickTimeout = Emulator.getIntUnixTimestamp(); AchievementManager.progressAchievement(Emulator.getGameEnvironment().getHabboManager().getHabbo(this.userId), Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetLevelUp")); this.room.sendComposer(new PetLevelUpdatedComposer(this).compose()); @@ -767,9 +688,9 @@ public class Pet implements ISerialize, Runnable { */ public void freeCommand() { this.task = null; - this.roomUnit.setGoalLocation(this.getRoomUnit().getCurrentLocation()); - this.roomUnit.clearStatus(); - this.roomUnit.setCanWalk(true); + this.getRoomUnit().walkTo(this.getRoomUnit().getCurrentPosition()); + this.getRoomUnit().clearStatuses(); + this.getRoomUnit().setCanWalk(true); this.say(this.petData.randomVocal(PetVocalsType.GENERIC_NEUTRAL)); } @@ -782,11 +703,11 @@ public class Pet implements ISerialize, Runnable { this.addHappiness(10); this.addExperience(10); this.addRespect(); - this.setNeedsUpdate(true); + this.setSqlUpdateNeeded(true); if (habbo != null) { habbo.getHabboStats().decreasePetRespectPointsToGive(); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new PetRespectNotificationComposer(this).compose()); + habbo.getRoomUnit().getRoom().sendComposer(new PetRespectNotificationComposer(this).compose()); AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("PetRespectGiver")); } @@ -810,18 +731,18 @@ public class Pet implements ISerialize, Runnable { */ public void removeFromRoom(boolean dontSendPackets) { - if (this.roomUnit != null && this.roomUnit.getCurrentLocation() != null) { - this.roomUnit.getCurrentLocation().removeUnit(this.roomUnit); + if (this.getRoomUnit() != null && this.getRoomUnit().getCurrentPosition() != null) { + this.getRoomUnit().getCurrentPosition().removeUnit(this.getRoomUnit()); } if (!dontSendPackets) { - room.sendComposer(new UserRemoveMessageComposer(this.roomUnit).compose()); - room.removePet(this.id); + room.sendComposer(new UserRemoveMessageComposer(this.getRoomUnit()).compose()); + room.getRoomUnitManager().removePet(this.id); } - this.roomUnit = null; + this.roomUnit.setRoom(null); this.room = null; - this.setNeedsUpdate(true); + this.setSqlUpdateNeeded(true); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java b/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java index 3fb62674..b9d03275 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/PetCommand.java @@ -59,7 +59,7 @@ public class PetCommand implements Comparable { if (this.action != null && pet.energy > this.energyCost && pet.happiness > this.happinessCost && Emulator.getRandom().nextInt((pet.level - this.level <= 0 ? 2 : pet.level - this.level) + 2) == 0) { if (this.action.petTask != pet.getTask()) { if (this.action.stopsPetWalking) { - pet.getRoomUnit().setGoalLocation(pet.getRoomUnit().getCurrentLocation()); + pet.getRoomUnit().walkTo(pet.getRoomUnit().getCurrentPosition()); } if (this.action.apply(pet, habbo, data)) { for (RoomUnitStatus status : this.action.statusToRemove) { @@ -67,10 +67,10 @@ public class PetCommand implements Comparable { } for (RoomUnitStatus status : this.action.statusToSet) { - pet.getRoomUnit().setStatus(status, "0"); + pet.getRoomUnit().addStatus(status, "0"); } - pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, this.action.gestureToSet); + pet.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, this.action.gestureToSet); pet.getRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); pet.addEnergy(-this.energyCost); pet.addHappiness(-this.happinessCost); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/PetData.java b/src/main/java/com/eu/habbo/habbohotel/pets/PetData.java index b9d621b2..5694128f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/PetData.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/PetData.java @@ -6,7 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetToy; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import lombok.Getter; @@ -93,7 +93,7 @@ public class PetData implements Comparable { } - public boolean haveNest(HabboItem nest) { + public boolean haveNest(RoomItem nest) { return this.haveNest(nest.getBaseItem()); } @@ -103,8 +103,8 @@ public class PetData implements Comparable { } - public HabboItem randomNest(THashSet items) { - List nestList = new ArrayList<>(); + public RoomItem randomNest(THashSet items) { + List nestList = new ArrayList<>(); for (InteractionNest nest : items) { if (this.haveNest(nest)) { @@ -132,7 +132,7 @@ public class PetData implements Comparable { } - public boolean haveFoodItem(HabboItem food) { + public boolean haveFoodItem(RoomItem food) { return this.haveFoodItem(food.getBaseItem()); } @@ -142,8 +142,8 @@ public class PetData implements Comparable { } - public HabboItem randomFoodItem(THashSet items) { - List foodList = new ArrayList<>(); + public RoomItem randomFoodItem(THashSet items) { + List foodList = new ArrayList<>(); for (InteractionPetFood food : items) { if (this.haveFoodItem(food)) { @@ -170,7 +170,7 @@ public class PetData implements Comparable { } - public boolean haveDrinkItem(HabboItem item) { + public boolean haveDrinkItem(RoomItem item) { return this.haveDrinkItem(item.getBaseItem()); } @@ -180,8 +180,8 @@ public class PetData implements Comparable { } - public HabboItem randomDrinkItem(THashSet items) { - List drinkList = new ArrayList<>(); + public RoomItem randomDrinkItem(THashSet items) { + List drinkList = new ArrayList<>(); for (InteractionPetDrink drink : items) { if (this.haveDrinkItem(drink)) { @@ -208,7 +208,7 @@ public class PetData implements Comparable { } - public boolean haveToyItem(HabboItem toy) { + public boolean haveToyItem(RoomItem toy) { return this.haveToyItem(toy.getBaseItem()); } @@ -218,8 +218,8 @@ public class PetData implements Comparable { } - public HabboItem randomToyItem(THashSet toys) { - List toyList = new ArrayList<>(); + public RoomItem randomToyItem(THashSet toys) { + List toyList = new ArrayList<>(); for (InteractionPetToy toy : toys) { if (this.haveToyItem(toy)) { @@ -235,10 +235,10 @@ public class PetData implements Comparable { return null; } - public HabboItem randomToyHabboItem(THashSet items) { - List itemList = new ArrayList<>(); + public RoomItem randomToyHabboItem(THashSet items) { + List itemList = new ArrayList<>(); - for (HabboItem item : items) { + for (RoomItem item : items) { if (this.haveToyItem(item)) { itemList.add(item); } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java b/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java index ea7f570c..3de9317a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/PetManager.java @@ -7,7 +7,6 @@ import com.eu.habbo.habbohotel.items.interactions.pets.*; import com.eu.habbo.habbohotel.pets.actions.*; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import gnu.trove.map.TIntIntMap; import gnu.trove.map.hash.THashMap; @@ -407,7 +406,7 @@ public class PetManager { client.getHabbo().getHabboInfo().getId() ); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); pet.run(); return pet; } @@ -421,7 +420,7 @@ public class PetManager { public Pet createPet(int type, int race, String name, GameClient client) { if (this.petData.containsKey(type)) { Pet pet = new Pet(type, race, "FFFFFF", name, client.getHabbo().getHabboInfo().getId()); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); pet.run(); return pet; } @@ -443,9 +442,8 @@ public class PetManager { pet.setUserId(habbo.getHabboInfo().getId()); pet.setRoom(room); - pet.setRoomUnit(new RoomUnit()); - pet.getRoomUnit().setPathFinderRoom(room); - pet.setNeedsUpdate(true); + pet.getRoomUnit().setRoom(room); + pet.setSqlUpdateNeeded(true); pet.run(); return pet; } @@ -462,9 +460,8 @@ public class PetManager { pet.setUserId(habbo.getHabboInfo().getId()); pet.setRoom(room); - pet.setRoomUnit(new RoomUnit()); - pet.getRoomUnit().setPathFinderRoom(room); - pet.setNeedsUpdate(true); + pet.getRoomUnit().setRoom(room); + pet.setSqlUpdateNeeded(true); pet.run(); return pet; @@ -482,9 +479,8 @@ public class PetManager { pet.setUserId(habbo.getHabboInfo().getId()); pet.setRoom(room); - pet.setRoomUnit(new RoomUnit()); - pet.getRoomUnit().setPathFinderRoom(room); - pet.setNeedsUpdate(true); + pet.getRoomUnit().setRoom(room); + pet.setSqlUpdateNeeded(true); pet.run(); return pet; diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java b/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java index fb26f720..d846e793 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/RideablePet.java @@ -37,6 +37,10 @@ public class RideablePet extends Pet { this.hasSaddle = hasSaddle; } + public boolean hasRider() { + return this.rider != null; + } + public boolean anyoneCanRide() { return this.anyoneCanRide; } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionBreed.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionBreed.java index 7eb182de..3dfa32e3 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionBreed.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionBreed.java @@ -4,8 +4,8 @@ import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetBreedingNes import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.rooms.pets.breeding.GoToBreedingNestFailureComposer; import org.apache.commons.lang3.StringUtils; @@ -17,7 +17,7 @@ public class ActionBreed extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { InteractionPetBreedingNest nest = null; - for (HabboItem item : pet.getRoom().getRoomSpecialTypes().getItemsOfType(InteractionPetBreedingNest.class)) { + for (RoomItem item : pet.getRoom().getRoomSpecialTypes().getItemsOfType(InteractionPetBreedingNest.class)) { if (StringUtils.containsIgnoreCase(item.getBaseItem().getName(), pet.getPetData().getName()) && !((InteractionPetBreedingNest) item).boxFull()) { nest = (InteractionPetBreedingNest) item; break; @@ -25,7 +25,7 @@ public class ActionBreed extends PetAction { } if (nest != null) { - pet.getRoomUnit().setGoalLocation(pet.getRoom().getLayout().getTile(nest.getX(), nest.getY())); + pet.getRoomUnit().walkTo(pet.getRoom().getLayout().getTile(nest.getCurrentPosition().getX(), nest.getCurrentPosition().getY())); return true; } else { diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionCroak.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionCroak.java index 1301d7e3..2f8b1f31 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionCroak.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionCroak.java @@ -2,9 +2,7 @@ package com.eu.habbo.habbohotel.pets.actions; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetTasks; -import com.eu.habbo.habbohotel.pets.PetVocalsType; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.threading.runnables.PetClearPosture; @@ -17,7 +15,7 @@ public class ActionCroak extends ActionVocals { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - pet.getRoomUnit().setStatus(RoomUnitStatus.CROAK, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.CROAK, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.CROAK, null, false), this.minimumActionDuration); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDip.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDip.java index 9e86ee9a..3b1a11ee 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDip.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDip.java @@ -5,8 +5,8 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWater; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetVocalsType; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import gnu.trove.set.hash.THashSet; public class ActionDip extends PetAction { @@ -16,15 +16,15 @@ public class ActionDip extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - THashSet waterItems = pet.getRoom().getRoomSpecialTypes().getItemsOfType(InteractionWater.class); + THashSet waterItems = pet.getRoom().getRoomSpecialTypes().getItemsOfType(InteractionWater.class); if (waterItems.isEmpty()) { return false; } - HabboItem waterPatch = (HabboItem) waterItems.toArray()[Emulator.getRandom().nextInt(waterItems.size())]; + RoomItem waterPatch = (RoomItem) waterItems.toArray()[Emulator.getRandom().nextInt(waterItems.size())]; - pet.getRoomUnit().setGoalLocation(pet.getRoom().getLayout().getTile(waterPatch.getX(), waterPatch.getY())); + pet.getRoomUnit().walkTo(pet.getRoom().getLayout().getTile(waterPatch.getCurrentPosition().getX(), waterPatch.getCurrentPosition().getY())); if (pet.getHappiness() > 70) { pet.say(pet.getPetData().randomVocal(PetVocalsType.PLAYFUL)); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDown.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDown.java index dbdff378..b1edf2fe 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDown.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionDown.java @@ -20,11 +20,11 @@ public class ActionDown extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { if (pet.getTask() != PetTasks.DOWN && !pet.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) { - pet.getRoomUnit().setCmdLay(true); - pet.getRoomUnit().setStatus(RoomUnitStatus.LAY, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().setCmdLayEnabled(true); + pet.getRoomUnit().addStatus(RoomUnitStatus.LAY, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(() -> { - pet.getRoomUnit().setCmdLay(false); + pet.getRoomUnit().setCmdLayEnabled(false); pet.clearPosture(); }, this.minimumActionDuration); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHang.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHang.java index 0d610ee5..38c17c1f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHang.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHang.java @@ -21,7 +21,7 @@ public class ActionHang extends PetAction { boolean findTree = pet.findPetItem(PetTasks.HANG, InteractionPetTree.class); if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { pet.getRoomUnit().setCanWalk(false); - pet.getRoomUnit().setStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.HANG, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(() -> { pet.getRoomUnit().setCanWalk(true); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHere.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHere.java index da0b5948..9c97ab2d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHere.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionHere.java @@ -16,7 +16,7 @@ public class ActionHere extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - pet.getRoomUnit().setGoalLocation(pet.getRoom().getLayout().getTileInFront(habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getBodyRotation().getValue())); + pet.getRoomUnit().walkTo(pet.getRoom().getLayout().getTileInFront(habbo.getRoomUnit().getCurrentPosition(), habbo.getRoomUnit().getBodyRotation().getValue())); pet.getRoomUnit().setCanWalk(true); if (pet.getHappiness() > 50) { diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionMoveForward.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionMoveForward.java index abaac92e..e00b3914 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionMoveForward.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionMoveForward.java @@ -13,7 +13,7 @@ public class ActionMoveForward extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - pet.getRoomUnit().setGoalLocation(pet.getRoom().getLayout().getTileInFront(pet.getRoomUnit().getCurrentLocation(), pet.getRoomUnit().getBodyRotation().getValue())); + pet.getRoomUnit().walkTo(pet.getRoom().getLayout().getTileInFront(pet.getRoomUnit().getCurrentPosition(), pet.getRoomUnit().getBodyRotation().getValue())); pet.getRoomUnit().setCanWalk(true); pet.say(pet.getPetData().randomVocal(PetVocalsType.GENERIC_NEUTRAL)); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayDead.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayDead.java index e62ef857..31f6a0d7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayDead.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayDead.java @@ -18,7 +18,7 @@ public class ActionPlayDead extends PetAction { public boolean apply(Pet pet, Habbo habbo, String[] data) { pet.clearPosture(); - pet.getRoomUnit().setStatus(RoomUnitStatus.DEAD, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.DEAD, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); if (pet.getHappiness() > 50) pet.say(pet.getPetData().randomVocal(PetVocalsType.PLAYFUL)); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayFootball.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayFootball.java index f5f12c94..c34c7eab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayFootball.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionPlayFootball.java @@ -5,8 +5,8 @@ import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetVocalsType; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; public class ActionPlayFootball extends PetAction { public ActionPlayFootball() { @@ -21,9 +21,9 @@ public class ActionPlayFootball extends PetAction { if(room == null || room.getLayout() == null) return false; - HabboItem foundBall = null; + RoomItem foundBall = null; - for(HabboItem item : room.getFloorItems()) { + for(RoomItem item : room.getRoomItemManager().getFloorItems().values()) { if(item instanceof InteractionPushable) { foundBall = item; } @@ -32,7 +32,7 @@ public class ActionPlayFootball extends PetAction { if(foundBall == null) return false; - pet.getRoomUnit().setGoalLocation(room.getLayout().getTile(foundBall.getX(), foundBall.getY())); + pet.getRoomUnit().walkTo(room.getLayout().getTile(foundBall.getCurrentPosition().getX(), foundBall.getCurrentPosition().getY())); if (pet.getHappiness() > 75) pet.say(pet.getPetData().randomVocal(PetVocalsType.PLAYFUL)); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRelax.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRelax.java index 25b70b38..8b472609 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRelax.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRelax.java @@ -21,7 +21,7 @@ public class ActionRelax extends PetAction { else pet.say(pet.getPetData().randomVocal(PetVocalsType.GENERIC_NEUTRAL)); - pet.getRoomUnit().setStatus(RoomUnitStatus.RELAX, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.RELAX, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRingOfFire.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRingOfFire.java index fcaaee3f..963b1e73 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRingOfFire.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRingOfFire.java @@ -21,7 +21,7 @@ public class ActionRingOfFire extends PetAction { boolean findTree = pet.findPetItem(PetTasks.RING_OF_FIRE, InteractionPetTree.class); if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { pet.getRoomUnit().setCanWalk(false); - pet.getRoomUnit().setStatus(RoomUnitStatus.RINGOFFIRE, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.RINGOFFIRE, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(() -> { pet.getRoomUnit().setCanWalk(true); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRoll.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRoll.java index 8a757d5f..31777d91 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRoll.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionRoll.java @@ -21,7 +21,7 @@ public class ActionRoll extends PetAction { boolean findTree = pet.findPetItem(PetTasks.ROLL, InteractionPetTree.class); if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { pet.getRoomUnit().setCanWalk(false); - pet.getRoomUnit().setStatus(RoomUnitStatus.ROLL, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.ROLL, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(() -> { pet.getRoomUnit().setCanWalk(true); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSit.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSit.java index b3ce2f51..6d40cea4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSit.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSit.java @@ -21,11 +21,11 @@ public class ActionSit extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { if (pet.getTask() != PetTasks.SIT && !pet.getRoomUnit().hasStatus(RoomUnitStatus.SIT)) { - pet.getRoomUnit().setCmdSit(true); - pet.getRoomUnit().setStatus(RoomUnitStatus.SIT, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().setCmdSitEnabled(true); + pet.getRoomUnit().addStatus(RoomUnitStatus.SIT, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(() -> { - pet.getRoomUnit().setCmdSit(false); + pet.getRoomUnit().setCmdSitEnabled(false); pet.clearPosture(); }, this.minimumActionDuration); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java index 3ca54d83..c802ce9d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionSwing.java @@ -21,7 +21,7 @@ public class ActionSwing extends PetAction { boolean findTree = pet.findPetItem(PetTasks.SWING, InteractionPetTree.class); if (!findTree && pet.getPetData().getToyItems().stream().noneMatch(item -> item.getInteractionType().getType() == InteractionPetTree.class)) { pet.getRoomUnit().setCanWalk(false); - pet.getRoomUnit().setStatus(RoomUnitStatus.SWING, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.SWING, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(() -> { pet.getRoomUnit().setCanWalk(true); diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnLeft.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnLeft.java index a04efc81..310e89ca 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnLeft.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnLeft.java @@ -3,7 +3,7 @@ package com.eu.habbo.habbohotel.pets.actions; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetVocalsType; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.users.Habbo; public class ActionTurnLeft extends PetAction { @@ -13,8 +13,8 @@ public class ActionTurnLeft extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - pet.getRoomUnit().setBodyRotation(RoomUserRotation.values()[(pet.getRoomUnit().getBodyRotation().getValue() - 1 < 0 ? 7 : pet.getRoomUnit().getBodyRotation().getValue() - 1)]); - pet.getRoomUnit().setHeadRotation(RoomUserRotation.values()[(pet.getRoomUnit().getHeadRotation().getValue() - 1 < 0 ? 7 : pet.getRoomUnit().getHeadRotation().getValue() - 1)]); + pet.getRoomUnit().setBodyRotation(RoomRotation.values()[(pet.getRoomUnit().getBodyRotation().getValue() - 1 < 0 ? 7 : pet.getRoomUnit().getBodyRotation().getValue() - 1)]); + pet.getRoomUnit().setHeadRotation(RoomRotation.values()[(pet.getRoomUnit().getHeadRotation().getValue() - 1 < 0 ? 7 : pet.getRoomUnit().getHeadRotation().getValue() - 1)]); pet.say(pet.getPetData().randomVocal(PetVocalsType.GENERIC_NEUTRAL)); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnRight.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnRight.java index 6bb19b73..eac44d4f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnRight.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionTurnRight.java @@ -3,7 +3,7 @@ package com.eu.habbo.habbohotel.pets.actions; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.PetAction; import com.eu.habbo.habbohotel.pets.PetVocalsType; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.users.Habbo; public class ActionTurnRight extends PetAction { @@ -13,8 +13,8 @@ public class ActionTurnRight extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - pet.getRoomUnit().setBodyRotation(RoomUserRotation.values()[(pet.getRoomUnit().getBodyRotation().getValue() + 1 > 7 ? 0 : pet.getRoomUnit().getBodyRotation().getValue() + 1)]); - pet.getRoomUnit().setHeadRotation(RoomUserRotation.values()[(pet.getRoomUnit().getHeadRotation().getValue() + 1 > 7 ? 0 : pet.getRoomUnit().getHeadRotation().getValue() + 1)]); + pet.getRoomUnit().setBodyRotation(RoomRotation.values()[(pet.getRoomUnit().getBodyRotation().getValue() + 1 > 7 ? 0 : pet.getRoomUnit().getBodyRotation().getValue() + 1)]); + pet.getRoomUnit().setHeadRotation(RoomRotation.values()[(pet.getRoomUnit().getHeadRotation().getValue() + 1 > 7 ? 0 : pet.getRoomUnit().getHeadRotation().getValue() + 1)]); pet.say(pet.getPetData().randomVocal(PetVocalsType.GENERIC_NEUTRAL)); return true; } diff --git a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionWave.java b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionWave.java index 2675d8b6..3d4652a7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionWave.java +++ b/src/main/java/com/eu/habbo/habbohotel/pets/actions/ActionWave.java @@ -19,7 +19,7 @@ public class ActionWave extends PetAction { @Override public boolean apply(Pet pet, Habbo habbo, String[] data) { - pet.getRoomUnit().setStatus(RoomUnitStatus.WAVE, pet.getRoomUnit().getCurrentLocation().getStackHeight() + ""); + pet.getRoomUnit().addStatus(RoomUnitStatus.WAVE, pet.getRoomUnit().getCurrentPosition().getStackHeight() + ""); Emulator.getThreading().run(new PetClearPosture(pet, RoomUnitStatus.WAVE, null, false), this.minimumActionDuration); if (pet.getHappiness() > 40) { diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/CustomRoomLayout.java b/src/main/java/com/eu/habbo/habbohotel/rooms/CustomRoomLayout.java index 0399ff1a..e648cf7c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/CustomRoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/CustomRoomLayout.java @@ -17,7 +17,7 @@ public class CustomRoomLayout extends RoomLayout implements Runnable { public CustomRoomLayout(ResultSet set, Room room) { super(set, room); - this.roomId = room.getId(); + this.roomId = room.getRoomInfo().getId(); } @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 afb0a400..3dd6ee2c 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -12,22 +12,16 @@ import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.items.ICycleable; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.*; -import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; -import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; -import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere; -import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter; -import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile; -import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; -import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; -import com.eu.habbo.habbohotel.items.interactions.pets.*; -import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; -import com.eu.habbo.habbohotel.messenger.MessengerBuddy; 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.pets.RideablePet; -import com.eu.habbo.habbohotel.users.*; +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.RoomPet; +import com.eu.habbo.habbohotel.users.DanceType; +import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ISerialize; @@ -36,30 +30,31 @@ import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.generic.alerts.GenericErrorComposer; import com.eu.habbo.messages.outgoing.generic.alerts.HabboBroadcastMessageComposer; import com.eu.habbo.messages.outgoing.guilds.HabboGroupDetailsMessageComposer; -import com.eu.habbo.messages.outgoing.hotelview.CloseConnectionMessageComposer; -import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; -import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer; -import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; import com.eu.habbo.messages.outgoing.polls.infobus.QuestionAnsweredComposer; import com.eu.habbo.messages.outgoing.polls.infobus.QuestionComposer; -import com.eu.habbo.messages.outgoing.rooms.*; -import com.eu.habbo.messages.outgoing.rooms.items.*; -import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; +import com.eu.habbo.messages.outgoing.rooms.FlatAccessDeniedMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.FlatAccessibleMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.HeightMapUpdateMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; +import com.eu.habbo.messages.outgoing.rooms.items.ItemUpdateMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.items.ObjectUpdateMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.items.OneWayDoorStatusMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.RemainingMutePeriodComposer; import com.eu.habbo.plugin.Event; -import com.eu.habbo.plugin.events.furniture.*; +import com.eu.habbo.plugin.events.furniture.FurnitureRolledEvent; +import com.eu.habbo.plugin.events.furniture.FurnitureStackHeightEvent; import com.eu.habbo.plugin.events.rooms.RoomLoadedEvent; import com.eu.habbo.plugin.events.rooms.RoomUnloadedEvent; import com.eu.habbo.plugin.events.rooms.RoomUnloadingEvent; -import com.eu.habbo.plugin.events.users.*; +import com.eu.habbo.plugin.events.users.UserExitRoomEvent; +import com.eu.habbo.plugin.events.users.UserIdleEvent; +import com.eu.habbo.plugin.events.users.UserRolledEvent; +import com.eu.habbo.plugin.events.users.UsernameTalkEvent; import com.eu.habbo.threading.runnables.YouAreAPirate; import gnu.trove.TCollections; -import gnu.trove.iterator.TIntObjectIterator; -import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.TIntIntMap; import gnu.trove.map.TIntObjectMap; -import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.TIntIntHashMap; import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.set.hash.THashSet; @@ -67,7 +62,6 @@ import io.netty.util.internal.ConcurrentSet; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.math3.util.Pair; import java.awt.*; import java.sql.Connection; @@ -80,18 +74,29 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; -import java.util.stream.Collectors; import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; @Slf4j public class Room implements Comparable, ISerialize, Runnable { + @Getter + private final RoomInfo roomInfo; + @Getter + private final RoomUnitManager roomUnitManager; + @Getter + private final RoomItemManager roomItemManager; + @Getter + private final RoomRightsManager roomRightsManager; + @Getter + private final RoomWordFilterManager roomWordFilterManager; + @Getter + private RoomTraxManager roomTraxManager; private static final String CAUGHT_EXCEPTION = "Caught exception"; - - public static final Comparator SORT_SCORE = (o1, o2) -> o2.getScore() - o1.getScore(); - public static final Comparator SORT_ID = (o1, o2) -> o2.getId() - o1.getId(); - private static final TIntObjectHashMap defaultMoodData = new TIntObjectHashMap<>(); - //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; @@ -104,43 +109,18 @@ public class Room implements Comparable, ISerialize, Runnable { public static int ROLLERS_MAXIMUM_ROLL_AVATARS = 1; public static boolean MUTEAREA_CAN_WHISPER = false; public static final double MAXIMUM_FURNI_HEIGHT = 40d; - - - static { - for (int i = 1; i <= 3; i++) { - RoomMoodlightData data = RoomMoodlightData.fromString(""); - data.setId(i); - defaultMoodData.put(i, data); - } - } - - public final Object roomUnitLock = new Object(); - public final ConcurrentHashMap> tileCache = new ConcurrentHashMap<>(); + public final ConcurrentHashMap> tileCache = new ConcurrentHashMap<>(); public final List userVotes; @Getter - private final ConcurrentHashMap currentHabbos = new ConcurrentHashMap<>(3); - @Getter private final TIntObjectMap habboQueue = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); - @Getter - private final TIntObjectMap currentBots = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); - @Getter - private final TIntObjectMap currentPets = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); private final THashSet activeTrades; - @Getter - private final TIntArrayList rights; private final TIntIntHashMap mutedHabbos; private final TIntObjectHashMap bannedHabbos; @Getter private final ConcurrentSet games; @Getter private final TIntObjectMap furniOwnerNames; - @Getter private final TIntIntMap furniOwnerCount; - @Getter - private final TIntObjectMap moodlightData; - @Getter - private final THashSet wordFilterWords; - private final TIntObjectMap roomItems; private final Object loadLock = new Object(); //Use appropriately. Could potentially cause memory leaks when used incorrectly. public volatile boolean preventUnloading = false; @@ -157,117 +137,15 @@ public class Room implements Comparable, ISerialize, Runnable { private int wordQuizEnd = 0; public ScheduledFuture roomCycleTask; @Getter - private final int id; - @Getter - @Setter - private int ownerId; - @Getter - @Setter - private String ownerName; - @Getter - private String name; - @Getter - private String description; - @Getter @Setter private RoomLayout layout; - private boolean overrideModel; private final String layoutName; @Getter - private String password; - @Getter @Setter - private RoomState state; - @Setter - @Getter - private int usersMax; - @Getter - @Setter - private volatile int score; - @Getter - @Setter - private volatile int category; - @Getter - @Setter - private String floorPaint; - @Getter - @Setter - private String wallPaint; - @Getter - @Setter - private String backgroundPaint; - @Getter - @Setter - private int wallSize; - @Getter - @Setter - private int wallHeight; - @Getter - @Setter - private int floorSize; - @Setter - @Getter - private int guildId; - @Getter - @Setter - private String tags; - @Setter - @Getter - private volatile boolean publicRoom; - @Setter - @Getter - private volatile boolean staffPromotedRoom; - @Getter - private volatile boolean allowPets; - @Setter - @Getter - private volatile boolean allowPetsEat; - @Setter - @Getter - private volatile boolean allowWalkthrough; - @Setter - @Getter private volatile boolean allowBotsWalk; - @Setter @Getter + @Setter private volatile boolean allowEffects; - @Setter - @Getter - private volatile boolean hideWall; - @Setter - @Getter - private volatile int chatMode; - @Setter - @Getter - private volatile int chatWeight; - @Setter - @Getter - private volatile int chatSpeed; - @Setter - @Getter - private volatile int chatDistance; - @Setter - @Getter - private volatile int chatProtection; - @Setter - @Getter - private volatile int muteOption; - @Setter - @Getter - private volatile int kickOption; - @Setter - @Getter - private volatile int banOption; - @Setter - @Getter - private volatile int pollId; - private volatile boolean promoted; - @Getter - @Setter - private volatile int tradeMode; - private volatile boolean moveDiagonally; - private volatile boolean jukeboxActive; - private volatile boolean hideWired; @Getter private RoomPromotion promotion; @Setter @@ -276,78 +154,42 @@ public class Room implements Comparable, ISerialize, Runnable { private volatile boolean loaded; @Getter private volatile boolean preLoaded; - private int idleCycles; - private volatile int unitCounter; - @Getter - private volatile int rollerSpeed; + private int roomIdleCycles; private final int muteTime = Emulator.getConfig().getInt("hotel.flood.mute.time", 30); private long rollerCycle = System.currentTimeMillis(); - @Setter @Getter + @Setter private volatile int lastTimerReset = Emulator.getIntUnixTimestamp(); - @Setter @Getter + @Setter private volatile boolean muted; @Getter private RoomSpecialTypes roomSpecialTypes; - @Getter - private TraxManager traxManager; private boolean cycleOdd; @Getter private long cycleTimestamp; + @Getter + final HashMap triggersOnRoom; public Room(ResultSet set) throws SQLException { - this.id = set.getInt("id"); - this.ownerId = set.getInt("owner_id"); - this.ownerName = set.getString("owner_name"); - this.name = set.getString("name"); - this.description = set.getString("description"); - this.password = set.getString("password"); - this.state = RoomState.valueOf(set.getString("state").toUpperCase()); - this.usersMax = set.getInt("users_max"); - this.score = set.getInt("score"); - this.category = set.getInt("category"); - this.floorPaint = set.getString("paper_floor"); - this.wallPaint = set.getString("paper_wall"); - this.backgroundPaint = set.getString("paper_landscape"); - this.wallSize = set.getInt("thickness_wall"); - this.wallHeight = set.getInt("wall_height"); - this.floorSize = set.getInt("thickness_floor"); - this.tags = set.getString("tags"); - this.publicRoom = set.getBoolean("is_public"); - this.staffPromotedRoom = set.getBoolean("is_staff_picked"); - this.allowPets = set.getBoolean("allow_other_pets"); - this.allowPetsEat = set.getBoolean("allow_other_pets_eat"); - this.allowWalkthrough = set.getBoolean("allow_walkthrough"); - this.hideWall = set.getBoolean("allow_hidewall"); - this.chatMode = set.getInt("chat_mode"); - this.chatWeight = set.getInt("chat_weight"); - this.chatSpeed = set.getInt("chat_speed"); - this.chatDistance = set.getInt("chat_hearing_distance"); - this.chatProtection = set.getInt("chat_protection"); - this.muteOption = set.getInt("who_can_mute"); - this.kickOption = set.getInt("who_can_kick"); - this.banOption = set.getInt("who_can_ban"); - this.pollId = set.getInt("poll_id"); - this.guildId = set.getInt("guild_id"); - this.rollerSpeed = set.getInt("roller_speed"); - this.overrideModel = set.getString("override_model").equals("1"); - this.layoutName = set.getString("model"); - this.promoted = set.getString("promoted").equals("1"); - this.jukeboxActive = set.getString("jukebox_active").equals("1"); - this.hideWired = set.getString("hidewired").equals("1"); + this.roomInfo = new RoomInfo(set); + this.roomUnitManager = new RoomUnitManager(this); + this.roomItemManager = new RoomItemManager(this); + this.roomRightsManager = new RoomRightsManager(this); + this.roomWordFilterManager = new RoomWordFilterManager(this); + this.layoutName = set.getString("model"); this.bannedHabbos = new TIntObjectHashMap<>(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_promotions WHERE room_id = ? AND end_timestamp > ? LIMIT 1")) { - if (this.promoted) { - statement.setInt(1, this.id); + if (this.roomInfo.isPromoted()) { + statement.setInt(1, this.roomInfo.getId()); statement.setInt(2, Emulator.getIntUnixTimestamp()); try (ResultSet promotionSet = statement.executeQuery()) { - this.promoted = false; + this.roomInfo.setPromoted(false); if (promotionSet.next()) { - this.promoted = true; + this.roomInfo.setPromoted(true); this.promotion = new RoomPromotion(this, promotionSet); } } @@ -358,29 +200,19 @@ public class Room implements Comparable, ISerialize, Runnable { log.error(CAUGHT_SQL_EXCEPTION, e); } - this.tradeMode = set.getInt("trade_mode"); - this.moveDiagonally = set.getString("move_diagonally").equals("1"); - this.preLoaded = true; this.allowBotsWalk = true; this.allowEffects = true; this.furniOwnerNames = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); this.furniOwnerCount = TCollections.synchronizedMap(new TIntIntHashMap(0)); - this.roomItems = TCollections.synchronizedMap(new TIntObjectHashMap<>(0)); - this.wordFilterWords = new THashSet<>(0); - this.moodlightData = new TIntObjectHashMap<>(defaultMoodData); - - for (String s : set.getString("moodlight_data").split(";")) { - RoomMoodlightData data = RoomMoodlightData.fromString(s); - this.moodlightData.put(data.getId(), data); - } this.mutedHabbos = new TIntIntHashMap(); this.games = new ConcurrentSet<>(); this.activeTrades = new THashSet<>(0); - this.rights = new TIntArrayList(); this.userVotes = new ArrayList<>(); + + this.triggersOnRoom = new HashMap<>(); } public synchronized void loadData() { @@ -391,25 +223,18 @@ public class Room implements Comparable, ISerialize, Runnable { this.preLoaded = false; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { - synchronized (this.roomUnitLock) { - this.unitCounter = 0; - this.currentHabbos.clear(); - this.currentPets.clear(); - this.currentBots.clear(); - } + this.roomUnitManager.clear(); this.roomSpecialTypes = new RoomSpecialTypes(); this.loadLayout(); - this.loadRights(connection); - this.loadItems(connection); + this.roomRightsManager.load(connection); + this.roomItemManager.load(connection); this.loadHeightmap(); - this.loadBots(connection); - this.loadPets(connection); - this.loadWordFilter(connection); - this.loadWiredData(connection); + this.roomUnitManager.load(connection); + this.roomWordFilterManager.load(connection); - this.idleCycles = 0; + this.roomIdleCycles = 0; this.loaded = true; this.roomCycleTask = Emulator.getThreading().getService().scheduleAtFixedRate(this, 500, 500, TimeUnit.MILLISECONDS); @@ -417,17 +242,17 @@ public class Room implements Comparable, ISerialize, Runnable { log.error(CAUGHT_EXCEPTION, e); } - this.traxManager = new TraxManager(this); + this.roomTraxManager = new RoomTraxManager(this); - if (this.jukeboxActive) { - this.traxManager.play(0); - for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionJukeBox.class)) { - this.updateItem(item.setExtradata("1")); + if (this.roomInfo.isJukeboxEnabled()) { + this.roomTraxManager.play(0); + for (RoomItem item : this.roomSpecialTypes.getItemsOfType(InteractionJukeBox.class)) { + this.updateItem(item.setExtraData("1")); } } - for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) { - this.updateItem(item.setExtradata("1")); + for (RoomItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) { + this.updateItem(item.setExtraData("1")); } } @@ -437,7 +262,7 @@ public class Room implements Comparable, ISerialize, Runnable { private synchronized void loadLayout() { try { if (this.layout == null) { - if (this.overrideModel) { + if (this.roomInfo.isModelOverridden()) { this.layout = Emulator.getGameEnvironment().getRoomManager().loadCustomLayout(this); } else { this.layout = Emulator.getGameEnvironment().getRoomManager().loadLayout(this.layoutName, this); @@ -460,149 +285,13 @@ public class Room implements Comparable, ISerialize, Runnable { } } } else { - log.error("Unknown Room Layout for Room (ID: {})", this.id); + log.error("Unknown Room Layout for Room (ID: {})", this.roomInfo.getId()); } } catch (Exception e) { log.error(CAUGHT_EXCEPTION, e); } } - private synchronized void loadItems(Connection connection) { - this.roomItems.clear(); - - try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE room_id = ?")) { - statement.setInt(1, this.id); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - this.addHabboItem(Emulator.getGameEnvironment().getItemManager().loadHabboItem(set)); - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - - if (this.itemCount() > Room.MAXIMUM_FURNI) { - log.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.getId(), this.itemCount(), Room.MAXIMUM_FURNI); - } - } - - private synchronized void loadWiredData(Connection connection) { - try (PreparedStatement statement = connection.prepareStatement("SELECT id, wired_data FROM items WHERE room_id = ? AND wired_data<>''")) { - statement.setInt(1, this.id); - - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - try { - HabboItem item = this.getHabboItem(set.getInt("id")); - - if (item instanceof InteractionWired interactionWired) { - interactionWired.loadWiredData(set, this); - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - - 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.user_id = users.id WHERE room_id = ?")) { - statement.setInt(1, this.id); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - Bot b = Emulator.getGameEnvironment().getBotManager().loadBot(set); - - if (b != null) { - b.setRoom(this); - b.setRoomUnit(new RoomUnit()); - b.getRoomUnit().setPathFinderRoom(this); - b.getRoomUnit().setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y"))); - if (b.getRoomUnit().getCurrentLocation() == null || b.getRoomUnit().getCurrentLocation().getState() == RoomTileState.INVALID) { - b.getRoomUnit().setZ(this.getLayout().getDoorTile().getStackHeight()); - b.getRoomUnit().setLocation(this.getLayout().getDoorTile()); - b.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection())); - } else { - b.getRoomUnit().setZ(set.getDouble("z")); - b.getRoomUnit().setPreviousLocationZ(set.getDouble("z")); - b.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]); - } - b.getRoomUnit().setRoomUnitType(RoomUnitType.BOT); - b.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]); - b.getRoomUnit().setInRoom(true); - this.giveEffect(b.getRoomUnit(), set.getInt("effect"), Integer.MAX_VALUE); - this.addBot(b); - } - } - } - } 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(); - - 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.id); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - Pet pet = PetManager.loadPet(set); - pet.setRoom(this); - pet.setRoomUnit(new RoomUnit()); - pet.getRoomUnit().setPathFinderRoom(this); - pet.getRoomUnit().setLocation(this.layout.getTile((short) set.getInt("x"), (short) set.getInt("y"))); - if (pet.getRoomUnit().getCurrentLocation() == null || pet.getRoomUnit().getCurrentLocation().getState() == RoomTileState.INVALID) { - pet.getRoomUnit().setZ(this.getLayout().getDoorTile().getStackHeight()); - pet.getRoomUnit().setLocation(this.getLayout().getDoorTile()); - pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection())); - } else { - pet.getRoomUnit().setZ(set.getDouble("z")); - pet.getRoomUnit().setRotation(RoomUserRotation.values()[set.getInt("rot")]); - } - pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET); - pet.getRoomUnit().setCanWalk(true); - this.addPet(pet); - - this.getFurniOwnerNames().put(pet.getUserId(), set.getString("pet_owner_name")); - - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - - private synchronized void loadWordFilter(Connection connection) { - this.wordFilterWords.clear(); - - try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_wordfilter WHERE room_id = ?")) { - statement.setInt(1, this.id); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - this.wordFilterWords.add(set.getString("word")); - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - public void updateTile(RoomTile tile) { if (tile != null) { tile.setStackHeight(this.getStackHeight(tile.getX(), tile.getY(), false)); @@ -620,30 +309,32 @@ public class Room implements Comparable, ISerialize, Runnable { this.sendComposer(new HeightMapUpdateMessageComposer(this, tiles).compose()); } - private RoomTileState calculateTileState(RoomTile tile) { + public RoomTileState calculateTileState(RoomTile tile) { return this.calculateTileState(tile, null); } - private RoomTileState calculateTileState(RoomTile tile, HabboItem exclude) { + public RoomTileState calculateTileState(RoomTile tile, RoomItem exclude) { if (tile == null || tile.getState() == RoomTileState.INVALID) return RoomTileState.INVALID; RoomTileState result = RoomTileState.OPEN; - THashSet items = this.getItemsAt(tile); + THashSet items = this.roomItemManager.getItemsAt(tile); if (items == null) return RoomTileState.INVALID; - HabboItem tallestItem = null; + RoomItem tallestItem = null; - for (HabboItem item : items) { + for (RoomItem item : items) { if (exclude != null && item == exclude) continue; if (item.getBaseItem().allowLay()) { return RoomTileState.LAY; } - if (tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item)) - continue; + if (tallestItem != null) { + if (tallestItem.getCurrentZ() + Item.getCurrentHeight(tallestItem) > item.getCurrentZ() + Item.getCurrentHeight(item)) + continue; + } result = this.checkStateForItem(item, tile); tallestItem = item; @@ -652,7 +343,7 @@ public class Room implements Comparable, ISerialize, Runnable { return result; } - private RoomTileState checkStateForItem(HabboItem item, RoomTile tile) { + private RoomTileState checkStateForItem(RoomItem item, RoomTile tile) { RoomTileState result = RoomTileState.BLOCKED; if (item.isWalkable()) { @@ -671,102 +362,22 @@ public class Room implements Comparable, ISerialize, Runnable { return result; } - public boolean tileWalkable(RoomTile t) { - return this.tileWalkable(t.getX(), t.getY()); - } - - public boolean tileWalkable(short x, short y) { - boolean walkable = this.layout.tileWalkable(x, y); - RoomTile tile = this.getLayout().getTile(x, y); - - if ((walkable && tile != null) && (tile.hasUnits() && !this.allowWalkthrough)) { - walkable = false; - } - - return walkable; - } - - public void pickUpItem(HabboItem item, Habbo picker) { - if (item == null) - return; - - if (Emulator.getPluginManager().isRegistered(FurniturePickedUpEvent.class, true)) { - Event furniturePickedUpEvent = new FurniturePickedUpEvent(item, picker); - Emulator.getPluginManager().fireEvent(furniturePickedUpEvent); - - if (furniturePickedUpEvent.isCancelled()) - return; - } - - this.removeHabboItem(item.getId()); - item.onPickUp(this); - item.setRoomId(0); - item.needsUpdate(true); - - if (item.getBaseItem().getType() == FurnitureType.FLOOR) { - this.sendComposer(new RemoveFloorItemComposer(item).compose()); - - THashSet updatedTiles = new THashSet<>(); - Rectangle rectangle = RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - - for (short x = (short) rectangle.x; x < rectangle.x + rectangle.getWidth(); x++) { - for (short y = (short) rectangle.y; y < rectangle.y + rectangle.getHeight(); y++) { - double stackHeight = this.getStackHeight(x, y, false); - RoomTile tile = this.layout.getTile(x, y); - - if (tile != null) { - tile.setStackHeight(stackHeight); - updatedTiles.add(tile); - } - } - } - this.sendComposer(new HeightMapUpdateMessageComposer(this, updatedTiles).compose()); - this.updateTiles(updatedTiles); - updatedTiles.forEach(tile -> { - this.updateHabbosAt(tile.getX(), tile.getY()); - this.updateBotsAt(tile.getX(), tile.getY()); - }); - } else if (item.getBaseItem().getType() == FurnitureType.WALL) { - this.sendComposer(new ItemRemoveMessageComposer(item).compose()); - } - - Habbo habbo = (picker != null && picker.getHabboInfo().getId() == item.getId() ? picker : Emulator.getGameServer().getGameClientManager().getHabbo(item.getUserId())); - if (habbo != null) { - habbo.getInventory().getItemsComponent().addItem(item); - habbo.getClient().sendResponse(new UnseenItemsComposer(item)); - habbo.getClient().sendResponse(new FurniListInvalidateComposer()); - } - Emulator.getThreading().run(item); - } - - public void updateHabbosAt(Rectangle rectangle) { - for (short i = (short) rectangle.x; i < rectangle.x + rectangle.width; i++) { - for (short j = (short) rectangle.y; j < rectangle.y + rectangle.height; j++) { - this.updateHabbosAt(i, j); - } - } - } - - public void updateHabbo(Habbo habbo) { - this.updateRoomUnit(habbo.getRoomUnit()); - } - public void updateRoomUnit(RoomUnit roomUnit) { - HabboItem item = this.getTopItemAt(roomUnit.getX(), roomUnit.getY()); + RoomItem item = this.roomItemManager.getTopItemAt(roomUnit.getCurrentPosition().getX(), roomUnit.getCurrentPosition().getY()); - if ((item == null && !roomUnit.isCmdSit()) || (item != null && !item.getBaseItem().allowSit())) + if ((item == null && !roomUnit.isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit())) roomUnit.removeStatus(RoomUnitStatus.SIT); - double oldZ = roomUnit.getZ(); + double oldZ = roomUnit.getCurrentZ(); if (item != null) { if (item.getBaseItem().allowSit()) { - roomUnit.setZ(item.getZ()); + roomUnit.setCurrentZ(item.getCurrentZ()); } else { - roomUnit.setZ(item.getZ() + Item.getCurrentHeight(item)); + roomUnit.setCurrentZ(item.getCurrentZ() + Item.getCurrentHeight(item)); } - if (oldZ != roomUnit.getZ()) { + if (oldZ != roomUnit.getCurrentZ()) { this.scheduledTasks.add(() -> { try { item.onWalkOn(roomUnit, Room.this, null); @@ -780,96 +391,6 @@ public class Room implements Comparable, ISerialize, Runnable { this.sendComposer(new UserUpdateComposer(roomUnit).compose()); } - public void updateHabbosAt(short x, short y) { - this.updateHabbosAt(x, y, this.getHabbosAt(x, y)); - } - - public void updateHabbosAt(short x, short y, List habbos) { - HabboItem item = this.getTopItemAt(x, y); - - for (Habbo habbo : habbos) { - - double oldZ = habbo.getRoomUnit().getZ(); - RoomUserRotation oldRotation = habbo.getRoomUnit().getBodyRotation(); - double z = habbo.getRoomUnit().getCurrentLocation().getStackHeight(); - boolean updated = false; - - if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !habbo.getRoomUnit().isCmdSit()) || (item != null && !item.getBaseItem().allowSit()))) { - habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT); - updated = true; - } - - if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !habbo.getRoomUnit().isCmdLay()) || (item != null && !item.getBaseItem().allowLay()))) { - habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY); - updated = true; - } - - if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) { - habbo.getRoomUnit().setZ(item.getZ()); - habbo.getRoomUnit().setPreviousLocationZ(item.getZ()); - habbo.getRoomUnit().setRotation(RoomUserRotation.fromValue(item.getRotation())); - } else { - habbo.getRoomUnit().setZ(z); - habbo.getRoomUnit().setPreviousLocationZ(z); - } - - if (habbo.getRoomUnit().getCurrentLocation().is(x, y) && (oldZ != z || updated || oldRotation != habbo.getRoomUnit().getBodyRotation())) { - habbo.getRoomUnit().statusUpdate(true); - } - } - } - - public void updateBotsAt(short x, short y) { - HabboItem topItem = this.getTopItemAt(x, y); - - THashSet roomUnits = new THashSet<>(); - - this.getBotsAt(this.layout.getTile(x, y)).forEach(bot -> { - if (topItem != null) { - if (topItem.getBaseItem().allowSit()) { - bot.getRoomUnit().setZ(topItem.getZ()); - bot.getRoomUnit().setPreviousLocationZ(topItem.getZ()); - bot.getRoomUnit().setRotation(RoomUserRotation.fromValue(topItem.getRotation())); - } else { - bot.getRoomUnit().setZ(topItem.getZ() + Item.getCurrentHeight(topItem)); - - if (topItem.getBaseItem().allowLay()) { - bot.getRoomUnit().setStatus(RoomUnitStatus.LAY, (topItem.getZ() + topItem.getBaseItem().getHeight()) + ""); - } - } - } else { - bot.getRoomUnit().setZ(bot.getRoomUnit().getCurrentLocation().getStackHeight()); - bot.getRoomUnit().setPreviousLocationZ(bot.getRoomUnit().getCurrentLocation().getStackHeight()); - } - roomUnits.add(bot.getRoomUnit()); - }); - - if (!roomUnits.isEmpty()) { - this.sendComposer(new UserUpdateComposer(roomUnits).compose()); - } - } - - public void pickupPetsForHabbo(Habbo habbo) { - THashSet pets = new THashSet<>(); - - synchronized (this.currentPets) { - for (Pet pet : this.currentPets.valueCollection()) { - if (pet.getUserId() == habbo.getHabboInfo().getId()) { - pets.add(pet); - } - } - } - - for (Pet pet : pets) { - pet.removeFromRoom(); - Emulator.getThreading().run(pet); - habbo.getInventory().getPetsComponent().addPet(pet); - habbo.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); - this.currentPets.remove(pet.getId()); - } - - } - public void startTrade(Habbo userOne, Habbo userTwo) { RoomTrade trade = new RoomTrade(userOne, userTwo, this); synchronized (this.activeTrades) { @@ -897,270 +418,10 @@ 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.traxManager != null && !this.traxManager.disposed()) { - this.traxManager.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(); - - removeAllPets(ownerId); - - synchronized (this.roomItems) { - TIntObjectIterator iterator = this.roomItems.iterator(); - - - for (int i = this.roomItems.size(); i-- > 0; ) { - try { - iterator.advance(); - - if (iterator.value().needsUpdate()) - iterator.value().run(); - } catch (NoSuchElementException e) { - break; - } - } - } - - if (this.roomSpecialTypes != null) { - this.roomSpecialTypes.dispose(); - } - - synchronized (this.roomItems) { - this.roomItems.clear(); - } - - synchronized (this.habboQueue) { - this.habboQueue.clear(); - } - - - for (Habbo habbo : this.currentHabbos.values()) { - Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this); - } - - this.sendComposer(new CloseConnectionMessageComposer().compose()); - - this.currentHabbos.clear(); - - - TIntObjectIterator botIterator = this.currentBots.iterator(); - - for (int i = this.currentBots.size(); i-- > 0; ) { - try { - botIterator.advance(); - botIterator.value().needsUpdate(true); - Emulator.getThreading().run(botIterator.value()); - } catch (NoSuchElementException e) { - log.error(CAUGHT_EXCEPTION, e); - break; - } - } - - this.currentBots.clear(); - this.currentPets.clear(); - } 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.getUserCount() != this.getUserCount()) { - return o.getCurrentHabbos().size() - this.getCurrentHabbos().size(); - } - - return this.id - o.id; - } - - @Override - public void serialize(ServerMessage message) { - message.appendInt(this.id); - message.appendString(this.name); - if (this.isPublicRoom()) { - message.appendInt(0); - message.appendString(""); - } else { - message.appendInt(this.ownerId); - message.appendString(this.ownerName); - } - message.appendInt(this.state.getState()); - message.appendInt(this.getUserCount()); - message.appendInt(this.usersMax); - message.appendString(this.description); - message.appendInt(0); - message.appendInt(this.score); - message.appendInt(0); - message.appendInt(this.category); - - String[] tags = Arrays.stream(this.tags.split(";")).filter(t -> !t.isEmpty()).toArray(String[]::new); - message.appendInt(tags.length); - for (String s : tags) { - message.appendString(s); - } - - int base = 0; - - if (this.getGuildId() > 0) { - base = base | 2; - } - - if (this.isPromoted()) { - base = base | 4; - } - - if (!this.isPublicRoom()) { - base = base | 8; - } - - - message.appendInt(base); - - - if (this.getGuildId() > 0) { - Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.getGuildId()); - if (g != null) { - message.appendInt(g.getId()); - message.appendString(g.getName()); - message.appendString(g.getBadge()); - } else { - message.appendInt(0); - message.appendString(""); - message.appendString(""); - } - } - - if (this.promoted) { - 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(); PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ? WHERE id = ?")) { - statement.setString(1, this.name); - statement.setString(2, this.description); - statement.setString(3, this.password); - statement.setString(4, this.state.name().toLowerCase()); - statement.setInt(5, this.usersMax); - statement.setInt(6, this.category); - statement.setInt(7, this.score); - statement.setString(8, this.floorPaint); - statement.setString(9, this.wallPaint); - statement.setString(10, this.backgroundPaint); - statement.setInt(11, this.wallSize); - statement.setInt(12, this.wallHeight); - statement.setInt(13, this.floorSize); - StringBuilder moodLightData = new StringBuilder(); - - int id = 1; - for (RoomMoodlightData data : this.moodlightData.valueCollection()) { - data.setId(id); - moodLightData.append(data).append(";"); - id++; - } - - statement.setString(14, moodLightData.toString()); - statement.setString(15, this.tags); - statement.setString(16, this.allowPets ? "1" : "0"); - statement.setString(17, this.allowPetsEat ? "1" : "0"); - statement.setString(18, this.allowWalkthrough ? "1" : "0"); - statement.setString(19, this.hideWall ? "1" : "0"); - statement.setInt(20, this.chatMode); - statement.setInt(21, this.chatWeight); - statement.setInt(22, this.chatSpeed); - statement.setInt(23, this.chatDistance); - statement.setInt(24, this.chatProtection); - statement.setInt(25, this.muteOption); - statement.setInt(26, this.kickOption); - statement.setInt(27, this.banOption); - statement.setInt(28, this.pollId); - statement.setInt(29, this.guildId); - statement.setInt(30, this.rollerSpeed); - statement.setString(31, this.overrideModel ? "1" : "0"); - statement.setString(32, this.staffPromotedRoom ? "1" : "0"); - statement.setString(33, this.promoted ? "1" : "0"); - statement.setInt(34, this.tradeMode); - statement.setString(35, this.moveDiagonally ? "1" : "0"); - statement.setInt(36, this.ownerId); - statement.setString(37, this.ownerName); - statement.setString(38, this.jukeboxActive ? "1" : "0"); - statement.setString(39, this.hideWired ? "1" : "0"); - statement.setInt(40, this.id); - statement.executeUpdate(); - this.needsUpdate = false; - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - } - } - - private void updateDatabaseUserCount() { + 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.currentHabbos.size()); - statement.setInt(2, this.id); + statement.setInt(1, this.roomUnitManager.getRoomHabbosCount()); + statement.setInt(2, this.roomInfo.getId()); statement.executeUpdate(); } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); @@ -1172,7 +433,6 @@ public class Room implements Comparable, ISerialize, Runnable { this.cycleTimestamp = System.currentTimeMillis(); final boolean[] foundRightHolder = {false}; - boolean loaded; synchronized (this.loadLock) { loaded = this.loaded; @@ -1192,44 +452,35 @@ public class Room implements Comparable, ISerialize, Runnable { task.cycle(this); } - if (!this.currentHabbos.isEmpty()) { - this.idleCycles = 0; + if (!this.roomUnitManager.getCurrentHabbos().isEmpty()) { + this.roomIdleCycles = 0; THashSet updatedUnit = new THashSet<>(); ArrayList toKick = new ArrayList<>(); - final Room room = this; - final long millis = System.currentTimeMillis(); - for (Habbo habbo : this.currentHabbos.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()) { - this.giveEffect(habbo, 0, -1); + habbo.getRoomUnit().giveEffect(0, -1); } if (habbo.getRoomUnit().isKicked()) { habbo.getRoomUnit().setKickCount(habbo.getRoomUnit().getKickCount() + 1); if (habbo.getRoomUnit().getKickCount() >= 5) { - this.scheduledTasks.add(() -> Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, room)); + this.scheduledTasks.add(() -> Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this)); continue; } } if (Emulator.getConfig().getBoolean("hotel.rooms.auto.idle")) { if (!habbo.getRoomUnit().isIdle()) { - habbo.getRoomUnit().increaseIdleTimer(); + habbo.getRoomUnit().incrementIdleTicks(); if (habbo.getRoomUnit().isIdle()) { boolean danceIsNone = (habbo.getRoomUnit().getDanceType() == DanceType.NONE); @@ -1239,9 +490,9 @@ public class Room implements Comparable, ISerialize, Runnable { WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo}); } } else { - habbo.getRoomUnit().increaseIdleTimer(); + habbo.getRoomUnit().incrementIdleTicks(); - if (!this.isOwner(habbo) && habbo.getRoomUnit().getIdleTimer() >= Room.IDLE_CYCLES_KICK) { + if (!this.getRoomInfo().isRoomOwner(habbo) && habbo.getRoomUnit().getIdleTicks() >= Room.IDLE_CYCLES_KICK) { UserExitRoomEvent event = new UserExitRoomEvent(habbo, UserExitRoomEvent.UserExitRoomReason.KICKED_IDLE); Emulator.getPluginManager().fireEvent(event); @@ -1252,10 +503,10 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting") && this.ownerId != habbo.getHabboInfo().getId()) { + if (Emulator.getConfig().getBoolean("hotel.rooms.deco_hosting") && this.roomInfo.getOwnerInfo().getId() != habbo.getHabboInfo().getId()) { //Check if the time already have 1 minute (120 / 2 = 60s) if (habbo.getRoomUnit().getTimeInRoom() >= 120) { - AchievementManager.progressAchievement(this.ownerId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting")); + AchievementManager.progressAchievement(this.roomInfo.getOwnerInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting")); habbo.getRoomUnit().resetTimeInRoom(); } else { habbo.getRoomUnit().increaseTimeInRoom(); @@ -1272,7 +523,10 @@ public class Room implements Comparable, ISerialize, Runnable { habbo.getHabboStats().getChatCounter().decrementAndGet(); } - if (this.cycleRoomUnit(habbo.getRoomUnit())) { + habbo.getRoomUnit().cycle(); + + if(habbo.getRoomUnit().isStatusUpdateNeeded()) { + habbo.getRoomUnit().setStatusUpdateNeeded(false); updatedUnit.add(habbo.getRoomUnit()); } } @@ -1283,14 +537,14 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (!this.currentBots.isEmpty()) { - TIntObjectIterator botIterator = this.currentBots.iterator(); - for (int i = this.currentBots.size(); i-- > 0; ) { + if (!this.roomUnitManager.getCurrentBots().isEmpty()) { + Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); + + while(botIterator.hasNext()) { try { final Bot bot; try { - botIterator.advance(); - bot = botIterator.value(); + bot = botIterator.next(); } catch (Exception e) { break; } @@ -1301,10 +555,10 @@ public class Room implements Comparable, ISerialize, Runnable { continue; } - botIterator.value().cycle(this.allowBotsWalk); + bot.getRoomUnit().cycle(); - - if (this.cycleRoomUnit(bot.getRoomUnit())) { + if(bot.getRoomUnit().isStatusUpdateNeeded()) { + bot.getRoomUnit().setStatusUpdateNeeded(false); updatedUnit.add(bot.getRoomUnit()); } @@ -1316,26 +570,22 @@ public class Room implements Comparable, ISerialize, Runnable { } } - if (!this.currentPets.isEmpty() && this.allowBotsWalk) { - TIntObjectIterator petIterator = this.currentPets.iterator(); - for (int i = this.currentPets.size(); i-- > 0; ) { + if (!this.roomUnitManager.getCurrentPets().isEmpty() && this.allowBotsWalk) { + Iterator petIterator = this.roomUnitManager.getCurrentPets().values().iterator(); + while(petIterator.hasNext()) { + final Pet pet; try { - petIterator.advance(); - } catch (NoSuchElementException e) { - log.error(CAUGHT_EXCEPTION, e); + pet = petIterator.next(); + } catch (Exception e) { break; } - Pet pet = petIterator.value(); - if (this.cycleRoomUnit(pet.getRoomUnit())) { - updatedUnit.add(pet.getRoomUnit()); - } - + pet.getRoomUnit().cycle(); 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)) { @@ -1346,7 +596,7 @@ public class Room implements Comparable, ISerialize, Runnable { } - if (this.rollerSpeed != -1 && this.rollerCycle >= this.rollerSpeed) { + if (this.roomInfo.getRollerSpeed() != -1 && this.rollerCycle >= this.roomInfo.getRollerSpeed()) { this.rollerCycle = 0; THashSet messages = new THashSet<>(); @@ -1359,27 +609,27 @@ public class Room implements Comparable, ISerialize, Runnable { this.roomSpecialTypes.getRollers().forEachValue(roller -> { - HabboItem newRoller = null; + RoomItem newRoller = null; - RoomTile rollerTile = this.getLayout().getTile(roller.getX(), roller.getY()); + RoomTile rollerTile = this.layout.getTile(roller.getCurrentPosition().getX(), roller.getCurrentPosition().getY()); if (rollerTile == null) return true; - THashSet itemsOnRoller = new THashSet<>(); + THashSet itemsOnRoller = new THashSet<>(); - for (HabboItem item : getItemsAt(rollerTile)) { - if (item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) { + for (RoomItem item : this.roomItemManager.getItemsAt(rollerTile)) { + if (item.getCurrentZ() >= roller.getCurrentZ() + Item.getCurrentHeight(roller)) { itemsOnRoller.add(item); } } itemsOnRoller.remove(roller); - if (!rollerTile.hasUnits() && itemsOnRoller.isEmpty()) + if (!this.roomUnitManager.areRoomUnitsAt(rollerTile) && itemsOnRoller.isEmpty()) return true; - RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation()); + RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getCurrentPosition().getX(), roller.getCurrentPosition().getY()), roller.getRotation()); if (tileInFront == null) return true; @@ -1393,30 +643,30 @@ public class Room implements Comparable, ISerialize, Runnable { if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.getState() == RoomTileState.SIT || tileInFront.getState() == RoomTileState.LAY)) return true; - if (tileInFront.hasUnits()) + if (this.roomUnitManager.areRoomUnitsAt(tileInFront)) return true; - THashSet itemsNewTile = new THashSet<>(); - itemsNewTile.addAll(getItemsAt(tileInFront)); + THashSet itemsNewTile = new THashSet<>(); + itemsNewTile.addAll(this.roomItemManager.getItemsAt(tileInFront)); itemsNewTile.removeAll(itemsOnRoller); - itemsOnRoller.removeIf(item -> item.getX() != roller.getX() || item.getY() != roller.getY() || rollerFurniIds.contains(item.getId())); + itemsOnRoller.removeIf(item -> item.getCurrentPosition().getX() != roller.getCurrentPosition().getX() || item.getCurrentPosition().getY() != roller.getCurrentPosition().getY() || rollerFurniIds.contains(item.getId())); - HabboItem topItem = Room.this.getTopItemAt(tileInFront.getX(), tileInFront.getY()); + RoomItem topItem = this.roomItemManager.getTopItemAt(tileInFront.getX(), tileInFront.getY()); boolean allowUsers = true; boolean allowFurniture = true; boolean stackContainsRoller = false; - for (HabboItem item : itemsNewTile) { - if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtradata().equals("1"))) { + for (RoomItem item : itemsNewTile) { + if (!(item.getBaseItem().allowWalk() || item.getBaseItem().allowSit()) && !(item instanceof InteractionGate && item.getExtraData().equals("1"))) { allowUsers = false; } if (item instanceof InteractionRoller) { newRoller = item; stackContainsRoller = true; - if ((item.getZ() != roller.getZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) { + if ((item.getCurrentZ() != roller.getCurrentZ() || (itemsNewTile.size() > 1 && item != topItem)) && !InteractionRoller.NO_RULES) { allowUsers = false; allowFurniture = false; continue; @@ -1448,34 +698,34 @@ public class Room implements Comparable, ISerialize, Runnable { roomUserRolledEvent = new UserRolledEvent(null, null, null); } - ArrayList unitsOnTile = new ArrayList<>(rollerTile.getUnits()); + ArrayList unitsOnTile = new ArrayList<>(this.roomUnitManager.getRoomUnitsAt(rollerTile)); - for (RoomUnit unit : rollerTile.getUnits()) { - if (unit.getRoomUnitType() == RoomUnitType.PET) { - Pet pet = this.getPet(unit); + for (RoomUnit roomUnit : this.roomUnitManager.getRoomUnitsAt(rollerTile)) { + if (roomUnit instanceof RoomPet) { + Pet pet = this.roomUnitManager.getPetByRoomUnit(roomUnit); if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) { - unitsOnTile.remove(unit); + unitsOnTile.remove(roomUnit); } } } THashSet usersRolledThisTile = new THashSet<>(); - for (RoomUnit unit : unitsOnTile) { - if (rolledUnitIds.contains(unit.getId())) continue; + for (RoomUnit roomUnit : unitsOnTile) { + if (rolledUnitIds.contains(roomUnit.getVirtualId())) continue; if (usersRolledThisTile.size() >= Room.ROLLERS_MAXIMUM_ROLL_AVATARS) break; if (stackContainsRoller && !allowFurniture && !(topItem != null && topItem.isWalkable())) continue; - if (unit.hasStatus(RoomUnitStatus.MOVE)) + if (roomUnit.hasStatus(RoomUnitStatus.MOVE)) continue; - double newZ = unit.getZ() + zOffset; + double newZ = roomUnit.getCurrentZ() + zOffset; - if (roomUserRolledEvent != null && unit.getRoomUnitType() == RoomUnitType.USER) { - roomUserRolledEvent = new UserRolledEvent(getHabbo(unit), roller, tileInFront); + if (roomUserRolledEvent != null && roomUnit.getRoomUnitType() == RoomUnitType.HABBO) { + roomUserRolledEvent = new UserRolledEvent(this.getRoomUnitManager().getHabboByRoomUnit(roomUnit), roller, tileInFront); Emulator.getPluginManager().fireEvent(roomUserRolledEvent); if (roomUserRolledEvent.isCancelled()) @@ -1484,51 +734,47 @@ public class Room implements Comparable, ISerialize, Runnable { // horse riding boolean isRiding = false; - if (unit.getRoomUnitType() == RoomUnitType.USER) { - Habbo rollingHabbo = this.getHabbo(unit); + if (roomUnit.getRoomUnitType() == RoomUnitType.HABBO) { + Habbo rollingHabbo = this.getRoomUnitManager().getHabboByRoomUnit(roomUnit); if (rollingHabbo != null && rollingHabbo.getHabboInfo() != null) { - RideablePet riding = rollingHabbo.getHabboInfo().getRiding(); - if (riding != null) { - RoomUnit ridingUnit = riding.getRoomUnit(); - newZ = ridingUnit.getZ() + zOffset; - rolledUnitIds.add(ridingUnit.getId()); + RideablePet ridingPet = rollingHabbo.getRoomUnit().getRidingPet(); + if (ridingPet != null) { + RoomUnit ridingUnit = ridingPet.getRoomUnit(); + newZ = ridingUnit.getCurrentZ() + zOffset; + rolledUnitIds.add(ridingUnit.getVirtualId()); updatedUnit.remove(ridingUnit); - messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentLocation(), ridingUnit.getZ(), tileInFront, newZ, room)); + messages.add(new RoomUnitOnRollerComposer(ridingUnit, roller, ridingUnit.getCurrentPosition(), ridingUnit.getCurrentZ(), tileInFront, newZ, this)); isRiding = true; } } } - usersRolledThisTile.add(unit.getId()); - rolledUnitIds.add(unit.getId()); - updatedUnit.remove(unit); - messages.add(new RoomUnitOnRollerComposer(unit, roller, unit.getCurrentLocation(), unit.getZ() + (isRiding ? 1 : 0), tileInFront, newZ + (isRiding ? 1 : 0), room)); + usersRolledThisTile.add(roomUnit.getVirtualId()); + rolledUnitIds.add(roomUnit.getVirtualId()); + updatedUnit.remove(roomUnit); + messages.add(new RoomUnitOnRollerComposer(roomUnit, roller, roomUnit.getCurrentPosition(), roomUnit.getCurrentZ() + (isRiding ? 1 : 0), tileInFront, newZ + (isRiding ? 1 : 0), this)); if (itemsOnRoller.isEmpty()) { - HabboItem item = room.getTopItemAt(tileInFront.getX(), tileInFront.getY()); + RoomItem item = this.getRoomItemManager().getTopItemAt(tileInFront.getX(), tileInFront.getY()); if (item != null && itemsNewTile.contains(item) && !itemsOnRoller.contains(item)) { Emulator.getThreading().run(() -> { - if (unit.getGoalLocation() == rollerTile) { + if (roomUnit.getTargetPosition() == rollerTile) { try { - item.onWalkOn(unit, room, new Object[]{rollerTile, tileInFront}); + item.onWalkOn(roomUnit, this, new Object[]{rollerTile, tileInFront}); } catch (Exception e) { log.error(CAUGHT_EXCEPTION, e); } } - }, this.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY); + }, this.roomInfo.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY); } } - - if (unit.hasStatus(RoomUnitStatus.SIT)) { - unit.setSitUpdate(true); - } } } if (!messages.isEmpty()) { for (MessageComposer message : messages) { - room.sendComposer(message.compose()); + this.sendComposer(message.compose()); } messages.clear(); } @@ -1541,11 +787,13 @@ public class Room implements Comparable, ISerialize, Runnable { } if (newRoller == null || topItem == newRoller) { - List sortedItems = new ArrayList<>(itemsOnRoller); - sortedItems.sort((o1, o2) -> Double.compare(o2.getZ(), o1.getZ())); + List sortedItems = new ArrayList<>(itemsOnRoller); + sortedItems.sort((o1, o2) -> { + return Double.compare(o2.getCurrentZ(), o1.getCurrentZ()); + }); - for (HabboItem item : sortedItems) { - if ((item.getX() == roller.getX() && item.getY() == roller.getY() && zOffset <= 0) && (item != roller)) { + for (RoomItem item : sortedItems) { + if ((item.getCurrentPosition().getX() == roller.getCurrentPosition().getX() && item.getCurrentPosition().getY() == roller.getCurrentPosition().getY() && zOffset <= 0) && (item != roller)) { if (furnitureRolledEvent != null) { furnitureRolledEvent = new FurnitureRolledEvent(item, roller, tileInFront); Emulator.getPluginManager().fireEvent(furnitureRolledEvent); @@ -1554,7 +802,7 @@ public class Room implements Comparable, ISerialize, Runnable { continue; } - messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, room)); + messages.add(new FloorItemOnRollerComposer(item, roller, tileInFront, zOffset, this)); rollerFurniIds.add(item.getId()); } } @@ -1564,7 +812,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (!messages.isEmpty()) { for (MessageComposer message : messages) { - room.sendComposer(message.compose()); + this.sendComposer(message.compose()); } messages.clear(); } @@ -1574,7 +822,7 @@ public class Room implements Comparable, ISerialize, Runnable { int currentTime = (int) (this.cycleTimestamp / 1000); - for (HabboItem pyramid : this.roomSpecialTypes.getItemsOfType(InteractionPyramid.class)) { + for (RoomItem pyramid : this.roomSpecialTypes.getItemsOfType(InteractionPyramid.class)) { if (pyramid instanceof InteractionPyramid interactionPyramid && interactionPyramid.getNextChange() < currentTime) { interactionPyramid.change(this); } @@ -1587,11 +835,11 @@ public class Room implements Comparable, ISerialize, Runnable { this.sendComposer(new UserUpdateComposer(updatedUnit).compose()); } - this.traxManager.cycle(); + this.roomTraxManager.cycle(); } else { - if (this.idleCycles < 60) - this.idleCycles++; + if (this.roomIdleCycles < 60) + this.roomIdleCycles++; else this.dispose(); } @@ -1600,8 +848,10 @@ public class Room implements Comparable, ISerialize, Runnable { synchronized (this.habboQueue) { if (!this.habboQueue.isEmpty() && !foundRightHolder[0]) { this.habboQueue.forEachEntry((a, b) -> { - if (b.isOnline() && b.getHabboInfo().getRoomQueueId() == Room.this.getId()) { - b.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); + if (b.isOnline()) { + if (b.getHabboInfo().getRoomQueueId() == this.roomInfo.getId()) { + b.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); + } } return true; }); @@ -1619,159 +869,184 @@ public class Room implements Comparable, ISerialize, Runnable { } } - - private boolean cycleRoomUnit(RoomUnit unit) { - boolean update = unit.needsStatusUpdate(); - if (unit.hasStatus(RoomUnitStatus.SIGN)) { - this.sendComposer(new UserUpdateComposer(unit).compose()); - unit.removeStatus(RoomUnitStatus.SIGN); + @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); + } + } } - if (unit.isWalking() && unit.getPath() != null && !unit.getPath().isEmpty()) { - if (!unit.cycle(this)) { - return true; + 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 { - if (unit.hasStatus(RoomUnitStatus.MOVE) && !unit.isAnimateWalk()) { - unit.removeStatus(RoomUnitStatus.MOVE); + message.appendInt(this.roomInfo.getOwnerInfo().getId()); + message.appendString(this.roomInfo.getOwnerInfo().getUsername()); + } - update = true; - } + 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()); - if (!unit.isWalking() && !unit.isCmdSit()) { - RoomTile thisTile = this.getLayout().getTile(unit.getX(), unit.getY()); - HabboItem topItem = this.getTallestChair(thisTile); + 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); + } - if (topItem == null || !topItem.getBaseItem().allowSit()) { - if (unit.hasStatus(RoomUnitStatus.SIT)) { - unit.removeStatus(RoomUnitStatus.SIT); - update = true; + 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(); } - } else if (thisTile.getState() == RoomTileState.SIT && (!unit.hasStatus(RoomUnitStatus.SIT) || unit.isSitUpdate())) { - this.dance(unit, DanceType.NONE); - unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem)) + ""); - unit.setZ(topItem.getZ()); - unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); - unit.setSitUpdate(false); - return true; - } - } - } - if (!unit.isWalking() && !unit.isCmdLay()) { - HabboItem topItem = this.getTopItemAt(unit.getX(), unit.getY()); + this.roomCycleTask.cancel(false); + this.scheduledTasks.clear(); + this.scheduledComposers.clear(); + this.loaded = false; - if (topItem == null || !topItem.getBaseItem().allowLay()) { - if (unit.hasStatus(RoomUnitStatus.LAY)) { - unit.removeStatus(RoomUnitStatus.LAY); - update = true; - } - } else { - if (!unit.hasStatus(RoomUnitStatus.LAY)) { - unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) + ""); - unit.setRotation(RoomUserRotation.values()[topItem.getRotation() % 4]); + this.tileCache.clear(); - if (topItem.getRotation() == 0 || topItem.getRotation() == 4) { - unit.setLocation(this.layout.getTile(unit.getX(), topItem.getY())); - } else { - unit.setLocation(this.layout.getTile(topItem.getX(), unit.getY())); + synchronized (this.mutedHabbos) { + this.mutedHabbos.clear(); } - update = true; + + 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 (update) { - unit.statusUpdate(false); - } - - return update; - } - - public void setName(String name) { - this.name = name; - - if (this.name.length() > 50) { - this.name = this.name.substring(0, 50); - } - - if (this.hasGuild()) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guildId); - - if (guild != null) { - guild.setRoomName(name); + 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)); } - public void setDescription(String description) { - this.description = description; - - if (this.description.length() > 250) { - this.description = this.description.substring(0, 250); - } - } - - public boolean hasCustomLayout() { - return this.overrideModel; - } - - public void setHasCustomLayout(boolean overrideModel) { - this.overrideModel = overrideModel; - } - - public void setPassword(String password) { - this.password = password; - - if (this.password.length() > 20) { - this.password = this.password.substring(0, 20); - } - } - - public boolean moveDiagonally() { - return this.moveDiagonally; - } - - public void moveDiagonally(boolean moveDiagonally) { - this.moveDiagonally = moveDiagonally; - this.layout.moveDiagonally(this.moveDiagonally); + public void setDiagonalMoveEnabled(boolean moveDiagonally) { + this.roomInfo.setDiagonalMoveEnabled(moveDiagonally); + this.layout.moveDiagonally(moveDiagonally); this.needsUpdate = true; } - public boolean hasGuild() { - return this.guildId != 0; - } - - public String getGuildName() { - if (this.hasGuild()) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guildId); - - if (guild != null) { - return guild.getName(); - } - } - - return ""; - } - - public void setAllowPets(boolean allowPets) { - this.allowPets = allowPets; - if (!allowPets) { - removeAllPets(ownerId); - } - } - public Color getBackgroundTonerColor() { Color color = new Color(0, 0, 0); - TIntObjectIterator iterator = this.roomItems.iterator(); + Iterator iterator = this.roomItemManager.getCurrentItems().values().iterator(); - for (int i = this.roomItems.size(); i > 0; i--) { + for (int i = this.roomItemManager.getCurrentItems().size(); i > 0; i--) { try { - iterator.advance(); - HabboItem object = iterator.value(); + RoomItem object = iterator.next(); if (object instanceof InteractionBackgroundToner) { - String[] extraData = object.getExtradata().split(":"); + String[] extraData = object.getExtraData().split(":"); if (extraData.length == 4 && extraData[0].equalsIgnoreCase("1")) { return Color.getHSBColor(Integer.parseInt(extraData[1]), Integer.parseInt(extraData[2]), Integer.parseInt(extraData[3])); @@ -1785,67 +1060,20 @@ public class Room implements Comparable, ISerialize, Runnable { return color; } - public void removeAllPets() { - removeAllPets(-1); - } - - /** - * Removes all pets from the room except if the owner id is excludeUserId - * - * @param excludeUserId Habbo id to keep pets - */ - public void removeAllPets(int excludeUserId) { - ArrayList toRemovePets = new ArrayList<>(); - ArrayList removedPets = new ArrayList<>(); - synchronized (this.currentPets) { - for (Pet pet : this.currentPets.valueCollection()) { - try { - if (pet.getUserId() != excludeUserId) { - toRemovePets.add(pet); - } - - } catch (NoSuchElementException e) { - log.error(CAUGHT_EXCEPTION, e); - break; - } - } - } - - for (Pet pet : toRemovePets) { - removedPets.add(pet); - - pet.removeFromRoom(); - - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); - if (habbo != null) { - habbo.getInventory().getPetsComponent().addPet(pet); - habbo.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); - } - - pet.setNeedsUpdate(true); - pet.run(); - } - - for (Pet pet : removedPets) { - this.currentPets.remove(pet.getId()); - } - } - public void setRollerSpeed(int rollerSpeed) { - this.rollerSpeed = rollerSpeed; + this.roomInfo.setRollerSpeed(rollerSpeed); this.rollerCycle = 0; this.needsUpdate = true; } public String[] filterAnything() { - return new String[]{this.getOwnerName(), this.getGuildName(), this.getDescription(), this.getPromotionDesc()}; + return new String[]{this.roomInfo.getOwnerInfo().getUsername(), this.roomInfo.getGuildName(), this.roomInfo.getDescription(), this.getPromotionDesc()}; } public boolean isPromoted() { - this.promoted = this.promotion != null && this.promotion.getEndTimestamp() > Emulator.getIntUnixTimestamp(); + this.roomInfo.setPromoted(this.promotion != null && this.promotion.getEndTimestamp() > Emulator.getIntUnixTimestamp()); this.needsUpdate = true; - - return this.promoted; + return this.roomInfo.isPromoted(); } public String getPromotionDesc() { @@ -1857,7 +1085,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public void createPromotion(String title, String description, int category) { - this.promoted = true; + this.roomInfo.setPromoted(true); if (this.promotion == null) { this.promotion = new RoomPromotion(this, title, description, Emulator.getIntUnixTimestamp() + (120 * 60), Emulator.getIntUnixTimestamp(), category); @@ -1869,7 +1097,7 @@ public class Room implements Comparable, ISerialize, Runnable { } try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_promotions (room_id, title, description, end_timestamp, start_timestamp, category) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE title = ?, description = ?, end_timestamp = ?, category = ?")) { - statement.setInt(1, this.id); + statement.setInt(1, this.roomInfo.getId()); statement.setString(2, title); statement.setString(3, description); statement.setInt(4, this.promotion.getEndTimestamp()); @@ -1929,14 +1157,6 @@ public class Room implements Comparable, ISerialize, Runnable { return game; } - public int getUserCount() { - return this.currentHabbos.size(); - } - - public Collection getHabbos() { - return this.currentHabbos.values(); - } - public String getFurniOwnerName(int userId) { return this.furniOwnerNames.get(userId); } @@ -1961,290 +1181,8 @@ public class Room implements Comparable, ISerialize, Runnable { return true; } - public void addHabboItem(HabboItem item) { - if (item == null) - return; - - synchronized (this.roomItems) { - try { - this.roomItems.put(item.getId(), item); - } catch (Exception ignored) { - - } - } - - synchronized (this.furniOwnerCount) { - this.furniOwnerCount.put(item.getUserId(), this.furniOwnerCount.get(item.getUserId()) + 1); - } - - synchronized (this.furniOwnerNames) { - if (!this.furniOwnerNames.containsKey(item.getUserId())) { - HabboInfo habbo = HabboManager.getOfflineHabboInfo(item.getUserId()); - - if (habbo != null) { - this.furniOwnerNames.put(item.getUserId(), habbo.getUsername()); - } else { - log.error("Failed to find username for item (ID: {}, UserID: {})", item.getId(), item.getUserId()); - } - } - } - - //TODO: Move this list - synchronized (this.roomSpecialTypes) { - if (item instanceof ICycleable) { - this.roomSpecialTypes.addCycleTask((ICycleable) item); - } - - if (item instanceof InteractionWiredTrigger interactionWiredTrigger) { - this.roomSpecialTypes.addTrigger(interactionWiredTrigger); - } else if (item instanceof InteractionWiredEffect interactionWiredEffect) { - this.roomSpecialTypes.addEffect(interactionWiredEffect); - } else if (item instanceof InteractionWiredCondition interactionWiredCondition) { - this.roomSpecialTypes.addCondition(interactionWiredCondition); - } else if (item instanceof InteractionWiredExtra interactionWiredExtra) { - this.roomSpecialTypes.addExtra(interactionWiredExtra); - } else if (item instanceof InteractionBattleBanzaiTeleporter interactionBattleBanzaiTeleporter) { - this.roomSpecialTypes.addBanzaiTeleporter(interactionBattleBanzaiTeleporter); - } else if (item instanceof InteractionRoller interactionRoller) { - this.roomSpecialTypes.addRoller(interactionRoller); - } else if (item instanceof InteractionGameScoreboard interactionGameScoreboard) { - this.roomSpecialTypes.addGameScoreboard(interactionGameScoreboard); - } else if (item instanceof InteractionGameGate interactionGameGate) { - this.roomSpecialTypes.addGameGate(interactionGameGate); - } else if (item instanceof InteractionGameTimer interactionGameTimer) { - this.roomSpecialTypes.addGameTimer(interactionGameTimer); - } else if (item instanceof InteractionFreezeExitTile interactionFreezeExitTile) { - this.roomSpecialTypes.addFreezeExitTile(interactionFreezeExitTile); - } else if (item instanceof InteractionNest interactionNest) { - this.roomSpecialTypes.addNest(interactionNest); - } else if (item instanceof InteractionPetDrink interactionPetDrink) { - this.roomSpecialTypes.addPetDrink(interactionPetDrink); - } else if (item instanceof InteractionPetFood interactionPetFood) { - this.roomSpecialTypes.addPetFood(interactionPetFood); - } else if (item instanceof InteractionPetToy interactionPetToy) { - this.roomSpecialTypes.addPetToy(interactionPetToy); - } else if (item instanceof InteractionPetTree) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionPetTrampoline) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionMoodLight) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionPyramid) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionMusicDisc) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionBattleBanzaiSphere) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionTalkingFurniture) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionWater) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionWaterItem) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionMuteArea) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionBuildArea) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionTagPole) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionTagField) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionJukeBox) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionPetBreedingNest) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionBlackHole) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionWiredHighscore) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionStickyPole) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof WiredBlob) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionTent) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionSnowboardSlope) { - this.roomSpecialTypes.addUndefined(item); - } else if (item instanceof InteractionFireworks) { - this.roomSpecialTypes.addUndefined(item); - } - - } - } - - public HabboItem getHabboItem(int id) { - if (this.roomItems == null || this.roomSpecialTypes == null) - return null; // room not loaded completely - - HabboItem item; - synchronized (this.roomItems) { - item = this.roomItems.get(id); - } - - if (item == null) - item = this.roomSpecialTypes.getBanzaiTeleporter(id); - - if (item == null) - item = this.roomSpecialTypes.getTrigger(id); - - if (item == null) - item = this.roomSpecialTypes.getEffect(id); - - if (item == null) - item = this.roomSpecialTypes.getCondition(id); - - if (item == null) - item = this.roomSpecialTypes.getGameGate(id); - - if (item == null) - item = this.roomSpecialTypes.getGameScorebord(id); - - if (item == null) - item = this.roomSpecialTypes.getGameTimer(id); - - if (item == null) - item = this.roomSpecialTypes.getFreezeExitTiles().get(id); - - if (item == null) - item = this.roomSpecialTypes.getRoller(id); - - if (item == null) - item = this.roomSpecialTypes.getNest(id); - - if (item == null) - item = this.roomSpecialTypes.getPetDrink(id); - - if (item == null) - item = this.roomSpecialTypes.getPetFood(id); - - return item; - } - - void removeHabboItem(int id) { - this.removeHabboItem(this.getHabboItem(id)); - } - - - public void removeHabboItem(HabboItem item) { - if (item != null) { - - HabboItem i; - synchronized (this.roomItems) { - i = this.roomItems.remove(item.getId()); - } - - if (i != null) { - synchronized (this.furniOwnerCount) { - synchronized (this.furniOwnerNames) { - int count = this.furniOwnerCount.get(i.getUserId()); - - if (count > 1) - this.furniOwnerCount.put(i.getUserId(), count - 1); - else { - this.furniOwnerCount.remove(i.getUserId()); - this.furniOwnerNames.remove(i.getUserId()); - } - } - } - - if (item instanceof ICycleable) { - this.roomSpecialTypes.removeCycleTask((ICycleable) item); - } - - if (item instanceof InteractionBattleBanzaiTeleporter) { - this.roomSpecialTypes.removeBanzaiTeleporter((InteractionBattleBanzaiTeleporter) item); - } else if (item instanceof InteractionWiredTrigger) { - this.roomSpecialTypes.removeTrigger((InteractionWiredTrigger) item); - } else if (item instanceof InteractionWiredEffect) { - this.roomSpecialTypes.removeEffect((InteractionWiredEffect) item); - } else if (item instanceof InteractionWiredCondition) { - this.roomSpecialTypes.removeCondition((InteractionWiredCondition) item); - } else if (item instanceof InteractionWiredExtra) { - this.roomSpecialTypes.removeExtra((InteractionWiredExtra) item); - } else if (item instanceof InteractionRoller) { - this.roomSpecialTypes.removeRoller((InteractionRoller) item); - } else if (item instanceof InteractionGameScoreboard) { - this.roomSpecialTypes.removeScoreboard((InteractionGameScoreboard) item); - } else if (item instanceof InteractionGameGate) { - this.roomSpecialTypes.removeGameGate((InteractionGameGate) item); - } else if (item instanceof InteractionGameTimer) { - this.roomSpecialTypes.removeGameTimer((InteractionGameTimer) item); - } else if (item instanceof InteractionFreezeExitTile) { - this.roomSpecialTypes.removeFreezeExitTile((InteractionFreezeExitTile) item); - } else if (item instanceof InteractionNest) { - this.roomSpecialTypes.removeNest((InteractionNest) item); - } else if (item instanceof InteractionPetDrink) { - this.roomSpecialTypes.removePetDrink((InteractionPetDrink) item); - } else if (item instanceof InteractionPetFood) { - this.roomSpecialTypes.removePetFood((InteractionPetFood) item); - } else if (item instanceof InteractionPetToy) { - this.roomSpecialTypes.removePetToy((InteractionPetToy) item); - } else if (item instanceof InteractionPetTree) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionPetTrampoline) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionMoodLight) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionPyramid) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionMusicDisc) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionBattleBanzaiSphere) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionTalkingFurniture) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionWaterItem) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionWater) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionMuteArea) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionTagPole) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionTagField) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionJukeBox) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionPetBreedingNest) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionBlackHole) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionWiredHighscore) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionStickyPole) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof WiredBlob) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionTent) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionSnowboardSlope) { - this.roomSpecialTypes.removeUndefined(item); - } else if (item instanceof InteractionBuildArea) { - this.roomSpecialTypes.removeUndefined(item); - } - } - } - } - - public List getFloorItems() { - return roomItems.valueCollection().stream().filter(i -> i.getBaseItem().getType() == FurnitureType.FLOOR).toList(); - } - - public List getWallItems() { - return roomItems.valueCollection().stream().filter(i -> i.getBaseItem().getType() == FurnitureType.WALL).toList(); - } - - public List getPostItNotes() { - return roomItems.valueCollection().stream().filter(i -> i.getBaseItem().getInteractionType().getType() == InteractionPostIt.class).toList(); - } - - public void addHabbo(Habbo habbo) { - synchronized (this.roomUnitLock) { - habbo.getRoomUnit().setId(this.unitCounter); - this.currentHabbos.put(habbo.getHabboInfo().getId(), habbo); - this.unitCounter++; - this.updateDatabaseUserCount(); - } + public List getPostItNotes() { + return this.roomItemManager.getCurrentItems().values().stream().filter(i -> i.getBaseItem().getInteractionType().getType() == InteractionPostIt.class).toList(); } public void kickHabbo(Habbo habbo, boolean alert) { @@ -2253,271 +1191,52 @@ public class Room implements Comparable, ISerialize, Runnable { } habbo.getRoomUnit().setKicked(true); - habbo.getRoomUnit().setGoalLocation(this.layout.getDoorTile()); + habbo.getRoomUnit().walkTo(this.layout.getDoorTile()); - if (habbo.getRoomUnit().getPath() == null || habbo.getRoomUnit().getPath().size() <= 1 || this.isPublicRoom()) { + if (habbo.getRoomUnit().getPath() == null || habbo.getRoomUnit().getPath().size() <= 1 || this.roomInfo.isPublicRoom()) { habbo.getRoomUnit().setCanWalk(true); Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this); } } - public void removeHabbo(Habbo habbo) { - removeHabbo(habbo, false); - } - - public void removeHabbo(Habbo habbo, boolean sendRemovePacket) { - if (habbo.getRoomUnit() != null && habbo.getRoomUnit().getCurrentLocation() != null) { - habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit()); - } - - synchronized (this.roomUnitLock) { - this.currentHabbos.remove(habbo.getHabboInfo().getId()); - } - - if (sendRemovePacket && habbo.getRoomUnit() != null && !habbo.getRoomUnit().isTeleporting()) { - this.sendComposer(new UserRemoveMessageComposer(habbo.getRoomUnit()).compose()); - } - - if (habbo.getRoomUnit().getCurrentLocation() != null) { - HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); - - if (item != null) { - try { - item.onWalkOff(habbo.getRoomUnit(), this, new Object[]{}); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - } - - if (habbo.getHabboInfo().getCurrentGame() != null && this.getGame(habbo.getHabboInfo().getCurrentGame()) != null) { - this.getGame(habbo.getHabboInfo().getCurrentGame()).removeHabbo(habbo); - } - - RoomTrade trade = this.getActiveTradeForHabbo(habbo); - - if (trade != null) { - trade.stopTrade(habbo); - } - - if (habbo.getHabboInfo().getId() != this.ownerId) { - this.pickupPetsForHabbo(habbo); - } - - this.updateDatabaseUserCount(); - } - - public void addBot(Bot bot) { - synchronized (this.roomUnitLock) { - bot.getRoomUnit().setId(this.unitCounter); - this.currentBots.put(bot.getId(), bot); - this.unitCounter++; - } - } - - public void addPet(Pet pet) { - synchronized (this.roomUnitLock) { - pet.getRoomUnit().setId(this.unitCounter); - this.currentPets.put(pet.getId(), pet); - this.unitCounter++; - - Habbo habbo = this.getHabbo(pet.getUserId()); - if (habbo != null) { - this.furniOwnerNames.put(pet.getUserId(), this.getHabbo(pet.getUserId()).getHabboInfo().getUsername()); - } - } - } - - public Bot getBot(int botId) { - return this.currentBots.get(botId); - } - - public Bot getBot(RoomUnit roomUnit) { - return getBot(roomUnit.getId()); - } - - public Bot getBotByRoomUnitId(int id) { - synchronized (this.currentBots) { - return currentBots.valueCollection().stream().filter(b -> b.getRoomUnit().getId() == id).findFirst().orElse(null); - } - } - - public List getBots(String name) { - synchronized (this.currentBots) { - return currentBots.valueCollection().stream().filter(b -> b.getName().equalsIgnoreCase(name)).toList(); - - } - } - - public boolean hasBotsAt(final int x, final int y) { - final boolean[] result = {false}; - - synchronized (this.currentBots) { - this.currentBots.forEachValue(object -> { - if (object.getRoomUnit().getX() == x && object.getRoomUnit().getY() == y) { - result[0] = true; - return false; - } - - return true; - }); - } - - return result[0]; - } - - public Pet getPet(int petId) { - return this.currentPets.get(petId); - } - - public Pet getPet(RoomUnit roomUnit) { - return currentPets.valueCollection().stream().filter(p -> p.getRoomUnit() == roomUnit).findFirst().orElse(null); - } - - public boolean removeBot(Bot bot) { - synchronized (this.currentBots) { - if (this.currentBots.containsKey(bot.getId())) { - if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentLocation() != null) { - bot.getRoomUnit().getCurrentLocation().removeUnit(bot.getRoomUnit()); - } - - this.currentBots.remove(bot.getId()); - bot.getRoomUnit().setInRoom(false); - bot.setRoom(null); - this.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose()); - bot.setRoomUnit(null); - return true; - } - } - - return false; - } - - public void placePet(Pet pet, short x, short y, double z) { - synchronized (this.currentPets) { - RoomTile tile = this.layout.getTile(x, y); - - if (tile == null) { - tile = this.layout.getDoorTile(); - } - - pet.setRoomUnit(new RoomUnit()); - pet.setRoom(this); - pet.getRoomUnit() - .setGoalLocation(tile) - .setLocation(tile) - .setRoomUnitType(RoomUnitType.PET) - .setCanWalk(true) - .setPathFinderRoom(this) - .setPreviousLocationZ(z) - .setZ(z); - - if (pet.getRoomUnit().getCurrentLocation() == null) { - pet.getRoomUnit() - .setLocation(this.getLayout().getDoorTile()) - .setRotation(RoomUserRotation.fromValue(this.getLayout().getDoorDirection())); - } - - pet.setNeedsUpdate(true); - this.furniOwnerNames.put(pet.getUserId(), this.getHabbo(pet.getUserId()).getHabboInfo().getUsername()); - this.addPet(pet); - this.sendComposer(new RoomPetComposer(pet).compose()); - } - } - - public Pet removePet(int petId) { - return this.currentPets.remove(petId); - } - - public boolean hasHabbosAt(int x, int y) { - return getHabbos().stream().anyMatch(h -> h.getRoomUnit().getX() == x && h.getRoomUnit().getY() == y); - } - - public boolean hasPetsAt(int x, int y) { - synchronized (this.currentPets) { - return currentPets.valueCollection().stream().anyMatch(p -> p.getRoomUnit().getX() == x && p.getRoomUnit().getY() == y); - } - } - - public List getPetsAt(RoomTile tile) { - synchronized (this.currentPets) { - return currentPets.valueCollection().stream().filter(p -> p.getRoomUnit().getCurrentLocation().equals(tile)).toList(); - } - } - - public List getBotsAt(RoomTile tile) { - synchronized (this.currentBots) { - return currentBots.valueCollection().stream().filter(b -> b.getRoomUnit().getCurrentLocation().equals(tile)).toList(); - } - } - - public List getHabbosAt(short x, short y) { - return this.getHabbosAt(this.layout.getTile(x, y)); - } - - public List getHabbosAt(RoomTile tile) { - return getHabbos().stream().filter(h -> h.getRoomUnit().getCurrentLocation().equals(tile)).toList(); - } - - public THashSet getHabbosAndBotsAt(short x, short y) { - return this.getHabbosAndBotsAt(this.layout.getTile(x, y)); - } - - public THashSet getHabbosAndBotsAt(RoomTile tile) { - THashSet list = new THashSet<>(); - list.addAll(getBotsAt(tile).stream().map(Bot::getRoomUnit).toList()); - list.addAll(getHabbosAt(tile).stream().map(Habbo::getRoomUnit).toList()); - - return list; - } - - public THashSet getHabbosOnItem(HabboItem item) { + public THashSet getHabbosOnItem(RoomItem item) { THashSet habbos = new THashSet<>(); - for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) { - for (short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++) { - habbos.addAll(this.getHabbosAt(x, y)); + 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); + habbos.addAll(this.roomUnitManager.getHabbosAt(tile)); } } return habbos; } - public THashSet getBotsOnItem(HabboItem item) { + public THashSet getBotsOnItem(RoomItem item) { THashSet bots = new THashSet<>(); - for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) { - for (short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++) { - bots.addAll(this.getBotsAt(this.getLayout().getTile(x, y))); + 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)); } } return bots; } - public THashSet getPetsOnItem(HabboItem item) { + public THashSet getPetsOnItem(RoomItem item) { THashSet pets = new THashSet<>(); - for (short x = item.getX(); x < item.getX() + item.getBaseItem().getLength(); x++) { - for (short y = item.getY(); y < item.getY() + item.getBaseItem().getWidth(); y++) { - pets.addAll(this.getPetsAt(this.getLayout().getTile(x, y))); + 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); + pets.addAll(this.roomUnitManager.getPetsAt(tile)); } } return pets; } - public void teleportHabboToItem(Habbo habbo, HabboItem item) { - this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); - } - - public void teleportHabboToLocation(Habbo habbo, short x, short y) { - this.teleportRoomUnitToLocation(habbo.getRoomUnit(), x, y, 0.0); - } - - public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item) { - this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item)); - } - - public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y) { - this.teleportRoomUnitToLocation(roomUnit, x, y, 0.0); + public void teleportHabboToItem(Habbo habbo, RoomItem item) { + this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), item.getCurrentZ() + Item.getCurrentHeight(item)); } public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y, double z) { @@ -2529,9 +1248,8 @@ public class Room implements Comparable, ISerialize, Runnable { } roomUnit.setLocation(tile); - roomUnit.setGoalLocation(tile); - roomUnit.setZ(z); - roomUnit.setPreviousLocationZ(z); + roomUnit.walkTo(tile); + roomUnit.setCurrentZ(z); this.updateRoomUnit(roomUnit); @@ -2545,7 +1263,7 @@ public class Room implements Comparable, ISerialize, Runnable { } public boolean isMuted(Habbo habbo) { - if (this.isOwner(habbo) || this.hasRights(habbo)) + if (this.getRoomInfo().isRoomOwner(habbo) || this.roomRightsManager.hasRights(habbo)) return false; if (this.mutedHabbos.containsKey(habbo.getHabboInfo().getId())) { @@ -2562,19 +1280,17 @@ public class Room implements Comparable, ISerialize, Runnable { } public void habboEntered(Habbo habbo) { - habbo.getRoomUnit().setAnimateWalk(false); - - synchronized (this.currentBots) { - if (habbo.getHabboInfo().getId() != this.getOwnerId()) + synchronized (this.roomUnitManager.getCurrentBots()) { + if (habbo.getHabboInfo().getId() != this.roomInfo.getOwnerInfo().getId()) return; - TIntObjectIterator botIterator = this.currentBots.iterator(); + Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); - for (int i = this.currentBots.size(); i-- > 0; ) { + while (botIterator.hasNext()) { try { - botIterator.advance(); + Bot bot = botIterator.next(); - if (botIterator.value() instanceof VisitorBot visitorBot) { + if (bot instanceof VisitorBot visitorBot) { visitorBot.onUserEnter(habbo); break; } @@ -2584,7 +1300,7 @@ public class Room implements Comparable, ISerialize, Runnable { } } - HabboItem doorTileTopItem = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); + RoomItem doorTileTopItem = this.roomItemManager.getTopItemAt(habbo.getRoomUnit().getCurrentPosition().getX(), habbo.getRoomUnit().getCurrentPosition().getY()); if (doorTileTopItem != null && !(doorTileTopItem instanceof InteractionTeleportTile)) { try { doorTileTopItem.onWalkOn(habbo.getRoomUnit(), this, new Object[]{}); @@ -2617,7 +1333,7 @@ public class Room implements Comparable, ISerialize, Runnable { return; } - if (habbo.getHabboInfo().getCurrentRoom() != this) + if (habbo.getRoomUnit().getRoom() != this) return; long millis = System.currentTimeMillis(); @@ -2636,7 +1352,7 @@ public class Room implements Comparable, ISerialize, Runnable { Emulator.getPluginManager().fireEvent(event); if (!event.isCancelled() && !event.isIdle()) { - this.unIdle(habbo); + habbo.getRoomUnit().unIdle(); } this.sendComposer(new UserTypingMessageComposer(habbo.getRoomUnit(), false).compose()); @@ -2644,22 +1360,22 @@ public class Room implements Comparable, ISerialize, Runnable { if (roomChatMessage == null || roomChatMessage.getMessage() == null || roomChatMessage.getMessage().equals("")) return; - if (!habbo.hasRight(Permission.ACC_NOMUTE) && (!MUTEAREA_CAN_WHISPER || chatType != RoomChatType.WHISPER)) { - for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class)) { - if (((InteractionMuteArea) area).inSquare(habbo.getRoomUnit().getCurrentLocation())) { + if (!habbo.hasPermissionRight(Permission.ACC_NOMUTE) && (!MUTEAREA_CAN_WHISPER || chatType != RoomChatType.WHISPER)) { + for (RoomItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionMuteArea.class)) { + if (((InteractionMuteArea) area).inSquare(habbo.getRoomUnit().getCurrentPosition())) { return; } } } - if (!this.wordFilterWords.isEmpty() && !habbo.hasRight(Permission.ACC_CHAT_NO_FILTER)) { - for (String string : this.wordFilterWords) { + if (!this.roomWordFilterManager.getFilteredWords().isEmpty() && !habbo.hasPermissionRight(Permission.ACC_CHAT_NO_FILTER)) { + for (String string : this.roomWordFilterManager.getFilteredWords()) { roomChatMessage.setMessage(roomChatMessage.getMessage().replaceAll("(?i)" + Pattern.quote(string), "bobba")); } } - if (!habbo.hasRight(Permission.ACC_NOMUTE)) { - if (this.isMuted() && !this.hasRights(habbo)) { + if (!habbo.hasPermissionRight(Permission.ACC_NOMUTE)) { + if (this.isMuted() && !this.roomRightsManager.hasRights(habbo)) { return; } @@ -2671,28 +1387,28 @@ public class Room implements Comparable, ISerialize, Runnable { if (chatType != RoomChatType.WHISPER) { if (Emulator.getGameEnvironment().getCommandsManager().handleCommand(habbo.getClient(), roomChatMessage.getUnfilteredMessage())) { - WiredHandler.handle(WiredTriggerType.SAY_COMMAND, habbo.getRoomUnit(), habbo.getHabboInfo().getCurrentRoom(), new Object[]{roomChatMessage.getMessage()}); + WiredHandler.handle(WiredTriggerType.SAY_COMMAND, habbo.getRoomUnit(), habbo.getRoomUnit().getRoom(), new Object[]{roomChatMessage.getMessage()}); roomChatMessage.isCommand = true; return; } if (!ignoreWired) { - if (WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, habbo.getRoomUnit(), habbo.getHabboInfo().getCurrentRoom(), new Object[]{roomChatMessage.getMessage()})) { + if (WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, habbo.getRoomUnit(), habbo.getRoomUnit().getRoom(), new Object[]{roomChatMessage.getMessage()})) { habbo.getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(roomChatMessage.getMessage(), habbo, habbo, roomChatMessage.getBubble()))); return; } } } - if (!habbo.hasRight(Permission.ACC_CHAT_NO_FLOOD)) { + if (!habbo.hasPermissionRight(Permission.ACC_CHAT_NO_FLOOD)) { final int chatCounter = habbo.getHabboStats().getChatCounter().addAndGet(1); if (chatCounter > 3) { final boolean floodRights = Emulator.getConfig().getBoolean("flood.with.rights"); - final boolean hasRights = this.hasRights(habbo); + final boolean hasRights = this.roomRightsManager.hasRights(habbo); if (floodRights || !hasRights) { - if (this.chatProtection == 0 || (this.chatProtection == 1 && chatCounter > 4) || (this.chatProtection == 2 && chatCounter > 5)) { + if (this.roomInfo.getChatProtection() == 0 || (this.roomInfo.getChatProtection() == 1 && chatCounter > 4) || (this.roomInfo.getChatProtection() == 2 && chatCounter > 5)) { this.floodMuteHabbo(habbo, muteTime); return; } @@ -2714,7 +1430,7 @@ public class Room implements Comparable, ISerialize, Runnable { } ServerMessage clearPrefixMessage = prefixMessage != null ? new UserNameChangedMessageComposer(habbo).compose() : null; - Rectangle tentRectangle = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentLocation()); + Rectangle tentRectangle = this.roomSpecialTypes.tentAt(habbo.getRoomUnit().getCurrentPosition()); String trimmedMessage = roomChatMessage.getMessage().replaceAll("\\s+$", ""); @@ -2733,7 +1449,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.getHabbos()) { + for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) { if (h == roomChatMessage.getTargetHabbo() || h == habbo) { if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { if (prefixMessage != null) { @@ -2748,19 +1464,19 @@ public class Room implements Comparable, ISerialize, Runnable { continue; } - if (h.hasRight(Permission.ACC_SEE_WHISPERS)) { + if (h.hasPermissionRight(Permission.ACC_SEE_WHISPERS)) { h.getClient().sendResponse(staffMessage); } } } else if (chatType == RoomChatType.TALK) { ServerMessage message = new ChatMessageComposer(roomChatMessage).compose(); - boolean noChatLimit = habbo.hasRight(Permission.ACC_CHAT_NO_LIMIT); + boolean noChatLimit = habbo.hasPermissionRight(Permission.ACC_CHAT_NO_LIMIT); - for (Habbo h : this.getHabbos()) { - if ((h.getRoomUnit().getCurrentLocation().distance(habbo.getRoomUnit().getCurrentLocation()) <= this.chatDistance || + for (Habbo h : this.roomUnitManager.getCurrentHabbos().values()) { + if ((h.getRoomUnit().getCurrentPosition().distance(habbo.getRoomUnit().getCurrentPosition()) <= this.roomInfo.getChatDistance() || h.equals(habbo) || - this.hasRights(h) || - noChatLimit) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentLocation()))) { + this.roomRightsManager.hasRights(h) || + noChatLimit) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentPosition()))) { if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { if (prefixMessage != null && !h.getHabboStats().isPreferOldChat()) { h.getClient().sendResponse(prefixMessage); @@ -2778,11 +1494,11 @@ public class Room implements Comparable, ISerialize, Runnable { } else if (chatType == RoomChatType.SHOUT) { ServerMessage message = new ShoutMessageComposer(roomChatMessage).compose(); - for (Habbo h : this.getHabbos()) { + 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 - if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentLocation()))) { + if (!h.getHabboStats().userIgnored(habbo.getHabboInfo().getId()) && (tentRectangle == null || RoomLayout.tileInSquare(tentRectangle, h.getRoomUnit().getCurrentPosition()))) { if (prefixMessage != null && !h.getHabboStats().isPreferOldChat()) { h.getClient().sendResponse(prefixMessage); } @@ -2798,13 +1514,12 @@ public class Room implements Comparable, ISerialize, Runnable { } if (chatType == RoomChatType.TALK || chatType == RoomChatType.SHOUT) { - synchronized (this.currentBots) { - TIntObjectIterator botIterator = this.currentBots.iterator(); + synchronized (this.roomUnitManager.getCurrentBots()) { + Iterator botIterator = this.roomUnitManager.getCurrentBots().values().iterator(); - for (int i = this.currentBots.size(); i-- > 0; ) { + while (botIterator.hasNext()) { try { - botIterator.advance(); - Bot bot = botIterator.value(); + Bot bot = botIterator.next(); bot.onUserSay(roomChatMessage); } catch (NoSuchElementException e) { @@ -2815,10 +1530,10 @@ public class Room implements Comparable, ISerialize, Runnable { } if (roomChatMessage.getBubble().triggersTalkingFurniture()) { - THashSet items = this.roomSpecialTypes.getItemsOfType(InteractionTalkingFurniture.class); + THashSet items = this.roomSpecialTypes.getItemsOfType(InteractionTalkingFurniture.class); - for (HabboItem item : items) { - if (this.layout.getTile(item.getX(), item.getY()).distance(habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("furniture.talking.range")) { + for (RoomItem item : items) { + if (this.layout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()).distance(habbo.getRoomUnit().getCurrentPosition()) <= Emulator.getConfig().getInt("furniture.talking.range")) { int count = Emulator.getConfig().getInt(item.getBaseItem().getName() + ".message.count", 0); if (count > 0) { @@ -2830,11 +1545,11 @@ public class Room implements Comparable, ISerialize, Runnable { try { item.onClick(habbo.getClient(), this, new Object[0]); - item.setExtradata("1"); + item.setExtraData("1"); updateItemState(item); Emulator.getThreading().run(() -> { - item.setExtradata("0"); + item.setExtraData("0"); updateItemState(item); }, 2000); @@ -2857,7 +1572,7 @@ public class Room implements Comparable, ISerialize, Runnable { * @param tentRectangle The whole tent area from where the sending Habbo is saying something */ private void showTentChatMessageOutsideTentIfPermitted(Habbo receivingHabbo, RoomChatMessage roomChatMessage, Rectangle tentRectangle) { - if (receivingHabbo != null && receivingHabbo.hasRight(Permission.ACC_SEE_TENTCHAT) && tentRectangle != null && !RoomLayout.tileInSquare(tentRectangle, receivingHabbo.getRoomUnit().getCurrentLocation())) { + if (receivingHabbo != null && receivingHabbo.hasPermissionRight(Permission.ACC_SEE_TENTCHAT) && tentRectangle != null && !RoomLayout.tileInSquare(tentRectangle, receivingHabbo.getRoomUnit().getCurrentPosition())) { RoomChatMessage staffChatMessage = new RoomChatMessage(roomChatMessage); staffChatMessage.setMessage("[" + Emulator.getTexts().getValue("hotel.room.tent.prefix") + "] " + staffChatMessage.getMessage()); final ServerMessage staffMessage = new WhisperMessageComposer(staffChatMessage).compose(); @@ -2868,14 +1583,13 @@ public class Room implements Comparable, ISerialize, Runnable { public THashSet getLockedTiles() { THashSet lockedTiles = new THashSet<>(); - TIntObjectIterator iterator = this.roomItems.iterator(); + Iterator iterator = this.roomItemManager.getCurrentItems().values().iterator(); - for (int i = this.roomItems.size(); i-- > 0; ) { - HabboItem item; + for (int i = this.roomItemManager.getCurrentItems().size(); i-- > 0; ) { + RoomItem item; try { - iterator.advance(); - item = iterator.value(); + item = iterator.next(); } catch (Exception e) { break; } @@ -2883,13 +1597,13 @@ public class Room implements Comparable, ISerialize, Runnable { if (item.getBaseItem().getType() != FurnitureType.FLOOR) continue; - boolean found = lockedTiles.stream().anyMatch(tile -> tile.getX() == item.getX() && tile.getY() == item.getY()); + boolean found = lockedTiles.stream().anyMatch(tile -> tile.getX() == item.getCurrentPosition().getX() && tile.getY() == item.getCurrentPosition().getY()); if (!found) { if (item.getRotation() == 0 || item.getRotation() == 4) { for (short y = 0; y < item.getBaseItem().getLength(); y++) { for (short x = 0; x < item.getBaseItem().getWidth(); x++) { - RoomTile tile = this.layout.getTile((short) (item.getX() + x), (short) (item.getY() + y)); + RoomTile tile = this.layout.getTile((short) (item.getCurrentPosition().getX() + x), (short) (item.getCurrentPosition().getY() + y)); if (tile != null) { lockedTiles.add(tile); @@ -2899,7 +1613,7 @@ public class Room implements Comparable, ISerialize, Runnable { } else { for (short y = 0; y < item.getBaseItem().getWidth(); y++) { for (short x = 0; x < item.getBaseItem().getLength(); x++) { - RoomTile tile = this.layout.getTile((short) (item.getX() + x), (short) (item.getY() + y)); + RoomTile tile = this.layout.getTile((short) (item.getCurrentPosition().getX() + x), (short) (item.getCurrentPosition().getY() + y)); if (tile != null) { lockedTiles.add(tile); @@ -2913,207 +1627,7 @@ public class Room implements Comparable, ISerialize, Runnable { return lockedTiles; } - @Deprecated - public THashSet getItemsAt(int x, int y) { - RoomTile tile = this.getLayout().getTile((short) x, (short) y); - - if (tile != null) { - return this.getItemsAt(tile); - } - - return new THashSet<>(0); - } - - public THashSet getItemsAt(RoomTile tile) { - return getItemsAt(tile, false); - } - - public THashSet getItemsAt(RoomTile tile, boolean returnOnFirst) { - THashSet items = new THashSet<>(0); - - if (tile == null) - return items; - - if (this.loaded) { - THashSet cachedItems = this.tileCache.get(tile); - if (cachedItems != null) - return cachedItems; - } - - TIntObjectIterator iterator = this.roomItems.iterator(); - - for (int i = this.roomItems.size(); i-- > 0; ) { - HabboItem item; - try { - iterator.advance(); - item = iterator.value(); - } catch (Exception e) { - break; - } - - if (item == null) - continue; - - if (item.getBaseItem().getType() != FurnitureType.FLOOR) - continue; - - int width, length; - - if (item.getRotation() != 2 && item.getRotation() != 6) { - width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1; - length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1; - } else { - width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1; - length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1; - } - - if (!(tile.getX() >= item.getX() && tile.getX() <= item.getX() + width - 1 && tile.getY() >= item.getY() && tile.getY() <= item.getY() + length - 1)) - continue; - - items.add(item); - - if (returnOnFirst) { - return items; - } - } - - if (this.loaded) { - this.tileCache.put(tile, items); - } - - return items; - } - - public THashSet getItemsAt(int x, int y, double minZ) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.getItemsAt(x, y)) { - if (item.getZ() < minZ) - continue; - - items.add(item); - } - return items; - } - - public THashSet getItemsAt(Class type, int x, int y) { - THashSet items = new THashSet<>(); - - for (HabboItem item : this.getItemsAt(x, y)) { - if (!item.getClass().equals(type)) - continue; - - items.add(item); - } - return items; - } - - public boolean hasItemsAt(int x, int y) { - RoomTile tile = this.getLayout().getTile((short) x, (short) y); - - if (tile == null) - return false; - - return !this.getItemsAt(tile, true).isEmpty(); - } - - public HabboItem getTopItemAt(int x, int y) { - return this.getTopItemAt(x, y, null); - } - - public HabboItem getTopItemAt(int x, int y, HabboItem exclude) { - RoomTile tile = this.getLayout().getTile((short) x, (short) y); - - if (tile == null) - return null; - - HabboItem highestItem = null; - - for (HabboItem item : this.getItemsAt(x, y)) { - if (exclude != null && exclude == item) - continue; - - if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item)) - continue; - - highestItem = item; - } - - return highestItem; - } - - public HabboItem getTopItemAt(THashSet tiles, HabboItem exclude) { - HabboItem highestItem = null; - for (RoomTile tile : tiles) { - - if (tile == null) - continue; - - for (HabboItem item : this.getItemsAt(tile.getX(), tile.getY())) { - if (exclude != null && exclude == item) - continue; - - if (highestItem != null && highestItem.getZ() + Item.getCurrentHeight(highestItem) > item.getZ() + Item.getCurrentHeight(item)) - continue; - - highestItem = item; - } - } - - return highestItem; - } - - public double getTopHeightAt(int x, int y) { - HabboItem item = this.getTopItemAt(x, y); - if (item != null) { - return (item.getZ() + Item.getCurrentHeight(item) - (item.getBaseItem().allowSit() ? 1 : 0)); - } else { - return this.layout.getHeightAtSquare(x, y); - } - } - - public HabboItem getLowestChair(RoomTile tile) { - HabboItem lowestChair = null; - - THashSet items = this.getItemsAt(tile); - if (items != null && !items.isEmpty()) { - for (HabboItem item : items) { - - if (!item.getBaseItem().allowSit()) - continue; - - if (lowestChair != null && lowestChair.getZ() < item.getZ()) - continue; - - lowestChair = item; - } - } - - return lowestChair; - } - - public HabboItem getTallestChair(RoomTile tile) { - HabboItem lowestChair = null; - - THashSet items = this.getItemsAt(tile); - if (items != null && !items.isEmpty()) { - for (HabboItem item : items) { - - if (!item.getBaseItem().allowSit()) - continue; - - if (lowestChair != null && lowestChair.getZ() + Item.getCurrentHeight(lowestChair) > item.getZ() + Item.getCurrentHeight(item)) - continue; - - lowestChair = item; - } - } - - return lowestChair; - } - - public double getStackHeight(short x, short y, boolean calculateHeightmap, HabboItem exclude) { - + public double getStackHeight(short x, short y, boolean calculateHeightmap, RoomItem exclude) { if (x < 0 || y < 0 || this.layout == null) return calculateHeightmap ? Short.MAX_VALUE : 0.0; @@ -3127,19 +1641,23 @@ public class Room implements Comparable, ISerialize, Runnable { double height = this.layout.getHeightAtSquare(x, y); boolean canStack = true; - THashSet stackHelpers = this.getItemsAt(InteractionStackHelper.class, x, y); + THashSet stackHelpers = this.roomItemManager.getItemsAt(InteractionStackHelper.class, x, y); - for (HabboItem item : stackHelpers) { + for (RoomItem item : stackHelpers) { if (item == exclude) continue; - return calculateHeightmap ? item.getZ() * 256.0D : item.getZ(); + if (calculateHeightmap) { + return item.getCurrentZ() * 256.0D; + } else { + return item.getCurrentZ(); + } } - HabboItem item = this.getTopItemAt(x, y, exclude); + RoomItem item = this.roomItemManager.getTopItemAt(x, y, exclude); if (item != null) { canStack = item.getBaseItem().allowStack(); - height = item.getZ() + (item.getBaseItem().allowSit() ? 0 : Item.getCurrentHeight(item)); + height = item.getCurrentZ() + (item.getBaseItem().allowSit() ? 0 : Item.getCurrentHeight(item)); } if (calculateHeightmap) { @@ -3153,75 +1671,43 @@ 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.getItemsAt(x, y); - - for (HabboItem item : items) { - if (item.getClass() == type) { - return true; - } + public boolean canSitOrLayAt(RoomTile tile) { + if(tile == null) { + return false; } - return false; - } - - public boolean canSitOrLayAt(int x, int y) { - if (this.hasHabbosAt(x, y)) + if (this.roomUnitManager.hasHabbosAt(tile)) return false; - THashSet items = this.getItemsAt(x, y); + THashSet items = this.roomItemManager.getItemsAt(tile); return this.canSitAt(items) || this.canLayAt(items); } public boolean canSitAt(int x, int y) { - if (this.hasHabbosAt(x, y)) - return false; + RoomTile tile = this.layout.getTile((short) x, (short) y); - return this.canSitAt(this.getItemsAt(x, y)); - } - - boolean canWalkAt(RoomTile roomTile) { - if (roomTile == null) { + if(tile == null) { return false; } - if (roomTile.getState() == RoomTileState.INVALID) + if (this.roomUnitManager.hasHabbosAt(tile)) return false; - HabboItem topItem = null; - boolean canWalk = true; - THashSet items = this.getItemsAt(roomTile); - if (items != null) { - for (HabboItem 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; + return this.canSitAt(this.roomItemManager.getItemsAt(tile)); } - boolean canSitAt(THashSet items) { + boolean canSitAt(THashSet items) { if (items == null) return false; - HabboItem tallestItem = null; + RoomItem tallestItem = null; - for (HabboItem item : items) { - if (tallestItem != null && tallestItem.getZ() + Item.getCurrentHeight(tallestItem) > item.getZ() + Item.getCurrentHeight(item)) - continue; + for (RoomItem item : items) { + if (tallestItem != null) { + if (tallestItem.getCurrentZ() + Item.getCurrentHeight(tallestItem) > item.getCurrentZ() + Item.getCurrentHeight(item)) + continue; + } tallestItem = item; } @@ -3232,18 +1718,18 @@ public class Room implements Comparable, ISerialize, Runnable { return tallestItem.getBaseItem().allowSit(); } - public boolean canLayAt(int x, int y) { - return this.canLayAt(this.getItemsAt(x, y)); + public boolean canLayAt(RoomTile tile) { + return this.canLayAt(this.roomItemManager.getItemsAt(tile)); } - boolean canLayAt(THashSet items) { + boolean canLayAt(THashSet items) { if (items == null || items.isEmpty()) return true; - HabboItem topItem = null; + RoomItem topItem = null; - for (HabboItem item : items) { - if ((topItem == null || item.getZ() > topItem.getZ())) { + for (RoomItem item : items) { + if ((topItem == null || item.getCurrentZ() > topItem.getCurrentZ())) { topItem = item; } } @@ -3262,53 +1748,20 @@ public class Room implements Comparable, ISerialize, Runnable { return null; } - public Habbo getHabbo(String username) { - for (Habbo habbo : this.getHabbos()) { - if (habbo.getHabboInfo().getUsername().equalsIgnoreCase(username)) - return habbo; - } - return null; - } - - public Habbo getHabbo(RoomUnit roomUnit) { - for (Habbo habbo : this.getHabbos()) { - if (habbo.getRoomUnit() == roomUnit) - return habbo; - } - return null; - } - - public Habbo getHabbo(int userId) { - return this.currentHabbos.get(userId); - } - - public Habbo getHabboByRoomUnitId(int roomUnitId) { - for (Habbo habbo : this.getHabbos()) { - if (habbo.getRoomUnit().getId() == roomUnitId) - return habbo; - } - - return null; + public void alert(String message) { + this.sendComposer(new HabboBroadcastMessageComposer(message).compose()); } public void sendComposer(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (habbo.getClient() == null) continue; habbo.getClient().sendResponse(message); } } - public void sendComposerToHabbosWithRights(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { - if (this.hasRights(habbo)) { - habbo.getClient().sendResponse(message); - } - } - } - public void petChat(ServerMessage message) { - for (Habbo habbo : this.getHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (!habbo.getHabboStats().isIgnorePets()) habbo.getClient().sendResponse(message); } @@ -3319,35 +1772,19 @@ public class Room implements Comparable, ISerialize, Runnable { return; } - for (Habbo habbo : this.getHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { if (habbo == null) { return ; } if (!habbo.getHabboStats().isIgnoreBots()) habbo.getClient().sendResponse(message); } } - private void loadRights(Connection connection) { - this.rights.clear(); - try (PreparedStatement statement = connection.prepareStatement("SELECT user_id FROM room_rights WHERE room_id = ?")) { - statement.setInt(1, this.id); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - this.rights.add(set.getInt(DatabaseConstants.USER_ID)); - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } catch (Exception e) { - log.error(CAUGHT_EXCEPTION, e); - } - } - private void loadBans(Connection connection) { this.bannedHabbos.clear(); try (PreparedStatement statement = connection.prepareStatement("SELECT users.username, users.id, room_bans.* FROM room_bans INNER JOIN users ON room_bans.user_id = users.id WHERE ends > ? AND room_bans.room_id = ?")) { statement.setInt(1, Emulator.getIntUnixTimestamp()); - statement.setInt(2, this.id); + statement.setInt(2, this.roomInfo.getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) { if (this.bannedHabbos.containsKey(set.getInt(DatabaseConstants.USER_ID))) @@ -3362,13 +1799,15 @@ public class Room implements Comparable, ISerialize, Runnable { } public RoomRightLevels getGuildRightLevel(Habbo habbo) { - if (this.guildId > 0 && habbo.getHabboStats().hasGuild(this.guildId)) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(this.guildId); + if(!this.roomInfo.hasGuild()) { + return RoomRightLevels.NONE; + } - if (Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(habbo.getHabboInfo().getId()) != null) + if (habbo.getHabboStats().hasGuild(this.roomInfo.getGuild().getId())) { + if (Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(this.roomInfo.getGuild()).get(habbo.getHabboInfo().getId()) != null) return RoomRightLevels.GUILD_ADMIN; - if (guild.isRights()) { + if (this.roomInfo.getGuild().isRights()) { return RoomRightLevels.GUILD_RIGHTS; } } @@ -3376,162 +1815,6 @@ public class Room implements Comparable, ISerialize, Runnable { return RoomRightLevels.NONE; } - /** - * @deprecated Deprecated since 2.5.0. Use {@link #getGuildRightLevel(Habbo)} instead. - */ - @Deprecated - public int guildRightLevel(Habbo habbo) { - return this.getGuildRightLevel(habbo).getLevel(); - } - - public boolean isOwner(Habbo habbo) { - return habbo.getHabboInfo().getId() == this.ownerId || habbo.hasRight(Permission.ACC_ANYROOMOWNER); - } - - public boolean hasRights(Habbo habbo) { - return this.isOwner(habbo) || this.rights.contains(habbo.getHabboInfo().getId()) || (habbo.getRoomUnit().getRightsLevel() != RoomRightLevels.NONE && this.currentHabbos.containsKey(habbo.getHabboInfo().getId())); - } - - public void giveRights(Habbo habbo) { - if (habbo != null) { - this.giveRights(habbo.getHabboInfo().getId()); - } - } - - public void giveRights(int userId) { - if (this.rights.contains(userId)) - return; - - if (this.rights.add(userId)) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_rights VALUES (?, ?)")) { - statement.setInt(1, this.id); - statement.setInt(2, userId); - statement.execute(); - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - } - - Habbo habbo = this.getHabbo(userId); - - if (habbo != null) { - this.refreshRightsForHabbo(habbo); - - this.sendComposer(new FlatControllerAddedComposer(this, habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername()).compose()); - } else { - Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.ownerId); - - if (owner != null) { - MessengerBuddy buddy = owner.getMessenger().getFriend(userId); - - if (buddy != null) { - this.sendComposer(new FlatControllerAddedComposer(this, userId, buddy.getUsername()).compose()); - } - } - } - } - - public void removeRights(int userId) { - Habbo habbo = this.getHabbo(userId); - - if (Emulator.getPluginManager().fireEvent(new UserRightsTakenEvent(this.getHabbo(this.getOwnerId()), userId, habbo)).isCancelled()) - return; - - this.sendComposer(new FlatControllerRemovedComposer(this, userId).compose()); - - if (this.rights.remove(userId)) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ? AND user_id = ?")) { - statement.setInt(1, this.id); - statement.setInt(2, userId); - statement.execute(); - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - } - - if (habbo != null) { - this.ejectUserFurni(habbo.getHabboInfo().getId()); - habbo.getRoomUnit().setRightsLevel(RoomRightLevels.NONE); - habbo.getRoomUnit().removeStatus(RoomUnitStatus.FLAT_CONTROL); - this.refreshRightsForHabbo(habbo); - } - } - - public void removeAllRights() { - for (int userId : rights.toArray()) { - this.ejectUserFurni(userId); - } - - this.rights.clear(); - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ?")) { - statement.setInt(1, this.id); - statement.execute(); - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - - this.refreshRightsInRoom(); - } - - void refreshRightsInRoom() { - Room room = this; - for (Habbo habbo : this.getHabbos()) { - if (habbo.getHabboInfo().getCurrentRoom() == room) { - this.refreshRightsForHabbo(habbo); - } - } - } - - public void refreshRightsForHabbo(Habbo habbo) { - HabboItem item; - RoomRightLevels flatCtrl = RoomRightLevels.NONE; - if (habbo.getHabboStats().isRentingSpace()) { - item = this.getHabboItem(habbo.getHabboStats().getRentedItemId()); - - if (item != null) { - return; - } - } - - if (habbo.hasRight(Permission.ACC_ANYROOMOWNER) || this.isOwner(habbo)) { - habbo.getClient().sendResponse(new YouAreOwnerMessageComposer()); - flatCtrl = RoomRightLevels.MODERATOR; - } else if (this.hasRights(habbo) && !this.hasGuild()) { - flatCtrl = RoomRightLevels.RIGHTS; - } else if (this.hasGuild()) { - flatCtrl = this.getGuildRightLevel(habbo); - } - - habbo.getClient().sendResponse(new YouAreControllerMessageComposer(flatCtrl)); - habbo.getRoomUnit().setStatus(RoomUnitStatus.FLAT_CONTROL, flatCtrl.getLevel() + ""); - habbo.getRoomUnit().setRightsLevel(flatCtrl); - habbo.getRoomUnit().statusUpdate(true); - - if (flatCtrl.equals(RoomRightLevels.MODERATOR)) { - habbo.getClient().sendResponse(new FlatControllersComposer(this)); - } - } - - public THashMap getUsersWithRights() { - THashMap rightsMap = new THashMap<>(); - - if (!this.rights.isEmpty()) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS username, users.id as user_id FROM room_rights INNER JOIN users ON room_rights.user_id = users.id WHERE room_id = ?")) { - statement.setInt(1, this.id); - try (ResultSet set = statement.executeQuery()) { - while (set.next()) { - rightsMap.put(set.getInt(DatabaseConstants.USER_ID), set.getString("username")); - } - } - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } - } - - return rightsMap; - } - public void unbanHabbo(int userId) { RoomBan ban = this.bannedHabbos.remove(userId); @@ -3545,7 +1828,7 @@ public class Room implements Comparable, ISerialize, Runnable { public boolean isBanned(Habbo habbo) { RoomBan ban = this.bannedHabbos.get(habbo.getHabboInfo().getId()); - boolean banned = ban != null && ban.getEndTimestamp() > Emulator.getIntUnixTimestamp() && !habbo.hasRight(Permission.ACC_ANYROOMOWNER) && !habbo.hasRight(Permission.ACC_ENTERANYROOM); + boolean banned = ban != null && ban.getEndTimestamp() > Emulator.getIntUnixTimestamp() && !habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) && !habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM); if (!banned && ban != null) { this.unbanHabbo(habbo.getHabboInfo().getId()); @@ -3562,84 +1845,15 @@ public class Room implements Comparable, ISerialize, Runnable { this.bannedHabbos.put(roomBan.getUserId(), roomBan); } - public void makeSit(Habbo habbo) { - if (habbo.getRoomUnit() == null) return; - - if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) || !habbo.getRoomUnit().canForcePosture()) { - return; - } - - this.dance(habbo, DanceType.NONE); - habbo.getRoomUnit().setCmdSit(true); - habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[habbo.getRoomUnit().getBodyRotation().getValue() - habbo.getRoomUnit().getBodyRotation().getValue() % 2]); - habbo.getRoomUnit().setStatus(RoomUnitStatus.SIT, 0.5 + ""); - this.sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose()); - } - - public void makeStand(Habbo habbo) { - if (habbo.getRoomUnit() == null) return; - - HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); - if (item == null || !item.getBaseItem().allowSit() || !item.getBaseItem().allowLay()) { - habbo.getRoomUnit().setCmdStand(true); - habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[habbo.getRoomUnit().getBodyRotation().getValue() - habbo.getRoomUnit().getBodyRotation().getValue() % 2]); - habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT); - this.sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose()); - } - } - - public void giveEffect(Habbo habbo, int effectId, int duration, boolean ignoreChecks) { - if (habbo != null && habbo.getRoomUnit() != null && this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) { - this.giveEffect(habbo.getRoomUnit(), effectId, duration, ignoreChecks); - } - } - - public void giveEffect(Habbo habbo, int effectId, int duration) { - if (habbo != null && habbo.getRoomUnit() != null && this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) { - this.giveEffect(habbo.getRoomUnit(), effectId, duration, false); - } - } - - public void giveEffect(RoomUnit roomUnit, int effectId, int duration) { - this.giveEffect(roomUnit, effectId, duration, false); - } - - public void giveEffect(RoomUnit roomUnit, int effectId, int duration, boolean ignoreChecks) { - if (roomUnit == null || roomUnit.getRoom() == null) return; - - Habbo habbo = roomUnit.getRoom().getHabbo(roomUnit); - - if (roomUnit.getRoomUnitType() == RoomUnitType.USER && (habbo == null || habbo.getHabboInfo().isInGame() && !ignoreChecks)) { return; } - if (duration == -1 || duration == Integer.MAX_VALUE) { - duration = Integer.MAX_VALUE; - } else { - duration += Emulator.getIntUnixTimestamp(); - } - - if ((this.allowEffects || ignoreChecks) && !roomUnit.isSwimming()) { - roomUnit.setEffectId(effectId, duration); - this.sendComposer(new AvatarEffectMessageComposer(roomUnit).compose()); - } - } - - public void giveHandItem(Habbo habbo, int handItem) { - this.giveHandItem(habbo.getRoomUnit(), handItem); - } - - public void giveHandItem(RoomUnit roomUnit, int handItem) { - roomUnit.setHandItem(handItem); - this.sendComposer(new CarryObjectMessageComposer(roomUnit).compose()); - } - - public void updateItem(HabboItem item) { + public void updateItem(RoomItem item) { if (!this.isLoaded()) { return; } - if (item != null && item.getRoomId() == this.id && item.getBaseItem() != null) { + if (item != null && item.getRoomId() == this.roomInfo.getId() && item.getBaseItem() != null) { if (item.getBaseItem().getType() == FurnitureType.FLOOR) { this.sendComposer(new ObjectUpdateMessageComposer(item).compose()); - this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); + this.updateTiles(this.layout.getTilesAt(this.layout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); } else if (item.getBaseItem().getType() == FurnitureType.WALL) { this.sendComposer(new ItemUpdateMessageComposer(item).compose()); } @@ -3647,7 +1861,7 @@ public class Room implements Comparable, ISerialize, Runnable { } - public void updateItemState(HabboItem item) { + public void updateItemState(RoomItem item) { if (!item.isLimited()) { this.sendComposer(new OneWayDoorStatusMessageComposer(item).compose()); } else { @@ -3657,7 +1871,7 @@ public class Room implements Comparable, ISerialize, Runnable { if (item.getBaseItem().getType() == FurnitureType.FLOOR) { if (this.layout == null) return; - this.updateTiles(this.getLayout().getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); + this.updateTiles(this.layout.getTilesAt(this.layout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); if (item instanceof InteractionMultiHeight interactionMultiHeight) { interactionMultiHeight.updateUnitsOnItem(this); @@ -3672,95 +1886,18 @@ public class Room implements Comparable, ISerialize, Runnable { public int getUserUniqueFurniCount(int userId) { THashSet items = new THashSet<>(); - for (HabboItem item : this.roomItems.valueCollection()) { - if (!items.contains(item.getBaseItem()) && item.getUserId() == userId) items.add(item.getBaseItem()); + for (RoomItem item : this.roomItemManager.getCurrentItems().values()) { + if (!items.contains(item.getBaseItem()) && item.getOwnerInfo().getId() == userId) items.add(item.getBaseItem()); } return items.size(); } - public void ejectUserFurni(int userId) { - THashSet items = new THashSet<>(); - - TIntObjectIterator iterator = this.roomItems.iterator(); - - for (int i = this.roomItems.size(); i-- > 0; ) { - try { - iterator.advance(); - } catch (Exception e) { - break; - } - - if (iterator.value().getUserId() == userId) { - items.add(iterator.value()); - iterator.value().setRoomId(0); - } - } - - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - - if (habbo != null) { - habbo.getInventory().getItemsComponent().addItems(items); - habbo.getClient().sendResponse(new UnseenItemsComposer(items)); - } - - for (HabboItem i : items) { - this.pickUpItem(i, null); - } - } - - public void ejectUserItem(HabboItem item) { - this.pickUpItem(item, null); - } - - - public void ejectAll() { - this.ejectAll(null); - } - - - public void ejectAll(Habbo habbo) { - THashMap> userItemsMap = new THashMap<>(); - - synchronized (this.roomItems) { - TIntObjectIterator iterator = this.roomItems.iterator(); - - for (int i = this.roomItems.size(); i-- > 0; ) { - try { - iterator.advance(); - } catch (Exception e) { - break; - } - - if (habbo != null && iterator.value().getUserId() == habbo.getHabboInfo().getId()) - continue; - - if (iterator.value() instanceof InteractionPostIt) - continue; - - userItemsMap.computeIfAbsent(iterator.value().getUserId(), k -> new THashSet<>()).add(iterator.value()); - } - } - - for (Map.Entry> entrySet : userItemsMap.entrySet()) { - for (HabboItem i : entrySet.getValue()) { - this.pickUpItem(i, null); - } - - Habbo user = Emulator.getGameEnvironment().getHabboManager().getHabbo(entrySet.getKey()); - - if (user != null) { - user.getInventory().getItemsComponent().addItems(entrySet.getValue()); - user.getClient().sendResponse(new UnseenItemsComposer(entrySet.getValue())); - } - } - } - public void refreshGuild(Guild guild) { - if (guild.getRoomId() == this.id) { + if (guild.getRoomId() == this.roomInfo.getId()) { THashSet members = Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild.getId()); - for (Habbo habbo : this.getHabbos()) { + for (Habbo habbo : this.roomUnitManager.getCurrentHabbos().values()) { Optional member = members.stream().filter(m -> m.getUserId() == habbo.getHabboInfo().getId()).findAny(); if (member.isEmpty()) continue; @@ -3773,100 +1910,24 @@ public class Room implements Comparable, ISerialize, Runnable { } public void refreshGuildColors(Guild guild) { - if (guild.getRoomId() == this.id) { - TIntObjectIterator iterator = this.roomItems.iterator(); + if (guild.getRoomId() == this.roomInfo.getId()) { + Iterator iterator = this.roomItemManager.getCurrentItems().values().iterator(); - for (int i = this.roomItems.size(); i-- > 0; ) { - try { - iterator.advance(); - } catch (Exception e) { - break; - } + for (int i = this.roomItemManager.getCurrentItems().size(); i-- > 0; ) { + RoomItem roomItem = iterator.next(); - HabboItem habboItem = iterator.value(); - - if (habboItem instanceof InteractionGuildFurni interactionGuildFurni && interactionGuildFurni.getGuildId() == guild.getId()) { - this.updateItem(habboItem); + if (roomItem instanceof InteractionGuildFurni interactionGuildFurni && interactionGuildFurni.getGuildId() == guild.getId()) { + this.updateItem(roomItem); } } } } public void refreshGuildRightsInRoom() { - for (Habbo habbo : this.getHabbos()) { - if ((habbo.getHabboInfo().getCurrentRoom() == this && habbo.getHabboInfo().getId() != this.ownerId) - && (!(habbo.hasRight(Permission.ACC_ANYROOMOWNER) || habbo.hasRight(Permission.ACC_MOVEROTATE)))) - this.refreshRightsForHabbo(habbo); - } - } - - - public void idle(Habbo habbo) { - habbo.getRoomUnit().setIdle(); - - if (habbo.getRoomUnit().getDanceType() != DanceType.NONE) { - this.dance(habbo, DanceType.NONE); - } - - this.sendComposer(new SleepMessageComposer(habbo.getRoomUnit()).compose()); - WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo}); - } - - public void unIdle(Habbo habbo) { - if (habbo == null || habbo.getRoomUnit() == null) return; - habbo.getRoomUnit().resetIdleTimer(); - this.sendComposer(new SleepMessageComposer(habbo.getRoomUnit()).compose()); - WiredHandler.handle(WiredTriggerType.UNIDLES, habbo.getRoomUnit(), this, new Object[]{habbo}); - } - - public void dance(Habbo habbo, DanceType danceType) { - this.dance(habbo.getRoomUnit(), danceType); - } - - public void dance(RoomUnit unit, DanceType danceType) { - if (unit.getDanceType() != danceType) { - boolean isDancing = !unit.getDanceType().equals(DanceType.NONE); - unit.setDanceType(danceType); - this.sendComposer(new DanceMessageComposer(unit).compose()); - - if (danceType.equals(DanceType.NONE) && isDancing) { - WiredHandler.handle(WiredTriggerType.STOPS_DANCING, unit, this, new Object[]{unit}); - } else if (!danceType.equals(DanceType.NONE) && !isDancing) { - WiredHandler.handle(WiredTriggerType.STARTS_DANCING, unit, this, new Object[]{unit}); - } - } - } - - public void addToWordFilter(String word) { - synchronized (this.wordFilterWords) { - if (this.wordFilterWords.contains(word)) - return; - - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT IGNORE INTO room_wordfilter VALUES (?, ?)")) { - statement.setInt(1, this.getId()); - statement.setString(2, word); - statement.execute(); - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - return; - } - - this.wordFilterWords.add(word); - } - } - - public void removeFromWordFilter(String word) { - synchronized (this.wordFilterWords) { - this.wordFilterWords.remove(word); - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ? AND word = ?")) { - statement.setInt(1, this.getId()); - statement.setString(2, word); - statement.execute(); - } catch (SQLException e) { - log.error(CAUGHT_SQL_EXCEPTION, e); - } + 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); } } @@ -3905,453 +1966,4 @@ public class Room implements Comparable, ISerialize, Runnable { public boolean hasVotedInWordQuiz(Habbo habbo) { return this.userVotes.contains(habbo.getHabboInfo().getId()); } - - public void alert(String message) { - this.sendComposer(new HabboBroadcastMessageComposer(message).compose()); - } - - public int itemCount() { - return this.roomItems.size(); - } - - public void setJukeBoxActive(boolean jukeBoxActive) { - this.jukeboxActive = jukeBoxActive; - this.needsUpdate = true; - } - - public boolean isHideWired() { - return this.hideWired; - } - - public void setHideWired(boolean hideWired) { - this.hideWired = hideWired; - - if (this.hideWired) { - for (HabboItem item : this.roomSpecialTypes.getTriggers()) { - this.sendComposer(new RemoveFloorItemComposer(item).compose()); - } - - for (HabboItem item : this.roomSpecialTypes.getEffects()) { - this.sendComposer(new RemoveFloorItemComposer(item).compose()); - } - - for (HabboItem item : this.roomSpecialTypes.getConditions()) { - this.sendComposer(new RemoveFloorItemComposer(item).compose()); - } - - for (HabboItem item : this.roomSpecialTypes.getExtras()) { - this.sendComposer(new RemoveFloorItemComposer(item).compose()); - } - } else { - this.sendComposer(new ObjectsMessageComposer(this.furniOwnerNames, this.roomSpecialTypes.getTriggers()).compose()); - this.sendComposer(new ObjectsMessageComposer(this.furniOwnerNames, this.roomSpecialTypes.getEffects()).compose()); - this.sendComposer(new ObjectsMessageComposer(this.furniOwnerNames, this.roomSpecialTypes.getConditions()).compose()); - this.sendComposer(new ObjectsMessageComposer(this.furniOwnerNames, this.roomSpecialTypes.getExtras()).compose()); - } - } - - public FurnitureMovementError canPlaceFurnitureAt(HabboItem item, Habbo habbo, RoomTile tile, int rotation) { - if (this.itemCount() >= Room.MAXIMUM_FURNI) { - return FurnitureMovementError.MAX_ITEMS; - } - - if (tile == null || tile.getState() == RoomTileState.INVALID) { - return FurnitureMovementError.INVALID_MOVE; - } - - rotation %= 8; - if (this.hasRights(habbo) || this.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS) || habbo.hasRight(Permission.ACC_MOVEROTATE)) { - return FurnitureMovementError.NONE; - } - - if (habbo.getHabboStats().isRentingSpace()) { - HabboItem rentSpace = this.getHabboItem(habbo.getHabboStats().getRentedItemId()); - - if (rentSpace != null) { - if (!RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getX(), rentSpace.getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(tile.getX(), tile.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation))) { - return FurnitureMovementError.NO_RIGHTS; - } else { - return FurnitureMovementError.NONE; - } - } - } - - for (HabboItem area : this.getRoomSpecialTypes().getItemsOfType(InteractionBuildArea.class)) { - if (((InteractionBuildArea) area).inSquare(tile) && ((InteractionBuildArea) area).isBuilder(habbo.getHabboInfo().getUsername())) { - return FurnitureMovementError.NONE; - } - } - - return FurnitureMovementError.NO_RIGHTS; - } - - public FurnitureMovementError furnitureFitsAt(RoomTile tile, HabboItem item, int rotation) { - return furnitureFitsAt(tile, item, rotation, true); - } - - public FurnitureMovementError furnitureFitsAt(RoomTile tile, HabboItem item, int rotation, boolean checkForUnits) { - if (!this.layout.fitsOnMap(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation)) - return FurnitureMovementError.INVALID_MOVE; - - if (item instanceof InteractionStackHelper) return FurnitureMovementError.NONE; - - - THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - for (RoomTile t : occupiedTiles) { - if (t.getState() == RoomTileState.INVALID) return FurnitureMovementError.INVALID_MOVE; - 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.hasHabbosAt(t.getX(), t.getY())) - return FurnitureMovementError.TILE_HAS_HABBOS; - if (checkForUnits && this.hasBotsAt(t.getX(), t.getY())) return FurnitureMovementError.TILE_HAS_BOTS; - if (checkForUnits && this.hasPetsAt(t.getX(), t.getY())) return FurnitureMovementError.TILE_HAS_PETS; - } - } - - Optional stackHelper = this.getItemsAt(tile).stream().filter(InteractionStackHelper.class::isInstance).findAny(); - - List>> tileFurniList = new ArrayList<>(); - for (RoomTile t : occupiedTiles) { - tileFurniList.add(Pair.create(t, this.getItemsAt(t))); - - HabboItem topItem = this.getTopItemAt(t.getX(), t.getY(), item); - if (topItem != null && !topItem.getBaseItem().allowStack() && !t.getAllowStack()) { - return FurnitureMovementError.CANT_STACK; - } - - if ((stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class) || topItem != null && (topItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && (item.getBaseItem().getInteractionType().getType() == InteractionWater.class || item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class))) { - return FurnitureMovementError.CANT_STACK; - } - } - - if (!item.canStackAt(this, tileFurniList)) { - return FurnitureMovementError.CANT_STACK; - } - - return FurnitureMovementError.NONE; - } - - public FurnitureMovementError placeFloorFurniAt(HabboItem item, RoomTile tile, int rotation, Habbo owner) { - boolean pluginHelper = false; - if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) { - FurniturePlacedEvent event = Emulator.getPluginManager().fireEvent(new FurniturePlacedEvent(item, owner, tile)); - - if (event.isCancelled()) { - return FurnitureMovementError.CANCEL_PLUGIN_PLACE; - } - - pluginHelper = event.hasPluginHelper(); - } - - THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - - FurnitureMovementError fits = furnitureFitsAt(tile, item, rotation); - - if (!fits.equals(FurnitureMovementError.NONE) && !pluginHelper) { - return fits; - } - - double height = tile.getStackHeight(); - - for (RoomTile tile2 : occupiedTiles) { - double sHeight = tile2.getStackHeight(); - if (sHeight > height) { - height = sHeight; - } - } - - if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) { - FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, owner, 0.00, height)); - if (event.hasChangedHeight()) { - height = event.getUpdatedHeight(); - } - } - - item.setZ(height); - item.setX(tile.getX()); - item.setY(tile.getY()); - item.setRotation(rotation); - if (!this.furniOwnerNames.containsKey(item.getUserId()) && owner != null) { - this.furniOwnerNames.put(item.getUserId(), owner.getHabboInfo().getUsername()); - } - - item.needsUpdate(true); - this.addHabboItem(item); - item.setRoomId(this.id); - item.onPlace(this); - this.updateTiles(occupiedTiles); - this.sendComposer(new ObjectAddMessageComposer(item, this.getFurniOwnerName(item.getUserId())).compose()); - - for (RoomTile t : occupiedTiles) { - this.updateHabbosAt(t.getX(), t.getY()); - this.updateBotsAt(t.getX(), t.getY()); - } - - Emulator.getThreading().run(item); - return FurnitureMovementError.NONE; - } - - public FurnitureMovementError placeWallFurniAt(HabboItem item, String wallPosition, Habbo owner) { - if (!(this.hasRights(owner) || this.getGuildRightLevel(owner).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { - return FurnitureMovementError.NO_RIGHTS; - } - - if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) { - Event furniturePlacedEvent = new FurniturePlacedEvent(item, owner, null); - Emulator.getPluginManager().fireEvent(furniturePlacedEvent); - - if (furniturePlacedEvent.isCancelled()) - return FurnitureMovementError.CANCEL_PLUGIN_PLACE; - } - - item.setWallPosition(wallPosition); - if (!this.furniOwnerNames.containsKey(item.getUserId()) && owner != null) { - this.furniOwnerNames.put(item.getUserId(), owner.getHabboInfo().getUsername()); - } - this.sendComposer(new ItemAddMessageComposer(item, this.getFurniOwnerName(item.getUserId())).compose()); - item.needsUpdate(true); - this.addHabboItem(item); - item.setRoomId(this.id); - item.onPlace(this); - Emulator.getThreading().run(item); - return FurnitureMovementError.NONE; - } - - public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor) { - return moveFurniTo(item, tile, rotation, actor, true, true); - } - - public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor, boolean sendUpdates) { - return moveFurniTo(item, tile, rotation, actor, sendUpdates, true); - } - - public FurnitureMovementError moveFurniTo(HabboItem item, RoomTile tile, int rotation, Habbo actor, boolean sendUpdates, boolean checkForUnits) { - RoomTile oldLocation = this.layout.getTile(item.getX(), item.getY()); - - boolean pluginHelper = false; - if (Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true)) { - FurnitureMovedEvent event = Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, tile)); - if (event.isCancelled()) { - return FurnitureMovementError.CANCEL_PLUGIN_MOVE; - } - pluginHelper = event.hasPluginHelper(); - } - - boolean magicTile = item instanceof InteractionStackHelper; - - Optional stackHelper = this.getItemsAt(tile).stream().filter(InteractionStackHelper.class::isInstance).findAny(); - - //Check if can be placed at new position - THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - THashSet newOccupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - - HabboItem topItem = this.getTopItemAt(occupiedTiles, null); - - if ((stackHelper.isEmpty() && !pluginHelper) || item.getBaseItem().getInteractionType().getType() == InteractionWater.class) { - if (oldLocation != tile) { - for (RoomTile t : occupiedTiles) { - HabboItem tileTopItem = this.getTopItemAt(t.getX(), t.getY()); - if (!magicTile && (tileTopItem != null && tileTopItem != item ? (t.getState().equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack() || - (tileTopItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && (item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class || item.getBaseItem().getInteractionType().getType() == InteractionWater.class))) : this.calculateTileState(t, item).equals(RoomTileState.INVALID)) || stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class) { - return FurnitureMovementError.CANT_STACK; - } - - if (!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit())) { - if (checkForUnits && !magicTile) { - if (this.hasHabbosAt(t.getX(), t.getY())) - return FurnitureMovementError.TILE_HAS_HABBOS; - if (this.hasBotsAt(t.getX(), t.getY())) - return FurnitureMovementError.TILE_HAS_BOTS; - if (this.hasPetsAt(t.getX(), t.getY())) - return FurnitureMovementError.TILE_HAS_PETS; - } - } - } - } - - List>> tileFurniList = new ArrayList<>(); - for (RoomTile t : occupiedTiles) { - tileFurniList.add(Pair.create(t, this.getItemsAt(t))); - } - - if (!magicTile && !item.canStackAt(this, tileFurniList)) { - return FurnitureMovementError.CANT_STACK; - } - } - - THashSet oldOccupiedTiles = this.layout.getTilesAt(this.layout.getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); - - int oldRotation = item.getRotation(); - - if (oldRotation != rotation) { - item.setRotation(rotation); - if (Emulator.getPluginManager().isRegistered(FurnitureRotatedEvent.class, true)) { - Event furnitureRotatedEvent = new FurnitureRotatedEvent(item, actor, oldRotation); - Emulator.getPluginManager().fireEvent(furnitureRotatedEvent); - - if (furnitureRotatedEvent.isCancelled()) { - item.setRotation(oldRotation); - return FurnitureMovementError.CANCEL_PLUGIN_ROTATE; - } - } - - if ((stackHelper.isEmpty() && topItem != null && topItem != item && !topItem.getBaseItem().allowStack()) || (topItem != null && topItem != item && topItem.getZ() + Item.getCurrentHeight(topItem) + Item.getCurrentHeight(item) > MAXIMUM_FURNI_HEIGHT)) { - item.setRotation(oldRotation); - return FurnitureMovementError.CANT_STACK; - } - - // ) - } - //Place at new position - - double height; - - if (stackHelper.isPresent()) { - height = stackHelper.get().getExtradata().isEmpty() ? Double.parseDouble("0.0") : (Double.parseDouble(stackHelper.get().getExtradata()) / 100); - } else if (item == topItem) { - height = item.getZ(); - } else { - height = this.getStackHeight(tile.getX(), tile.getY(), false, item); - for (RoomTile til : occupiedTiles) { - double sHeight = this.getStackHeight(til.getX(), til.getY(), false, item); - if (sHeight > height) { - height = sHeight; - } - } - } - - if (height > MAXIMUM_FURNI_HEIGHT) return FurnitureMovementError.CANT_STACK; - if (height < this.getLayout().getHeightAtSquare(tile.getX(), tile.getY())) - return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor - - if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) { - FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, actor, 0.00, height)); - if (event.hasChangedHeight()) { - height = event.getUpdatedHeight(); - } - } - - if (height > MAXIMUM_FURNI_HEIGHT) return FurnitureMovementError.CANT_STACK; - if (height < this.getLayout().getHeightAtSquare(tile.getX(), tile.getY())) - return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor - - item.setX(tile.getX()); - item.setY(tile.getY()); - item.setZ(height); - if (magicTile) { - item.setZ(tile.getZ()); - item.setExtradata("" + item.getZ() * 100); - } - if (item.getZ() > MAXIMUM_FURNI_HEIGHT) { - item.setZ(MAXIMUM_FURNI_HEIGHT); - } - - - //Update Furniture - item.onMove(this, oldLocation, tile); - item.needsUpdate(true); - Emulator.getThreading().run(item); - - if (sendUpdates) { - this.sendComposer(new ObjectUpdateMessageComposer(item).compose()); - } - - //Update old & new tiles - occupiedTiles.removeAll(oldOccupiedTiles); - occupiedTiles.addAll(oldOccupiedTiles); - this.updateTiles(occupiedTiles); - - //Update Habbos at old position - for (RoomTile t : occupiedTiles) { - this.updateHabbosAt( - t.getX(), - t.getY(), - this.getHabbosAt(t.getX(), t.getY()) - /*.stream() - .filter(h -> !h.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || h.getRoomUnit().getGoal() == t) - .collect(Collectors.toCollection(THashSet::new))*/ - ); - this.updateBotsAt(t.getX(), t.getY()); - } - if (Emulator.getConfig().getBoolean("wired.place.under", false)) { - for (RoomTile t : newOccupiedTiles) { - for (Habbo h : this.getHabbosAt(t.getX(), t.getY())) { - try { - item.onWalkOn(h.getRoomUnit(), this, null); - } catch (Exception ignored) { - - } - } - } - } - return FurnitureMovementError.NONE; - } - - public FurnitureMovementError slideFurniTo(HabboItem item, RoomTile tile, int rotation) { - boolean magicTile = item instanceof InteractionStackHelper; - - //Check if can be placed at new position - THashSet occupiedTiles = this.layout.getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); - - List>> tileFurniList = new ArrayList<>(); - for (RoomTile t : occupiedTiles) { - tileFurniList.add(Pair.create(t, this.getItemsAt(t))); - } - - if (!magicTile && !item.canStackAt(this, tileFurniList)) { - return FurnitureMovementError.CANT_STACK; - } - - item.setRotation(rotation); - - //Place at new position - if (magicTile) { - item.setZ(tile.getZ()); - item.setExtradata("" + item.getZ() * 100); - } - if (item.getZ() > MAXIMUM_FURNI_HEIGHT) { - item.setZ(MAXIMUM_FURNI_HEIGHT); - } - double offset = this.getStackHeight(tile.getX(), tile.getY(), false, item) - item.getZ(); - this.sendComposer(new FloorItemOnRollerComposer(item, null, tile, offset, this).compose()); - - //Update Habbos at old position - for (RoomTile t : occupiedTiles) { - this.updateHabbosAt(t.getX(), t.getY()); - this.updateBotsAt(t.getX(), t.getY()); - } - return FurnitureMovementError.NONE; - } - - public THashSet getRoomUnits() { - return getRoomUnits(null); - } - - public THashSet getRoomUnits(RoomTile atTile) { - THashSet units = new THashSet<>(); - - for (Habbo habbo : this.currentHabbos.values()) { - if (habbo != null && habbo.getRoomUnit() != null && habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom().getId() == this.getId() && (atTile == null || habbo.getRoomUnit().getCurrentLocation() == atTile)) { - units.add(habbo.getRoomUnit()); - } - } - - for (Pet pet : this.currentPets.valueCollection()) { - if (pet != null && pet.getRoomUnit() != null && pet.getRoomUnit().getRoom() != null && pet.getRoomUnit().getRoom().getId() == this.getId() && (atTile == null || pet.getRoomUnit().getCurrentLocation() == atTile)) { - units.add(pet.getRoomUnit()); - } - } - - for (Bot bot : this.currentBots.valueCollection()) { - if (bot != null && bot.getRoomUnit() != null && bot.getRoomUnit().getRoom() != null && bot.getRoomUnit().getRoom().getId() == this.getId() && (atTile == null || bot.getRoomUnit().getCurrentLocation() == atTile)) { - units.add(bot.getRoomUnit()); - } - } - - return units; - } - - public Collection getRoomUnitsAt(RoomTile tile) { - THashSet roomUnits = getRoomUnits(); - return roomUnits.stream().filter(unit -> unit.getCurrentLocation() == tile).collect(Collectors.toSet()); - } -} +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatMessage.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatMessage.java index f5ae4749..c3dfb3f7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatMessage.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomChatMessage.java @@ -3,6 +3,7 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.core.DatabaseLoggable; import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ISerialize; import com.eu.habbo.messages.ServerMessage; @@ -48,7 +49,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { public RoomChatMessage(MessageHandler message) { if (message.packet.getMessageId() == Incoming.whisperEvent) { String data = message.packet.readString(); - this.targetHabbo = message.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(data.split(" ")[0]); + this.targetHabbo = message.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboByUsername(data.split(" ")[0]); this.message = data.substring(data.split(" ")[0].length() + 1); } else { this.message = message.packet.readString(); @@ -59,7 +60,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { this.bubble = RoomChatMessageBubbles.NORMAL; } - if (!message.client.getHabbo().hasRight(Permission.ACC_ANYCHATCOLOR)) { + if (!message.client.getHabbo().hasPermissionRight(Permission.ACC_ANYCHATCOLOR)) { for (Integer i : RoomChatMessage.BANNED_BUBBLES) { if (i == this.bubble.getType()) { this.bubble = RoomChatMessageBubbles.NORMAL; @@ -69,7 +70,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { } this.habbo = message.client.getHabbo(); - this.roomUnitId = this.habbo.getRoomUnit().getId(); + this.roomUnitId = this.habbo.getRoomUnit().getVirtualId(); this.unfilteredMessage = this.message; this.timestamp = Emulator.getIntUnixTimestamp(); @@ -93,7 +94,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { this.unfilteredMessage = message; this.habbo = null; this.bubble = bubble; - this.roomUnitId = roomUnit.getId(); + this.roomUnitId = roomUnit.getVirtualId(); } public RoomChatMessage(String message, Habbo habbo, RoomChatMessageBubbles bubble) { @@ -102,7 +103,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { this.habbo = habbo; this.bubble = bubble; this.checkEmotion(); - this.roomUnitId = habbo.getRoomUnit().getId(); + this.roomUnitId = habbo.getRoomUnit().getVirtualId(); this.message = this.message.replace("\r", "").replace("\n", ""); if (this.bubble.isOverridable() && this.getHabbo().getHabboStats().getChatColor() != RoomChatMessageBubbles.NORMAL) @@ -116,7 +117,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { this.targetHabbo = targetHabbo; this.bubble = bubble; this.checkEmotion(); - this.roomUnitId = this.habbo.getRoomUnit().getId(); + this.roomUnitId = this.habbo.getRoomUnit().getVirtualId(); this.message = this.message.replace("\r", "").replace("\n", ""); if (this.bubble.isOverridable() && this.getHabbo().getHabboStats().getChatColor() != RoomChatMessageBubbles.NORMAL) @@ -154,7 +155,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { @Override public void serialize(ServerMessage message) { if (this.habbo != null && this.bubble.isOverridable()) { - if (!this.habbo.hasRight(Permission.ACC_ANYCHATCOLOR)) { + if (!this.habbo.hasPermissionRight(Permission.ACC_ANYCHATCOLOR)) { for (Integer i : RoomChatMessage.BANNED_BUBBLES) { if (i == this.bubble.getType()) { this.bubble = RoomChatMessageBubbles.NORMAL; @@ -165,7 +166,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { } if (!this.getBubble().getPermission().isEmpty()) { - if (this.habbo != null && !this.habbo.hasRight(this.getBubble().getPermission())) { + if (this.habbo != null && !this.habbo.hasPermissionRight(this.getBubble().getPermission())) { this.bubble = RoomChatMessageBubbles.NORMAL; } } @@ -190,7 +191,7 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { } if (Emulator.getConfig().getBoolean("hotel.wordfilter.enabled", true) && Emulator.getConfig().getBoolean("hotel.wordfilter.rooms")) { - if (!this.habbo.hasRight(Permission.ACC_CHAT_NO_FILTER)) { + if (!this.habbo.hasPermissionRight(Permission.ACC_CHAT_NO_FILTER)) { if (!Emulator.getGameEnvironment().getWordFilter().autoReportCheck(this)) { if (!Emulator.getGameEnvironment().getWordFilter().hideMessageCheck(this.message)) { Emulator.getGameEnvironment().getWordFilter().filter(this, this.habbo); @@ -227,8 +228,8 @@ public class RoomChatMessage implements Runnable, ISerialize, DatabaseLoggable { statement.setString(3, this.unfilteredMessage); statement.setInt(4, this.timestamp); - if (this.habbo.getHabboInfo().getCurrentRoom() != null) { - statement.setInt(5, this.habbo.getHabboInfo().getCurrentRoom().getId()); + if (this.habbo.getRoomUnit().getRoom() != null) { + statement.setInt(5, this.habbo.getRoomUnit().getRoom().getRoomInfo().getId()); } else { statement.setInt(5, 0); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomInfo.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomInfo.java new file mode 100644 index 00000000..ac7f27b4 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomInfo.java @@ -0,0 +1,242 @@ +package com.eu.habbo.habbohotel.rooms; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.guilds.Guild; +import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboInfo; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; + +@Getter +@Setter +@Slf4j +public class RoomInfo { + private final int id; + private HabboInfo ownerInfo; + private volatile RoomCategory category; + private String name; + private String description; + private RoomState state; + private int maxUsers; + private String password; + private Guild guild; + private volatile int score; + private String tags; + private String floorPaint; + private String wallPaint; + private String landscapePaint; + private int wallThickness; + private int wallHeight; + private int floorThickness; + private volatile boolean hideWalls; + private volatile boolean allowPets; + private volatile boolean allowPetsEat; + private volatile boolean allowWalkthrough; + private volatile int chatMode; + private volatile int chatWeight; + private volatile int chatSpeed; + private volatile int chatDistance; + private volatile int chatProtection; + private volatile int whoCanMuteOption; + private volatile int whoCanKickOption; + private volatile int whoCanBanOption; + private volatile int tradeMode; + private volatile boolean diagonalMoveEnabled; + private volatile int rollerSpeed; + private int pollId; + private volatile boolean jukeboxEnabled; + private volatile boolean hiddenWiredEnabled; + private volatile boolean staffPicked; + private volatile boolean promoted; + private volatile boolean publicRoom; + private boolean modelOverridden; + private HashMap moodLightData; + private final HashMap defaultMoodData; + + public RoomInfo(ResultSet set) throws SQLException { + this.id = set.getInt("id"); + this.ownerInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(set.getInt("owner_id")); + this.name = set.getString("name"); + this.description = set.getString("description"); + this.category = Emulator.getGameEnvironment().getRoomManager().getCategory(set.getInt("category")); + this.state = RoomState.valueOf(set.getString("state").toUpperCase()); + this.maxUsers = set.getInt("users_max"); + this.password = set.getString("password"); + this.guild = Emulator.getGameEnvironment().getGuildManager().getGuild(set.getInt("guild_id")); + this.score = set.getInt("score"); + this.tags = set.getString("tags"); + + this.floorPaint = set.getString("paper_floor"); + this.wallPaint = set.getString("paper_wall"); + this.landscapePaint = set.getString("paper_landscape"); + this.wallThickness = set.getInt("thickness_wall"); + this.wallHeight = set.getInt("wall_height"); + this.floorThickness = set.getInt("thickness_floor"); + this.hideWalls = set.getBoolean("allow_hidewall"); + + this.allowPets = set.getBoolean("allow_other_pets"); + this.allowPetsEat = set.getBoolean("allow_other_pets_eat"); + this.allowWalkthrough = set.getBoolean("allow_walkthrough"); + + this.chatMode = set.getInt("chat_mode"); + this.chatWeight = set.getInt("chat_weight"); + this.chatSpeed = set.getInt("chat_speed"); + this.chatDistance = set.getInt("chat_hearing_distance"); + this.chatProtection = set.getInt("chat_protection"); + + this.whoCanMuteOption = set.getInt("who_can_mute"); + this.whoCanKickOption = set.getInt("who_can_kick"); + this.whoCanBanOption = set.getInt("who_can_ban"); + this.tradeMode = set.getInt("trade_mode"); + this.diagonalMoveEnabled = set.getBoolean("move_diagonally"); + + this.rollerSpeed = set.getInt("roller_speed"); + + this.pollId = set.getInt("poll_id"); + + this.jukeboxEnabled = set.getBoolean("jukebox_active"); + this.hiddenWiredEnabled = set.getBoolean("hidewired"); + + this.staffPicked = set.getBoolean("is_staff_picked"); + this.promoted = set.getBoolean("promoted"); + this.publicRoom = set.getBoolean("is_public"); + + this.modelOverridden = set.getBoolean("override_model"); + + defaultMoodData = new HashMap<>(); + + for (int i = 1; i <= 3; i++) { + RoomMoodlightData data = RoomMoodlightData.fromString(""); + data.setId(i); + defaultMoodData.put(i, data); + } + + + this.moodLightData = new HashMap<>(); + + for (String s : set.getString("moodlight_data").split(";")) { + RoomMoodlightData data = RoomMoodlightData.fromString(s); + this.moodLightData.put(data.getId(), data); + } + + } + + public void update(Connection connection) { + try (PreparedStatement statement = connection.prepareStatement("UPDATE rooms SET name = ?, description = ?, password = ?, state = ?, users_max = ?, category = ?, score = ?, paper_floor = ?, paper_wall = ?, paper_landscape = ?, thickness_wall = ?, wall_height = ?, thickness_floor = ?, moodlight_data = ?, tags = ?, allow_other_pets = ?, allow_other_pets_eat = ?, allow_walkthrough = ?, allow_hidewall = ?, chat_mode = ?, chat_weight = ?, chat_speed = ?, chat_hearing_distance = ?, chat_protection =?, who_can_mute = ?, who_can_kick = ?, who_can_ban = ?, poll_id = ?, guild_id = ?, roller_speed = ?, override_model = ?, is_staff_picked = ?, promoted = ?, trade_mode = ?, move_diagonally = ?, owner_id = ?, owner_name = ?, jukebox_active = ?, hidewired = ? WHERE id = ?")) { + statement.setString(1, this.name); + statement.setString(2, this.description); + statement.setString(3, this.password); + statement.setString(4, this.state.name().toLowerCase()); + statement.setInt(5, this.maxUsers); + statement.setInt(6, this.category.getId()); + statement.setInt(7, this.score); + statement.setString(8, this.floorPaint); + statement.setString(9, this.wallPaint); + statement.setString(10, this.landscapePaint); + statement.setInt(11, this.wallThickness); + statement.setInt(12, this.wallHeight); + statement.setInt(13, this.floorThickness); + StringBuilder moodLightData = new StringBuilder(); + + int moodLightId = 1; + for (RoomMoodlightData data : this.moodLightData.values()) { + data.setId(moodLightId); + moodLightData.append(data).append(";"); + moodLightId++; + } + + statement.setString(14, moodLightData.toString()); + statement.setString(15, this.tags); + statement.setString(16, this.allowPets ? "1" : "0"); + statement.setString(17, this.allowPetsEat ? "1" : "0"); + statement.setString(18, this.allowWalkthrough ? "1" : "0"); + statement.setString(19, this.hideWalls ? "1" : "0"); + statement.setInt(20, this.chatMode); + statement.setInt(21, this.chatWeight); + statement.setInt(22, this.chatSpeed); + statement.setInt(23, this.chatDistance); + statement.setInt(24, this.chatProtection); + statement.setInt(25, this.whoCanMuteOption); + statement.setInt(26, this.whoCanKickOption); + statement.setInt(27, this.whoCanBanOption); + statement.setInt(28, this.pollId); + statement.setInt(29, (this.hasGuild()) ? this.guild.getId() : 0); + statement.setInt(30, this.rollerSpeed); + statement.setString(31, this.modelOverridden ? "1" : "0"); + statement.setString(32, this.staffPicked ? "1" : "0"); + statement.setString(33, this.promoted ? "1" : "0"); + statement.setInt(34, this.tradeMode); + statement.setString(35, this.diagonalMoveEnabled ? "1" : "0"); + statement.setInt(36, this.ownerInfo.getId()); + statement.setString(37, this.ownerInfo.getUsername()); + statement.setString(38, this.jukeboxEnabled ? "1" : "0"); + statement.setString(39, this.hiddenWiredEnabled ? "1" : "0"); + statement.setInt(40, this.id); + statement.executeUpdate(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + } + + public boolean hasGuild() { + return this.guild != null; + } + + public String getOwnerName() { + return this.getOwnerInfo().getUsername(); + } + + public boolean isRoomOwner(Habbo owner) { + return this.ownerInfo.getId() == owner.getHabboInfo().getId() || owner.hasPermissionRight(Permission.ACC_ANYROOMOWNER); + } + + public String[] filterAnything() { + return new String[]{this.getOwnerInfo().getUsername(), this.getGuildName(), this.getDescription()}; + } + + public String getGuildName() { + if (this.guild == null) { + return ""; + } + + return this.guild.getName(); + } + + public void setName(String name) { + this.name = name; + + if (this.name.length() > 50) { + this.name = this.name.substring(0, 50); + } + + if (this.guild != null) { + this.guild.setRoomName(name); + } + } + + public void setDescription(String description) { + this.description = description; + + if (this.description.length() > 250) { + this.description = this.description.substring(0, 250); + } + } + + public void setPassword(String password) { + this.password = password; + + if (this.password.length() > 20) { + this.password = this.password.substring(0, 20); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomItemManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomItemManager.java new file mode 100644 index 00000000..8e32ced6 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomItemManager.java @@ -0,0 +1,1115 @@ +package com.eu.habbo.habbohotel.rooms; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.FurnitureType; +import com.eu.habbo.habbohotel.items.ICycleable; +import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.items.interactions.*; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameGate; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameScoreboard; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere; +import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiTeleporter; +import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeExitTile; +import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagField; +import com.eu.habbo.habbohotel.items.interactions.games.tag.InteractionTagPole; +import com.eu.habbo.habbohotel.items.interactions.pets.*; +import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredBlob; +import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; +import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; +import com.eu.habbo.messages.outgoing.rooms.HeightMapUpdateMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.items.*; +import com.eu.habbo.plugin.Event; +import com.eu.habbo.plugin.events.furniture.*; +import gnu.trove.set.hash.THashSet; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.math3.util.Pair; + +import java.awt.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; + +@Slf4j +@Getter +public class RoomItemManager { + private final Room room; + private final RoomWiredManager wiredManager; + private final ConcurrentHashMap currentItems; + private final ConcurrentHashMap floorItems; + private final ConcurrentHashMap wallItems; + private final HashSet cycleTasks; + private final HashMap nests; + private final HashMap petDrinks; + private final HashMap petFoods; + private final HashMap petToys; + private final HashMap rollers; + private final HashMap gameScoreboards; + private final HashMap gameGates; + private final HashMap gameTimers; + private final HashMap banzaiTeleporters; + private final HashMap freezeExitTile; + private final HashMap undefinedSpecials; + + public RoomItemManager(Room room) { + this.room = room; + this.currentItems = new ConcurrentHashMap<>(); + this.wiredManager = new RoomWiredManager(room); + + this.floorItems = new ConcurrentHashMap<>(); + this.wallItems = new ConcurrentHashMap<>(); + + this.cycleTasks = new HashSet<>(0); + + this.nests = new HashMap<>(0); + this.petDrinks = new HashMap<>(0); + this.petFoods = new HashMap<>(0); + this.petToys = new HashMap<>(0); + + this.rollers = new HashMap<>(0); + + this.gameScoreboards = new HashMap<>(0); + this.gameGates = new HashMap<>(0); + this.gameTimers = new HashMap<>(0); + + this.banzaiTeleporters = new HashMap<>(0); + this.freezeExitTile = new HashMap<>(0); + + this.undefinedSpecials = new HashMap<>(0); + } + + public synchronized void load(Connection connection) { + this.loadItems(connection); + } + + private synchronized void loadItems(Connection connection) { + this.currentItems.clear(); + this.wiredManager.clear(); + + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + RoomItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set); + + if (item != null) { + this.addRoomItem(item); + } + } + } + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error("Caught Exception", e); + } + } + + public RoomItem getRoomItemById(int itemId) { + return this.currentItems.get(itemId); + } + + public void addRoomItem(RoomItem item) { + if (this.currentItems.size() > Room.MAXIMUM_FURNI) { + log.error("Room ID: {} has exceeded the furniture limit ({} > {}).", this.room.getRoomInfo().getId(), this.currentItems.size(), Room.MAXIMUM_FURNI); + } + + synchronized (this.currentItems) { + try { + this.currentItems.put(item.getId(), item); + this.sortItem(item); + //Deprecated + item.setRoomId(this.room.getRoomInfo().getId()); + item.setRoom(room); + } catch (Exception ignored) { + + } + } + } + + public void removeRoomItem(RoomItem roomItem) { + if (roomItem != null) { + + RoomItem removedItem; + synchronized (this.currentItems) { + removedItem = this.currentItems.remove(roomItem.getId()); + } + + if(removedItem.getBaseItem().getType().equals(FurnitureType.FLOOR)) { + this.floorItems.remove(removedItem.getId()); + } else if (removedItem.getBaseItem().getType().equals(FurnitureType.WALL)) { + this.wallItems.remove(removedItem.getId()); + } + + if (removedItem != null) { + if (roomItem instanceof ICycleable) { + this.removeCycleTask((ICycleable) roomItem); + } + + if (roomItem instanceof InteractionWired wired) { + this.wiredManager.removeWired(wired); + } else if (roomItem instanceof InteractionBattleBanzaiTeleporter) { + this.removeBanzaiTeleporter((InteractionBattleBanzaiTeleporter) roomItem); + } else if (roomItem instanceof InteractionRoller) { + this.removeRoller((InteractionRoller) roomItem); + } else if (roomItem instanceof InteractionGameScoreboard) { + this.removeScoreboard((InteractionGameScoreboard) roomItem); + } else if (roomItem instanceof InteractionGameGate) { + this.removeGameGate((InteractionGameGate) roomItem); + } else if (roomItem instanceof InteractionGameTimer) { + this.removeGameTimer((InteractionGameTimer) roomItem); + } else if (roomItem instanceof InteractionFreezeExitTile) { + this.removeFreezeExitTile((InteractionFreezeExitTile) roomItem); + } else if (roomItem instanceof InteractionNest) { + this.removeNest((InteractionNest) roomItem); + } else if (roomItem instanceof InteractionPetDrink) { + this.removePetDrink((InteractionPetDrink) roomItem); + } else if (roomItem instanceof InteractionPetFood) { + this.removePetFood((InteractionPetFood) roomItem); + } else if (roomItem instanceof InteractionPetToy) { + this.removePetToy((InteractionPetToy) roomItem); + } else if (roomItem instanceof InteractionPetTree) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionPetTrampoline) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionMoodLight) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionPyramid) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionMusicDisc) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionBattleBanzaiSphere) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionTalkingFurniture) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionWaterItem) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionWater) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionMuteArea) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionTagPole) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionTagField) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionJukeBox) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionPetBreedingNest) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionBlackHole) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionWiredHighscore) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionStickyPole) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof WiredBlob) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionTent) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionSnowboardSlope) { + this.removeUndefined(roomItem); + } else if (roomItem instanceof InteractionBuildArea) { + this.removeUndefined(roomItem); + } + } + } + } + + public HashSet getItemsOfType(Class type) { + return this.currentItems.values().stream() + .filter(item -> type.equals(item.getClass())) + .collect(Collectors.toCollection(HashSet::new)); + } + + public FurnitureMovementError canPlaceFurnitureAt(RoomItem item, Habbo habbo, RoomTile tile, int rotation) { + if (this.currentItems.size() >= Room.MAXIMUM_FURNI) { + return FurnitureMovementError.MAX_ITEMS; + } else if (item instanceof InteractionMoodLight && !this.getItemsOfType(InteractionMoodLight.class).isEmpty()) { + return FurnitureMovementError.MAX_DIMMERS; + } else if (item instanceof InteractionJukeBox && !this.getItemsOfType(InteractionJukeBox.class).isEmpty()) { + return FurnitureMovementError.MAX_SOUNDFURNI; + } else if (tile == null || tile.getState() == RoomTileState.INVALID) { + return FurnitureMovementError.INVALID_MOVE; + } else if (this.room.getRoomRightsManager().hasRights(habbo) || this.room.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS) || habbo.hasPermissionRight(Permission.ACC_MOVEROTATE)) { + return FurnitureMovementError.NONE; + } + + rotation %= 8; + + if (habbo.getHabboStats().isRentingSpace()) { + RoomItem rentSpace = this.currentItems.get(habbo.getHabboStats().getRentedItemId()); + + if (rentSpace != null) { + if (!RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getCurrentPosition().getX(), rentSpace.getCurrentPosition().getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(tile.getX(), tile.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation))) { + return FurnitureMovementError.NO_RIGHTS; + } else { + return FurnitureMovementError.NONE; + } + } + } + + //TODO CHECK THIS SITUATION + for (RoomItem area : this.getItemsOfType(InteractionBuildArea.class)) { + if (((InteractionBuildArea) area).inSquare(tile) && ((InteractionBuildArea) area).isBuilder(habbo.getHabboInfo().getUsername())) { + return FurnitureMovementError.NONE; + } + } + + return FurnitureMovementError.NO_RIGHTS; + } + + public FurnitureMovementError placeFloorItemAt(RoomItem item, RoomTile tile, int rotation, Habbo actor) { + FurnitureMovementError error = this.canPlaceFurnitureAt(item, actor, tile, rotation); + + if(!error.equals(FurnitureMovementError.NONE)) { + return error; + } + + boolean pluginHelper = false; + + if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) { + FurniturePlacedEvent event = Emulator.getPluginManager().fireEvent(new FurniturePlacedEvent(item, actor, tile)); + + if (event.isCancelled()) { + return FurnitureMovementError.CANCEL_PLUGIN_PLACE; + } + + pluginHelper = event.hasPluginHelper(); + } + + THashSet occupiedTiles = this.room.getLayout().getTilesAt(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); + + FurnitureMovementError fits = this.furnitureFitsAt(tile, item, rotation, true); + + if (!fits.equals(FurnitureMovementError.NONE) && !pluginHelper) { + return fits; + } + + double height = tile.getStackHeight(); + + for (RoomTile tile2 : occupiedTiles) { + double sHeight = tile2.getStackHeight(); + if (sHeight > height) { + height = sHeight; + } + } + + if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) { + FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, actor, 0.00, height)); + if (event.hasChangedHeight()) { + height = event.getUpdatedHeight(); + } + } + + item.setCurrentPosition(tile); + item.setCurrentZ(height); + item.setRotation(rotation); + item.setSqlUpdateNeeded(true); + + this.addRoomItem(item); + + item.onPlace(this.room); + this.room.updateTiles(occupiedTiles); + + this.room.sendComposer(new ObjectAddMessageComposer(item, this.room.getFurniOwnerName(item.getOwnerInfo().getId())).compose()); + + for (RoomTile t : occupiedTiles) { + this.room.getRoomUnitManager().updateHabbosAt(t); + this.room.getRoomUnitManager().updateBotsAt(t); + } + + Emulator.getThreading().run(item); + return FurnitureMovementError.NONE; + } + + public FurnitureMovementError placeWallItemAt(RoomItem item, String wallPosition, Habbo owner) { + if (!(this.room.getRoomRightsManager().hasRights(owner) || this.room.getGuildRightLevel(owner).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { + return FurnitureMovementError.NO_RIGHTS; + } + + if (Emulator.getPluginManager().isRegistered(FurniturePlacedEvent.class, true)) { + Event furniturePlacedEvent = new FurniturePlacedEvent(item, owner, null); + Emulator.getPluginManager().fireEvent(furniturePlacedEvent); + + if (furniturePlacedEvent.isCancelled()) + return FurnitureMovementError.CANCEL_PLUGIN_PLACE; + } + + item.setWallPosition(wallPosition); + if (!this.room.getFurniOwnerNames().containsKey(item.getOwnerInfo().getId()) && owner != null) { + this.room.getFurniOwnerNames().put(item.getOwnerInfo().getId(), owner.getHabboInfo().getUsername()); + } + this.room.sendComposer(new ItemAddMessageComposer(item, this.room.getFurniOwnerName(item.getOwnerInfo().getId())).compose()); + item.setSqlUpdateNeeded(true); + this.addRoomItem(item); + //Deprecated + item.setRoomId(this.room.getRoomInfo().getId()); + item.setRoom(this.room); + item.onPlace(this.room); + Emulator.getThreading().run(item); + return FurnitureMovementError.NONE; + } + + public FurnitureMovementError moveItemTo(RoomItem item, RoomTile targetTile, int rotation, Habbo actor) { + return moveItemTo(item, targetTile, rotation, actor, true, true); + } + + public FurnitureMovementError moveItemTo(RoomItem item, RoomTile targetTile, int rotation, Habbo actor, boolean sendUpdates, boolean checkForUnits) { + FurnitureMovementError error = this.canPlaceFurnitureAt(item, actor, targetTile, rotation); + + if(!error.equals(FurnitureMovementError.NONE)) { + return error; + } + + RoomTile oldLocation = this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + + boolean pluginHelper = false; + if (Emulator.getPluginManager().isRegistered(FurnitureMovedEvent.class, true)) { + FurnitureMovedEvent event = Emulator.getPluginManager().fireEvent(new FurnitureMovedEvent(item, actor, oldLocation, targetTile)); + if (event.isCancelled()) { + return FurnitureMovementError.CANCEL_PLUGIN_MOVE; + } + pluginHelper = event.hasPluginHelper(); + } + + boolean magicTile = item instanceof InteractionStackHelper; + + Optional stackHelper = this.getItemsAt(targetTile).stream().filter(InteractionStackHelper.class::isInstance).findAny(); + + //Check if can be placed at new position + THashSet occupiedTiles = this.room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); + THashSet newOccupiedTiles = this.room.getLayout().getTilesAt(targetTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation); + + RoomItem topItem = this.getTopItemAt(occupiedTiles, null); + + if ((stackHelper.isEmpty() && !pluginHelper) || item.getBaseItem().getInteractionType().getType() == InteractionWater.class) { + if (oldLocation != targetTile) { + for (RoomTile t : occupiedTiles) { + RoomItem tileTopItem = this.getTopItemAt(t.getX(), t.getY()); + if (!magicTile && (tileTopItem != null && tileTopItem != item ? (t.getState().equals(RoomTileState.INVALID) || !t.getAllowStack() || !tileTopItem.getBaseItem().allowStack() || + (tileTopItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && (item.getBaseItem().getInteractionType().getType() != InteractionWaterItem.class || item.getBaseItem().getInteractionType().getType() == InteractionWater.class))) : this.room.calculateTileState(t, item).equals(RoomTileState.INVALID)) || stackHelper.isPresent() && item.getBaseItem().getInteractionType().getType() == InteractionWater.class) { + return FurnitureMovementError.CANT_STACK; + } + + if (!Emulator.getConfig().getBoolean("wired.place.under", false) || (Emulator.getConfig().getBoolean("wired.place.under", false) && !item.isWalkable() && !item.getBaseItem().allowSit())) { + if (checkForUnits && !magicTile) { + if (this.room.getRoomUnitManager().hasHabbosAt(t)) + return FurnitureMovementError.TILE_HAS_HABBOS; + if (!this.room.getRoomUnitManager().getBotsAt(t).isEmpty()) + return FurnitureMovementError.TILE_HAS_BOTS; + if (this.room.getRoomUnitManager().hasPetsAt(t)) + return FurnitureMovementError.TILE_HAS_PETS; + } + } + } + } + + List>> tileFurniList = new ArrayList<>(); + + for (RoomTile t : occupiedTiles) { + tileFurniList.add(Pair.create(t, this.getItemsAt(t))); + } + + if (!magicTile && !item.canStackAt(tileFurniList)) { + return FurnitureMovementError.CANT_STACK; + } + } + + THashSet oldOccupiedTiles = this.room.getLayout().getTilesAt(this.room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + + int oldRotation = item.getRotation(); + + if (oldRotation != rotation) { + item.setRotation(rotation); + + if (Emulator.getPluginManager().isRegistered(FurnitureRotatedEvent.class, true)) { + Event furnitureRotatedEvent = new FurnitureRotatedEvent(item, actor, oldRotation); + Emulator.getPluginManager().fireEvent(furnitureRotatedEvent); + + if (furnitureRotatedEvent.isCancelled()) { + item.setRotation(oldRotation); + return FurnitureMovementError.CANCEL_PLUGIN_ROTATE; + } + } + + if ((stackHelper.isEmpty() && topItem != null && topItem != item && !topItem.getBaseItem().allowStack()) || (topItem != null && topItem != item && topItem.getCurrentZ() + Item.getCurrentHeight(topItem) + Item.getCurrentHeight(item) > Room.MAXIMUM_FURNI_HEIGHT)) { + item.setRotation(oldRotation); + return FurnitureMovementError.CANT_STACK; + } + + // ) + } + //Place at new position + + double height; + + if (stackHelper.isPresent()) { + height = stackHelper.get().getExtraData().isEmpty() ? Double.parseDouble("0.0") : (Double.parseDouble(stackHelper.get().getExtraData()) / 100); + } else if (item == topItem) { + height = item.getCurrentZ(); + } else { + height = this.room.getStackHeight(targetTile.getX(), targetTile.getY(), false, item); + for (RoomTile til : occupiedTiles) { + double sHeight = this.room.getStackHeight(til.getX(), til.getY(), false, item); + if (sHeight > height) { + height = sHeight; + } + } + } + + if (height > Room.MAXIMUM_FURNI_HEIGHT) { + return FurnitureMovementError.CANT_STACK; + } + + if (height < this.room.getLayout().getHeightAtSquare(targetTile.getX(), targetTile.getY())) { + return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor + } + + if (Emulator.getPluginManager().isRegistered(FurnitureBuildheightEvent.class, true)) { + FurnitureBuildheightEvent event = Emulator.getPluginManager().fireEvent(new FurnitureBuildheightEvent(item, actor, 0.00, height)); + if (event.hasChangedHeight()) { + height = event.getUpdatedHeight(); + } + } + + if (height > Room.MAXIMUM_FURNI_HEIGHT) { + return FurnitureMovementError.CANT_STACK; + } + + if (height < this.room.getLayout().getHeightAtSquare(targetTile.getX(), targetTile.getY())) { + return FurnitureMovementError.CANT_STACK; //prevent furni going under the floor + } + + item.setCurrentPosition(targetTile); + item.setCurrentZ(height); + + if (magicTile) { + item.setCurrentZ(targetTile.getZ()); + item.setExtraData(String.valueOf(item.getCurrentZ() * 100)); + } + + if (item.getCurrentZ() > Room.MAXIMUM_FURNI_HEIGHT) { + item.setCurrentZ(Room.MAXIMUM_FURNI_HEIGHT); + } + + //Update Furniture + item.onMove(this.room, oldLocation, targetTile); + item.setSqlUpdateNeeded(true); + + Emulator.getThreading().run(item); + + if (sendUpdates) { + this.room.sendComposer(new ObjectUpdateMessageComposer(item).compose()); + } + + //Update old & new tiles + occupiedTiles.removeAll(oldOccupiedTiles); + occupiedTiles.addAll(oldOccupiedTiles); + + this.room.updateTiles(occupiedTiles); + + //Update Habbos at old position + for (RoomTile t : occupiedTiles) { + this.room.getRoomUnitManager().updateHabbosAt(t); + this.room.getRoomUnitManager().updateBotsAt(t); + } + + if (Emulator.getConfig().getBoolean("wired.place.under", false)) { + for (RoomTile t : newOccupiedTiles) { + for (Habbo h : this.room.getRoomUnitManager().getHabbosAt(t)) { + try { + item.onWalkOn(h.getRoomUnit(), this.room, null); + } catch (Exception ignored) { + + } + } + } + } + + return FurnitureMovementError.NONE; + } + + public void pickUpItem(RoomItem roomItem, Habbo picker) { + if (roomItem == null) { + return; + } + + if (Emulator.getPluginManager().isRegistered(FurniturePickedUpEvent.class, true)) { + Event furniturePickedUpEvent = new FurniturePickedUpEvent(roomItem, picker); + Emulator.getPluginManager().fireEvent(furniturePickedUpEvent); + + if (furniturePickedUpEvent.isCancelled()) + return; + } + + this.removeRoomItem(roomItem); + roomItem.onPickUp(this.room); + //Deprecated + roomItem.setRoomId(0); + roomItem.setRoom(null); + roomItem.setSqlUpdateNeeded(true); + + if (roomItem.getBaseItem().getType() == FurnitureType.FLOOR) { + this.room.sendComposer(new RemoveFloorItemComposer(roomItem).compose()); + + THashSet updatedTiles = new THashSet<>(); + Rectangle rectangle = RoomLayout.getRectangle(roomItem.getCurrentPosition().getX(), roomItem.getCurrentPosition().getY(), roomItem.getBaseItem().getWidth(), roomItem.getBaseItem().getLength(), roomItem.getRotation()); + + for (short x = (short) rectangle.x; x < rectangle.x + rectangle.getWidth(); x++) { + for (short y = (short) rectangle.y; y < rectangle.y + rectangle.getHeight(); y++) { + double stackHeight = this.room.getStackHeight(x, y, false); + RoomTile tile = this.room.getLayout().getTile(x, y); + + if (tile != null) { + tile.setStackHeight(stackHeight); + updatedTiles.add(tile); + } + } + } + + this.room.sendComposer(new HeightMapUpdateMessageComposer(this.room, updatedTiles).compose()); + this.room.updateTiles(updatedTiles); + + updatedTiles.forEach(tile -> { + this.room.getRoomUnitManager().updateHabbosAt(tile); + this.room.getRoomUnitManager().updateBotsAt(tile); + }); + } else if (roomItem.getBaseItem().getType() == FurnitureType.WALL) { + this.room.sendComposer(new ItemRemoveMessageComposer(roomItem).compose()); + } + + Habbo habbo; + habbo = picker != null && picker.getHabboInfo().getId() == roomItem.getId() ? (picker) : (Emulator.getGameServer().getGameClientManager().getHabbo(roomItem.getOwnerInfo().getId())); + if (habbo != null) { + habbo.getInventory().getItemsComponent().addItem(roomItem); + habbo.getClient().sendResponse(new UnseenItemsComposer(roomItem)); + habbo.getClient().sendResponse(new FurniListInvalidateComposer()); + } + Emulator.getThreading().run(roomItem); + } + + public void ejectUserItem(RoomItem item) { + this.pickUpItem(item, null); + } + + public void ejectUserFurni(int userId) { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); + HashSet userItems = this.currentItems.values().stream().filter(item -> item.getOwnerInfo().getId() == userId).collect(Collectors.toCollection(HashSet::new)); + + if (habbo != null) { + habbo.getInventory().getItemsComponent().addItems(userItems); + habbo.getClient().sendResponse(new UnseenItemsComposer(userItems)); + } + + for (RoomItem i : userItems) { + this.pickUpItem(i, null); + } + } + + public void ejectAllFurni() { + this.ejectAllFurni(null); + } + + public void ejectAllFurni(Habbo habbo) { + ConcurrentHashMap> userItemsMap = new ConcurrentHashMap<>(); + + for (RoomItem item : this.currentItems.values()) { + if ((habbo != null && item.getOwnerInfo().getId() == habbo.getHabboInfo().getId()) || item instanceof InteractionPostIt) { + continue; + } + + userItemsMap.computeIfAbsent(item.getOwnerInfo().getId(), k -> new HashSet<>()).add(item); + } + + for (Map.Entry> entrySet : userItemsMap.entrySet()) { + for (RoomItem i : entrySet.getValue()) { + this.pickUpItem(i, null); + } + + Habbo user = Emulator.getGameEnvironment().getHabboManager().getHabbo(entrySet.getKey()); + + if (user != null) { + user.getInventory().getItemsComponent().addItems(entrySet.getValue()); + user.getClient().sendResponse(new UnseenItemsComposer(entrySet.getValue())); + } + } + } + + public FurnitureMovementError furnitureFitsAt(RoomTile targetTile, RoomItem item, int rotation, boolean checkForUnits) { + RoomLayout layout = this.room.getLayout(); + boolean wiredPlaceUnder = Emulator.getConfig().getBoolean("wired.place.under", false); + Item baseItem = item.getBaseItem(); + + if (!layout.fitsOnMap(targetTile, baseItem.getWidth(), baseItem.getLength(), rotation)) { + return FurnitureMovementError.INVALID_MOVE; + } + + if (item instanceof InteractionStackHelper) { + return FurnitureMovementError.NONE; + } + + THashSet occupiedTiles = this.room.getLayout().getTilesAt(targetTile, baseItem.getWidth(), baseItem.getLength(), rotation); + + for (RoomTile occupiedTile : occupiedTiles) { + if (occupiedTile.getState() == RoomTileState.INVALID) { + return FurnitureMovementError.INVALID_MOVE; + } + + 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)) return FurnitureMovementError.TILE_HAS_BOTS; + if (checkForUnits && this.room.getRoomUnitManager().hasPetsAt(occupiedTile)) return FurnitureMovementError.TILE_HAS_PETS; + } + } + + Optional stackHelper = this.getItemsAt(targetTile).stream().filter(InteractionStackHelper.class::isInstance).findAny(); + + List>> tileFurniList = new ArrayList<>(); + + for (RoomTile t : occupiedTiles) { + tileFurniList.add(Pair.create(t, this.getItemsAt(t))); + + RoomItem topItem = this.getTopItemAt(t.getX(), t.getY(), item); + if (topItem != null && !topItem.getBaseItem().allowStack() && !t.getAllowStack()) { + return FurnitureMovementError.CANT_STACK; + } + + if ((stackHelper.isPresent() && baseItem.getInteractionType().getType() == InteractionWater.class) || topItem != null && (topItem.getBaseItem().getInteractionType().getType() == InteractionWater.class && (baseItem.getInteractionType().getType() == InteractionWater.class || baseItem.getInteractionType().getType() != InteractionWaterItem.class))) { + return FurnitureMovementError.CANT_STACK; + } + } + + if (!item.canStackAt(tileFurniList)) { + return FurnitureMovementError.CANT_STACK; + } + + return FurnitureMovementError.NONE; + } + + @Deprecated + public THashSet getItemsAt(int x, int y) { + RoomTile tile = this.room.getLayout().getTile((short) x, (short) y); + + if (tile != null) { + return this.getItemsAt(tile); + } + + return new THashSet<>(0); + } + + public THashSet getItemsAt(RoomTile tile) { + return getItemsAt(tile, false); + } + + public THashSet getItemsAt(RoomTile tile, boolean returnOnFirst) { + THashSet items = new THashSet<>(0); + + if (tile == null) { + return items; + } + + if (this.room.isLoaded()) { + THashSet cachedItems = this.room.tileCache.get(tile); + if (cachedItems != null) + return cachedItems; + } + + Iterator iterator = this.currentItems.values().iterator(); + + for (int i = this.currentItems.size(); i-- > 0; ) { + RoomItem item; + try { + item = iterator.next(); + } catch (Exception e) { + break; + } + + if (item == null || item.getBaseItem().getType() != FurnitureType.FLOOR) { + continue; + } + + int width, length; + + if (item.getRotation() != 2 && item.getRotation() != 6) { + width = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1; + length = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1; + } else { + width = item.getBaseItem().getLength() > 0 ? item.getBaseItem().getLength() : 1; + length = item.getBaseItem().getWidth() > 0 ? item.getBaseItem().getWidth() : 1; + } + + if (!(tile.getX() >= item.getCurrentPosition().getX() && tile.getX() <= item.getCurrentPosition().getX() + width - 1 && tile.getY() >= item.getCurrentPosition().getY() && tile.getY() <= item.getCurrentPosition().getY() + length - 1)) + continue; + + items.add(item); + + if (returnOnFirst) { + return items; + } + } + + if (this.room.isLoaded()) { + this.room.tileCache.put(tile, items); + } + + return items; + } + + public THashSet getItemsAt(int x, int y, double minZ) { + THashSet items = new THashSet<>(); + + for (RoomItem item : this.getItemsAt(x, y)) { + if (item.getCurrentZ() < minZ) + continue; + + items.add(item); + } + return items; + } + + public THashSet getItemsAt(Class type, int x, int y) { + THashSet items = new THashSet<>(); + + for (RoomItem item : this.getItemsAt(x, y)) { + if (!item.getClass().equals(type)) + continue; + + items.add(item); + } + return items; + } + + public boolean hasItemsAt(int x, int y) { + RoomTile tile = this.room.getLayout().getTile((short) x, (short) y); + + if (tile == null) + return false; + + return !this.getItemsAt(tile, true).isEmpty(); + } + + public RoomItem getTopItemAt(RoomTile tile) { + if(tile == null) { + return null; + } + + return this.getTopItemAt(tile.getX(), tile.getY(), null); + } + + public RoomItem getTopItemAt(int x, int y) { + return this.getTopItemAt(x, y, null); + } + + public RoomItem getTopItemAt(int x, int y, RoomItem exclude) { + RoomTile tile = this.room.getLayout().getTile((short) x, (short) y); + + if (tile == null) + return null; + + RoomItem highestItem = null; + + for (RoomItem item : this.getItemsAt(x, y)) { + if (exclude != null && exclude == item) + continue; + + if (highestItem != null) { + if (highestItem.getCurrentZ() + Item.getCurrentHeight(highestItem) > item.getCurrentZ() + Item.getCurrentHeight(item)) + continue; + } + + highestItem = item; + } + + return highestItem; + } + + public RoomItem getTopItemAt(THashSet tiles, RoomItem exclude) { + RoomItem highestItem = null; + for (RoomTile tile : tiles) { + + if (tile == null) + continue; + + for (RoomItem item : this.getItemsAt(tile.getX(), tile.getY())) { + if (exclude != null && exclude == item) + continue; + + if (highestItem != null) { + if (highestItem.getCurrentZ() + Item.getCurrentHeight(highestItem) > item.getCurrentZ() + Item.getCurrentHeight(item)) + continue; + } + + highestItem = item; + } + } + + return highestItem; + } + + public double getTopHeightAt(int x, int y) { + RoomItem item = this.getTopItemAt(x, y); + if (item != null) { + return (item.getCurrentZ() + Item.getCurrentHeight(item) - (item.getBaseItem().allowSit() ? 1 : 0)); + } else { + return this.room.getLayout().getHeightAtSquare(x, y); + } + } + + public RoomItem getLowestChair(RoomTile tile) { + RoomItem lowestChair = null; + + THashSet items = this.getItemsAt(tile); + if (items != null && !items.isEmpty()) { + for (RoomItem item : items) { + + if (!item.getBaseItem().allowSit()) + continue; + + if (lowestChair != null) { + if (lowestChair.getCurrentZ() < item.getCurrentZ()) continue; + } + + lowestChair = item; + } + } + + return lowestChair; + } + + public RoomItem getTallestChair(RoomTile tile) { + RoomItem lowestChair = null; + + THashSet items = this.getItemsAt(tile); + if (items != null && !items.isEmpty()) { + for (RoomItem item : items) { + + if (!item.getBaseItem().allowSit()) + continue; + + if (lowestChair != null) { + if (lowestChair.getCurrentZ() + Item.getCurrentHeight(lowestChair) > item.getCurrentZ() + Item.getCurrentHeight(item)) + continue; + } + + lowestChair = item; + } + } + + return lowestChair; + } + + public void addCycleTask(ICycleable task) { + this.cycleTasks.add(task); + } + + public void removeCycleTask(ICycleable task) { + this.cycleTasks.remove(task); + } + + public void addBanzaiTeleporter(InteractionBattleBanzaiTeleporter item) { + this.banzaiTeleporters.put(item.getId(), item); + } + + public void removeBanzaiTeleporter(InteractionBattleBanzaiTeleporter item) { + this.banzaiTeleporters.remove(item.getId()); + } + + public void addRoller(InteractionRoller item) { + synchronized (this.rollers) { + this.rollers.put(item.getId(), item); + } + } + + public void removeRoller(InteractionRoller roller) { + synchronized (this.rollers) { + this.rollers.remove(roller.getId()); + } + } + + public void addGameScoreboard(InteractionGameScoreboard scoreboard) { + this.gameScoreboards.put(scoreboard.getId(), scoreboard); + } + + public void removeScoreboard(InteractionGameScoreboard scoreboard) { + this.gameScoreboards.remove(scoreboard.getId()); + } + + public void addGameGate(InteractionGameGate gameGate) { + this.gameGates.put(gameGate.getId(), gameGate); + } + + public void removeGameGate(InteractionGameGate gameGate) { + this.gameGates.remove(gameGate.getId()); + } + + public void addGameTimer(InteractionGameTimer gameTimer) { + this.gameTimers.put(gameTimer.getId(), gameTimer); + } + + public void removeGameTimer(InteractionGameTimer gameTimer) { + this.gameTimers.remove(gameTimer.getId()); + } + + public void addFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { + this.freezeExitTile.put(freezeExitTile.getId(), freezeExitTile); + } + + public void removeFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { + this.freezeExitTile.remove(freezeExitTile.getId()); + } + + public void addNest(InteractionNest item) { + this.nests.put(item.getId(), item); + } + + public void removeNest(InteractionNest item) { + this.nests.remove(item.getId()); + } + + public void addPetDrink(InteractionPetDrink item) { + this.petDrinks.put(item.getId(), item); + } + + public void removePetDrink(InteractionPetDrink item) { + this.petDrinks.remove(item.getId()); + } + + public void addPetFood(InteractionPetFood item) { + this.petFoods.put(item.getId(), item); + } + + public void removePetFood(InteractionPetFood petFood) { + this.petFoods.remove(petFood.getId()); + } + + public InteractionPetToy getPetToy(int itemId) { + return this.petToys.get(itemId); + } + + public void addPetToy(InteractionPetToy item) { + this.petToys.put(item.getId(), item); + } + + public void removePetToy(InteractionPetToy petToy) { + this.petToys.remove(petToy.getId()); + } + + public void addUndefined(RoomItem item) { + synchronized (this.undefinedSpecials) { + this.undefinedSpecials.put(item.getId(), item); + } + } + + public void removeUndefined(RoomItem item) { + synchronized (this.undefinedSpecials) { + this.undefinedSpecials.remove(item.getId()); + } + } + + private void sortItem(RoomItem item) { + if(item.getBaseItem().getType().equals(FurnitureType.FLOOR)) { + this.floorItems.put(item.getId(), item); + this.sortFloorItem(item); + } else if(item.getBaseItem().getType().equals(FurnitureType.WALL)) { + this.wallItems.put(item.getId(), item); + } + } + + private void sortFloorItem(RoomItem item) { + if (item instanceof ICycleable) { + this.addCycleTask((ICycleable) item); + } + + if(item instanceof InteractionWired wired) { + this.wiredManager.addWired(wired); + } else if (item instanceof InteractionBattleBanzaiTeleporter interactionBattleBanzaiTeleporter) { + this.addBanzaiTeleporter(interactionBattleBanzaiTeleporter); + } else if (item instanceof InteractionRoller interactionRoller) { + this.addRoller(interactionRoller); + } else if (item instanceof InteractionGameScoreboard interactionGameScoreboard) { + this.addGameScoreboard(interactionGameScoreboard); + } else if (item instanceof InteractionGameGate interactionGameGate) { + this.addGameGate(interactionGameGate); + } else if (item instanceof InteractionGameTimer interactionGameTimer) { + this.addGameTimer(interactionGameTimer); + } else if (item instanceof InteractionFreezeExitTile interactionFreezeExitTile) { + this.addFreezeExitTile(interactionFreezeExitTile); + } else if (item instanceof InteractionNest interactionNest) { + this.addNest(interactionNest); + } else if (item instanceof InteractionPetDrink interactionPetDrink) { + this.addPetDrink(interactionPetDrink); + } else if (item instanceof InteractionPetFood interactionPetFood) { + this.addPetFood(interactionPetFood); + } else if (item instanceof InteractionPetToy interactionPetToy) { + this.addPetToy(interactionPetToy); + } else if (item instanceof InteractionPetTree) { + this.addUndefined(item); + } else if (item instanceof InteractionPetTrampoline) { + this.addUndefined(item); + } else if (item instanceof InteractionMoodLight) { + this.addUndefined(item); + } else if (item instanceof InteractionPyramid) { + this.addUndefined(item); + } else if (item instanceof InteractionMusicDisc) { + this.addUndefined(item); + } else if (item instanceof InteractionBattleBanzaiSphere) { + this.addUndefined(item); + } else if (item instanceof InteractionTalkingFurniture) { + this.addUndefined(item); + } else if (item instanceof InteractionWater) { + this.addUndefined(item); + } else if (item instanceof InteractionWaterItem) { + this.addUndefined(item); + } else if (item instanceof InteractionMuteArea) { + this.addUndefined(item); + } else if (item instanceof InteractionBuildArea) { + this.addUndefined(item); + } else if (item instanceof InteractionTagPole) { + this.addUndefined(item); + } else if (item instanceof InteractionTagField) { + this.addUndefined(item); + } else if (item instanceof InteractionJukeBox) { + this.addUndefined(item); + } else if (item instanceof InteractionPetBreedingNest) { + this.addUndefined(item); + } else if (item instanceof InteractionBlackHole) { + this.addUndefined(item); + } else if (item instanceof InteractionWiredHighscore) { + this.addUndefined(item); + } else if (item instanceof InteractionStickyPole) { + this.addUndefined(item); + } else if (item instanceof WiredBlob) { + this.addUndefined(item); + } else if (item instanceof InteractionTent) { + this.addUndefined(item); + } else if (item instanceof InteractionSnowboardSlope) { + this.addUndefined(item); + } else if (item instanceof InteractionFireworks) { + this.addUndefined(item); + } + } + + public void dispose() { + this.currentItems.values().parallelStream() + .filter(roomItem1 -> roomItem1.isSqlUpdateNeeded()) + .forEach(roomItem -> { + roomItem.run(); + this.currentItems.remove(roomItem.getId()); + }); + + this.floorItems.clear(); + this.wallItems.clear(); + + this.currentItems.clear(); + } +} 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 379fa44b..c147095b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayout.java @@ -1,14 +1,18 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; +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 gnu.trove.set.hash.THashSet; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import java.awt.*; import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.*; import java.util.List; +import java.util.*; @Slf4j public class RoomLayout { @@ -17,16 +21,30 @@ public class RoomLayout { public static double MAXIMUM_STEP_HEIGHT = 1.1; public static boolean ALLOW_FALLING = true; public boolean CANMOVEDIAGONALY = true; + @Getter private String name; + @Getter + @Setter private short doorX; + @Getter + @Setter private short doorY; + @Getter private short doorZ; + @Getter + @Setter private int doorDirection; + @Getter + @Setter private String heightmap; + @Getter private int mapSize; + @Getter private int mapSizeX; + @Getter private int mapSizeY; private RoomTile[][] roomTiles; + @Getter private RoomTile doorTile; private final Room room; @@ -143,62 +161,6 @@ public class RoomLayout { } } - public String getName() { - return this.name; - } - - public short getDoorX() { - return this.doorX; - } - - public void setDoorX(short doorX) { - this.doorX = doorX; - } - - public short getDoorY() { - return this.doorY; - } - - public void setDoorY(short doorY) { - this.doorY = doorY; - } - - public int getDoorZ() { - return this.doorZ; - } - - public RoomTile getDoorTile() { - return this.doorTile; - } - - public int getDoorDirection() { - return this.doorDirection; - } - - public void setDoorDirection(int doorDirection) { - this.doorDirection = doorDirection; - } - - public String getHeightmap() { - return this.heightmap; - } - - public void setHeightmap(String heightMap) { - this.heightmap = heightMap; - } - - public int getMapSize() { - return this.mapSize; - } - - public int getMapSizeX() { - return this.mapSizeX; - } - - public int getMapSizeY() { - return this.mapSizeY; - } - public short getHeightAtSquare(int x, int y) { if (x < 0 || y < 0 || @@ -241,8 +203,19 @@ public class RoomLayout { return !(x < 0 || y < 0 || x >= this.getMapSizeX() || y >= this.getMapSizeY()); } + public boolean tileWalkable(RoomTile tile) { + return this.tileWalkable(tile.getX(), tile.getY()); + } + public boolean tileWalkable(short x, short y) { - return this.tileExists(x, y) && this.roomTiles[x][y].getState() == RoomTileState.OPEN && this.roomTiles[x][y].isWalkable(); + boolean walkable = false; + + if(this.tileExists(x, y)) { + RoomTile tile = this.getTile(x, y); + walkable = tile.isWalkable() && (this.room.getRoomUnitManager().areRoomUnitsAt(tile) && !this.room.getRoomInfo().isAllowWalkthrough()); + } + + return walkable; } public boolean isVoidTile(short x, short y) { @@ -304,7 +277,13 @@ public class RoomLayout { continue; } - if (currentAdj.hasUnits() && doorTile.distance(currentAdj) > 2 && (!isWalktroughRetry || !this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) { + RoomUnit exception = null; + + if(roomUnit instanceof RoomAvatar roomAvatar && roomAvatar.isRiding()) { + exception = roomAvatar.getRidingPet().getRoomUnit(); + } + + if (this.room.getRoomUnitManager().areRoomUnitsAt(currentAdj, exception) && doorTile.distance(currentAdj) > 2 && (!isWalktroughRetry || !this.room.getRoomInfo().isAllowWalkthrough() || currentAdj.equals(goalLocation))) { closedList.add(currentAdj); openList.remove(currentAdj); continue; @@ -322,7 +301,7 @@ public class RoomLayout { } } - if (this.room.isAllowWalkthrough() && !isWalktroughRetry) { + if (this.room.getRoomInfo().isAllowWalkthrough() && !isWalktroughRetry) { return this.findPath(oldTile, newTile, goalLocation, roomUnit, true); } @@ -588,26 +567,33 @@ public class RoomLayout { return availableTiles; } - public RoomTile getRandomWalkableTilesAround(RoomUnit roomUnit, RoomTile tile, Room room, int radius) { - if(!this.tileExists(tile.getX(), tile.getY())) { - tile = this.getTile(roomUnit.getX(), roomUnit.getY()); - room.getBot(roomUnit).needsUpdate(true); - } + public RoomTile getRandomWalkableTilesAround(RoomBot roomBot, RoomTile tile, int radius) { + if(tile == null || !this.tileExists(tile.getX(), tile.getY()) || tile.getState().equals(RoomTileState.INVALID)) { + roomBot.setCanWalk(false); + return null; + } List newTiles = new ArrayList<>(); int minX = Math.max(0, tile.getX() - radius); int minY = Math.max(0, tile.getY() - radius); - int maxX = Math.min(room.getLayout().getMapSizeX(), tile.getX() + radius); - int maxY = Math.min(room.getLayout().getMapSizeY(), tile.getY() + radius); + int maxX = Math.min(this.room.getLayout().getMapSizeX(), tile.getX() + radius); + int maxY = Math.min(this.room.getLayout().getMapSizeY(), tile.getY() + radius); for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { - RoomTile tile2 = room.getLayout().getTile((short) x, (short) y); - if (tile2 != null && tile.getState() != RoomTileState.BLOCKED && tile.getState() != RoomTileState.INVALID) + RoomTile tile2 = this.room.getLayout().getTile((short) x, (short) y); + if (tile2 != null && tile2.getState() != RoomTileState.BLOCKED && tile2.getState() != RoomTileState.INVALID) { newTiles.add(tile2); + } } } + + if(newTiles.isEmpty()) { + log.debug("No Random tiles found."); + return null; + } + Collections.shuffle(newTiles); return newTiles.get(0); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayoutManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayoutManager.java new file mode 100644 index 00000000..c6a4c36d --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomLayoutManager.java @@ -0,0 +1,4 @@ +package com.eu.habbo.habbohotel.rooms; + +public class RoomLayoutManager { +} 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 17bbb7e8..9fb80e42 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomManager.java @@ -22,7 +22,13 @@ import com.eu.habbo.habbohotel.pets.PetData; import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.polls.Poll; import com.eu.habbo.habbohotel.polls.PollManager; -import com.eu.habbo.habbohotel.users.*; +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.RoomUnitType; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; +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.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.incoming.users.NewUserExperienceScriptProceedEvent; @@ -108,7 +114,7 @@ public class RoomManager { public CustomRoomLayout loadCustomLayout(Room room) { CustomRoomLayout layout = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_models_custom WHERE id = ? LIMIT 1")) { - statement.setInt(1, room.getId()); + statement.setInt(1, room.getRoomInfo().getId()); try (ResultSet set = statement.executeQuery()) { if (set.next()) { layout = new CustomRoomLayout(set, room); @@ -212,10 +218,10 @@ public class RoomManager { return rooms; } - public List getActiveRooms(int categoryId) { + public List getActiveRoomsByCategoryId(int categoryId) { List rooms = new ArrayList<>(); for (Room room : this.activeRooms.values()) { - if (categoryId == room.getCategory() || categoryId == -1) + if (categoryId == room.getRoomInfo().getCategory().getId() || categoryId == -1) rooms.add(room); } Collections.sort(rooms); @@ -226,10 +232,13 @@ public class RoomManager { public ArrayList getRoomsForHabbo(Habbo habbo) { ArrayList rooms = new ArrayList<>(); for (Room room : this.activeRooms.values()) { - if (room.getOwnerId() == habbo.getHabboInfo().getId()) + if (room.getRoomInfo().isRoomOwner(habbo)) { rooms.add(room); + } } + rooms.sort(Room.SORT_ID); + return rooms; } @@ -245,7 +254,7 @@ public class RoomManager { statement.setString(1, username); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - rooms.add(this.loadRoom(set.getInt("id"))); + rooms.add(this.getRoom(set.getInt("id"))); } } } catch (SQLException e) { @@ -255,15 +264,15 @@ public class RoomManager { return rooms; } - public Room loadRoom(int id) { - return loadRoom(id, false); + public Room getRoom(int roomId) { + return getRoom(roomId, false); } - public Room loadRoom(int id, boolean loadData) { + public Room getRoom(int id, boolean loadData) { Room room = null; if (this.activeRooms.containsKey(id)) { - room = this.activeRooms.get(id); + room = this.getActiveRoomById(id); if (loadData && (room.isPreLoaded() && !room.isLoaded())) { room.loadData(); @@ -285,7 +294,7 @@ public class RoomManager { } if (room != null) { - this.activeRooms.put(room.getId(), room); + this.activeRooms.put(room.getRoomInfo().getId(), room); } } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); @@ -295,7 +304,7 @@ public class RoomManager { } - public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int usersMax, int categoryId, int tradeType) { + public Room createRoom(int ownerId, String ownerName, String name, String description, String modelName, int maxUsers, int categoryId, int tradeType) { Room room = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement( @@ -305,13 +314,13 @@ public class RoomManager { statement.setString(3, name); statement.setString(4, description); statement.setString(5, modelName); - statement.setInt(6, usersMax); + statement.setInt(6, maxUsers); statement.setInt(7, categoryId); statement.setInt(8, tradeType); statement.execute(); try (ResultSet set = statement.getGeneratedKeys()) { if (set.next()) - room = this.loadRoom(set.getInt(1)); + room = this.getRoom(set.getInt(1)); } } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); @@ -320,12 +329,9 @@ public class RoomManager { return room; } - public Room createRoomForHabbo(Habbo habbo, String name, String description, String modelName, int usersMax, int categoryId, int tradeType) { Room room = this.createRoom(habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername(), name, description, modelName, usersMax, categoryId, tradeType); - Emulator.getPluginManager().fireEvent(new NavigatorRoomCreatedEvent(habbo, room)); - return room; } @@ -346,8 +352,12 @@ public class RoomManager { public void unloadRoomsForHabbo(Habbo habbo) { List roomsToDispose = new ArrayList<>(); for (Room room : this.activeRooms.values()) { - if (!room.isPublicRoom() && !room.isStaffPromotedRoom() && room.getOwnerId() == habbo.getHabboInfo().getId() && room.getUserCount() == 0 && (this.roomCategories.get(room.getCategory()) == null || !this.roomCategories.get(room.getCategory()).isPublic())) { - roomsToDispose.add(room); + if (!room.getRoomInfo().isPublicRoom()) { + if (!room.getRoomInfo().isStaffPicked() && room.getRoomInfo().getOwnerInfo().getId() == habbo.getHabboInfo().getId()) { + if (room.getRoomUnitManager().getRoomHabbosCount() == 0 && (this.roomCategories.get(room.getRoomInfo().getCategory().getId()) == null || !this.roomCategories.get(room.getRoomInfo().getCategory().getId()).isPublic())) { + roomsToDispose.add(room); + } + } } } @@ -356,22 +366,24 @@ public class RoomManager { continue; room.dispose(); - this.activeRooms.remove(room.getId()); + this.activeRooms.remove(room.getRoomInfo().getId()); } } public void clearInactiveRooms() { THashSet roomsToDispose = new THashSet<>(); for (Room room : this.activeRooms.values()) { - if (!room.isPublicRoom() && !room.isStaffPromotedRoom() && !Emulator.getGameServer().getGameClientManager().containsHabbo(room.getOwnerId()) && room.isPreLoaded()) { - roomsToDispose.add(room); + if (!room.getRoomInfo().isPublicRoom()) { + if (!room.getRoomInfo().isStaffPicked() && !Emulator.getGameServer().getGameClientManager().containsHabbo(room.getRoomInfo().getOwnerInfo().getId()) && room.isPreLoaded()) { + roomsToDispose.add(room); + } } } for (Room room : roomsToDispose) { room.dispose(); - if (room.getUserCount() == 0) - this.activeRooms.remove(room.getId()); + if (room.getRoomUnitManager().getRoomHabbosCount() == 0) + this.activeRooms.remove(room.getRoomInfo().getId()); } } @@ -395,32 +407,28 @@ public class RoomManager { return layout; } - public void unloadRoom(Room room) { - room.dispose(); - } - public void uncacheRoom(Room room) { - this.activeRooms.remove(room.getId()); + this.activeRooms.remove(room.getRoomInfo().getId()); } public void voteForRoom(Habbo habbo, Room room) { - if (habbo.getHabboInfo().getCurrentRoom() != null && room != null && habbo.getHabboInfo().getCurrentRoom() == room) { + if (habbo.getRoomUnit().getRoom() != null && room != null && habbo.getRoomUnit().getRoom() == room) { if (this.hasVotedForRoom(habbo, room)) return; UserVoteRoomEvent event = new UserVoteRoomEvent(room, habbo); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) return; - room.setScore(room.getScore() + 1); + room.getRoomInfo().setScore(room.getRoomInfo().getScore() + 1); room.setNeedsUpdate(true); - habbo.getHabboStats().getVotedRooms().push(room.getId()); - for (Habbo h : room.getHabbos()) { - h.getClient().sendResponse(new RoomRatingComposer(room.getScore(), !this.hasVotedForRoom(h, room))); + habbo.getHabboStats().getVotedRooms().push(room.getRoomInfo().getId()); + for (Habbo h : room.getRoomUnitManager().getCurrentHabbos().values()) { + h.getClient().sendResponse(new RoomRatingComposer(room.getRoomInfo().getScore(), !this.hasVotedForRoom(h, room))); } try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_votes VALUES (?, ?)")) { statement.setInt(1, habbo.getHabboInfo().getId()); - statement.setInt(2, room.getId()); + statement.setInt(2, room.getRoomInfo().getId()); statement.execute(); } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); @@ -429,18 +437,18 @@ public class RoomManager { } boolean hasVotedForRoom(Habbo habbo, Room room) { - if (room.getOwnerId() == habbo.getHabboInfo().getId()) + if (room.getRoomInfo().getOwnerInfo().getId() == habbo.getHabboInfo().getId()) return true; for (int i : habbo.getHabboStats().getVotedRooms().toArray()) { - if (i == room.getId()) + if (i == room.getRoomInfo().getId()) return true; } return false; } - public Room getRoom(int roomId) { + public Room getActiveRoomById(int roomId) { return this.activeRooms.get(roomId); } @@ -452,188 +460,166 @@ public class RoomManager { return this.activeRooms.size(); } - public void enterRoom(Habbo habbo, int roomId, String password) { - this.enterRoom(habbo, roomId, password, false, null); + public void enterRoom(Habbo habbo, int roomId, String password, boolean forceEnter) { + this.enterRoom(habbo, roomId, password, forceEnter, null); } - public void enterRoom(Habbo habbo, int roomId, String password, boolean overrideChecks) { - this.enterRoom(habbo, roomId, password, overrideChecks, null); - } + public void enterRoom(Habbo habbo, int roomId, String password, boolean forceEnter, RoomTile spawnLocation) { + Room room = this.getRoom(roomId, true); - public void enterRoom(Habbo habbo, int roomId, String password, boolean overrideChecks, RoomTile doorLocation) { - Room room = this.loadRoom(roomId, true); - - if (room == null) - return; - - if (habbo.getHabboInfo().getLoadingRoom() != 0 && room.getId() != habbo.getHabboInfo().getLoadingRoom()) { - habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); - habbo.getHabboInfo().setLoadingRoom(0); + if (room == null) { + log.error("User (ID: {}) is trying to enter a corrupted room (ID: {})", habbo.getHabboInfo().getId(), roomId); return; } - if (Emulator.getPluginManager().fireEvent(new UserEnterRoomEvent(habbo, room)).isCancelled() - && habbo.getHabboInfo().getCurrentRoom() == null) { + if (habbo.getRoomUnit().isLoadingRoom() && room.getRoomInfo().getId() != habbo.getRoomUnit().getLoadingRoom().getRoomInfo().getId()) { habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); - habbo.getHabboInfo().setLoadingRoom(0); + habbo.getRoomUnit().setLoadingRoom(null); return; } - if (room.isBanned(habbo) && !habbo.hasRight(Permission.ACC_ANYROOMOWNER) && !habbo.hasRight(Permission.ACC_ENTERANYROOM)) { + //Fire Plugin Event + if (Emulator.getPluginManager().fireEvent(new UserEnterRoomEvent(habbo, room)).isCancelled() && habbo.getRoomUnit().getRoom() == null) { + habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); + habbo.getRoomUnit().setLoadingRoom(null); + return; + } + + //If Habbo is banned AND doesn't have Permissions can't enter to room + if (room.isBanned(habbo) && !room.getRoomInfo().isRoomOwner(habbo) && !habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM)) { habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_BANNED)); return; } + //If room is full AND user doesn't have Permissions can't enter to room + if (room.getRoomUnitManager().getRoomHabbosCount() >= room.getRoomInfo().getMaxUsers() && !room.getRoomRightsManager().hasRights(habbo) && !habbo.hasPermissionRight(Permission.ACC_FULLROOMS)) { + habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_GUESTROOM_FULL)); + return; + } + if (habbo.getHabboInfo().getRoomQueueId() != roomId) { - Room queRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room queRoom = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (queRoom != null) { queRoom.removeFromQueue(habbo); } } - if (overrideChecks || - room.isOwner(habbo) || - room.getState() == RoomState.OPEN || - habbo.hasRight(Permission.ACC_ANYROOMOWNER) || - habbo.hasRight(Permission.ACC_ENTERANYROOM) || - room.hasRights(habbo) || - (room.getState().equals(RoomState.INVISIBLE) && room.hasRights(habbo)) || - (room.hasGuild() && room.getGuildRightLevel(habbo).isGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { - this.openRoom(habbo, room, doorLocation); - } else if (room.getState() == RoomState.LOCKED) { - boolean rightsFound = false; + /** + * If override checks open room + * If habbo is owner open room + * If room state is 'OPEN' open room + * If habbo has permissions open room + * If habbo has guild rights open room + */ + if (forceEnter || room.getRoomInfo().isRoomOwner(habbo) || room.getRoomInfo().getState() == RoomState.OPEN || habbo.hasPermissionRight(Permission.ACC_ENTERANYROOM) || room.getRoomRightsManager().hasRights(habbo) || (room.getRoomInfo().getState().equals(RoomState.INVISIBLE) && room.getRoomRightsManager().hasRights(habbo)) || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(habbo).isGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { + this.openRoom(habbo, room, spawnLocation); + } else if (room.getRoomInfo().getState() == RoomState.LOCKED) { + boolean habbosWithRights = false; - synchronized (room.roomUnitLock) { - for (Habbo current : room.getHabbos()) { - if (room.hasRights(current) || current.getHabboInfo().getId() == room.getOwnerId() || (room.hasGuild() && room.getGuildRightLevel(current).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { + synchronized (room.getRoomUnitManager().roomUnitLock) { + 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())); - rightsFound = true; + habbosWithRights = true; } } } - if (!rightsFound) { + if (!habbosWithRights) { habbo.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); - habbo.getHabboInfo().setLoadingRoom(0); + habbo.getRoomUnit().setLoadingRoom(null); return; } habbo.getHabboInfo().setRoomQueueId(roomId); habbo.getClient().sendResponse(new DoorbellMessageComposer("")); room.addToQueue(habbo); - } else if (room.getState() == RoomState.PASSWORD) { - if (room.getPassword().equalsIgnoreCase(password)) - this.openRoom(habbo, room, doorLocation); + } else if (room.getRoomInfo().getState() == RoomState.PASSWORD) { + if (room.getRoomInfo().getPassword().equalsIgnoreCase(password)) { + this.openRoom(habbo, room, spawnLocation); + } else { habbo.getClient().sendResponse(new GenericErrorComposer(GenericErrorComposer.WRONG_PASSWORD_USED)); habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); - habbo.getHabboInfo().setLoadingRoom(0); + habbo.getRoomUnit().setLoadingRoom(null); } } else { habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); - habbo.getHabboInfo().setLoadingRoom(0); + habbo.getRoomUnit().setLoadingRoom(null); } } - void openRoom(Habbo habbo, Room room, RoomTile doorLocation) { - if (room == null || room.getLayout() == null) + void openRoom(Habbo habbo, Room room, RoomTile spawnLocation) { + if (room.getLayout() == null) { return; + } if (Emulator.getConfig().getBoolean("hotel.room.enter.logs")) { this.logEnter(habbo, room); } if (habbo.getHabboInfo().getRoomQueueId() > 0) { - Room r = Emulator.getGameEnvironment().getRoomManager().getRoom(habbo.getHabboInfo().getRoomQueueId()); + Room queuedRoom = this.getActiveRoomById(habbo.getHabboInfo().getRoomQueueId()); - if (r != null) { - r.removeFromQueue(habbo); + if (queuedRoom != null) { + queuedRoom.removeFromQueue(habbo); } } habbo.getHabboInfo().setRoomQueueId(0); habbo.getClient().sendResponse(new FlatAccessibleMessageComposer("")); - if (habbo.getRoomUnit() != null) { - RoomUnit existingRoom = habbo.getRoomUnit(); - if (existingRoom.getRoom() != null) { - if (existingRoom.getCurrentLocation() != null) - existingRoom.getCurrentLocation().removeUnit(existingRoom); - existingRoom.getRoom().sendComposer(new UserRemoveMessageComposer(existingRoom).compose()); - } - habbo.getRoomUnit().setRoom(null); - } + RoomHabbo roomHabbo = habbo.getRoomUnit(); - habbo.setRoomUnit(new RoomUnit()); + roomHabbo.clear(); - habbo.getRoomUnit().clearStatus(); - if (habbo.getRoomUnit().getCurrentLocation() == null) { - habbo.getRoomUnit().setLocation(doorLocation != null ? doorLocation : room.getLayout().getDoorTile()); - if (habbo.getRoomUnit().getCurrentLocation() != null) - habbo.getRoomUnit().setZ(habbo.getRoomUnit().getCurrentLocation().getStackHeight()); + if (roomHabbo.getCurrentPosition() == null) { + RoomTile spawnTile = spawnLocation == null ? room.getLayout().getDoorTile() : spawnLocation; + RoomRotation spawnDirection = RoomRotation.values()[room.getLayout().getDoorDirection()]; - if (doorLocation == null) { - habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); - habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); - } else { - habbo.getRoomUnit().setCanLeaveRoomByDoor(false); - habbo.getRoomUnit().setTeleporting(true); - HabboItem topItem = room.getTopItemAt(doorLocation.getX(), doorLocation.getY()); - if (topItem != null) { - habbo.getRoomUnit().setRotation(RoomUserRotation.values()[topItem.getRotation()]); + if(spawnLocation != null) { + roomHabbo.setCanLeaveRoomByDoor(false); + roomHabbo.setTeleporting(true); + RoomItem topItem = room.getRoomItemManager().getTopItemAt(spawnLocation); + + if(topItem != null) { + spawnDirection = RoomRotation.values()[topItem.getRotation()]; } } - } - habbo.getRoomUnit().setRoomUnitType(RoomUnitType.USER); - if (room.isBanned(habbo)) { - habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_BANNED)); - return; + this.handleSpawnLocation(roomHabbo, spawnTile, spawnDirection); } - if (room.getUserCount() >= room.getUsersMax() && !habbo.hasRight(Permission.ACC_FULLROOMS) && !room.hasRights(habbo)) { - habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_GUESTROOM_FULL)); - return; - } - - habbo.getRoomUnit().clearStatus(); - habbo.getRoomUnit().setCmdTeleport(false); - habbo.getClient().sendResponse(new OpenConnectionMessageComposer()); - habbo.getRoomUnit().setInRoom(true); - if (habbo.getHabboInfo().getCurrentRoom() != room && habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().removeHabbo(habbo, true); - } else if (!habbo.getHabboStats().isBlockFollowing() && habbo.getHabboInfo().getCurrentRoom() == null) { + if (!habbo.getHabboStats().isBlockFollowing() && roomHabbo.getRoom() == null) { habbo.getMessenger().connectionChanged(habbo, true, true); } - if (habbo.getHabboInfo().getLoadingRoom() != 0) { - Room oldRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(habbo.getHabboInfo().getLoadingRoom()); - if (oldRoom != null) { - oldRoom.removeFromQueue(habbo); - } + if (roomHabbo.isLoadingRoom()) { + roomHabbo.getLoadingRoom().removeFromQueue(habbo); + roomHabbo.setLoadingRoom(null); } - habbo.getHabboInfo().setLoadingRoom(room.getId()); + roomHabbo.setLoadingRoom(room); habbo.getClient().sendResponse(new RoomReadyMessageComposer(room)); - if (!room.getWallPaint().equals("0.0")) - habbo.getClient().sendResponse(new RoomPropertyMessageComposer("wallpaper", room.getWallPaint())); + if (!room.getRoomInfo().getWallPaint().equals("0.0")) + habbo.getClient().sendResponse(new RoomPropertyMessageComposer("wallpaper", room.getRoomInfo().getWallPaint())); - if (!room.getFloorPaint().equals("0.0")) - habbo.getClient().sendResponse(new RoomPropertyMessageComposer("floor", room.getFloorPaint())); + if (!room.getRoomInfo().getFloorPaint().equals("0.0")) + habbo.getClient().sendResponse(new RoomPropertyMessageComposer("floor", room.getRoomInfo().getFloorPaint())); - habbo.getClient().sendResponse(new RoomPropertyMessageComposer("landscape", room.getBackgroundPaint())); + habbo.getClient().sendResponse(new RoomPropertyMessageComposer("landscape", room.getRoomInfo().getLandscapePaint())); - room.refreshRightsForHabbo(habbo); + room.getRoomRightsManager().refreshRightsForHabbo(habbo); - habbo.getClient().sendResponse(new RoomRatingComposer(room.getScore(), !this.hasVotedForRoom(habbo, room))); + habbo.getClient().sendResponse(new RoomRatingComposer(room.getRoomInfo().getScore(), !this.hasVotedForRoom(habbo, room))); - habbo.getRoomUnit().setFastWalk(habbo.getRoomUnit().isFastWalk() && habbo.hasCommand("cmd_fastwalk", room.hasRights(habbo))); + roomHabbo.setCmdFastWalkEnabled(roomHabbo.isCmdFastWalkEnabled() && habbo.canExecuteCommand("cmd_fastwalk", room.getRoomRightsManager().hasRights(habbo))); if (room.isPromoted()) { habbo.getClient().sendResponse(new RoomEventComposer(room, room.getPromotion())); @@ -641,62 +627,60 @@ public class RoomManager { habbo.getClient().sendResponse(new RoomEventComposer(null, null)); } - if (room.getOwnerId() != habbo.getHabboInfo().getId() && !habbo.getHabboStats().visitedRoom(room.getId())) { - AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomEntry")); + if (!room.getRoomInfo().isRoomOwner(habbo)) { + if (!habbo.getHabboStats().visitedRoom(room.getRoomInfo().getId())) { + AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomEntry")); + } } } public void enterRoom(final Habbo habbo, final Room room) { - if (habbo.getHabboInfo().getLoadingRoom() != room.getId()) { - if (habbo.getHabboInfo().getLoadingRoom() != 0) { - habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); - } + if (habbo.getRoomUnit().isLoadingRoom() && room.getRoomInfo().getId() != habbo.getRoomUnit().getLoadingRoom().getRoomInfo().getId()) { + habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); + habbo.getRoomUnit().setLoadingRoom(null); return; } - habbo.getRoomUnit() - .removeStatus(RoomUnitStatus.FLAT_CONTROL) - .setPathFinderRoom(room) - .setHandItem(0) - .setRightsLevel(RoomRightLevels.NONE); + RoomHabbo roomHabbo = habbo.getRoomUnit(); - habbo.getHabboInfo().setLoadingRoom(0) - .setCurrentRoom(room); + roomHabbo.removeStatus(RoomUnitStatus.FLAT_CONTROL); + roomHabbo.setHandItem(0); + roomHabbo.setRightsLevel(RoomRightLevels.NONE); + roomHabbo.setRoom(room); + roomHabbo.setLoadingRoom(null); - room.refreshRightsForHabbo(habbo); - if (habbo.getRoomUnit().isKicked() && !habbo.getRoomUnit().canWalk()) { + room.getRoomRightsManager().refreshRightsForHabbo(habbo); + + if (habbo.getRoomUnit().isKicked() && !habbo.getRoomUnit().isCanWalk()) { habbo.getRoomUnit().setCanWalk(true); } - habbo.getRoomUnit().setKicked(false); - if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting()) { - RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY()); + roomHabbo.setKicked(false); + + if (roomHabbo.getCurrentPosition() == null && !habbo.getRoomUnit().isTeleporting()) { + RoomTile doorTile = room.getLayout().getDoorTile(); + RoomRotation doorDirection = RoomRotation.values()[room.getLayout().getDoorDirection()]; if (doorTile != null) { - habbo.getRoomUnit().setLocation(doorTile); - habbo.getRoomUnit().setZ(doorTile.getStackHeight()); + this.handleSpawnLocation(roomHabbo, doorTile, doorDirection); } - - habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); - habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); } - habbo.getRoomUnit().setPathFinderRoom(room); - habbo.getRoomUnit().resetIdleTimer(); + roomHabbo.resetIdleTicks(); + roomHabbo.setInvisible(false); - habbo.getRoomUnit().setInvisible(false); - room.addHabbo(habbo); + room.getRoomUnitManager().addRoomUnit(habbo); - List habbos = new ArrayList<>(); - if (!room.getCurrentHabbos().isEmpty()) { + List visibleHabbos = new ArrayList<>(); - Collection habbosToSendEnter = room.getCurrentHabbos().values(); - Collection visibleHabbos = room.getHabbos(); + 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, visibleHabbos)); + HabboAddedToRoomEvent event = Emulator.getPluginManager().fireEvent(new HabboAddedToRoomEvent(habbo, room, habbosToSendEnter, allHabbos)); habbosToSendEnter = event.getHabbosToSendEnter(); - visibleHabbos = event.getVisibleHabbos(); + allHabbos = event.getVisibleHabbos(); } habbosToSendEnter.stream().map(Habbo::getClient).filter(Objects::nonNull).forEach(client -> { @@ -704,11 +688,11 @@ public class RoomManager { client.sendResponse(new UserUpdateComposer(habbo.getRoomUnit()).compose()); }); - habbos = visibleHabbos.stream().filter(h -> !h.getRoomUnit().isInvisible()).toList(); + visibleHabbos = allHabbos.stream().filter(h -> !h.getRoomUnit().isInvisible()).toList(); - synchronized (room.roomUnitLock) { - habbo.getClient().sendResponse(new RoomUsersComposer(habbos)); - habbo.getClient().sendResponse(new UserUpdateComposer(habbos)); + synchronized (room.getRoomUnitManager().roomUnitLock) { + habbo.getClient().sendResponse(new RoomUsersComposer(visibleHabbos)); + habbo.getClient().sendResponse(new UserUpdateComposer(visibleHabbos)); } if (habbo.getHabboStats().getGuild() != 0) { @@ -720,27 +704,30 @@ public class RoomManager { } int effect = habbo.getInventory().getEffectsComponent().getActivatedEffect(); - room.giveEffect(habbo.getRoomUnit(), effect, -1); + habbo.getRoomUnit().giveEffect(effect, -1); } - habbo.getClient().sendResponse(new RoomUsersComposer(room.getCurrentBots().valueCollection(), true)); - if (!room.getCurrentBots().isEmpty()) { - room.getCurrentBots().valueCollection().stream() + habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values())); + + 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.getCurrentBots().valueCollection() - .forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getZ()))); + room.getRoomUnitManager().getCurrentBots().values() + .forEach(b -> habbo.getClient().sendResponse(new UserUpdateComposer(b.getRoomUnit(), b.getRoomUnit().getCurrentZ()))); } - habbo.getClient().sendResponse(new RoomEntryInfoMessageComposer(room, room.isOwner(habbo))); + habbo.getClient().sendResponse(new RoomEntryInfoMessageComposer(room, room.getRoomInfo().isRoomOwner(habbo))); habbo.getClient().sendResponse(new RoomVisualizationSettingsComposer(room)); habbo.getClient().sendResponse(new GetGuestRoomResultComposer(room, habbo.getClient().getHabbo(), false, true)); - habbo.getClient().sendResponse(new ItemsComposer(room)); - final THashSet floorItems = new THashSet<>(); - THashSet allFloorItems = new THashSet<>(room.getFloorItems()); + habbo.getClient().sendResponse(new ItemsComposer(room)); + + final THashSet floorItems = new THashSet<>(); + + THashSet allFloorItems = new THashSet<>(room.getRoomItemManager().getFloorItems().values()); if (Emulator.getPluginManager().isRegistered(RoomFloorItemsLoadEvent.class, true)) { RoomFloorItemsLoadEvent roomFloorItemsLoadEvent = Emulator.getPluginManager().fireEvent(new RoomFloorItemsLoadEvent(habbo, allFloorItems)); @@ -750,7 +737,7 @@ public class RoomManager { } allFloorItems.forEach(object -> { - if (room.isHideWired() && object instanceof InteractionWired) + if (room.getRoomInfo().isHiddenWiredEnabled() && object instanceof InteractionWired) return true; floorItems.add(object); @@ -765,9 +752,9 @@ public class RoomManager { habbo.getClient().sendResponse(new ObjectsMessageComposer(room.getFurniOwnerNames(), floorItems)); floorItems.clear(); - if (!room.getCurrentPets().isEmpty()) { - habbo.getClient().sendResponse(new RoomPetComposer(room.getCurrentPets())); - room.getCurrentPets().valueCollection().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()) { @@ -781,45 +768,45 @@ public class RoomManager { } THashMap guildBadges = new THashMap<>(); - for (Habbo roomHabbo : habbos) { - if (roomHabbo.getRoomUnit().getDanceType().getType() > 0) { - habbo.getClient().sendResponse(new DanceMessageComposer(roomHabbo.getRoomUnit())); + for (Habbo visibleHabbo : visibleHabbos) { + if (visibleHabbo.getRoomUnit().getDanceType().getType() > 0) { + habbo.getClient().sendResponse(new DanceMessageComposer(visibleHabbo.getRoomUnit())); } - if (roomHabbo.getRoomUnit().getHandItem() > 0) { - habbo.getClient().sendResponse(new CarryObjectMessageComposer(roomHabbo.getRoomUnit())); + if (visibleHabbo.getRoomUnit().getHandItem() > 0) { + habbo.getClient().sendResponse(new CarryObjectMessageComposer(visibleHabbo.getRoomUnit())); } - if (roomHabbo.getRoomUnit().getEffectId() > 0) { - habbo.getClient().sendResponse(new AvatarEffectMessageComposer(roomHabbo.getRoomUnit())); + if (visibleHabbo.getRoomUnit().getEffectId() > 0) { + habbo.getClient().sendResponse(new AvatarEffectMessageComposer(visibleHabbo.getRoomUnit())); } - if (roomHabbo.getRoomUnit().isIdle()) { - habbo.getClient().sendResponse(new SleepMessageComposer(roomHabbo.getRoomUnit())); + if (visibleHabbo.getRoomUnit().isIdle()) { + habbo.getClient().sendResponse(new SleepMessageComposer(visibleHabbo.getRoomUnit())); } - if (roomHabbo.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { - roomHabbo.getClient().sendResponse(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.IGNORED)); + if (visibleHabbo.getHabboStats().userIgnored(habbo.getHabboInfo().getId())) { + visibleHabbo.getClient().sendResponse(new IgnoreResultMessageComposer(habbo, IgnoreResultMessageComposer.IGNORED)); } - if (!roomHabbo.getHabboStats().allowTalk()) { - habbo.getClient().sendResponse(new IgnoreResultMessageComposer(roomHabbo, IgnoreResultMessageComposer.MUTED)); - } else if (habbo.getHabboStats().userIgnored(roomHabbo.getHabboInfo().getId())) { - habbo.getClient().sendResponse(new IgnoreResultMessageComposer(roomHabbo, IgnoreResultMessageComposer.IGNORED)); + if (!visibleHabbo.getHabboStats().allowTalk()) { + habbo.getClient().sendResponse(new IgnoreResultMessageComposer(visibleHabbo, IgnoreResultMessageComposer.MUTED)); + } else if (habbo.getHabboStats().userIgnored(visibleHabbo.getHabboInfo().getId())) { + habbo.getClient().sendResponse(new IgnoreResultMessageComposer(visibleHabbo, IgnoreResultMessageComposer.IGNORED)); } - if (roomHabbo.getHabboStats().getGuild() != 0 && !guildBadges.containsKey(roomHabbo.getHabboStats().getGuild())) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(roomHabbo.getHabboStats().getGuild()); + if (visibleHabbo.getHabboStats().getGuild() != 0 && !guildBadges.containsKey(visibleHabbo.getHabboStats().getGuild())) { + Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(visibleHabbo.getHabboStats().getGuild()); if (guild != null) { - guildBadges.put(roomHabbo.getHabboStats().getGuild(), guild.getBadge()); + guildBadges.put(visibleHabbo.getHabboStats().getGuild(), guild.getBadge()); } } - if (roomHabbo.getRoomUnit().getRoomUnitType().equals(RoomUnitType.PET)) { + if (visibleHabbo.getRoomUnit().getRoomUnitType().equals(RoomUnitType.PET)) { try { - habbo.getClient().sendResponse(new UserRemoveMessageComposer(roomHabbo.getRoomUnit())); - habbo.getClient().sendResponse(new RoomUserPetComposer(((PetData) roomHabbo.getHabboStats().getCache().get("pet_type")).getType(), (Integer) roomHabbo.getHabboStats().getCache().get("pet_race"), (String) roomHabbo.getHabboStats().getCache().get("pet_color"), roomHabbo)); + habbo.getClient().sendResponse(new UserRemoveMessageComposer(visibleHabbo.getRoomUnit())); + habbo.getClient().sendResponse(new RoomUserPetComposer(((PetData) visibleHabbo.getHabboStats().getCache().get("pet_type")).getType(), (Integer) visibleHabbo.getHabboStats().getCache().get("pet_race"), (String) visibleHabbo.getHabboStats().getCache().get("pet_color"), visibleHabbo)); } catch (Exception ignored) { } @@ -828,8 +815,8 @@ public class RoomManager { habbo.getClient().sendResponse(new HabboGroupBadgesMessageComposer(guildBadges)); - if ((room.hasRights(habbo) - || (room.hasGuild() + if ((room.getRoomRightsManager().hasRights(habbo) + || (room.getRoomInfo().hasGuild() && room.getGuildRightLevel(habbo).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) && !room.getHabboQueue().isEmpty()) { for (Habbo waiting : room.getHabboQueue().valueCollection()) { @@ -837,11 +824,13 @@ public class RoomManager { } } - if (room.getPollId() > 0 && !PollManager.donePoll(habbo.getClient().getHabbo(), room.getPollId())) { - Poll poll = Emulator.getGameEnvironment().getPollManager().getPoll(room.getPollId()); + if (room.getRoomInfo().getPollId() > 0) { + if (!PollManager.donePoll(habbo.getClient().getHabbo(), room.getRoomInfo().getPollId())) { + Poll poll = Emulator.getGameEnvironment().getPollManager().getPoll(room.getRoomInfo().getPollId()); - if (poll != null) { - habbo.getClient().sendResponse(new PollOfferComposer(poll)); + if (poll != null) { + habbo.getClient().sendResponse(new PollOfferComposer(poll)); + } } } @@ -856,21 +845,23 @@ public class RoomManager { WiredHandler.handle(WiredTriggerType.ENTER_ROOM, habbo.getRoomUnit(), room, null); room.habboEntered(habbo); - if (!habbo.getHabboStats().isNux() && (room.isOwner(habbo) || room.isPublicRoom())) { - NewUserExperienceScriptProceedEvent.handle(habbo); + if (!habbo.getHabboStats().isNux()) { + if (room.getRoomInfo().isRoomOwner(habbo) || room.getRoomInfo().isPublicRoom()) { + NewUserExperienceScriptProceedEvent.handle(habbo); + } } } void logEnter(Habbo habbo, Room room) { habbo.getHabboStats().roomEnterTimestamp = Emulator.getIntUnixTimestamp(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_enter_log (room_id, user_id, timestamp) VALUES(?, ?, ?)")) { - statement.setInt(1, room.getId()); + statement.setInt(1, room.getRoomInfo().getId()); statement.setInt(2, habbo.getHabboInfo().getId()); statement.setInt(3, (int) (habbo.getHabboStats().getRoomEnterTimestamp())); statement.execute(); - if (!habbo.getHabboStats().visitedRoom(room.getId())) - habbo.getHabboStats().addVisitRoom(room.getId()); + if (!habbo.getHabboStats().visitedRoom(room.getRoomInfo().getId())) + habbo.getHabboStats().addVisitRoom(room.getRoomInfo().getId()); } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); } @@ -881,20 +872,18 @@ public class RoomManager { } public void leaveRoom(Habbo habbo, Room room, boolean redirectToHotelView) { - if (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom() == room) { - habbo.getRoomUnit().setPathFinderRoom(null); - + if (habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom().equals(room)) { this.logExit(habbo); - room.removeHabbo(habbo, true); + room.getRoomUnitManager().removeHabbo(habbo, true); if (redirectToHotelView) { habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); } - habbo.getHabboInfo().setCurrentRoom(null); - habbo.getRoomUnit().setKicked(false); - if (room.getOwnerId() != habbo.getHabboInfo().getId()) { - AchievementManager.progressAchievement(room.getOwnerId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"), (int) Math.floor((Emulator.getIntUnixTimestamp() - habbo.getHabboStats().roomEnterTimestamp) / 60000.0)); + habbo.getRoomUnit().setPreviousRoom(room); + + if (!room.getRoomInfo().isRoomOwner(habbo)) { + AchievementManager.progressAchievement(room.getRoomInfo().getOwnerInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoHosting"), (int) Math.floor((Emulator.getIntUnixTimestamp() - habbo.getHabboStats().roomEnterTimestamp) / 60000.0)); } habbo.getMessenger().connectionChanged(habbo, habbo.isOnline(), false); @@ -908,21 +897,21 @@ public class RoomManager { control.getRoomUnit().getCacheable().remove("controller"); } - if (habbo.getHabboInfo().getRiding() != null) { - if (habbo.getHabboInfo().getRiding().getRoomUnit() != null) { - habbo.getHabboInfo().getRiding().getRoomUnit().setGoalLocation(habbo.getHabboInfo().getRiding().getRoomUnit().getCurrentLocation()); + if (habbo.getRoomUnit().isRiding()) { + if (habbo.getRoomUnit().getRidingPet().getRoomUnit() != null) { + habbo.getRoomUnit().getRidingPet().getRoomUnit().walkTo(habbo.getRoomUnit().getRidingPet().getRoomUnit().getCurrentPosition()); } - habbo.getHabboInfo().getRiding().setTask(PetTasks.FREE); - habbo.getHabboInfo().getRiding().setRider(null); - habbo.getHabboInfo().setRiding(null); + habbo.getRoomUnit().getRidingPet().setTask(PetTasks.FREE); + habbo.getRoomUnit().getRidingPet().setRider(null); + habbo.getRoomUnit().setRidingPet(null); } - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); if (room != null) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE room_enter_log SET exit_timestamp = ? WHERE user_id = ? AND room_id = ? ORDER BY timestamp DESC LIMIT 1")) { statement.setInt(1, Emulator.getIntUnixTimestamp()); statement.setInt(2, habbo.getHabboInfo().getId()); - statement.setInt(3, room.getId()); + statement.setInt(3, room.getRoomInfo().getId()); statement.execute(); } catch (SQLException e) { log.error(CAUGHT_SQL_EXCEPTION, e); @@ -934,7 +923,7 @@ public class RoomManager { Map tagCount = new HashMap<>(); for (Room room : this.activeRooms.values()) { - for (String s : room.getTags().split(";")) { + for (String s : room.getRoomInfo().getTags().split(";")) { int i = 0; if (tagCount.get(s) != null) i++; @@ -946,12 +935,12 @@ public class RoomManager { } public ArrayList getPublicRooms() { - return this.activeRooms.values().stream().filter(Room::isPublicRoom).sorted(Room.SORT_ID) .collect(Collectors.toCollection(ArrayList::new)); + return this.activeRooms.values().stream().filter(room -> room.getRoomInfo().isPublicRoom()).sorted(Room.SORT_ID) .collect(Collectors.toCollection(ArrayList::new)); } public ArrayList getPopularRooms(int count) { return this.activeRooms.values().stream() - .filter(room -> room.getUserCount() > 0 && (!room.isPublicRoom() || RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB)) + .filter(room -> room.getRoomUnitManager().getRoomHabbosCount() > 0 && (!room.getRoomInfo().isPublicRoom() || RoomManager.SHOW_PUBLIC_IN_POPULAR_TAB)) .sorted() .limit(count) .collect(Collectors.toCollection(ArrayList::new)); @@ -959,7 +948,7 @@ public class RoomManager { public List getPopularRooms(int count, int category) { return this.activeRooms.values().stream() - .filter(room -> !room.isPublicRoom() && room.getCategory() == category) + .filter(room -> !room.getRoomInfo().isPublicRoom() && room.getRoomInfo().getCategory().getId() == category) .sorted() .limit(count) .toList(); @@ -969,12 +958,12 @@ public class RoomManager { Map> rooms = new HashMap<>(); for (Room room : this.activeRooms.values()) { - if (!room.isPublicRoom()) { - if (!rooms.containsKey(room.getCategory())) { - rooms.put(room.getCategory(), new ArrayList<>()); + if (!room.getRoomInfo().isPublicRoom()) { + if (!rooms.containsKey(room.getRoomInfo().getCategory().getId())) { + rooms.put(room.getRoomInfo().getCategory().getId(), new ArrayList<>()); } - rooms.get(room.getCategory()).add(room); + rooms.get(room.getRoomInfo().getCategory().getId()).add(room); } } @@ -993,7 +982,7 @@ public class RoomManager { } public List getRoomsWithName(String name) { - List rooms = new ArrayList<>(activeRooms.values().stream().filter(room -> room.getName().equalsIgnoreCase(name)).toList()); + List rooms = new ArrayList<>(activeRooms.values().stream().filter(room -> room.getRoomInfo().getName().equalsIgnoreCase(name)).toList()); if (rooms.size() < 25) { rooms.addAll(this.getOfflineRoomsWithName(name)); @@ -1016,7 +1005,7 @@ public class RoomManager { Room r = new Room(set); rooms.add(r); - this.activeRooms.put(r.getId(), r); + this.activeRooms.put(r.getRoomInfo().getId(), r); } } } catch (SQLException e) { @@ -1030,7 +1019,7 @@ public class RoomManager { ArrayList rooms = new ArrayList<>(); for (Room room : this.activeRooms.values()) { - for (String s : room.getTags().split(";")) { + for (String s : room.getRoomInfo().getTags().split(";")) { if (s.equalsIgnoreCase(tag)) { rooms.add(room); break; @@ -1047,10 +1036,10 @@ public class RoomManager { ArrayList rooms = new ArrayList<>(); for (Room room : this.activeRooms.values()) { - if (room.getGuildId() == 0) + if (room.getRoomInfo().getGuild().getId() == 0) continue; - if (room.getName().toLowerCase().contains(name.toLowerCase())) + if (room.getRoomInfo().getName().toLowerCase().contains(name.toLowerCase())) rooms.add(room); } @@ -1076,7 +1065,7 @@ public class RoomManager { Room r = new Room(set); rooms.add(r); - this.activeRooms.put(r.getId(), r); + this.activeRooms.put(r.getRoomInfo().getId(), r); } } } catch (SQLException e) { @@ -1094,10 +1083,10 @@ public class RoomManager { continue; Habbo friend = Emulator.getGameEnvironment().getHabboManager().getHabbo(buddy.getId()); - if (friend == null || friend.getHabboInfo().getCurrentRoom() == null) + if (friend == null || friend.getRoomUnit().getRoom() == null) continue; - rooms.add(friend.getHabboInfo().getCurrentRoom()); + rooms.add(friend.getRoomUnit().getRoom()); } Collections.sort(rooms); @@ -1139,7 +1128,7 @@ public class RoomManager { if (room == null) { room = new Room(set); - this.activeRooms.put(room.getId(), room); + this.activeRooms.put(room.getRoomInfo().getId(), room); } rooms.add(room); @@ -1158,12 +1147,12 @@ public class RoomManager { final ArrayList rooms = new ArrayList<>(); habbo.getHabboStats().getFavoriteRooms().forEach(value -> { - Room room = RoomManager.this.getRoom(value); + Room room = RoomManager.this.getActiveRoomById(value); if (room != null) { - if (room.getState() == RoomState.INVISIBLE) { + if (room.getRoomInfo().getState() == RoomState.INVISIBLE) { room.loadData(); - if (!room.hasRights(habbo)) return true; + if (!room.getRoomRightsManager().hasRights(habbo)) return true; } rooms.add(room); } @@ -1226,8 +1215,8 @@ public class RoomManager { if (friend == null || friend.getHabboInfo() == null) continue; - Room room = friend.getHabboInfo().getCurrentRoom(); - if (room != null && !rooms.contains(room) && room.hasRights(habbo)) rooms.add(room); + Room room = friend.getRoomUnit().getRoom(); + if (room != null && !rooms.contains(room) && room.getRoomRightsManager().hasRights(habbo)) rooms.add(room); if (rooms.size() >= limit) break; } @@ -1290,29 +1279,29 @@ public class RoomManager { return activeRooms.values().stream().filter(Room::isPromoted).collect(Collectors.toCollection(ArrayList::new)); } public ArrayList getRoomsStaffPromoted() { - return activeRooms.values().stream().filter(Room::isStaffPromotedRoom).collect(Collectors.toCollection(ArrayList::new)); + return activeRooms.values().stream().filter(room -> room.getRoomInfo().isStaffPicked()).collect(Collectors.toCollection(ArrayList::new)); } public ArrayList filterRoomsByOwner(List rooms, String filter) { - return rooms.stream().filter(r -> r.getOwnerName().equalsIgnoreCase(filter)).collect(Collectors.toCollection(ArrayList::new)); + return rooms.stream().filter(r -> r.getRoomInfo().getOwnerInfo().getUsername().equalsIgnoreCase(filter)).collect(Collectors.toCollection(ArrayList::new)); } public ArrayList filterRoomsByName(List rooms, String filter) { - return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase())).collect(Collectors.toCollection(ArrayList::new)); + return rooms.stream().filter(room -> room.getRoomInfo().getName().toLowerCase().contains(filter.toLowerCase())).collect(Collectors.toCollection(ArrayList::new)); } public ArrayList filterRoomsByNameAndDescription(List rooms, String filter) { - return rooms.stream().filter(room -> room.getName().toLowerCase().contains(filter.toLowerCase()) || room.getDescription().toLowerCase().contains(filter.toLowerCase())).collect(Collectors.toCollection(ArrayList::new)); + return rooms.stream().filter(room -> room.getRoomInfo().getName().toLowerCase().contains(filter.toLowerCase()) || room.getRoomInfo().getDescription().toLowerCase().contains(filter.toLowerCase())).collect(Collectors.toCollection(ArrayList::new)); } public ArrayList filterRoomsByTag(List rooms, String filter) { ArrayList r = new ArrayList<>(); for (Room room : rooms) { - if (room.getTags().split(";").length == 0) + if (room.getRoomInfo().getTags().split(";").length == 0) continue; - for (String s : room.getTags().split(";")) { + for (String s : room.getRoomInfo().getTags().split(";")) { if (s.equalsIgnoreCase(filter)) r.add(room); } @@ -1322,8 +1311,8 @@ public class RoomManager { } public ArrayList filterRoomsByGroup(List rooms, String filter) { - return rooms.stream().filter(room -> room.getGuildId() != 0) - .filter(room -> Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId()).getName().toLowerCase().contains(filter.toLowerCase())) + return rooms.stream().filter(room -> room.getRoomInfo().getGuild().getId() != 0) + .filter(room -> Emulator.getGameEnvironment().getGuildManager().getGuild(room.getRoomInfo().getGuild().getId()).getName().toLowerCase().contains(filter.toLowerCase())) .collect(Collectors.toCollection(ArrayList::new)); } @@ -1339,8 +1328,8 @@ public class RoomManager { public CustomRoomLayout insertCustomLayout(Room room, String map, int doorX, int doorY, int doorDirection) { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_models_custom (id, name, door_x, door_y, door_dir, heightmap) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE door_x = ?, door_y = ?, door_dir = ?, heightmap = ?")) { - statement.setInt(1, room.getId()); - statement.setString(2, "custom_" + room.getId()); + statement.setInt(1, room.getRoomInfo().getId()); + statement.setString(2, "custom_" + room.getRoomInfo().getId()); statement.setInt(3, doorX); statement.setInt(4, doorY); statement.setInt(5, doorDirection); @@ -1358,28 +1347,27 @@ public class RoomManager { } public void banUserFromRoom(Habbo rights, int userId, int roomId, RoomBanTypes length) { - Room room = this.getRoom(roomId); + Room room = this.getActiveRoomById(roomId); if (room == null) return; - if (rights != null && !room.hasRights(rights)) - return; + if (rights != null && !room.getRoomRightsManager().hasRights(rights)) return; String name = ""; Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo != null) { - if (habbo.hasRight(Permission.ACC_UNKICKABLE)) { + if (habbo.hasPermissionRight(Permission.ACC_UNKICKABLE)) { return; } name = habbo.getHabboInfo().getUsername(); } else { - HabboInfo info = HabboManager.getOfflineHabboInfo(userId); + HabboInfo info = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(userId); if (info != null) { - if (info.getPermissionGroup().hasRight(Permission.ACC_UNKICKABLE, false)) { + if (info.getPermissionGroup().hasPermissionRight(Permission.ACC_UNKICKABLE, false)) { return; } name = info.getUsername(); @@ -1395,12 +1383,18 @@ public class RoomManager { room.addRoomBan(roomBan); - if (habbo != null && habbo.getHabboInfo().getCurrentRoom() == room) { - room.removeHabbo(habbo, true); + if (habbo != null && habbo.getRoomUnit().getRoom() == room) { + room.getRoomUnitManager().removeHabbo(habbo, true); habbo.getClient().sendResponse(new CantConnectMessageComposer(CantConnectMessageComposer.ROOM_ERROR_BANNED)); } } + public void handleSpawnLocation(RoomHabbo roomHabbo, RoomTile location, RoomRotation direction) { + roomHabbo.setLocation(location); + roomHabbo.setCurrentZ(location.getStackHeight()); + roomHabbo.setRotation(direction); + } + public void registerGameType(Class gameClass) { gameTypes.add(gameClass); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomPromotion.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomPromotion.java index e8bc4f23..02933c3e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomPromotion.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomPromotion.java @@ -50,7 +50,7 @@ public class RoomPromotion { statement.setString(1, this.title); statement.setString(2, this.description); statement.setInt(3, this.category); - statement.setInt(4, this.room.getId()); + statement.setInt(4, this.room.getRoomInfo().getId()); statement.executeUpdate(); } catch (SQLException e) { log.error("Caught SQL exception", e); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java new file mode 100644 index 00000000..be3a7955 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomRightsManager.java @@ -0,0 +1,207 @@ +package com.eu.habbo.habbohotel.rooms; + +import com.eu.habbo.Emulator; +import com.eu.habbo.database.DatabaseConstants; +import com.eu.habbo.habbohotel.messenger.MessengerBuddy; +import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.outgoing.rooms.*; +import com.eu.habbo.plugin.events.users.UserRightsTakenEvent; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; + +@Slf4j +@Getter +@Setter +public class RoomRightsManager { + private final Room room; + private final List rights; + + public RoomRightsManager(Room room) { + this.room = room; + this.rights = new ArrayList<>(); + } + + public synchronized void load(Connection connection) { + this.loadRights(connection); + } + + private void loadRights(Connection connection) { + this.rights.clear(); + try (PreparedStatement statement = connection.prepareStatement("SELECT user_id FROM room_rights WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + this.rights.add(set.getInt(DatabaseConstants.USER_ID)); + } + } + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error("Caught Exception", e); + } + } + + 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().getCurrentHabbos().containsKey(habbo.getHabboInfo().getId())); + } + + public HashMap getUsersWithRights() { + HashMap rightsMap = new HashMap<>(); + + if (this.rights.isEmpty()) { + return rightsMap; + } + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); + PreparedStatement statement = connection.prepareStatement("SELECT users.username AS username, users.id AS user_id FROM room_rights INNER JOIN users ON room_rights.user_id = users.id WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + int userId = set.getInt("user_id"); + String username = set.getString("username"); + rightsMap.put(userId, username); + } + } + } catch (SQLException e) { + log.error("Error while fetching users with rights:", e); + } + + return rightsMap; + } + + public void giveRights(Habbo habbo) { + if (this.rights.contains(habbo.getHabboInfo().getId())) { + return; + } + + this.rights.add(habbo.getHabboInfo().getId()); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_rights VALUES (?, ?)")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.setInt(2, habbo.getHabboInfo().getId()); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + + this.room.getRoomRightsManager().refreshRightsForHabbo(habbo); + this.room.sendComposer(new FlatControllerAddedComposer(this.room, habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername()).compose()); + } + + public void giveRights(MessengerBuddy buddy) { + if (this.rights.contains(buddy.getId())) { + return; + } + + this.rights.add(buddy.getId()); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_rights VALUES (?, ?)")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.setInt(2, buddy.getId()); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + + Habbo roomOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.room.getRoomInfo().getOwnerInfo().getId()); + + if (roomOwner != null) { + this.room.sendComposer(new FlatControllerAddedComposer(this.room, buddy.getId(), buddy.getUsername()).compose()); + } + } + + public void removeRights(int userId) { + Habbo habbo = this.room.getRoomUnitManager().getRoomHabboById(userId); + + if (Emulator.getPluginManager().fireEvent(new UserRightsTakenEvent(this.room.getRoomUnitManager().getRoomHabboById(this.room.getRoomInfo().getOwnerInfo().getId()), userId, habbo)).isCancelled()) + return; + + this.room.sendComposer(new FlatControllerRemovedComposer(this.room, userId).compose()); + + if (this.rights.remove(Integer.valueOf(userId))) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ? AND user_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.setInt(2, userId); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + } + + if (habbo != null) { + this.room.getRoomItemManager().ejectUserFurni(habbo.getHabboInfo().getId()); + habbo.getRoomUnit().setRightsLevel(RoomRightLevels.NONE); + habbo.getRoomUnit().removeStatus(RoomUnitStatus.FLAT_CONTROL); + this.refreshRightsForHabbo(habbo); + } + } + + public void removeAllRights() { + for (int userId : this.rights) { + this.room.getRoomItemManager().ejectUserFurni(userId); + } + + this.rights.clear(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + + this.refreshRightsInRoom(); + } + + private void refreshRightsInRoom() { + for (Habbo habbo : this.room.getRoomUnitManager().getCurrentHabbos().values()) { + if (habbo.getRoomUnit().getRoom() == room) { + this.refreshRightsForHabbo(habbo); + } + } + } + + public void refreshRightsForHabbo(Habbo habbo) { + RoomItem item; + RoomRightLevels flatCtrl = RoomRightLevels.NONE; + + if (habbo.getHabboStats().isRentingSpace()) { + item = this.room.getRoomItemManager().getCurrentItems().get(habbo.getHabboStats().getRentedItemId()); + + if (item != null) { + return; + } + } + + if (habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || this.room.getRoomInfo().isRoomOwner(habbo)) { + habbo.getClient().sendResponse(new YouAreOwnerMessageComposer()); + flatCtrl = RoomRightLevels.MODERATOR; + } else if (this.hasRights(habbo) && !this.room.getRoomInfo().hasGuild()) { + flatCtrl = RoomRightLevels.RIGHTS; + } else if (this.room.getRoomInfo().hasGuild()) { + flatCtrl = this.room.getGuildRightLevel(habbo); + } + + habbo.getClient().sendResponse(new YouAreControllerMessageComposer(flatCtrl)); + + habbo.getRoomUnit().addStatus(RoomUnitStatus.FLAT_CONTROL, String.valueOf(flatCtrl.getLevel())); + habbo.getRoomUnit().setRightsLevel(flatCtrl); + + if (flatCtrl.equals(RoomRightLevels.MODERATOR)) { + habbo.getClient().sendResponse(new FlatControllersComposer(this.room)); + } + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java index 3ce54325..8a84944a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomSpecialTypes.java @@ -19,7 +19,7 @@ import com.eu.habbo.habbohotel.items.interactions.pets.InteractionNest; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetDrink; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetFood; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetToy; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -27,10 +27,8 @@ import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.awt.*; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; +import java.util.*; public class RoomSpecialTypes { private final THashMap banzaiTeleporters; @@ -40,7 +38,7 @@ public class RoomSpecialTypes { private final THashMap petToys; private final THashMap rollers; - private final THashMap> wiredTriggers; + private final HashMap> wiredTriggers; private final THashMap> wiredEffects; private final THashMap> wiredConditions; private final THashMap wiredExtras; @@ -50,7 +48,7 @@ public class RoomSpecialTypes { private final THashMap gameTimers; private final THashMap freezeExitTile; - private final THashMap undefined; + private final THashMap undefined; private final THashSet cycleTasks; public RoomSpecialTypes() { @@ -61,7 +59,7 @@ public class RoomSpecialTypes { this.petToys = new THashMap<>(0); this.rollers = new THashMap<>(0); - this.wiredTriggers = new THashMap<>(0); + this.wiredTriggers = new HashMap<>(0); this.wiredEffects = new THashMap<>(0); this.wiredConditions = new THashMap<>(0); this.wiredExtras = new THashMap<>(0); @@ -229,7 +227,7 @@ public class RoomSpecialTypes { public InteractionWiredTrigger getTrigger(int itemId) { synchronized (this.wiredTriggers) { - for (Map.Entry> map : this.wiredTriggers.entrySet()) { + for (Map.Entry> map : this.wiredTriggers.entrySet()) { for (InteractionWiredTrigger trigger : map.getValue()) { if (trigger.getId() == itemId) return trigger; @@ -244,7 +242,7 @@ public class RoomSpecialTypes { synchronized (this.wiredTriggers) { THashSet triggers = new THashSet<>(); - for (Map.Entry> map : this.wiredTriggers.entrySet()) { + for (Map.Entry> map : this.wiredTriggers.entrySet()) { triggers.addAll(map.getValue()); } @@ -252,7 +250,7 @@ public class RoomSpecialTypes { } } - public THashSet getTriggers(WiredTriggerType type) { + public List getTriggers(WiredTriggerType type) { return this.wiredTriggers.get(type); } @@ -260,10 +258,9 @@ public class RoomSpecialTypes { synchronized (this.wiredTriggers) { THashSet triggers = new THashSet<>(); - for (Map.Entry> map : this.wiredTriggers.entrySet()) { + for (Map.Entry> map : this.wiredTriggers.entrySet()) { for (InteractionWiredTrigger trigger : map.getValue()) { - if (trigger.getX() == x && trigger.getY() == y) - triggers.add(trigger); + if (trigger.getCurrentPosition().getX() == x && trigger.getCurrentPosition().getY() == y) triggers.add(trigger); } } @@ -274,7 +271,7 @@ public class RoomSpecialTypes { public void addTrigger(InteractionWiredTrigger trigger) { synchronized (this.wiredTriggers) { if (!this.wiredTriggers.containsKey(trigger.getType())) - this.wiredTriggers.put(trigger.getType(), new THashSet<>()); + this.wiredTriggers.put(trigger.getType(), new ArrayList<>()); this.wiredTriggers.get(trigger.getType()).add(trigger); } @@ -326,8 +323,7 @@ public class RoomSpecialTypes { for (Map.Entry> map : this.wiredEffects.entrySet()) { for (InteractionWiredEffect effect : map.getValue()) { - if (effect.getX() == x && effect.getY() == y) - effects.add(effect); + if (effect.getCurrentPosition().getX() == x && effect.getCurrentPosition().getY() == y) effects.add(effect); } } @@ -354,7 +350,6 @@ public class RoomSpecialTypes { } } - public InteractionWiredCondition getCondition(int itemId) { synchronized (this.wiredConditions) { for (Map.Entry> map : this.wiredConditions.entrySet()) { @@ -392,7 +387,7 @@ public class RoomSpecialTypes { for (Map.Entry> map : this.wiredConditions.entrySet()) { for (InteractionWiredCondition condition : map.getValue()) { - if (condition.getX() == x && condition.getY() == y) + if (condition.getCurrentPosition().getX() == x && condition.getCurrentPosition().getY() == y) conditions.add(condition); } } @@ -438,7 +433,7 @@ public class RoomSpecialTypes { THashSet extras = new THashSet<>(); for (Map.Entry map : this.wiredExtras.entrySet()) { - if (map.getValue().getX() == x && map.getValue().getY() == y) { + if (map.getValue().getCurrentPosition().getX() == x && map.getValue().getCurrentPosition().getY() == y) { extras.add(map.getValue()); } } @@ -462,7 +457,7 @@ public class RoomSpecialTypes { public boolean hasExtraType(short x, short y, Class type) { synchronized (this.wiredExtras) { for (Map.Entry map : this.wiredExtras.entrySet()) { - if (map.getValue().getX() == x && map.getValue().getY() == y && map.getValue().getClass().isAssignableFrom(type)) { + if (map.getValue().getCurrentPosition().getX() == x && map.getValue().getCurrentPosition().getY() == y && map.getValue().getClass().isAssignableFrom(type)) { return true; } } @@ -639,14 +634,14 @@ public class RoomSpecialTypes { } } - public void addFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { - this.freezeExitTile.put(freezeExitTile.getId(), freezeExitTile); - } - public THashMap getFreezeExitTiles() { return this.freezeExitTile; } + public void addFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { + this.freezeExitTile.put(freezeExitTile.getId(), freezeExitTile); + } + public void removeFreezeExitTile(InteractionFreezeExitTile freezeExitTile) { this.freezeExitTile.remove(freezeExitTile.getId()); } @@ -655,22 +650,22 @@ public class RoomSpecialTypes { return !this.freezeExitTile.isEmpty(); } - public void addUndefined(HabboItem item) { + public void addUndefined(RoomItem item) { synchronized (this.undefined) { this.undefined.put(item.getId(), item); } } - public void removeUndefined(HabboItem item) { + public void removeUndefined(RoomItem item) { synchronized (this.undefined) { this.undefined.remove(item.getId()); } } - public THashSet getItemsOfType(Class type) { - THashSet items = new THashSet<>(); + public THashSet getItemsOfType(Class type) { + THashSet items = new THashSet<>(); synchronized (this.undefined) { - for (HabboItem item : this.undefined.values()) { + for (RoomItem item : this.undefined.values()) { if (item.getClass() == type) items.add(item); } @@ -679,11 +674,11 @@ public class RoomSpecialTypes { return items; } - public HabboItem getLowestItemsOfType(Class type) { - HabboItem i = null; + public RoomItem getLowestItemsOfType(Class type) { + RoomItem i = null; synchronized (this.undefined) { - for (HabboItem item : this.undefined.values()) { - if (i == null || item.getZ() < i.getZ()) { + for (RoomItem item : this.undefined.values()) { + if (i == null || item.getCurrentZ() < i.getCurrentZ()) { if (item.getClass().isAssignableFrom(type)) { i = item; } @@ -727,8 +722,8 @@ public class RoomSpecialTypes { } public Rectangle tentAt(RoomTile location) { - for (HabboItem item : this.getItemsOfType(InteractionTent.class)) { - Rectangle rectangle = RoomLayout.getRectangle(item.getX(), item.getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); + for (RoomItem item : this.getItemsOfType(InteractionTent.class)) { + Rectangle rectangle = RoomLayout.getRectangle(item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); if (RoomLayout.tileInSquare(rectangle, location)) { return rectangle; } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java index eda3e0b5..b7f0a7d7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomState.java @@ -6,12 +6,8 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum RoomState { - OPEN(0), - LOCKED(1), - PASSWORD(2), - INVISIBLE(3); - - private final int state; - - + OPEN, + LOCKED, + PASSWORD, + INVISIBLE } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java index cea73922..463df5cf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTile.java @@ -1,12 +1,13 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.habbohotel.items.Item; -import gnu.trove.set.hash.THashSet; +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.types.RoomAvatar; import lombok.Getter; import lombok.Setter; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; public class RoomTile { @Getter @@ -15,10 +16,12 @@ public class RoomTile { private final short y; @Getter private final short z; - private final THashSet units; + private final HashSet roomUnits; + private final HashSet roomItems; @Setter @Getter private RoomTileState state; + @Getter private double stackHeight; private boolean allowStack = true; @Getter @@ -37,7 +40,8 @@ public class RoomTile { this.stackHeight = z; this.state = state; this.setAllowStack(allowStack); - this.units = new THashSet<>(); + this.roomUnits = new HashSet<>(); + this.roomItems = new HashSet<>(); } public RoomTile(RoomTile tile) { @@ -54,24 +58,9 @@ public class RoomTile { if (this.state == RoomTileState.INVALID) { this.allowStack = false; } - this.units = tile.units; - } - public RoomTile() { - x = 0; - y = 0; - z = 0; - this.stackHeight = 0; - this.state = RoomTileState.INVALID; - this.allowStack = false; - this.diagonally = false; - this.gCosts = 0; - this.hCosts = 0; - this.units = null; - } - - public double getStackHeight() { - return this.stackHeight; + this.roomUnits = tile.roomUnits; + this.roomItems = tile.roomItems; } public void setStackHeight(double stackHeight) { @@ -119,6 +108,10 @@ public class RoomTile { ((RoomTile) o).y == this.y; } + public boolean equals(int x, int y) { + return this.x == x && this.y == y; + } + public RoomTile copy() { return new RoomTile(this); } @@ -173,33 +166,36 @@ public class RoomTile { return this.x == x && this.y == y; } - public List getUnits() { - synchronized (this.units) { - return new ArrayList<>(this.units); + public void addRoomUnit(RoomUnit roomUnit) { + synchronized (this.roomUnits) { + this.roomUnits.add(roomUnit); } } - public void addUnit(RoomUnit unit) { - synchronized (this.units) { - if (!this.units.contains(unit)) { - this.units.add(unit); + public void removeUnit(RoomUnit roomUnit) { + synchronized (this.roomUnits) { + if(!this.roomUnits.contains(roomUnit)) { + return; + } + + this.roomUnits.remove(roomUnit); + + if(roomUnit instanceof RoomAvatar roomAvatar && roomAvatar.isRiding()) { + this.roomUnits.remove(roomAvatar.getRidingPet().getRoomUnit()); } } } - public void removeUnit(RoomUnit unit) { - synchronized (this.units) { - this.units.remove(unit); + //TODO Move this to RoomUnit + public boolean unitIsOnFurniOnTile(RoomUnit roomUnit, Item item) { + if ((roomUnit.getCurrentPosition().getX() < this.x || roomUnit.getCurrentPosition().getX() >= this.x + item.getLength())) { + return false; } - } - public boolean hasUnits() { - synchronized (this.units) { - return this.units.size() > 0; + if (roomUnit.getCurrentPosition().getY() < this.y) { + return false; } - } - public boolean unitIsOnFurniOnTile(RoomUnit unit, Item item) { - return (unit.getX() >= this.x && unit.getX() < this.x + item.getLength()) && (unit.getY() >= this.y && unit.getY() < this.y + item.getWidth()); + return roomUnit.getCurrentPosition().getY() < this.y + item.getWidth(); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTileState.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTileState.java index 634ae4c1..96958ca8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTileState.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTileState.java @@ -2,18 +2,9 @@ package com.eu.habbo.habbohotel.rooms; public enum RoomTileState { - OPEN, - - BLOCKED, - - INVALID, - - SIT, - - LAY } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java index a6231fa3..1e29ff96 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTrade.java @@ -1,8 +1,9 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; @@ -15,6 +16,7 @@ import lombok.extern.slf4j.Slf4j; import java.sql.*; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; @@ -43,7 +45,7 @@ public class RoomTrade { protected void initializeTradeStatus() { for (RoomTradeUser roomTradeUser : this.users) { if (!roomTradeUser.getHabbo().getRoomUnit().hasStatus(RoomUnitStatus.TRADING)) { - roomTradeUser.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.TRADING, ""); + roomTradeUser.getHabbo().getRoomUnit().addStatus(RoomUnitStatus.TRADING, ""); if (!roomTradeUser.getHabbo().getRoomUnit().isWalking()) this.room.sendComposer(new UserUpdateComposer(roomTradeUser.getHabbo().getRoomUnit()).compose()); } @@ -54,7 +56,7 @@ public class RoomTrade { this.sendMessageToUsers(new TradingOpenComposer(this)); } - public void offerItem(Habbo habbo, HabboItem item) { + public void offerItem(Habbo habbo, RoomItem item) { RoomTradeUser user = this.getRoomTradeUserForHabbo(habbo); if (user.getItems().contains(item)) @@ -67,10 +69,10 @@ public class RoomTrade { this.updateWindow(); } - public void offerMultipleItems(Habbo habbo, THashSet items) { + public void offerMultipleItems(Habbo habbo, THashSet items) { RoomTradeUser user = this.getRoomTradeUserForHabbo(habbo); - for (HabboItem item : items) { + for (RoomItem item : items) { if (!user.getItems().contains(item)) { habbo.getInventory().getItemsComponent().removeHabboItem(item); user.getItems().add(item); @@ -81,7 +83,7 @@ public class RoomTrade { this.updateWindow(); } - public void removeItem(Habbo habbo, HabboItem item) { + public void removeItem(Habbo habbo, RoomItem item) { RoomTradeUser user = this.getRoomTradeUserForHabbo(habbo); if (!user.getItems().contains(item)) @@ -137,9 +139,9 @@ public class RoomTrade { boolean tradeItems() { for (RoomTradeUser roomTradeUser : this.users) { - for (HabboItem item : roomTradeUser.getItems()) { + for (RoomItem item : roomTradeUser.getItems()) { if (roomTradeUser.getHabbo().getInventory().getItemsComponent().getHabboItem(item.getId()) != null) { - this.sendMessageToUsers(new TradingCloseComposer(roomTradeUser.getHabbo().getRoomUnit().getId(), TradingCloseComposer.ITEMS_NOT_FOUND)); + this.sendMessageToUsers(new TradingCloseComposer(roomTradeUser.getHabbo().getRoomUnit().getVirtualId(), TradingCloseComposer.ITEMS_NOT_FOUND)); return false; } } @@ -177,35 +179,35 @@ public class RoomTrade { } } - int userOneId = userOne.getHabbo().getHabboInfo().getId(); - int userTwoId = userTwo.getHabbo().getHabboInfo().getId(); + HabboInfo userOneInfo = userOne.getHabbo().getHabboInfo(); + HabboInfo userTwoInfo = userTwo.getHabbo().getHabboInfo(); try (PreparedStatement statement = connection.prepareStatement("UPDATE items SET user_id = ? WHERE id = ? LIMIT 1")) { try (PreparedStatement stmt = connection.prepareStatement("INSERT INTO room_trade_log_items (id, item_id, user_id) VALUES (?, ?, ?)")) { - for (HabboItem item : userOne.getItems()) { - item.setUserId(userTwoId); - statement.setInt(1, userTwoId); + for (RoomItem item : userOne.getItems()) { + item.setOwnerInfo(userTwoInfo); + statement.setInt(1, userTwoInfo.getId()); statement.setInt(2, item.getId()); statement.addBatch(); if (logTrades) { stmt.setInt(1, tradeId); stmt.setInt(2, item.getId()); - stmt.setInt(3, userOneId); + stmt.setInt(3, userOneInfo.getId()); stmt.addBatch(); } } - for (HabboItem item : userTwo.getItems()) { - item.setUserId(userOneId); - statement.setInt(1, userOneId); + for (RoomItem item : userTwo.getItems()) { + item.setOwnerInfo(userOneInfo); + statement.setInt(1, userOneInfo.getId()); statement.setInt(2, item.getId()); statement.addBatch(); if (logTrades) { stmt.setInt(1, tradeId); stmt.setInt(2, item.getId()); - stmt.setInt(3, userTwoId); + stmt.setInt(3, userTwoInfo.getId()); stmt.addBatch(); } } @@ -221,15 +223,15 @@ public class RoomTrade { log.error("Caught SQL exception", e); } - THashSet itemsUserOne = new THashSet<>(userOne.getItems()); - THashSet itemsUserTwo = new THashSet<>(userTwo.getItems()); + HashSet itemsUserOne = new HashSet<>(userOne.getItems()); + HashSet itemsUserTwo = new HashSet<>(userTwo.getItems()); userOne.clearItems(); userTwo.clearItems(); int creditsForUserTwo = 0; - THashSet creditFurniUserOne = new THashSet<>(); - for (HabboItem item : itemsUserOne) { + HashSet creditFurniUserOne = new HashSet<>(); + for (RoomItem item : itemsUserOne) { int worth = RoomTrade.getCreditsByItem(item); if (worth > 0) { creditsForUserTwo += worth; @@ -240,8 +242,8 @@ public class RoomTrade { itemsUserOne.removeAll(creditFurniUserOne); int creditsForUserOne = 0; - THashSet creditFurniUserTwo = new THashSet<>(); - for (HabboItem item : itemsUserTwo) { + THashSet creditFurniUserTwo = new THashSet<>(); + for (RoomItem item : itemsUserTwo) { int worth = RoomTrade.getCreditsByItem(item); if (worth > 0) { creditsForUserOne += worth; @@ -328,7 +330,7 @@ public class RoomTrade { return this.users; } - public static int getCreditsByItem(HabboItem item) { + public static int getCreditsByItem(RoomItem item) { if (!Emulator.getConfig().getBoolean("redeem.currency.trade")) return 0; if (!item.getBaseItem().getName().startsWith("CF_") && !item.getBaseItem().getName().startsWith("CFC_")) return 0; diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTradeUser.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTradeUser.java index 5fb7f103..339757af 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTradeUser.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTradeUser.java @@ -1,15 +1,17 @@ package com.eu.habbo.habbohotel.rooms; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.Setter; +import java.util.HashSet; + public class RoomTradeUser { @Getter private final Habbo habbo; - private final THashSet items; + @Getter + private final HashSet items; @Setter @Getter private int userId; @@ -28,19 +30,19 @@ public class RoomTradeUser { this.accepted = false; this.confirmed = false; - this.items = new THashSet<>(); + this.items = new HashSet<>(); } public void confirm() { this.confirmed = true; } - public void addItem(HabboItem item) { + public void addItem(RoomItem item) { this.items.add(item); } - public HabboItem getItem(int itemId) { - for (HabboItem item : this.items) { + public RoomItem getItem(int itemId) { + for (RoomItem item : this.items) { if (item.getId() == itemId) { return item; } @@ -49,10 +51,6 @@ public class RoomTradeUser { return null; } - public THashSet getItems() { - return this.items; - } - public void putItemsIntoInventory() { this.habbo.getInventory().getItemsComponent().addItems(this.items); } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/TraxManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java similarity index 90% rename from src/main/java/com/eu/habbo/habbohotel/rooms/TraxManager.java rename to src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java index 1982f52e..02727127 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/TraxManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomTraxManager.java @@ -7,8 +7,8 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.SoundTrack; import com.eu.habbo.habbohotel.items.interactions.InteractionJukeBox; import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; @@ -29,7 +29,7 @@ import java.util.List; import java.util.stream.Collectors; @Slf4j -public class TraxManager implements Disposable { +public class RoomTraxManager implements Disposable { public static int NORMAL_JUKEBOX_LIMIT = 10; public static int LARGE_JUKEBOX_LIMIT = 20; private final Room room; @@ -47,7 +47,7 @@ public class TraxManager implements Disposable { private boolean disposed = false; - public TraxManager(Room room) { + public RoomTraxManager(Room room) { this.room = room; //Check if room has a Jukebox already on DB @@ -55,7 +55,7 @@ public class TraxManager implements Disposable { if (this.jukeBox == null) { //Check again if there's a jukebox on room but has not been saved on DB before - for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionJukeBox.class)) { + for (RoomItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionJukeBox.class)) { this.jukeBox = (InteractionJukeBox) item; } @@ -71,10 +71,10 @@ public class TraxManager implements Disposable { public InteractionJukeBox loadRoomJukebox() { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_trax WHERE room_id = ?")) { - statement.setInt(1, this.room.getId()); + statement.setInt(1, this.room.getRoomInfo().getId()); try (ResultSet set = statement.executeQuery()) { if (set.next()) { - HabboItem jukebox = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("trax_item_id")); + RoomItem jukebox = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("trax_item_id")); if (jukebox != null) { if (!(jukebox instanceof InteractionJukeBox)) { return null; @@ -100,7 +100,7 @@ public class TraxManager implements Disposable { statement.setInt(1, this.jukeBox.getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - HabboItem musicDisc = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("item_id")); + RoomItem musicDisc = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("item_id")); if (musicDisc != null) { if (!(musicDisc instanceof InteractionMusicDisc) || musicDisc.getRoomId() != -1) { deleteSongFromPlaylist(this.jukeBox.getId(), musicDisc.getId()); @@ -135,7 +135,7 @@ public class TraxManager implements Disposable { if (this.jukeBox != null) return; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement_1 = connection.prepareStatement("INSERT INTO room_trax (room_id, trax_item_id) VALUES (?, ?)")) { - statement_1.setInt(1, this.room.getId()); + statement_1.setInt(1, this.room.getRoomInfo().getId()); statement_1.setInt(2, jukeBox.getId()); statement_1.execute(); } @@ -153,7 +153,7 @@ public class TraxManager implements Disposable { if (this.jukeBox.getId() != jukeBox.getId()) return; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement_1 = connection.prepareStatement("DELETE FROM room_trax WHERE room_id = ?")) { - statement_1.setInt(1, this.room.getId()); + statement_1.setInt(1, this.room.getRoomInfo().getId()); statement_1.execute(); } catch (SQLException e) { @@ -185,7 +185,7 @@ public class TraxManager implements Disposable { public void play(int index, Habbo starter) { if (this.currentlyPlaying == null) { - this.jukeBox.setExtradata("1"); + this.jukeBox.setExtraData("1"); this.room.updateItem(this.jukeBox); } @@ -195,7 +195,8 @@ public class TraxManager implements Disposable { this.currentlyPlaying = this.songs.get(index); if (this.currentlyPlaying != null) { - this.room.setJukeBoxActive(true); + this.room.getRoomInfo().setJukeboxEnabled(true); + this.room.setNeedsUpdate(true); this.startedTimestamp = Emulator.getIntUnixTimestamp(); this.playingIndex = index; @@ -217,14 +218,15 @@ public class TraxManager implements Disposable { AchievementManager.progressAchievement(this.starter, Emulator.getGameEnvironment().getAchievementManager().getAchievement("MusicPlayer"), (Emulator.getIntUnixTimestamp() - cycleStartedTimestamp) / 60); } - this.room.setJukeBoxActive(false); + this.room.getRoomInfo().setJukeboxEnabled(false); + this.room.setNeedsUpdate(true); this.currentlyPlaying = null; this.startedTimestamp = 0; this.cycleStartedTimestamp = 0; this.starter = null; this.playingIndex = 0; - this.jukeBox.setExtradata("0"); + this.jukeBox.setExtraData("0"); this.room.updateItem(this.jukeBox); this.room.sendComposer(new NowPlayingMessageComposer(null, -1, 0).compose()); @@ -264,8 +266,10 @@ public class TraxManager implements Disposable { this.room.sendComposer(new JukeboxSongDisksMessageComposer(this.songs, this.totalLength).compose()); + //Deprecated musicDisc.setRoomId(-1); - musicDisc.needsUpdate(true); + musicDisc.setRoom(null); + musicDisc.setSqlUpdateNeeded(true); Emulator.getThreading().run(musicDisc); habbo.getInventory().getItemsComponent().removeHabboItem(musicDisc); @@ -291,12 +295,13 @@ public class TraxManager implements Disposable { } this.room.sendComposer(new JukeboxSongDisksMessageComposer(this.songs, this.totalLength).compose()); - + //Deprecated musicDisc.setRoomId(0); - musicDisc.needsUpdate(true); + musicDisc.setRoom(null); + musicDisc.setSqlUpdateNeeded(true); Emulator.getThreading().run(musicDisc); - Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(musicDisc.getUserId()); + Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(musicDisc.getOwnerInfo().getId()); if (owner != null) { owner.getInventory().getItemsComponent().addItem(musicDisc); @@ -317,16 +322,18 @@ public class TraxManager implements Disposable { statement.setInt(1, jukebox.getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) { - HabboItem musicDisc = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("item_id")); + RoomItem musicDisc = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set.getInt("item_id")); deleteSongFromPlaylist(jukebox.getId(), set.getInt("item_id")); if (musicDisc != null) { if (musicDisc instanceof InteractionMusicDisc && musicDisc.getRoomId() == -1) { + //Deprecated musicDisc.setRoomId(0); - musicDisc.needsUpdate(true); + musicDisc.setRoom(null); + musicDisc.setSqlUpdateNeeded(true); Emulator.getThreading().run(musicDisc); - Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(musicDisc.getUserId()); + Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(musicDisc.getOwnerInfo().getId()); if (owner != null) { owner.getInventory().getItemsComponent().addItem(musicDisc); @@ -393,7 +400,7 @@ public class TraxManager implements Disposable { } public void sendUpdatedSongList() { - this.room.getHabbos().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/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java deleted file mode 100644 index 91d778cf..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ /dev/null @@ -1,752 +0,0 @@ -package com.eu.habbo.habbohotel.rooms; - -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.items.interactions.interfaces.ConditionalGate; -import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.pets.RideablePet; -import com.eu.habbo.habbohotel.users.DanceType; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; -import com.eu.habbo.plugin.Event; -import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; -import com.eu.habbo.plugin.events.roomunit.RoomUnitSetGoalEvent; -import com.eu.habbo.plugin.events.users.UserIdleEvent; -import com.eu.habbo.plugin.events.users.UserTakeStepEvent; -import com.eu.habbo.threading.runnables.RoomUnitKick; -import com.eu.habbo.util.pathfinding.Rotation; -import gnu.trove.map.TMap; -import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import lombok.extern.slf4j.Slf4j; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -@Slf4j -public class RoomUnit { - - @Getter - @Setter - private boolean isWiredTeleporting = false; - @Getter - @Setter - private boolean isLeavingTeleporter = false; - @Getter - @Setter - private boolean isSwimming = false; - @Getter - private final ConcurrentHashMap status; - private final THashMap cacheable; - @Getter - @Setter - private boolean canRotate = true; - @Getter - @Setter - private boolean animateWalk = false; - @Getter - @Setter - private boolean cmdTeleport = false; - @Getter - @Setter - private boolean cmdSit = false; - @Setter - @Getter - private boolean cmdStand = false; - @Getter - @Setter - private boolean cmdLay = false; - @Setter - @Getter - private boolean sitUpdate = false; - @Getter - @Setter - private boolean isTeleporting = false; - @Getter - @Setter - private boolean isKicked; - @Getter - @Setter - private int kickCount = 0; - private int id; - @Getter - private RoomTile startLocation; - @Getter - @Setter - private RoomTile botStartLocation; - @Getter - private RoomTile previousLocation; - @Getter - @Setter - @Accessors(chain = true) - private double previousLocationZ; - private RoomTile currentLocation; - @Getter - private RoomTile goalLocation; - @Getter - private double z; - private int tilesWalked; - @Getter - @Setter - private boolean inRoom; - @Setter - @Accessors(chain = true) - private boolean canWalk; - @Setter - @Getter - private boolean fastWalk = false; - private boolean statusUpdate = false; - @Getter - @Setter - @Accessors(chain = true) - private boolean invisible = false; - @Setter - private boolean canLeaveRoomByDoor = true; - @Setter - private RoomUserRotation bodyRotation = RoomUserRotation.NORTH; - @Getter - @Setter - private RoomUserRotation headRotation = RoomUserRotation.NORTH; - @Getter - @Setter - private DanceType danceType; - @Getter - @Setter - @Accessors(chain = true) - private RoomUnitType roomUnitType; - @Getter - @Setter - private Deque path = new LinkedList<>(); - private int handItem; - private long handItemTimestamp; - private int walkTimeOut; - private int effectId; - private int effectEndTimestamp; - private int previousEffectId; - private int previousEffectEndTimestamp; - private int timeInRoom; - - private int idleTimer; - @Setter - @Getter - private Room room; - @Getter - @Setter - private RoomRightLevels rightsLevel = RoomRightLevels.NONE; - private final THashSet overridableTiles; - - public RoomUnit() { - this.id = 0; - this.inRoom = false; - this.canWalk = true; - this.status = new ConcurrentHashMap<>(); - this.cacheable = new THashMap<>(); - this.roomUnitType = RoomUnitType.UNKNOWN; - this.danceType = DanceType.NONE; - this.handItem = 0; - this.handItemTimestamp = 0; - this.walkTimeOut = Emulator.getIntUnixTimestamp(); - this.effectId = 0; - this.previousEffectId = 0; - this.previousEffectEndTimestamp = -1; - this.setKicked(false); - this.overridableTiles = new THashSet<>(); - this.timeInRoom = 0; - } - - public void clearWalking() { - this.goalLocation = null; - this.startLocation = this.currentLocation; - this.inRoom = false; - - this.status.clear(); - - this.cacheable.clear(); - } - - public void stopWalking() { - synchronized (this.status) { - this.status.remove(RoomUnitStatus.MOVE); - this.setGoalLocation(this.currentLocation); - } - } - - public boolean cycle(Room room) { - try { - if (handleRider(room)) - return this.statusUpdate; - - Habbo habboT = room.getHabbo(this); - if (!this.isWalking() && !this.isKicked() && this.status.remove(RoomUnitStatus.MOVE) == null && habboT != null) { - habboT.getHabboInfo().getRiding().getRoomUnit().status.remove(RoomUnitStatus.MOVE); - return true; - } - - if (this.status.remove(RoomUnitStatus.SIT) != null || this.status.remove(RoomUnitStatus.MOVE) != null || this.status.remove(RoomUnitStatus.LAY) != null) - this.statusUpdate = true; - - for (Map.Entry set : this.status.entrySet()) { - if (set.getKey().isRemoveWhenWalking()) { - this.status.remove(set.getKey()); - } - } - - if (this.path == null || this.path.isEmpty()) - return true; - - boolean canfastwalk = habboT == null || habboT.getHabboInfo().getRiding() == null; - - RoomTile next = this.path.poll(); - boolean overrideChecks = next != null && this.canOverrideTile(next); - - if (this.path.isEmpty()) { - this.setSitUpdate(true); - - if (next != null && next.hasUnits() && !overrideChecks) { - return false; - } - } - - Deque peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation, this); - - if (peekPath == null) peekPath = new LinkedList<>(); - - if (peekPath.size() >= 3) { - if (path.isEmpty()) return true; - - path.pop(); - //peekPath.pop(); //Start - peekPath.removeLast(); //End - - if (peekPath.peek() != next) { - next = peekPath.poll(); - for (int i = 0; i < peekPath.size(); i++) { - this.path.addFirst(peekPath.removeLast()); - } - } - } - - if (canfastwalk && this.fastWalk && this.path.size() > 1) { - next = this.path.poll(); - } - - if (next == null) - return true; - - Habbo habbo = room.getHabbo(this); - - this.status.remove(RoomUnitStatus.DEAD); - - if (habbo != null) { - if (this.isIdle()) { - UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); - Emulator.getPluginManager().fireEvent(event); - - if (!event.isCancelled() && !event.isIdle()) { - room.unIdle(habbo); - this.idleTimer = 0; - } - } - - if (Emulator.getPluginManager().isRegistered(UserTakeStepEvent.class, false)) { - Event e = new UserTakeStepEvent(habbo, room.getLayout().getTile(this.getX(), this.getY()), next); - Emulator.getPluginManager().fireEvent(e); - - if (e.isCancelled()) - return true; - } - } - - HabboItem item = room.getTopItemAt(next.getX(), next.getY()); - - double height = next.getStackHeight() - this.currentLocation.getStackHeight(); - if (!room.tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.getState() == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) { - this.room = room; - this.path.clear(); - this.findPath(); - - if (this.path.isEmpty()) { - this.status.remove(RoomUnitStatus.MOVE); - return false; - } - next = this.path.pop(); - - } - - boolean canSitNextTile = room.canSitAt(next.getX(), next.getY()); - - if (canSitNextTile) { - HabboItem tallestChair = room.getTallestChair(next); - - if (tallestChair != null) - item = tallestChair; - } - - if (next.equals(this.goalLocation) && next.getState() == RoomTileState.SIT && !overrideChecks - && (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT)) { - this.status.remove(RoomUnitStatus.MOVE); - return false; - } - - double zHeight = 0.0D; - if (habbo != null && habbo.getHabboInfo().getRiding() != null) { - zHeight += 1.0D; - } - - HabboItem habboItem = room.getTopItemAt(this.getX(), this.getY()); - if (habboItem != null && (habboItem != item || !RoomLayout.pointInSquare(habboItem.getX(), habboItem.getY(), habboItem.getX() + habboItem.getBaseItem().getWidth() - 1, habboItem.getY() + habboItem.getBaseItem().getLength() - 1, next.getX(), next.getY()))) - habboItem.onWalkOff(this, room, new Object[]{this.getCurrentLocation(), next}); - - - this.tilesWalked++; - - RoomUserRotation oldRotation = this.getBodyRotation(); - this.setRotation(RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), next.getX(), next.getY())]); - if (item != null) { - if (item != habboItem || !RoomLayout.pointInSquare(item.getX(), item.getY(), item.getX() + item.getBaseItem().getWidth() - 1, item.getY() + item.getBaseItem().getLength() - 1, this.getX(), this.getY())) { - if (item.canWalkOn(this, room, null)) { - item.onWalkOn(this, room, new Object[]{this.getCurrentLocation(), next}); - } else if (item instanceof ConditionalGate conditionalGate) { - this.setRotation(oldRotation); - this.tilesWalked--; - this.setGoalLocation(this.currentLocation); - this.status.remove(RoomUnitStatus.MOVE); - room.sendComposer(new UserUpdateComposer(this).compose()); - - if (habbo != null) { - conditionalGate.onRejected(this, this.getRoom(), new Object[]{}); - } - return false; - } - } else { - item.onWalk(this, room, new Object[]{this.getCurrentLocation(), next}); - } - - zHeight += item.getZ(); - - if (!item.getBaseItem().allowSit() && !item.getBaseItem().allowLay()) { - zHeight += Item.getCurrentHeight(item); - } - } else { - zHeight += room.getLayout().getHeightAtSquare(next.getX(), next.getY()); - } - - - this.setPreviousLocation(this.getCurrentLocation()); - - this.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + zHeight); - if (habbo != null && habbo.getHabboInfo().getRiding() != null) { - RoomUnit ridingUnit = habbo.getHabboInfo().getRiding().getRoomUnit(); - - if (ridingUnit != null) { - ridingUnit.setPreviousLocationZ(this.getZ()); - this.setZ(zHeight - 1.0); - ridingUnit.setRotation(RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), next.getX(), next.getY())]); - ridingUnit.setPreviousLocation(this.getCurrentLocation()); - ridingUnit.setGoalLocation(this.getGoalLocation()); - ridingUnit.setStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + (zHeight - 1.0)); - room.sendComposer(new UserUpdateComposer(ridingUnit).compose()); - } - } - - this.setZ(zHeight); - this.setCurrentLocation(room.getLayout().getTile(next.getX(), next.getY())); - this.resetIdleTimer(); - - if (habbo != null) { - HabboItem topItem = room.getTopItemAt(next.getX(), next.getY()); - - boolean isAtDoor = next.getX() == room.getLayout().getDoorX() && next.getY() == room.getLayout().getDoorY(); - boolean publicRoomKicks = !room.isPublicRoom() || Emulator.getConfig().getBoolean("hotel.room.public.doortile.kick"); - boolean invalidated = topItem != null && topItem.invalidatesToRoomKick(); - - if (this.canLeaveRoomByDoor && isAtDoor && publicRoomKicks && !invalidated) { - Emulator.getThreading().run(new RoomUnitKick(habbo, room, false), 500); - } - } - - return false; - - } catch (Exception e) { - log.error("Caught exception", e); - return false; - } - } - - private boolean handleRider(Room room) { - Habbo rider = null; - if (this.getRoomUnitType() == RoomUnitType.PET) { - Pet pet = room.getPet(this); - if (pet instanceof RideablePet rideablePet) { - rider = rideablePet.getRider(); - } - } - - if (rider != null) { - // copy things from rider - if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatus().containsKey(RoomUnitStatus.MOVE)) { - this.status.remove(RoomUnitStatus.MOVE); - } - - if (rider.getRoomUnit().getCurrentLocation().getX() != this.getX() || rider.getRoomUnit().getCurrentLocation().getY() != this.getY()) { - this.status.put(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentLocation().getX() + "," + rider.getRoomUnit().getCurrentLocation().getY() + "," + (rider.getRoomUnit().getCurrentLocation().getStackHeight())); - this.setPreviousLocation(rider.getRoomUnit().getPreviousLocation()); - this.setPreviousLocationZ(rider.getRoomUnit().getPreviousLocation().getStackHeight()); - this.setCurrentLocation(rider.getRoomUnit().getCurrentLocation()); - this.setZ(rider.getRoomUnit().getCurrentLocation().getStackHeight()); - } - - return true; - } - return false; - } - - public int getId() { - return this.id; - } - - public void setId(int id) { - this.id = id; - } - - public RoomTile getCurrentLocation() { - return this.currentLocation; - } - - public void setCurrentLocation(RoomTile location) { - if (location != null) { - if (this.currentLocation != null) { - this.currentLocation.removeUnit(this); - } - this.currentLocation = location; - location.addUnit(this); - } - } - - public short getX() { - return this.currentLocation.getX(); - } - - public short getY() { - return this.currentLocation.getY(); - } - - public void setZ(double z) { - this.z = z; - - if (this.room != null) { - Bot bot = this.room.getBot(this); - if (bot != null) { - bot.needsUpdate(true); - } - } - } - - public void setRotation(RoomUserRotation rotation) { - this.bodyRotation = rotation; - this.headRotation = rotation; - } - - public RoomUserRotation getBodyRotation() { - return this.bodyRotation; - } - - public boolean canWalk() { - return this.canWalk; - } - - public int tilesWalked() { - return this.tilesWalked; - } - - public RoomUnit setGoalLocation(RoomTile goalLocation) { - if (goalLocation != null) { - this.setGoalLocation(goalLocation, false); - } - return this; - } - - public void setGoalLocation(RoomTile goalLocation, boolean noReset) { - if (Emulator.getPluginManager().isRegistered(RoomUnitSetGoalEvent.class, false)) { - Event event = new RoomUnitSetGoalEvent(this.room, this, goalLocation); - Emulator.getPluginManager().fireEvent(event); - - if (event.isCancelled()) - return; - } - - /// Set start location - this.startLocation = this.currentLocation; - - if (goalLocation != null && !noReset) { - boolean isWalking = this.hasStatus(RoomUnitStatus.MOVE); - this.goalLocation = goalLocation; - this.findPath(); ///< Quadral: this is where we start formulating a path - if (!this.path.isEmpty()) { - this.tilesWalked = isWalking ? this.tilesWalked : 0; - this.setCmdSit(false); - } else { - this.goalLocation = this.currentLocation; - } - } - } - - public RoomUnit setLocation(RoomTile location) { - if (location != null) { - this.startLocation = location; - setPreviousLocation(location); - setCurrentLocation(location); - this.goalLocation = location; - this.botStartLocation = location; - } - return this; - } - - public void setPreviousLocation(RoomTile previousLocation) { - this.previousLocation = previousLocation; - this.previousLocationZ = this.z; - } - - public RoomUnit setPathFinderRoom(Room room) { - this.room = room; - return this; - } - - public void findPath() { - if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.getX(), this.goalLocation.getY()) || this.canOverrideTile(this.goalLocation))) { - Deque newPath = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this); - if (newPath != null) this.path = newPath; - } - } - - public boolean isAtGoal() { - return this.currentLocation.equals(this.goalLocation); - } - - public boolean isWalking() { - return !this.isAtGoal() && this.canWalk; - } - - public String getStatus(RoomUnitStatus key) { - return this.status.get(key); - } - - public RoomUnit removeStatus(RoomUnitStatus key) { - this.status.remove(key); - return this; - } - - public void setStatus(RoomUnitStatus key, String value) { - if (key != null && value != null) { - this.status.put(key, value); - } - } - - public boolean hasStatus(RoomUnitStatus key) { - return this.status.containsKey(key); - } - - public void clearStatus() { - this.status.clear(); - } - - public void statusUpdate(boolean update) { - this.statusUpdate = update; - } - - public boolean needsStatusUpdate() { - return this.statusUpdate; - } - - public TMap getCacheable() { - return this.cacheable; - } - - public int getHandItem() { - return this.handItem; - } - - public RoomUnit setHandItem(int handItem) { - this.handItem = handItem; - this.handItemTimestamp = System.currentTimeMillis(); - return this; - } - - public long getHandItemTimestamp() { - return this.handItemTimestamp; - } - - public int getEffectId() { - return this.effectId; - } - - - public void setEffectId(int effectId, int endTimestamp) { - this.effectId = effectId; - this.effectEndTimestamp = endTimestamp; - } - - public int getEffectEndTimestamp() { - return this.effectEndTimestamp; - } - - public int getPreviousEffectId() { - return this.previousEffectId; - } - - public void setPreviousEffectId(int effectId, int endTimestamp) { - this.previousEffectId = effectId; - this.previousEffectEndTimestamp = endTimestamp; - } - - public int getPreviousEffectEndTimestamp() { - return this.previousEffectEndTimestamp; - } - - public int getWalkTimeOut() { - return this.walkTimeOut; - } - - public void setWalkTimeOut(int walkTimeOut) { - this.walkTimeOut = walkTimeOut; - } - - public void increaseTimeInRoom() { - this.timeInRoom++; - } - - public int getTimeInRoom() { - return this.timeInRoom; - } - - public void resetTimeInRoom() { - this.timeInRoom = 0; - } - - public void increaseIdleTimer() { - this.idleTimer++; - } - - public boolean isIdle() { - return this.idleTimer > Room.IDLE_CYCLES; //Amount of room cycles / 2 = seconds. - } - - public int getIdleTimer() { - return this.idleTimer; - } - - public void resetIdleTimer() { - this.idleTimer = 0; - } - - public void setIdle() { - this.idleTimer = Room.IDLE_CYCLES + 1; - } - - public void lookAtPoint(RoomTile location) { - if (!this.isCanRotate()) return; - - if (Emulator.getPluginManager().isRegistered(RoomUnitLookAtPointEvent.class, false)) { - Event lookAtPointEvent = new RoomUnitLookAtPointEvent(this.room, this, location); - Emulator.getPluginManager().fireEvent(lookAtPointEvent); - - if (lookAtPointEvent.isCancelled()) - return; - } - - if (this.status.containsKey(RoomUnitStatus.LAY)) { - return; - } - - if (!this.status.containsKey(RoomUnitStatus.SIT)) { - this.bodyRotation = (RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), location.getX(), location.getY())]); - } - - RoomUserRotation rotation = (RoomUserRotation.values()[Rotation.Calculate(this.getX(), this.getY(), location.getX(), location.getY())]); - - if (Math.abs(rotation.getValue() - this.bodyRotation.getValue()) <= 1) { - this.headRotation = rotation; - } - } - - public boolean canOverrideTile(RoomTile tile) { - if (tile == null || room == null || room.getLayout() == null) return false; - - if (room.getItemsAt(tile).stream().anyMatch(i -> i.canOverrideTile(this, room, tile))) - return true; - - int tileIndex = (tile.getX() & 0xFF) | (tile.getY() << 12); - return this.overridableTiles.contains(tileIndex); - } - - public void addOverrideTile(RoomTile tile) { - int tileIndex = (tile.getX() & 0xFF) | (tile.getY() << 12); - if (!this.overridableTiles.contains(tileIndex)) { - this.overridableTiles.add(tileIndex); - } - } - - public void removeOverrideTile(RoomTile tile) { - if (room == null || room.getLayout() == null) return; - - int tileIndex = (tile.getX() & 0xFF) | (tile.getY() << 12); - this.overridableTiles.remove(tileIndex); - } - - public void clearOverrideTiles() { - this.overridableTiles.clear(); - } - - public boolean canLeaveRoomByDoor() { - return canLeaveRoomByDoor; - } - - public boolean canForcePosture() { - if (this.room == null) return false; - - HabboItem topItem = this.room.getTopItemAt(this.getX(), this.getY()); - - return (!(topItem instanceof InteractionWater) && !(topItem instanceof InteractionWaterItem)); - } - - public RoomTile getClosestTile(List tiles) { - return tiles.stream().min(Comparator.comparingDouble(a -> a.distance(this.getCurrentLocation()))).orElse(null); - } - - public RoomTile getClosestAdjacentTile(short x, short y, boolean diagonal) { - if (room == null) return null; - - RoomTile baseTile = room.getLayout().getTile(x, y); - - if (baseTile == null) return null; - - List rotations = new ArrayList<>(); - rotations.add(RoomUserRotation.SOUTH.getValue()); - rotations.add(RoomUserRotation.NORTH.getValue()); - rotations.add(RoomUserRotation.EAST.getValue()); - rotations.add(RoomUserRotation.WEST.getValue()); - - if (diagonal) { - rotations.add(RoomUserRotation.NORTH_EAST.getValue()); - rotations.add(RoomUserRotation.NORTH_WEST.getValue()); - rotations.add(RoomUserRotation.SOUTH_EAST.getValue()); - rotations.add(RoomUserRotation.SOUTH_WEST.getValue()); - } - - return this.getClosestTile( - rotations.stream() - .map(rotation -> room.getLayout().getTileInFront(baseTile, rotation)) - .filter(t -> t != null && t.isWalkable() && (this.getCurrentLocation().equals(t) - || !room.hasHabbosAt(t.getX(), t.getY()))) - .toList() - ); - } - -} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java new file mode 100644 index 00000000..5a111020 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitManager.java @@ -0,0 +1,619 @@ +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.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.RoomBot; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; +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; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; + +@Slf4j +@Getter +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; + + 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(); + } + + public synchronized void load(Connection connection) { + this.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(); + + 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()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + Pet pet = PetManager.loadPet(set); + + pet.setRoom(this.room); + pet.getRoomUnit().setRoom(this.room); + pet.getRoomUnit().setLocation(this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y"))); + if (pet.getRoomUnit().getCurrentPosition() == null || pet.getRoomUnit().getCurrentPosition().getState() == RoomTileState.INVALID) { + pet.getRoomUnit().setCurrentZ(this.room.getLayout().getDoorTile().getStackHeight()); + pet.getRoomUnit().setLocation(this.room.getLayout().getDoorTile()); + pet.getRoomUnit().setRotation(RoomRotation.fromValue(this.room.getLayout().getDoorDirection())); + } else { + pet.getRoomUnit().setCurrentZ(set.getDouble("z")); + pet.getRoomUnit().setRotation(RoomRotation.values()[set.getInt("rot")]); + } + pet.getRoomUnit().setRoomUnitType(RoomUnitType.PET); + pet.getRoomUnit().setCanWalk(true); + this.addRoomUnit(pet); + this.room.getFurniOwnerNames().put(pet.getUserId(), set.getString("pet_owner_name")); + } + } + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error("Caught Exception", e); + } + } + + public void addRoomUnit(Unit unit) { + synchronized (this.roomUnitLock) { + //TODO Maybe set the room in this method + + unit.getRoomUnit().setVirtualId(this.roomUnitCounter); + this.currentRoomUnits.put(unit.getRoomUnit().getVirtualId(), unit.getRoomUnit()); + this.roomUnitCounter++; + + switch (unit.getRoomUnit().getRoomUnitType()) { + case HABBO -> { + this.currentHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit); + unit.getRoomUnit().getRoom().updateDatabaseUserCount(); + } + case BOT -> { + this.currentBots.put(((Bot) unit).getId(), (Bot) unit); + } + case PET -> { + 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()); + } + } + } + } + } + + public Collection getRoomUnitsAt(RoomTile tile) { + return this.currentRoomUnits.values().stream().filter(roomUnit -> roomUnit.getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + } + + public boolean areRoomUnitsAt(RoomTile tile) { + return this.currentRoomUnits.values().stream().anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile)); + } + + public boolean areRoomUnitsAt(RoomTile tile, RoomUnit skippedRoomUnit) { + if(skippedRoomUnit == null) { + return this.areRoomUnitsAt(tile); + } + + return this.currentRoomUnits.values().stream().filter(roomUnit -> !roomUnit.equals(skippedRoomUnit)).anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile)); + } + + public List getAvatarsAt(RoomTile tile) { + return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList()); + } + + public int getRoomHabbosCount() { + return this.currentHabbos.size(); + } + + public boolean hasHabbosAt(RoomTile tile) { + return this.currentHabbos.values().stream().anyMatch(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)); + } + + public Collection getHabbosAt(RoomTile tile) { + return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + } + + public Habbo getRoomHabboById(int habboId) { + return this.currentHabbos.get(habboId); + } + + public Habbo getRoomHabboByUsername(String username) { + return this.currentHabbos.values().stream().filter(habbo -> habbo.getHabboInfo().getUsername().equalsIgnoreCase(username)).findFirst().orElse(null); + } + + public Habbo getHabboByVirtualId(int virtualId) { + return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit().getVirtualId() == virtualId).findFirst().orElse(null); + } + + public Habbo getHabboByRoomUnit(RoomUnit roomUnit) { + return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit() == roomUnit).findFirst().orElse(null); + } + + public void updateHabbosAt(RoomTile tile) { + Collection habbos = this.getHabbosAt(tile); + + if(habbos == null || habbos.isEmpty()) { + return; + } + + RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY()); + + for (Habbo habbo : habbos) { + double z = habbo.getRoomUnit().getCurrentPosition().getStackHeight(); + + if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !habbo.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) { + habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT); + } + + if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !habbo.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) { + habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY); + } + + if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) { + if(item.getBaseItem().allowSit()) { + habbo.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item))); + } else if(item.getBaseItem().allowLay()) { + habbo.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item))); + } + + habbo.getRoomUnit().setCurrentZ(item.getCurrentZ()); + habbo.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation())); + } else { + habbo.getRoomUnit().setCurrentZ(z); + } + } + } + + 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) { + RoomTile spawnTile = room.getLayout().getTile(x, y); + + if (spawnTile == null) { + spawnTile = room.getLayout().getDoorTile(); + } + + pet.setRoom(room); + pet.getRoomUnit().walkTo(spawnTile); + pet.getRoomUnit().setLocation(spawnTile) + .setRoomUnitType(RoomUnitType.PET) + .setCanWalk(true) + .setCurrentZ(z); + + if (pet.getRoomUnit().getCurrentPosition() == null) { + pet.getRoomUnit() + .setLocation(room.getLayout().getDoorTile()) + .setRotation(RoomRotation.fromValue(room.getLayout().getDoorDirection())); + } + + pet.setSqlUpdateNeeded(true); + room.getFurniOwnerNames().put(pet.getUserId(), this.getRoomHabboById(pet.getUserId()).getHabboInfo().getUsername()); + this.addRoomUnit(pet); + room.sendComposer(new RoomPetComposer(pet).compose()); + } + } + + public boolean hasPetsAt(RoomTile tile) { + return this.currentPets.values().stream().anyMatch(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)); + } + + public Collection getPetsAt(RoomTile tile) { + return this.currentPets.values().stream().filter(pet -> pet.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); + } + + public Pet getRoomPetById(int petId) { + return this.currentPets.get(petId); + } + + public Pet getPetByRoomUnit(RoomUnit roomUnit) { + return this.currentPets.values().stream().filter(pet -> pet.getRoomUnit() == roomUnit).findFirst().orElse(null); + } + + public void pickUpMyPets(Habbo owner) { + THashSet pets = new THashSet<>(); + + synchronized (this.currentPets) { + for (Pet pet : this.currentPets.values()) { + if (pet.getUserId() == owner.getHabboInfo().getId()) { + pets.add(pet); + } + } + } + + for (Pet pet : pets) { + pet.removeFromRoom(); + Emulator.getThreading().run(pet); + owner.getInventory().getPetsComponent().addPet(pet); + owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); + this.currentPets.remove(pet.getId()); + } + } + + public void removeHabbo(Habbo habbo, boolean sendRemovePacket) { + if(!this.currentHabbos.containsKey(habbo.getHabboInfo().getId())) { + return; + } + + RoomHabbo roomHabbo = habbo.getRoomUnit(); + + if(roomHabbo.getCurrentPosition() != null) { + roomHabbo.getCurrentPosition().removeUnit(habbo.getRoomUnit()); + } + + synchronized (this.roomUnitLock) { + this.currentHabbos.remove(habbo.getHabboInfo().getId()); + this.currentRoomUnits.remove(roomHabbo.getVirtualId()); + } + + roomHabbo.getRoom().sendComposer(new UserRemoveMessageComposer(roomHabbo).compose()); + + //MOVE THIS TO RoomTile.java -> removeUnit() + RoomItem item = roomHabbo.getRoom().getRoomItemManager().getTopItemAt(roomHabbo.getCurrentPosition()); + + if (item != null) { + try { + item.onWalkOff(habbo.getRoomUnit(), roomHabbo.getRoom(), new Object[]{}); + } catch (Exception e) { + log.error("Caught Exception", e); + } + } + + if (habbo.getHabboInfo().getCurrentGame() != null && roomHabbo.getRoom().getGame(habbo.getHabboInfo().getCurrentGame()) != null) { + roomHabbo.getRoom().getGame(habbo.getHabboInfo().getCurrentGame()).removeHabbo(habbo); + } + + RoomTrade trade = roomHabbo.getRoom().getActiveTradeForHabbo(habbo); + + if (trade != null) { + trade.stopTrade(habbo); + } + + if (!roomHabbo.getRoom().getRoomInfo().isRoomOwner(habbo)) { + this.pickUpMyPets(habbo); + } + + roomHabbo.getRoom().updateDatabaseUserCount(); + 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()); + return this.currentPets.remove(petId); + } + + public void removeAllPetsExceptRoomOwner() { + ArrayList toRemovePets = new ArrayList<>(); + ArrayList removedPets = new ArrayList<>(); + synchronized (this.currentPets) { + for (Pet pet : this.currentPets.values()) { + try { + if (pet.getUserId() != pet.getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId()) { + toRemovePets.add(pet); + } + + } catch (NoSuchElementException e) { + log.error("Caught exception", e); + break; + } + } + } + + for (Pet pet : toRemovePets) { + removedPets.add(pet); + + pet.removeFromRoom(); + + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); + if (habbo != null) { + habbo.getInventory().getPetsComponent().addPet(pet); + habbo.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); + } + + pet.setSqlUpdateNeeded(true); + pet.run(); + } + + for (Pet pet : removedPets) { + this.currentPets.remove(pet.getId()); + this.currentRoomUnits.remove(pet.getRoomUnit().getVirtualId()); + } + } + + public void clear() { + synchronized (this.roomUnitLock) { + this.currentRoomUnits.clear(); + this.currentHabbos.clear(); + this.currentBots.clear(); + this.currentPets.clear(); + this.roomUnitCounter = 0; + } + } + + public void dispose() { + for(Habbo habbo : this.currentHabbos.values()) { + Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room, true); + } + + 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(); + + Iterator petIterator = this.currentPets.values().iterator(); + + while(petIterator.hasNext()) { + try { + Pet pet = petIterator.next(); + pet.setSqlUpdateNeeded(true); + Emulator.getThreading().run(pet); + } catch (NoSuchElementException e) { + log.error("Caught Exception", e); + break; + } + } + + this.currentPets.clear(); + this.currentRoomUnits.clear(); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitStatus.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitStatus.java index c77c6326..734a28af 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitStatus.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitStatus.java @@ -6,7 +6,7 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum RoomUnitStatus { - MOVE("mv", true), + MOVE("mv"), // SIT SIT_IN("sit-in"), diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUserRotation.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUserRotation.java deleted file mode 100644 index 624afe34..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUserRotation.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.eu.habbo.habbohotel.rooms; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public enum RoomUserRotation { - NORTH(0), - NORTH_EAST(1), - EAST(2), - SOUTH_EAST(3), - SOUTH(4), - SOUTH_WEST(5), - WEST(6), - NORTH_WEST(7); - - private final int direction; - - - public static RoomUserRotation fromValue(int rotation) { - rotation %= 8; - for (RoomUserRotation rot : values()) { - if (rot.getValue() == rotation) { - return rot; - } - } - - return NORTH; - } - - public static RoomUserRotation counterClockwise(RoomUserRotation rotation) { - return fromValue(rotation.getValue() + 7); - } - - public static RoomUserRotation clockwise(RoomUserRotation rotation) { - return fromValue(rotation.getValue() + 9); - } - - public int getValue() { - return this.direction; - } - - public RoomUserRotation getOpposite() { - return switch (this) { - case NORTH -> RoomUserRotation.SOUTH; - case NORTH_EAST -> RoomUserRotation.SOUTH_WEST; - case EAST -> RoomUserRotation.WEST; - case SOUTH_EAST -> RoomUserRotation.NORTH_WEST; - case SOUTH -> RoomUserRotation.NORTH; - case SOUTH_WEST -> RoomUserRotation.NORTH_EAST; - case WEST -> RoomUserRotation.EAST; - case NORTH_WEST -> RoomUserRotation.SOUTH_EAST; - }; - } -} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWiredManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWiredManager.java new file mode 100644 index 00000000..816a1adb --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWiredManager.java @@ -0,0 +1,138 @@ +package com.eu.habbo.habbohotel.rooms; + +import com.eu.habbo.habbohotel.items.interactions.*; +import com.eu.habbo.habbohotel.wired.WiredConditionType; +import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +@Slf4j +@Getter +public class RoomWiredManager { + private final Room room; + private final ConcurrentHashMap currentWireds; + private final ConcurrentHashMap> currentWiredTriggers; + private final ConcurrentHashMap> currentWiredEffects; + private final ConcurrentHashMap> currentWiredConditions; + private final ConcurrentHashMap currentWiredExtras; + + public RoomWiredManager(Room room) { + this.room = room; + this.currentWireds = new ConcurrentHashMap<>(0); + this.currentWiredTriggers = new ConcurrentHashMap<>(0); + this.currentWiredEffects = new ConcurrentHashMap<>(0); + this.currentWiredConditions = new ConcurrentHashMap<>(0); + this.currentWiredExtras = new ConcurrentHashMap<>(0); + } + + public void addWired(InteractionWired wired) { + this.currentWireds.put(wired.getId(), wired); + sortWired(wired); + } + + public void removeWired(InteractionWired wired) { + InteractionWired w = this.currentWireds.remove(wired.getId()); + + if (w instanceof InteractionWiredTrigger trigger) { + removeWiredTrigger(trigger); + } else if (w instanceof InteractionWiredEffect effect) { + removeWiredEffect(effect); + } else if (w instanceof InteractionWiredCondition condition) { + removeWiredCondition(condition); + } else if (w instanceof InteractionWiredExtra extra) { + removeWiredExtra(extra); + } else { + log.error("Error occurred while removing undefined Wired Type"); + } + } + + private void sortWired(InteractionWired wired) { + if (wired instanceof InteractionWiredTrigger trigger) { + addWiredTrigger(trigger); + } else if (wired instanceof InteractionWiredEffect effect) { + addWiredEffect(effect); + } else if (wired instanceof InteractionWiredCondition condition) { + addWiredCondition(condition); + } else if (wired instanceof InteractionWiredExtra extra) { + addWiredExtra(extra); + } else { + log.error("Undefined Wired Type"); + } + } + + public void addWiredTrigger(InteractionWiredTrigger trigger) { + currentWiredTriggers.computeIfAbsent(trigger.getType(), k -> Collections.newSetFromMap(new ConcurrentHashMap<>())).add(trigger); + } + + public void removeWiredTrigger(InteractionWiredTrigger trigger) { + Set triggers = currentWiredTriggers.get(trigger.getType()); + if (triggers != null) { + triggers.remove(trigger); + if (triggers.isEmpty()) { + currentWiredTriggers.remove(trigger.getType()); + } + } + } + + public void addWiredEffect(InteractionWiredEffect effect) { + currentWiredEffects.computeIfAbsent(effect.getType(), k -> Collections.newSetFromMap(new ConcurrentHashMap<>())).add(effect); + } + + public void removeWiredEffect(InteractionWiredEffect effect) { + Set effects = currentWiredEffects.get(effect.getType()); + if (effects != null) { + effects.remove(effect); + if (effects.isEmpty()) { + currentWiredEffects.remove(effect.getType()); + } + } + } + + public void addWiredCondition(InteractionWiredCondition condition) { + currentWiredConditions.computeIfAbsent(condition.getType(), k -> Collections.newSetFromMap(new ConcurrentHashMap<>())).add(condition); + } + + public void removeWiredCondition(InteractionWiredCondition condition) { + Set conditions = currentWiredConditions.get(condition.getType()); + if (conditions != null) { + conditions.remove(condition); + if (conditions.isEmpty()) { + currentWiredConditions.remove(condition.getType()); + } + } + } + + public void addWiredExtra(InteractionWiredExtra extra) { + currentWiredExtras.put(extra.getId(), extra); + } + + public void removeWiredExtra(InteractionWiredExtra extra) { + currentWiredExtras.remove(extra.getId()); + } + + public void setHideWired(boolean hideWired) { + //TODO FIX THIS +// this.room.getRoomInfo().setHiddenWiredEnabled(hideWired); +// +// if (this.room.getRoomInfo().isHiddenWiredEnabled()) { +// for (RoomItem item : this.currentWireds.values()) { +// this.room.sendComposer(new RemoveFloorItemComposer(item).compose()); +// } +// } else { +// this.room.sendComposer(new ObjectsMessageComposer(this.room.getFurniOwnerNames(), this.currentWireds).compose()); +// } + } + + public void clear() { + this.currentWireds.clear(); + this.currentWiredTriggers.clear(); + this.currentWiredConditions.clear(); + this.currentWiredEffects.clear(); + this.currentWiredExtras.clear(); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWordFilterManager.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWordFilterManager.java new file mode 100644 index 00000000..446922b0 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomWordFilterManager.java @@ -0,0 +1,94 @@ +package com.eu.habbo.habbohotel.rooms; + +import com.eu.habbo.Emulator; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static com.eu.habbo.database.DatabaseConstants.CAUGHT_SQL_EXCEPTION; + +@Slf4j +@Getter +@Setter +@Accessors(chain = true) +public class RoomWordFilterManager { + private final Room room; + + private final List filteredWords; + + public RoomWordFilterManager(Room room) { + this.room = room; + this.filteredWords = new ArrayList<>(); + } + + public synchronized void load(Connection connection) { + this.filteredWords.clear(); + + try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM room_wordfilter WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + try (ResultSet set = statement.executeQuery()) { + while (set.next()) { + this.filteredWords.add(set.getString("word")); + } + } + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } catch (Exception e) { + log.error("Caught Exception", e); + } + } + + public void addWord(String word) { + synchronized (this.filteredWords) { + if (this.filteredWords.contains(word)) + return; + + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT IGNORE INTO room_wordfilter VALUES (?, ?)")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.setString(2, word); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + return; + } + + this.filteredWords.add(word); + } + } + + public void removeWord(String word) { + synchronized (this.filteredWords) { + this.filteredWords.remove(word); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ? AND word = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.setString(2, word); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + } + } + + public void removeAllWords() { + synchronized (this.filteredWords) { + this.filteredWords.clear(); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ?")) { + statement.setInt(1, this.room.getRoomInfo().getId()); + statement.execute(); + } catch (SQLException e) { + log.error(CAUGHT_SQL_EXCEPTION, e); + } + } + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/IRoomEntity.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/IRoomEntity.java new file mode 100644 index 00000000..00b27ebc --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/IRoomEntity.java @@ -0,0 +1,35 @@ +package com.eu.habbo.habbohotel.rooms.entities; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; + +public interface IRoomEntity { + Room getRoom(); + RoomEntity setRoom(Room room); + + RoomTile getPreviousPosition(); + RoomEntity setPreviousPosition(RoomTile previousPosition); + + double getPreviousZ(); + RoomEntity setPreviousZ(double previousZ); + + RoomTile getCurrentPosition(); + RoomEntity setCurrentPosition(RoomTile currentPosition); + + double getCurrentZ(); + RoomEntity setCurrentZ(double currentZ); + + RoomTile getNextPosition(); + RoomEntity setNextPosition(RoomTile nextPosition); + + double getNextZ(); + RoomEntity setNextZ(double nextZ); + + RoomTile getTargetPosition(); + RoomEntity setTargetPosition(RoomTile targetPosition); + + double getTargetZ(); + RoomEntity setTargetZ(double targetZ); + + void incrementTilesMoved(); +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/RoomEntity.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/RoomEntity.java new file mode 100644 index 00000000..dd664a3a --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/RoomEntity.java @@ -0,0 +1,77 @@ +package com.eu.habbo.habbohotel.rooms.entities; + +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +import java.util.Deque; + +@Getter +@Setter +@Accessors(chain = true) +public abstract class RoomEntity implements IRoomEntity { + protected Room room; + protected RoomTile previousPosition; + protected double previousZ; + protected RoomTile currentPosition; + protected double currentZ; + protected RoomTile nextPosition; + protected double nextZ; + protected RoomTile targetPosition; + protected double targetZ; + protected Deque path; + protected int tilesMoved; + + public boolean isAtGoal() { + if(this.targetPosition == null) { + return true; + } + + return this.currentPosition.equals(this.targetPosition); + } + + public RoomEntity setCurrentPosition(RoomTile tile) { + this.previousPosition = this.currentPosition; + this.currentPosition = tile; + return this; + } + + public RoomEntity setCurrentZ(double currentZ) { + this.previousZ = this.currentZ; + this.currentZ = Math.max(-9999, Math.min(currentZ, 9999)); + return this; + } + + protected void clearNextLocation() { + this.nextPosition = null; + this.nextZ = 0; + } + + public synchronized void incrementTilesMoved() { + this.tilesMoved++; + } + + public synchronized void decrementTilesMoved() { + this.tilesMoved--; + } + + public void clear() { + this.room = null; + + this.previousPosition = null; + this.previousZ = 0; + + this.currentPosition = null; + this.currentZ = 0; + + this.nextPosition = null; + this.nextZ = 0; + + this.targetPosition = null; + this.targetZ = 0; + + this.path = null; + } +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/RoomRotation.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/RoomRotation.java new file mode 100644 index 00000000..c32cfd6b --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/RoomRotation.java @@ -0,0 +1,56 @@ +package com.eu.habbo.habbohotel.rooms.entities; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum RoomRotation { + NORTH(0), + NORTH_EAST(1), + EAST(2), + SOUTH_EAST(3), + SOUTH(4), + SOUTH_WEST(5), + WEST(6), + NORTH_WEST(7); + + private final int direction; + + + public static RoomRotation fromValue(int rotation) { + rotation %= 8; + for (RoomRotation rot : values()) { + if (rot.getValue() == rotation) { + return rot; + } + } + + return NORTH; + } + + public static RoomRotation counterClockwise(RoomRotation rotation) { + return fromValue(rotation.getValue() + 7); + } + + public static RoomRotation clockwise(RoomRotation rotation) { + return fromValue(rotation.getValue() + 9); + } + + public int getValue() { + return this.direction; + } + + public RoomRotation getOpposite() { + return switch (this) { + case NORTH -> RoomRotation.SOUTH; + case NORTH_EAST -> RoomRotation.SOUTH_WEST; + case EAST -> RoomRotation.WEST; + case SOUTH_EAST -> RoomRotation.NORTH_WEST; + case SOUTH -> RoomRotation.NORTH; + case SOUTH_WEST -> RoomRotation.NORTH_EAST; + case WEST -> RoomRotation.EAST; + case NORTH_WEST -> RoomRotation.SOUTH_EAST; + }; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/ItemLimitedData.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/ItemLimitedData.java new file mode 100644 index 00000000..76df13cd --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/ItemLimitedData.java @@ -0,0 +1,13 @@ +package com.eu.habbo.habbohotel.rooms.entities.items; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; + +@Getter +@Setter +@Accessors(chain = true) +public class ItemLimitedData { + private int stack; + private int sells; +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java similarity index 60% rename from src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java rename to src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java index 9f1cfd7f..f828a1bf 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/items/RoomItem.java @@ -1,4 +1,4 @@ -package com.eu.habbo.habbohotel.users; +package com.eu.habbo.habbohotel.rooms.entities.items; import com.eu.habbo.Emulator; import com.eu.habbo.database.DatabaseConstants; @@ -11,7 +11,17 @@ import com.eu.habbo.habbohotel.items.IEventTriggers; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomLayout; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomTileState; +import com.eu.habbo.habbohotel.rooms.entities.RoomEntity; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.users.DanceType; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.habbohotel.users.HabboInfo; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -37,8 +47,28 @@ import java.util.Arrays; import java.util.List; @Slf4j -public abstract class HabboItem implements Runnable, IEventTriggers { - +@Getter +@Setter +@Accessors(chain = true) +public abstract class RoomItem extends RoomEntity implements Runnable, IEventTriggers { + private final int id; + private HabboInfo ownerInfo; + /** + * TODO FINISH GET RID OF THIS + */ + @Deprecated + private int roomId; + + private final Item baseItem; + private String wallPosition; + private int rotation; + private String extraData; + private int limitedStack; + private int limitedSells; + private boolean sqlUpdateNeeded = false; + private boolean sqlDeleteNeeded = false; + private boolean isFromGift = false; + @SuppressWarnings("rawtypes") private static final Class[] TOGGLING_INTERACTIONS = new Class[]{ InteractionGameTimer.class, @@ -47,52 +77,31 @@ public abstract class HabboItem implements Runnable, IEventTriggers { InteractionMultiHeight.class }; - @Getter - private final int id; - @Getter - @Setter - private int userId; - @Getter - @Setter - private int roomId; - @Getter - private final Item baseItem; - @Getter - @Setter - private String wallPosition; - @Setter - @Getter - private short x; - @Setter - @Getter - private short y; - @Getter - private double z; - @Getter - private int rotation; - @Setter - @Getter - @Accessors(chain = true) - private String extradata; - @Getter - private int limitedStack; - @Getter - private int limitedSells; - private boolean needsUpdate = false; - private boolean needsDelete = false; - private boolean isFromGift = false; - - public HabboItem(ResultSet set, Item baseItem) throws SQLException { + public RoomItem(ResultSet set, Item baseItem) throws SQLException { this.id = set.getInt("id"); - this.userId = set.getInt(DatabaseConstants.USER_ID); + this.ownerInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(set.getInt(DatabaseConstants.USER_ID)); + this.roomId = set.getInt("room_id"); + + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(set.getInt("room_id")); + this.setRoom(room); + this.baseItem = baseItem; this.wallPosition = set.getString("wall_pos"); - this.x = set.getShort("x"); - this.y = set.getShort("y"); - this.z = set.getDouble("z"); + + if(room != null) { + RoomTile itemTile = room.getLayout().getTile(set.getShort("x"), set.getShort("y")); + + if(itemTile == null) { + this.setRoom(null); + } else { + this.setCurrentPosition(itemTile); + this.setCurrentZ(set.getDouble("z")); + } + } + this.rotation = set.getInt("rot"); - this.extradata = set.getString("extra_data").isEmpty() ? "0" : set.getString("extra_data"); + this.extraData = set.getString("extra_data").isEmpty() ? "0" : set.getString("extra_data"); String ltdData = set.getString("limited_data"); if (!ltdData.isEmpty()) { @@ -101,37 +110,39 @@ public abstract class HabboItem implements Runnable, IEventTriggers { } } - public HabboItem(int id, int userId, Item item, String extradata, int limitedStack, int limitedSells) { + public RoomItem(int id, HabboInfo ownerInfo, Item item, String extraData, int limitedStack, int limitedSells) { this.id = id; - this.userId = userId; + this.ownerInfo = ownerInfo; + + //@Deprecated RoomItem this.roomId = 0; + this.baseItem = item; this.wallPosition = ""; - this.x = 0; - this.y = 0; - this.z = 0; + this.rotation = 0; - this.extradata = extradata.isEmpty() ? "0" : extradata; + this.extraData = extraData.isEmpty() ? "0" : extraData; this.limitedSells = limitedSells; this.limitedStack = limitedStack; + + this.setRoom(null); + this.setCurrentPosition(null); + this.setCurrentZ(0); } - public static RoomTile getSquareInFront(RoomLayout roomLayout, HabboItem item) { - return roomLayout.getTileInFront(roomLayout.getTile(item.getX(), item.getY()), item.getRotation()); + public static RoomTile getSquareInFront(RoomLayout roomLayout, RoomItem item) { + return roomLayout.getTileInFront(roomLayout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getRotation()); } public void serializeFloorData(ServerMessage serverMessage) { try { serverMessage.appendInt(this.getId()); serverMessage.appendInt(this.baseItem.getSpriteId()); - serverMessage.appendInt(this.x); - serverMessage.appendInt(this.y); + serverMessage.appendInt(this.getCurrentPosition().getX()); + serverMessage.appendInt(this.getCurrentPosition().getY()); serverMessage.appendInt(this.getRotation()); - serverMessage.appendString(Double.toString(this.z)); - - serverMessage.appendString((this.getBaseItem().getInteractionType().getType() == InteractionTrophy.class || this.getBaseItem().getInteractionType().getType() == InteractionCrackable.class || this.getBaseItem().getName().equalsIgnoreCase("gnome_box")) ? "1.0" : ((this.getBaseItem().allowWalk() || this.getBaseItem().allowSit() && this.roomId != 0) ? Item.getCurrentHeight(this) + "" : "")); - //serverMessage.appendString( ? "1.0" : ((this.getBaseItem().allowWalk() || this.getBaseItem().allowSit() && this.roomId != 0) ? Item.getCurrentHeight(this) : "")); - + serverMessage.appendString(Double.toString(this.getCurrentZ())); + serverMessage.appendString((this.getBaseItem().getInteractionType().getType() == InteractionTrophy.class || this.getBaseItem().getInteractionType().getType() == InteractionCrackable.class || this.getBaseItem().getName().equalsIgnoreCase("gnome_box")) ? "1.0" : ((this.getBaseItem().allowWalk() || this.getBaseItem().allowSit() && this.roomId != 0) ? String.valueOf(Item.getCurrentHeight(this)) : "")); } catch (Exception e) { log.error("Caught exception", e); } @@ -145,17 +156,17 @@ public abstract class HabboItem implements Runnable, IEventTriggers { } public void serializeWallData(ServerMessage serverMessage) { - serverMessage.appendString(this.getId() + ""); + serverMessage.appendString(String.valueOf(this.getId())); serverMessage.appendInt(this.baseItem.getSpriteId()); serverMessage.appendString(this.wallPosition); if (this instanceof InteractionPostIt) - serverMessage.appendString(this.extradata.split(" ")[0]); + serverMessage.appendString(this.extraData.split(" ")[0]); else - serverMessage.appendString(this.extradata); + serverMessage.appendString(this.extraData); serverMessage.appendInt(-1); serverMessage.appendInt(this.isUsable()); - serverMessage.appendInt(this.getUserId()); + serverMessage.appendInt(this.ownerInfo.getId()); } public int getGiftAdjustedId() { @@ -164,31 +175,10 @@ public abstract class HabboItem implements Runnable, IEventTriggers { return this.id; } - public void setZ(double z) { - if (z > 9999 || z < -9999) return; - this.z = z; - } - public void setRotation(int rotation) { this.rotation = (byte) (rotation % 8); } - public boolean needsUpdate() { - return this.needsUpdate; - } - - public boolean needsDelete() { - return needsDelete; - } - - public void needsUpdate(boolean value) { - this.needsUpdate = value; - } - - public void needsDelete(boolean value) { - this.needsDelete = value; - } - public boolean isLimited() { return this.limitedStack > 0; } @@ -198,24 +188,24 @@ public abstract class HabboItem implements Runnable, IEventTriggers { @Override public void run() { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { - if (this.needsDelete) { - this.needsUpdate = false; - this.needsDelete = false; + if (this.sqlDeleteNeeded) { + this.sqlUpdateNeeded = false; + this.sqlDeleteNeeded = false; try (PreparedStatement statement = connection.prepareStatement("DELETE FROM items WHERE id = ?")) { statement.setInt(1, this.getId()); statement.execute(); } - } else if (this.needsUpdate) { + } else if (this.sqlUpdateNeeded) { try (PreparedStatement statement = connection.prepareStatement("UPDATE items SET user_id = ?, room_id = ?, wall_pos = ?, x = ?, y = ?, z = ?, rot = ?, extra_data = ?, limited_data = ? WHERE id = ?")) { - statement.setInt(1, this.userId); - statement.setInt(2, this.roomId); + statement.setInt(1, this.ownerInfo.getId()); + statement.setInt(2, (this.getRoom() == null) ? 0 : this.getRoom().getRoomInfo().getId()); statement.setString(3, this.wallPosition); - statement.setInt(4, this.x); - statement.setInt(5, this.y); - statement.setDouble(6, Math.max(-9999, Math.min(9999, Math.round(this.z * Math.pow(10, 6)) / Math.pow(10, 6)))); + statement.setInt(4, this.getCurrentPosition().getX()); + statement.setInt(5, this.getCurrentPosition().getY()); + statement.setDouble(6, Math.max(-9999, Math.min(9999, Math.round(this.getCurrentZ() * Math.pow(10, 6)) / Math.pow(10, 6)))); statement.setInt(7, this.rotation); - statement.setString(8, this instanceof InteractionGuildGate ? "" : this.getDatabaseExtraData()); + statement.setString(8, this instanceof InteractionGuildGate ? "" : this.extraData); statement.setString(9, this.limitedStack + ":" + this.limitedSells); statement.setInt(10, this.id); statement.execute(); @@ -224,7 +214,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { log.error("SQLException trying to save HabboItem: " + this); } - this.needsUpdate = false; + this.sqlUpdateNeeded = false; } } catch (SQLException e) { @@ -243,7 +233,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { return; } - if ((this.getBaseItem().getStateCount() > 1 && !(this instanceof InteractionDice) || !(this instanceof InteractionSpinningBottle)) || Arrays.asList(HabboItem.TOGGLING_INTERACTIONS).contains(this.getClass()) || (objects != null && objects.length == 1 && objects[0].equals("TOGGLE_OVERRIDE"))) { + if ((this.getBaseItem().getStateCount() > 1 && !(this instanceof InteractionDice) || !(this instanceof InteractionSpinningBottle)) || Arrays.asList(RoomItem.TOGGLING_INTERACTIONS).contains(this.getClass()) || (objects != null && objects.length == 1 && objects[0].equals("TOGGLE_OVERRIDE"))) { WiredHandler.handle(WiredTriggerType.STATE_CHANGED, client.getHabbo().getRoomUnit(), room, new Object[]{this}); } } @@ -251,26 +241,42 @@ public abstract class HabboItem implements Runnable, IEventTriggers { @Override public void onWalkOn(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - /*if (objects != null && objects.length >= 1 && objects[0] instanceof InteractionWired) - return;*/ - WiredHandler.handle(WiredTriggerType.WALKS_ON_FURNI, roomUnit, room, new Object[]{this}); - if ((this.getBaseItem().allowSit() || this.getBaseItem().allowLay()) && !roomUnit.getDanceType().equals(DanceType.NONE)) { - roomUnit.setDanceType(DanceType.NONE); - room.sendComposer(new DanceMessageComposer(roomUnit).compose()); + if(roomUnit instanceof RoomAvatar roomAvatar) { + if ((this.getBaseItem().allowSit() || this.getBaseItem().allowLay()) && !roomAvatar.getDanceType().equals(DanceType.NONE)) { + roomAvatar.setDanceType(DanceType.NONE); + room.sendComposer(new DanceMessageComposer(roomAvatar).compose()); + } + + if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar); + + if (habbo != null && !habbo.getRoomUnit().isRiding()) { + if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) { + roomAvatar.giveEffect(this.getBaseItem().getEffectM(), -1); + return; + } + + if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) { + roomAvatar.giveEffect(this.getBaseItem().getEffectF(), -1); + } + } + } } - if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousLocation() != roomUnit.getGoalLocation() && roomUnit.getGoalLocation() == room.getLayout().getTile(this.x, this.y)) { - Habbo habbo = room.getHabbo(roomUnit); + if (!this.getBaseItem().getClothingOnWalk().isEmpty() && roomUnit.getPreviousPosition() != roomUnit.getTargetPosition()) { + if (this.getCurrentPosition().equals(roomUnit.getTargetPosition())) { + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomUnit); - if (habbo != null && habbo.getClient() != null) { - String[] clothingKeys = Arrays.stream(this.getBaseItem().getClothingOnWalk().split("\\.")).map(k -> k.split("-")[0]).toArray(String[]::new); - habbo.getHabboInfo().setLook(String.join(".", Arrays.stream(habbo.getHabboInfo().getLook().split("\\.")).filter(k -> !ArrayUtils.contains(clothingKeys, k.split("-")[0])).toArray(String[]::new)) + "." + this.getBaseItem().getClothingOnWalk()); + if (habbo != null && habbo.getClient() != null) { + String[] clothingKeys = Arrays.stream(this.getBaseItem().getClothingOnWalk().split("\\.")).map(k -> k.split("-")[0]).toArray(String[]::new); + habbo.getHabboInfo().setLook(String.join(".", Arrays.stream(habbo.getHabboInfo().getLook().split("\\.")).filter(k -> !ArrayUtils.contains(clothingKeys, k.split("-")[0])).toArray(String[]::new)) + "." + this.getBaseItem().getClothingOnWalk()); - habbo.getClient().sendResponse(new FigureUpdateComposer(habbo)); - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + habbo.getClient().sendResponse(new FigureUpdateComposer(habbo)); + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + } } } } @@ -281,29 +287,43 @@ public abstract class HabboItem implements Runnable, IEventTriggers { if(objects != null && objects.length > 0) { WiredHandler.handle(WiredTriggerType.WALKS_OFF_FURNI, roomUnit, room, new Object[]{this}); } + + if (roomUnit instanceof RoomAvatar roomAvatar) { + + Habbo habbo = room.getRoomUnitManager().getHabboByRoomUnit(roomAvatar); + + if (habbo != null && !habbo.getRoomUnit().isRiding()) { + if (habbo.getHabboInfo().getGender().equals(HabboGender.M) && this.getBaseItem().getEffectM() > 0) { + roomAvatar.giveEffect(0, -1); + } + + if (habbo.getHabboInfo().getGender().equals(HabboGender.F) && this.getBaseItem().getEffectF() > 0) { + roomAvatar.giveEffect(0, -1); + } + } + } } public abstract void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception; - public void onPlace(Room room) { //TODO: IMPORTANT: MAKE THIS GENERIC. (HOLES, ICE SKATE PATCHES, BLACK HOLE, BUNNY RUN FIELD, FOOTBALL FIELD) Achievement roomDecoAchievement = Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoFurniCount"); - Habbo owner = room.getHabbo(this.getUserId()); + Habbo owner = room.getRoomUnitManager().getRoomHabboById(this.ownerInfo.getId()); int furniCollecterProgress; if (owner == null) { - furniCollecterProgress = AchievementManager.getAchievementProgressForHabbo(this.getUserId(), roomDecoAchievement); + furniCollecterProgress = AchievementManager.getAchievementProgressForHabbo(this.ownerInfo.getId(), roomDecoAchievement); } else { furniCollecterProgress = owner.getHabboStats().getAchievementProgress(roomDecoAchievement); } - int difference = room.getUserFurniCount(this.getUserId()) - furniCollecterProgress; + int difference = room.getUserFurniCount(this.ownerInfo.getId()) - furniCollecterProgress; if (difference > 0) { if (owner != null) { AchievementManager.progressAchievement(owner, roomDecoAchievement, difference); } else { - AchievementManager.progressAchievement(this.getUserId(), roomDecoAchievement, difference); + AchievementManager.progressAchievement(this.ownerInfo.getId(), roomDecoAchievement, difference); } } @@ -311,24 +331,24 @@ public abstract class HabboItem implements Runnable, IEventTriggers { int uniqueFurniCollecterProgress; if (owner == null) { - uniqueFurniCollecterProgress = AchievementManager.getAchievementProgressForHabbo(this.getUserId(), roomDecoUniqueAchievement); + uniqueFurniCollecterProgress = AchievementManager.getAchievementProgressForHabbo(this.ownerInfo.getId(), roomDecoUniqueAchievement); } else { uniqueFurniCollecterProgress = owner.getHabboStats().getAchievementProgress(roomDecoUniqueAchievement); } - int uniqueDifference = room.getUserUniqueFurniCount(this.getUserId()) - uniqueFurniCollecterProgress; + int uniqueDifference = room.getUserUniqueFurniCount(this.ownerInfo.getId()) - uniqueFurniCollecterProgress; if (uniqueDifference > 0) { if (owner != null) { AchievementManager.progressAchievement(owner, roomDecoUniqueAchievement, uniqueDifference); } else { - AchievementManager.progressAchievement(this.getUserId(), roomDecoUniqueAchievement, uniqueDifference); + AchievementManager.progressAchievement(this.ownerInfo.getId(), roomDecoUniqueAchievement, uniqueDifference); } } } public void onPickUp(Room room) { if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { - HabboItem topItem2 = room.getTopItemAt(this.getX(), this.getY(), this); + RoomItem topItem2 = room.getRoomItemManager().getTopItemAt(this.getCurrentPosition().getX(), this.getCurrentPosition().getY(), this); int nextEffectM = 0; int nextEffectF = 0; @@ -339,21 +359,22 @@ public abstract class HabboItem implements Runnable, IEventTriggers { for (Habbo habbo : room.getHabbosOnItem(this)) { if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { - room.giveEffect(habbo, nextEffectM, -1); + habbo.getRoomUnit().giveEffect(nextEffectM, -1); } if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) { - room.giveEffect(habbo, nextEffectF, -1); + habbo.getRoomUnit().giveEffect(nextEffectF, -1); } } - for (Bot bot : room.getBotsAt(room.getLayout().getTile(this.getX(), this.getY()))) { + RoomTile tile = room.getLayout().getTile(this.getCurrentPosition().getX(), this.getCurrentPosition().getY()); + for (Bot bot : room.getRoomUnitManager().getBotsAt(tile)) { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { - room.giveEffect(bot.getRoomUnit(), nextEffectM, -1); + bot.getRoomUnit().giveEffect(nextEffectM, -1); } if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) { - room.giveEffect(bot.getRoomUnit(), nextEffectF, -1); + bot.getRoomUnit().giveEffect(nextEffectF, -1); } } } @@ -361,7 +382,7 @@ public abstract class HabboItem implements Runnable, IEventTriggers { public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { if (this.getBaseItem().getEffectF() > 0 || this.getBaseItem().getEffectM() > 0) { - HabboItem topItem2 = room.getTopItemAt(oldLocation.getX(), oldLocation.getY(), this); + RoomItem topItem2 = room.getRoomItemManager().getTopItemAt(oldLocation.getX(), oldLocation.getY(), this); int nextEffectM = 0; int nextEffectF = 0; @@ -376,13 +397,13 @@ public abstract class HabboItem implements Runnable, IEventTriggers { List newBots = new ArrayList<>(); for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) { - oldHabbos.addAll(room.getHabbosAt(tile)); - oldBots.addAll(room.getBotsAt(tile)); + oldHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile)); + oldBots.addAll(room.getRoomUnitManager().getBotsAt(tile)); } for (RoomTile tile : room.getLayout().getTilesAt(oldLocation, this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation())) { - newHabbos.addAll(room.getHabbosAt(tile)); - newBots.addAll(room.getBotsAt(tile)); + newHabbos.addAll(room.getRoomUnitManager().getHabbosAt(tile)); + newBots.addAll(room.getRoomUnitManager().getBotsAt(tile)); } oldHabbos.removeAll(newHabbos); @@ -393,51 +414,47 @@ public abstract class HabboItem implements Runnable, IEventTriggers { oldHabbos.forEach(habbo -> { if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { - room.giveEffect(habbo, finalNextEffectM, -1); + habbo.getRoomUnit().giveEffect(finalNextEffectM, -1); } if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) { - room.giveEffect(habbo, finalNextEffectF, -1); + habbo.getRoomUnit().giveEffect(finalNextEffectF, -1); } }); newHabbos.forEach(habbo -> { if (this.getBaseItem().getEffectM() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.M) && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { - room.giveEffect(habbo, this.getBaseItem().getEffectM(), -1); + habbo.getRoomUnit().giveEffect(this.getBaseItem().getEffectM(), -1); } if (this.getBaseItem().getEffectF() > 0 && habbo.getHabboInfo().getGender().equals(HabboGender.F) && habbo.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { - room.giveEffect(habbo, this.getBaseItem().getEffectF(), -1); + habbo.getRoomUnit().giveEffect(this.getBaseItem().getEffectF(), -1); } }); oldBots.forEach(bot -> { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectM()) { - room.giveEffect(bot.getRoomUnit(), finalNextEffectM, -1); + bot.getRoomUnit().giveEffect(finalNextEffectM, -1); } if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() == this.getBaseItem().getEffectF()) { - room.giveEffect(bot.getRoomUnit(), finalNextEffectF, -1); + bot.getRoomUnit().giveEffect(finalNextEffectF, -1); } }); newBots.forEach(bot -> { if (this.getBaseItem().getEffectM() > 0 && bot.getGender().equals(HabboGender.M) && bot.getRoomUnit().getEffectId() != this.getBaseItem().getEffectM()) { - room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectM(), -1); + bot.getRoomUnit().giveEffect(this.getBaseItem().getEffectM(), -1); } if (this.getBaseItem().getEffectF() > 0 && bot.getGender().equals(HabboGender.F) && bot.getRoomUnit().getEffectId() != this.getBaseItem().getEffectF()) { - room.giveEffect(bot.getRoomUnit(), this.getBaseItem().getEffectF(), -1); + bot.getRoomUnit().giveEffect(this.getBaseItem().getEffectF(), -1); } }); } } - public String getDatabaseExtraData() { - return this.getExtradata(); - } - @Override public String toString() { - return "ID: " + this.id + ", BaseID: " + this.getBaseItem().getId() + ", X: " + this.x + ", Y: " + this.y + ", Z: " + this.z + ", Extradata: " + this.extradata; + return "ID: " + this.id + ", BaseID: " + this.getBaseItem().getId() + ", X: " + this.getCurrentPosition().getX() + ", Y: " + this.getCurrentPosition().getY() + ", Z: " + this.getCurrentZ() + ", Extradata: " + this.extraData; } public boolean allowWiredResetState() { @@ -448,24 +465,14 @@ public abstract class HabboItem implements Runnable, IEventTriggers { return this.baseItem.getStateCount() > 1; } - public boolean canStackAt(Room room, List>> itemsAtLocation) { + public boolean canStackAt(List>> itemsAtLocation) { return true; } - public boolean isFromGift() { - return isFromGift; - } - - public void setFromGift(boolean fromGift) { - isFromGift = fromGift; - } - - public boolean invalidatesToRoomKick() { return false; } - public List getOccupyingTiles(RoomLayout layout) { List tiles = new ArrayList<>(); - Rectangle rect = RoomLayout.getRectangle(this.getX(), this.getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); + Rectangle rect = RoomLayout.getRectangle(this.getCurrentPosition().getX(), this.getCurrentPosition().getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); for (int i = rect.x; i < rect.x + rect.getWidth(); i++) { for (int j = rect.y; j < rect.y + rect.getHeight(); j++) { @@ -476,10 +483,6 @@ public abstract class HabboItem implements Runnable, IEventTriggers { return tiles; } - public RoomTile getOverrideGoalTile(RoomUnit unit, Room room, RoomTile tile) { - return tile; - } - public RoomTileState getOverrideTileState(RoomTile tile, Room room) { return null; } @@ -490,8 +493,8 @@ public abstract class HabboItem implements Runnable, IEventTriggers { public Rectangle getRectangle() { return RoomLayout.getRectangle( - this.getX(), - this.getY(), + this.getCurrentPosition().getX(), + this.getCurrentPosition().getY(), this.getBaseItem().getWidth(), this.getBaseItem().getLength(), this.getRotation()); @@ -499,8 +502,8 @@ public abstract class HabboItem implements Runnable, IEventTriggers { public Rectangle getRectangle(int marginX, int marginY) { return RoomLayout.getRectangle( - this.getX() - marginX, - this.getY() - marginY, + this.getCurrentPosition().getX() - marginX, + this.getCurrentPosition().getY() - marginY, this.getBaseItem().getWidth() + (marginX * 2), this.getBaseItem().getLength() + (marginY * 2), this.getRotation()); diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/IRoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/IRoomUnit.java new file mode 100644 index 00000000..a85eb9a6 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/IRoomUnit.java @@ -0,0 +1,4 @@ +package com.eu.habbo.habbohotel.rooms.entities.units; + +public interface IRoomUnit { +} 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 new file mode 100644 index 00000000..2ac2257d --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnit.java @@ -0,0 +1,616 @@ +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.*; +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; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; +import com.eu.habbo.habbohotel.units.Unit; +import com.eu.habbo.habbohotel.users.DanceType; +import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; +import com.eu.habbo.plugin.Event; +import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; +import com.eu.habbo.plugin.events.roomunit.RoomUnitSetGoalEvent; +import com.eu.habbo.util.pathfinding.Rotation; +import gnu.trove.map.hash.THashMap; +import gnu.trove.set.hash.THashSet; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +@Slf4j +@Getter +@Accessors(chain = true) +public abstract class RoomUnit extends RoomEntity { + @Setter + protected int virtualId; + @Setter + protected Unit unit; + @Setter + protected RoomUnitType roomUnitType; + @Setter + protected RoomRotation bodyRotation; + @Setter + protected RoomRotation headRotation; + @Setter + protected boolean canWalk; + @Setter + protected boolean canRotate; + @Setter + protected boolean isTeleporting; + @Setter + protected boolean cmdSitEnabled = false; + @Setter + protected boolean cmdStandEnabled = false; + @Setter + protected boolean cmdLayEnabled = false; + @Setter + protected boolean isSwimming = false; + @Setter + protected boolean cmdFastWalkEnabled; + @Setter + protected boolean temporalFastWalkEnabled; + protected final ConcurrentHashMap statuses; + @Setter + protected boolean statusUpdateNeeded; + @Setter + protected boolean isWiredTeleporting = false; + @Setter + protected boolean isLeavingTeleporter = false; + protected final THashMap cacheable; + @Setter + protected boolean isKicked; + @Setter + protected int kickCount = 0; + @Setter + @Accessors(chain = true) + protected boolean invisible = false; + @Setter + protected boolean canLeaveRoomByDoor = true; + @Setter + protected int walkTimeOut; + protected int timeInRoom; + protected RoomRightLevels rightsLevel = RoomRightLevels.NONE; + protected final THashSet overridableTiles; + + public RoomUnit() { + this.virtualId = 0; + this.bodyRotation = RoomRotation.NORTH; + this.headRotation = RoomRotation.NORTH; + this.canWalk = true; + this.canRotate = true; + this.isTeleporting = false; + this.cmdFastWalkEnabled = false; + this.statuses = new ConcurrentHashMap<>(); + this.statusUpdateNeeded = false; + + this.cacheable = new THashMap<>(); + this.roomUnitType = RoomUnitType.UNKNOWN; + this.walkTimeOut = Emulator.getIntUnixTimestamp(); + this.timeInRoom = 0; + + //RoomHabbo + this.isKicked = false; + this.overridableTiles = new THashSet<>(); + this.statusUpdateNeeded = false; + } + + public RoomItem getCurrentItem() { + return this.room.getRoomItemManager().getTopItemAt(this.currentPosition); + } + + public void cycle() { + if(this.isWalking()) { + this.processWalking(); + } else { + this.stopWalking(); + } + }; + + public boolean isInRoom() { + return this.room != null; + } + + @Override + public RoomUnit setCurrentPosition(RoomTile tile) { + super.setCurrentPosition(tile); + + if (this.previousPosition != null) { + this.previousPosition.removeUnit(this); + } + + if(this.currentPosition != null) { + tile.addRoomUnit(this); + } + + return this; + } + + public void setRotation(RoomRotation rotation) { + this.bodyRotation = rotation; + this.headRotation = rotation; + this.statusUpdateNeeded = true; + } + + public void stopWalking() { + synchronized (this.statuses) { + if(this.path != null) { + this.path.clear(); + } + + this.nextPosition = null; + this.targetPosition = null; + + this.removeStatus(RoomUnitStatus.MOVE); + this.handleSitStatus(); + this.handleLayStatus(); + + this.temporalFastWalkEnabled = false; + } + } + + @Override + public RoomUnit setCurrentZ(double currentZ) { + super.setCurrentZ(currentZ); + + if (this.room != null) { + Bot bot = this.room.getRoomUnitManager().getRoomBotById(getVirtualId()); + if (bot != null) { + bot.setSqlUpdateNeeded(true); + } + } + + this.statusUpdateNeeded = true; + return this; + } + + /** + * Sets the target position for the character's movement and calculates the path to reach the destination. + * + * @param goalLocation The target location (represented by a {@link RoomTile}) to which the character should move. + * @return {@code true} if the path calculation to the goal location is successful, {@code false} otherwise. + * Returns {@code false} if the goal location is not walkable or the character's current room does not allow sitting or laying at that location. + * Additionally, the path calculation may be canceled by registered plugins listening to {@link RoomUnitSetGoalEvent}. + * In such cases, the method also returns {@code false}. + */ + public boolean walkTo(RoomTile goalLocation) { + if(!goalLocation.isWalkable() && !this.room.canSitOrLayAt(goalLocation)) { + return false; + } + + if (Emulator.getPluginManager().isRegistered(RoomUnitSetGoalEvent.class, false)) { + Event event = new RoomUnitSetGoalEvent(this.room, this, goalLocation); + Emulator.getPluginManager().fireEvent(event); + + if (event.isCancelled()) + return false; + } + + if(this.nextPosition != null) { + this.setCurrentPosition(this.nextPosition); + this.setCurrentZ(this.nextZ); + } + + this.targetPosition = goalLocation; + this.findPath(); + return true; + } + + public RoomUnit setLocation(RoomTile location) { + if (location != null) { + this.setCurrentPosition(location); + this.targetPosition = location; + } + return this; + } + + /** + * Finds a path from the current position to the target position within a room's layout, if valid. + * The method checks if the room, layout, and target position are valid, and if the target position is walkable + * or can be occupied by sitting or laying, or if it can be overridden. + * If all conditions are met, the method attempts to find a path from the current position to the target position + * using the room's layout and sets the path accordingly. + * + * Pre-conditions: + * - The current object must have a valid room set (using the `setRoom(Room room)` method). + * - The target position must be set (using the `setTargetPosition(RoomTile targetPosition)` method). + * + * Post-conditions: + * - If a valid path is found from the current position to the target position, the path is set using the `setPath(Deque path)` method. + * + * Note: + * - The method relies on the validity of the room and layout, and whether the target position is walkable, or can be occupied by sitting or laying, + * or can be overridden. If any of these conditions are not met, the method will not attempt to find a path. + * - The `findPath()` method assumes that the room and layout are well-defined and consistent, and that the target position is within the boundaries of the room's layout. + * - The method may return `null` if no valid path is found from the current position to the target position. + */ + public void findPath() { + boolean hasValidRoom = this.room != null; + boolean hasValidLayout = hasValidRoom && this.room.getLayout() != null; + boolean hasValidTargetPosition = this.targetPosition != null; + boolean isTargetPositionWalkable = hasValidTargetPosition && this.targetPosition.isWalkable(); + boolean canSitOrLayAtTarget = hasValidTargetPosition && hasValidRoom && this.room.canSitOrLayAt(this.targetPosition); + boolean canOverrideTile = hasValidTargetPosition && this.canOverrideTile(this.targetPosition); + + if (hasValidLayout && (isTargetPositionWalkable || canSitOrLayAtTarget || canOverrideTile)) { + Deque newPath = this.room.getLayout().findPath(this.currentPosition, this.targetPosition, this.targetPosition, this); + if (newPath != null) { + this.setPath(newPath); + } + } + } + + public boolean isWalking() { + return !this.isAtGoal() && this.canWalk; + } + + public boolean hasStatus(RoomUnitStatus key) { + return this.statuses.containsKey(key); + } + + public String getStatus(RoomUnitStatus key) { + return this.statuses.get(key); + } + + public String getCurrentStatuses() { + StringBuilder status = new StringBuilder("/"); + + for (Map.Entry entry : this.statuses.entrySet()) { + status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); + } + + return status.toString(); + } + + public void addStatus(RoomUnitStatus key, String value) { + if (key != null && value != null) { + this.statuses.put(key, value); + this.statusUpdateNeeded = true; + } + } + + public RoomUnit removeStatus(RoomUnitStatus key) { + String statusRemoved = this.statuses.remove(key); + + if(statusRemoved != null) { + this.statusUpdateNeeded = true; + } + + return this; + } + + public void clearStatuses() { + this.statuses.clear(); + } + + public void setRightsLevel(RoomRightLevels rightsLevel) { + this.rightsLevel = rightsLevel; + this.statusUpdateNeeded = true; + } + + public void makeStand() { + RoomItem item = this.room.getRoomItemManager().getTopItemAt(this.currentPosition.getX(), this.currentPosition.getY()); + if (item == null || !item.getBaseItem().allowSit() || !item.getBaseItem().allowLay()) { + this.cmdStandEnabled = true; + this.bodyRotation = RoomRotation.values()[this.getBodyRotation().getValue() - this.getBodyRotation().getValue() % 2]; + this.removeStatus(RoomUnitStatus.SIT); + this.instantUpdate(); + } + } + + public void makeSit() { + if (this.hasStatus(RoomUnitStatus.SIT) || !this.canForcePosture()) { + return; + } + + this.cmdSitEnabled = true; + this.bodyRotation = RoomRotation.values()[this.getBodyRotation().getValue() - this.getBodyRotation().getValue() % 2]; + this.addStatus(RoomUnitStatus.SIT, "0.5"); + + if(this instanceof RoomAvatar roomAvatar) { + roomAvatar.setDance(DanceType.NONE); + } + + this.instantUpdate(); + } + + public void increaseTimeInRoom() { + this.timeInRoom++; + } + + public void resetTimeInRoom() { + this.timeInRoom = 0; + } + + public void lookAtPoint(RoomTile location) { + if (!this.isCanRotate()) { + return; + } + + if (Emulator.getPluginManager().isRegistered(RoomUnitLookAtPointEvent.class, false)) { + Event lookAtPointEvent = new RoomUnitLookAtPointEvent(this.room, this, location); + Emulator.getPluginManager().fireEvent(lookAtPointEvent); + + if (lookAtPointEvent.isCancelled()) + return; + } + + if (this.statuses.containsKey(RoomUnitStatus.LAY)) { + return; + } + + RoomRotation rotation = (RoomRotation.values()[Rotation.Calculate(this.currentPosition.getX(), this.currentPosition.getY(), location.getX(), location.getY())]); + + if (!this.statuses.containsKey(RoomUnitStatus.SIT)) { + this.bodyRotation = rotation; + } + + if (Math.abs(rotation.getValue() - this.bodyRotation.getValue()) <= 1) { + this.headRotation = rotation; + } + + this.statusUpdateNeeded = true; + } + + public boolean canOverrideTile(RoomTile tile) { + if (tile == null || this.room == null || this.room.getLayout() == null) return false; + + if (this.room.getRoomItemManager().getItemsAt(tile).stream().anyMatch(i -> i.canOverrideTile(this, this.room, tile))) + return true; + + int tileIndex = (tile.getX() & 0xFF) | (tile.getY() << 12); + return this.overridableTiles.contains(tileIndex); + } + + public void addOverrideTile(RoomTile tile) { + int tileIndex = (tile.getX() & 0xFF) | (tile.getY() << 12); + if (!this.overridableTiles.contains(tileIndex)) { + this.overridableTiles.add(tileIndex); + } + } + + public void removeOverrideTile(RoomTile tile) { + if (this.room == null || this.room.getLayout() == null) return; + + int tileIndex = (tile.getX() & 0xFF) | (tile.getY() << 12); + this.overridableTiles.remove(tileIndex); + } + + public boolean canForcePosture() { + if (this.room == null) return false; + + RoomItem topItem = this.room.getRoomItemManager().getTopItemAt(this.currentPosition.getX(), this.currentPosition.getY()); + + return (!(topItem instanceof InteractionWater) && !(topItem instanceof InteractionWaterItem)); + } + + public RoomTile getClosestTile(List tiles) { + return tiles.stream().min(Comparator.comparingDouble(a -> a.distance(this.currentPosition))).orElse(null); + } + + public RoomTile getClosestAdjacentTile(short x, short y, boolean diagonal) { + if (this.room == null) return null; + + RoomTile baseTile = this.room.getLayout().getTile(x, y); + + if (baseTile == null) return null; + + List rotations = new ArrayList<>(); + rotations.add(RoomRotation.SOUTH.getValue()); + rotations.add(RoomRotation.NORTH.getValue()); + rotations.add(RoomRotation.EAST.getValue()); + rotations.add(RoomRotation.WEST.getValue()); + + if (diagonal) { + rotations.add(RoomRotation.NORTH_EAST.getValue()); + rotations.add(RoomRotation.NORTH_WEST.getValue()); + rotations.add(RoomRotation.SOUTH_EAST.getValue()); + rotations.add(RoomRotation.SOUTH_WEST.getValue()); + } + + return this.getClosestTile( + rotations.stream() + .map(rotation -> this.room.getLayout().getTileInFront(baseTile, rotation)) + .filter(t -> t != null && t.isWalkable() && (this.currentPosition.equals(t) || !this.room.getRoomUnitManager().hasHabbosAt(t))) + .toList() + ); + } + + public void handleSitStatus() { + if(this.getCurrentItem() == null || !this.getCurrentItem().getBaseItem().allowSit()) { + return; + } + + if(!this.isCmdSitEnabled()) { + if(this.currentPosition.getState().equals(RoomTileState.SIT) && !this.hasStatus(RoomUnitStatus.SIT)) { + this.addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(this.getCurrentItem()))); + this.setCurrentZ(this.getCurrentItem().getCurrentZ()); + this.setRotation(RoomRotation.values()[this.getCurrentItem().getRotation()]); + } else if(!this.getCurrentItem().getBaseItem().allowSit() && this.hasStatus(RoomUnitStatus.SIT)) { + this.removeStatus(RoomUnitStatus.SIT); + this.instantUpdate(); + } + } + } + + public void handleLayStatus() { + if(this.getCurrentItem() == null || !this.getCurrentItem().getBaseItem().allowLay()) { + return; + } + + if(!this.isCmdLayEnabled()) { + if(this.currentPosition.getState().equals(RoomTileState.LAY) && !this.hasStatus(RoomUnitStatus.LAY)) { + this.addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(this.getCurrentItem()))); + this.setRotation(RoomRotation.values()[this.getCurrentItem().getRotation() % 4]); + } else if (!this.getCurrentItem().getBaseItem().allowLay() && this.hasStatus(RoomUnitStatus.LAY)) { + this.removeStatus(RoomUnitStatus.LAY); + this.instantUpdate(); + } + } + } + + /** + * Performs an instant update of the character's status to the connected room, if needed. + * The method checks if a status update is required based on the internal flag `statusUpdateNeeded`. + * If an update is needed, the method sends the character's updated status information to the room + * using the {@link UserUpdateComposer}, effectively synchronizing the character's status with other room participants. + * After the update is sent, the `statusUpdateNeeded` flag is reset to false until the next change in the character's status. + * Note: This method is typically called when an immediate status update is necessary, such as when a status change occurs + * and should be communicated to other room users without delay. + */ + public void instantUpdate() { + if(this.statusUpdateNeeded) { + this.statusUpdateNeeded = false; + this.room.sendComposer(new UserUpdateComposer(this).compose()); + } + } + + /** + * Processes the character's walking behavior based on its current walking state. + * If the character is currently walking, the method executes the necessary steps to continue the movement. + * The process involves updating the character's status, position, rotation, and height while moving along the computed path. + * If the character reaches the destination tile, walking is stopped. + * If the character encounters an invalid tile during its path, it recalculates the path to find an alternative route. + * The method also handles fast walking when enabled, allowing the character to move more quickly through the path. + * Note: This method is typically called in a loop to facilitate continuous character movement. + */ + public void processWalking() { + this.statuses.entrySet().removeIf(entry -> entry.getKey().isRemoveWhenWalking()); + + if(this.getNextPosition() != null) { + this.setCurrentPosition(this.getNextPosition()); + this.setCurrentZ(this.getNextZ()); + } + + if(this.path != null && !this.path.isEmpty()) { + RoomTile next = this.path.poll(); + + if(this.path.size() > 1 && (this.cmdFastWalkEnabled || this.temporalFastWalkEnabled)) { + next = this.path.poll(); + } + + if(next == null || !this.isValidTile(next)) { + this.path.clear(); + this.findPath(); + + if(this.path.isEmpty()) { + return; + } + + next = this.path.poll(); + } + + RoomRotation nextRotation = this.handleNextRotation(next); + double nextHeight = this.handleNextHeight(next); + + this.setRotation(nextRotation); + this.addStatus(RoomUnitStatus.MOVE, next.getX() + "," + next.getY() + "," + nextHeight); + this.nextPosition = next; + this.nextZ = nextHeight; + } else { + this.stopWalking(); + } + } + + private RoomRotation handleNextRotation(RoomTile next) { + return RoomRotation.values()[Rotation.Calculate(this.currentPosition.getX(), this.currentPosition.getY(), next.getX(), next.getY())]; + } + + private double handleNextHeight(RoomTile next) { + double height = 0.0D; + + if(this instanceof RoomAvatar roomAvatar && roomAvatar.isRiding()) { + height += 1.0D; + } + + RoomItem nextTileItem = this.room.getRoomItemManager().getTopItemAt(next); + + if(nextTileItem != null) { + height += nextTileItem.getNextZ(); + + if (!nextTileItem.getBaseItem().allowSit() && !nextTileItem.getBaseItem().allowLay()) { + height += Item.getCurrentHeight(nextTileItem); + } + } else { + height += this.room.getLayout().getHeightAtSquare(next.getX(), next.getY()); + } + + return height; + } + + /** + * Checks whether the provided {@link RoomTile} is a valid tile for the character to walk on. + * + * @param tile The {@link RoomTile} to be validated. + * @return {@code true} if the tile is valid for walking, {@code false} otherwise. + * Returns {@code true} if the character can override the tile (e.g., walk on furniture). + * Otherwise, the method checks various conditions to determine the tile's validity: + * - The tile's height difference from the character's current height should be within the allowable step height range. + * - The tile should not be blocked, invalid, or have an open state with a height difference above the maximum step height. + * - If the room allows walkthrough, the tile should not be occupied by other room units (excluding the character's target position). + * - If the room disallows walkthrough, the tile should not be occupied by any room units. + * - If there's a room item on the tile, it is considered a valid tile. + */ + private boolean isValidTile(RoomTile tile) { + boolean canOverrideTile = this.canOverrideTile(tile); + + if (canOverrideTile) { + return true; + } + + double heightDifference = tile.getStackHeight() - this.currentZ; + + RoomUnit exception = null; + + if(this instanceof RoomAvatar roomAvatar && roomAvatar.isRiding()) { + exception = roomAvatar.getRidingPet().getRoomUnit(); + } + + boolean areRoomUnitsAtTile = this.room.getRoomUnitManager().areRoomUnitsAt(tile, exception); + + boolean isAboveMaximumStepHeight = (!RoomLayout.ALLOW_FALLING && heightDifference < -RoomLayout.MAXIMUM_STEP_HEIGHT); + boolean isOpenTileAboveMaxHeight = (tile.getState() == RoomTileState.OPEN && heightDifference > RoomLayout.MAXIMUM_STEP_HEIGHT); + boolean isTileBlocked = tile.getState().equals(RoomTileState.BLOCKED) || tile.getState().equals(RoomTileState.INVALID); + + if(isTileBlocked || isAboveMaximumStepHeight || isOpenTileAboveMaxHeight) { + return false; + } else { + if(areRoomUnitsAtTile && this.targetPosition.equals(tile)) { + this.stopWalking(); + return false; + } + + if(areRoomUnitsAtTile && !this.room.getRoomInfo().isAllowWalkthrough()) { + return false; + } + } + + RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile); + + if(item != null) { + return true; + } + + return true; + } + + public void clear() { + super.clear(); + + this.canWalk = true; + this.canRotate = true; + this.cmdFastWalkEnabled = false; + this.clearStatuses(); + this.isKicked = false; + this.cacheable.clear(); + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitType.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnitType.java similarity index 73% rename from src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitType.java rename to src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnitType.java index c12f7a61..024e81ab 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnitType.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/RoomUnitType.java @@ -1,4 +1,4 @@ -package com.eu.habbo.habbohotel.rooms; +package com.eu.habbo.habbohotel.rooms.entities.units; import lombok.AllArgsConstructor; import lombok.Getter; @@ -6,11 +6,10 @@ import lombok.Getter; @Getter @AllArgsConstructor public enum RoomUnitType { - USER(1), + HABBO(1), BOT(4), PET(2), UNKNOWN(3); private final int typeId; - } 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 new file mode 100644 index 00000000..5b19e1db --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomAvatar.java @@ -0,0 +1,200 @@ +package com.eu.habbo.habbohotel.rooms.entities.units.types; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.pets.RideablePet; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import com.eu.habbo.habbohotel.users.DanceType; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.users.DanceMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Getter +@Setter +@Accessors(chain = true) +public abstract class RoomAvatar extends RoomUnit { + protected RideablePet ridingPet; + protected boolean rideLocked; + protected DanceType danceType; + protected int handItem; + protected long handItemTimestamp; + protected int effectId; + protected int effectEndTimestamp; + protected int previousEffectId; + protected int previousEffectEndTimestamp; + + public RoomAvatar() { + super(); + + this.ridingPet = null; + this.danceType = DanceType.NONE; + this.handItem = 0; + this.handItemTimestamp = 0; + this.effectId = 0; + this.effectEndTimestamp = -1; + this.previousEffectId = 0; + this.previousEffectEndTimestamp = -1; + } + + @Override + public void cycle() { + this.handleSignStatus(); + super.cycle(); + } + + @Override + public boolean walkTo(RoomTile goalLocation) { + if(goalLocation == null) { + return false; + } + + if (this.hasStatus(RoomUnitStatus.LAY)) { + if (this.room.getLayout().getTilesInFront(this.getCurrentPosition(), this.getBodyRotation().getValue(), 2).contains(goalLocation)) + return false; + } + + if (this.room.canLayAt(goalLocation)) { + RoomItem bed = this.room.getRoomItemManager().getTopItemAt(goalLocation.getX(), goalLocation.getY()); + + if (bed != null && bed.getBaseItem().allowLay()) { + this.room.getLayout().getTile(bed.getCurrentPosition().getX(), bed.getCurrentPosition().getY()); + RoomTile pillow = switch (bed.getRotation()) { + case 0, 4 -> this.room.getLayout().getTile(goalLocation.getX(), bed.getCurrentPosition().getY()); + case 2, 8 -> this.room.getLayout().getTile(bed.getCurrentPosition().getX(), goalLocation.getY()); + default -> this.room.getLayout().getTile(bed.getCurrentPosition().getX(), bed.getCurrentPosition().getY()); + }; + + if (pillow != null && this.room.canLayAt(pillow)) { + goalLocation = pillow; + } + } + } + + return super.walkTo(goalLocation); + } + + public void dismountPet(boolean isRemoving) { + if(!this.isRiding()) { + return; + } + + this.ridingPet.setRider(null); + this.ridingPet.setTask(PetTasks.FREE); + + this.giveEffect(0, -1); + this.setCurrentZ(this.ridingPet.getRoomUnit().getCurrentZ()); + this.stopWalking(); + + this.ridingPet.getRoomUnit().stopWalking(); + + this.instantUpdate(); + this.ridingPet.getRoomUnit().instantUpdate(); + + this.ridingPet = null; + + List availableTiles = isRemoving ? new ArrayList<>() : this.room.getLayout().getWalkableTilesAround(this.getCurrentPosition()); + + RoomTile tile = availableTiles.isEmpty() ? this.getCurrentPosition() : availableTiles.get(0); + this.walkTo(tile); + this.setStatusUpdateNeeded(true); + } + + public void setDance(DanceType danceType) { + if (this.danceType != danceType) { + boolean isDancing = !this.danceType.equals(DanceType.NONE); + this.danceType = danceType; + this.room.sendComposer(new DanceMessageComposer(this).compose()); + + if (danceType.equals(DanceType.NONE) && isDancing) { + WiredHandler.handle(WiredTriggerType.STOPS_DANCING, this, this.room, new Object[]{this}); + } else if (!danceType.equals(DanceType.NONE) && !isDancing) { + WiredHandler.handle(WiredTriggerType.STARTS_DANCING, this, this.room, new Object[]{this}); + } + } + } + + public RoomAvatar setHandItem(int handItem) { + this.handItem = handItem; + this.handItemTimestamp = System.currentTimeMillis(); + return this; + } + + public void giveEffect(int effectId, int duration) { + this.giveEffect(effectId, duration, false); + } + + public void giveEffect(int effectId, int duration, boolean forceEffect) { + if (!this.isInRoom()) { + return; + } + + if(this.getEffectId() == effectId) { + return; + } + + if(this instanceof RoomHabbo) { + Habbo habbo = this.room.getRoomUnitManager().getHabboByRoomUnit(this); + if(habbo == null || (habbo.getHabboInfo().isInGame() && !forceEffect)) { + return; + } + } + + if (duration == -1 || duration == Integer.MAX_VALUE) { + duration = Integer.MAX_VALUE; + } else { + duration += Emulator.getIntUnixTimestamp(); + } + + if ((this.room.isAllowEffects() || forceEffect) && !this.isSwimming()) { + this.effectId = effectId; + this.effectEndTimestamp = duration; + + this.room.sendComposer(new AvatarEffectMessageComposer(this).compose()); + } + } + + public void setPreviousEffectId(int effectId, int endTimestamp) { + this.previousEffectId = effectId; + this.previousEffectEndTimestamp = endTimestamp; + } + + private void handleSignStatus() { + if (this.hasStatus(RoomUnitStatus.SIGN)) { + this.room.sendComposer(new UserUpdateComposer(this).compose()); + this.removeStatus(RoomUnitStatus.SIGN); + } + } + + public boolean isRiding() { + return this.ridingPet != null; + } + + @Override + public void clear() { + super.clear(); + + this.ridingPet = null; + this.rideLocked = false; + this.danceType = DanceType.NONE; + this.handItem = 0; + this.handItemTimestamp = 0; + this.effectId = 0; + this.effectEndTimestamp = -1; + this.previousEffectId = 0; + this.previousEffectEndTimestamp = -1; + } +} 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/entities/units/types/RoomBot.java new file mode 100644 index 00000000..9368064c --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomBot.java @@ -0,0 +1,101 @@ +package com.eu.habbo.habbohotel.rooms.entities.units.types; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.bots.Bot; +import com.eu.habbo.habbohotel.rooms.RoomChatMessage; +import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUserAction; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import com.eu.habbo.messages.outgoing.rooms.users.ChatMessageComposer; +import com.eu.habbo.messages.outgoing.rooms.users.ExpressionMessageComposer; +import com.eu.habbo.plugin.Event; +import com.eu.habbo.plugin.events.bots.BotTalkEvent; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Getter +@Setter +@Accessors(chain = true) +public class RoomBot extends RoomAvatar { + private Bot unit; + + private RoomTile spawnTile; + private double spawnHeight; + + public RoomBot() { + super(); + } + + @Override + public void cycle() { + if (this.room.isAllowBotsWalk() && this.isCanWalk()) { + if (!this.isWalking()) { + if (this.getWalkTimeOut() < Emulator.getIntUnixTimestamp() && this.unit.getFollowingHabboId() == 0) { + this.walkTo(Emulator.getConfig().getBoolean("hotel.bot.limit.walking.distance", true) ? this.getRoom().getLayout().getRandomWalkableTilesAround(this, this.currentPosition, Emulator.getConfig().getInt("hotel.bot.limit.walking.distance.radius", 5)) : this.getRoom().getRandomWalkableTile()); + int timeOut = Emulator.getRandom().nextInt(20) * 2; + this.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp()); + } + } + } + + boolean hasChatLines = !this.unit.getChatLines().isEmpty(); + boolean hasAutoChatEnabled = this.unit.isChatAuto(); + boolean chatTimeOutPassed = Emulator.getIntUnixTimestamp() >= this.unit.getChatTimeOut(); + + if (hasChatLines && chatTimeOutPassed && hasAutoChatEnabled) { + if(this.unit.isChatRandom()) { + this.unit.setLastChatIndex((short) Emulator.getRandom().nextInt(this.unit.getChatLines().size())); + } else if(this.unit.getLastChatIndex() == this.unit.getChatLines().size() - 1) { + this.unit.resetLastChatIndex(); + } else { + this.unit.incrementLastChatIndex(); + } + + if (this.unit.getLastChatIndex() >= this.unit.getChatLines().size()) { + this.unit.resetLastChatIndex(); + } + + String message = this.unit.getChatLines().get(this.unit.getLastChatIndex()) + .replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), this.getRoom().getRoomInfo().getOwnerInfo().getUsername()) + .replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), String.valueOf(this.getRoom().getRoomItemManager().getCurrentItems().size())) + .replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.unit.getName()) + .replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), this.getRoom().getRoomInfo().getName()) + .replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), String.valueOf(this.getRoom().getRoomUnitManager().getRoomHabbosCount())); + + if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this, room, new Object[]{ message })) { + this.talk(message); + } + + this.unit.setChatTimeOut(Emulator.getIntUnixTimestamp() + this.unit.getChatDelay()); + } + + super.cycle(); + } + + public void talk(String message) { + if (Emulator.getPluginManager().isRegistered(BotTalkEvent.class, false)) { + Event event = new BotTalkEvent(this.unit, message); + Emulator.getPluginManager().fireEvent(event); + + if (event.isCancelled()) + return; + } + + this.unit.setChatTimestamp(Emulator.getIntUnixTimestamp()); + this.room.botChat(new ChatMessageComposer(new RoomChatMessage(message, this, RoomChatMessageBubbles.getBubble(this.unit.getBubbleId()))).compose()); + + if (message.equals("o/") || message.equals("_o/")) { + this.room.sendComposer(new ExpressionMessageComposer(this, RoomUserAction.WAVE).compose()); + } + } + + public RoomUnitType getRoomUnitType() { + return RoomUnitType.BOT; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomHabbo.java b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomHabbo.java new file mode 100644 index 00000000..66cbe021 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomHabbo.java @@ -0,0 +1,143 @@ +package com.eu.habbo.habbohotel.rooms.entities.units.types; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.pets.PetTasks; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; +import com.eu.habbo.habbohotel.users.DanceType; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; +import com.eu.habbo.messages.outgoing.rooms.users.RoomUnitOnRollerComposer; +import com.eu.habbo.messages.outgoing.rooms.users.SleepMessageComposer; +import com.eu.habbo.plugin.events.users.UserIdleEvent; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Getter +@Setter +@Accessors(chain = true) +public class RoomHabbo extends RoomAvatar { + private Habbo unit; + private Room loadingRoom; + private Room previousRoom; + + private boolean cmdTeleportEnabled; + +// @Setter +// private boolean isKicked; + private int kickCount; + private int idleTicks; + private boolean isSleeping; +// private final HashSet overridableTiles; + + public RoomHabbo() { + super(); + this.cmdTeleportEnabled = false; +// this.isKicked = false; +// this.overridableTiles = new HashSet<>(); + } + + @Override + public void cycle() { + super.cycle(); + } + + @Override + public boolean walkTo(RoomTile goalLocation) { + if(this.rideLocked || this.isTeleporting() || this.isKicked()) { + return false; + } + + if(this.cmdTeleportEnabled) { + if (this.isRiding()) { + this.room.sendComposer(new RoomUnitOnRollerComposer(this, null, this.currentPosition, this.currentZ, goalLocation, goalLocation.getStackHeight() + 1.0D, this.room).compose()); + this.room.sendComposer(new RoomUnitOnRollerComposer(this.ridingPet.getRoomUnit(), goalLocation, this.room).compose()); + } else { + this.room.sendComposer(new RoomUnitOnRollerComposer(this, goalLocation, this.room).compose()); + } + + return false; + } + + if (this.isRiding() && this.ridingPet.getTask() != null && this.ridingPet.getTask().equals(PetTasks.JUMP)) { + return false; + } + + // Reset idle status + if (this.isIdle()) { + UserIdleEvent event = new UserIdleEvent(this.unit, UserIdleEvent.IdleReason.WALKED, false); + Emulator.getPluginManager().fireEvent(event); + + if (!event.isCancelled()) { + if (!event.isIdle()) { + this.unIdle(); + } + } + } + + return super.walkTo(goalLocation); + } + + public boolean isLoadingRoom() { + return this.loadingRoom != null; + } + + public boolean hasPreviousRoom() { + return this.previousRoom != null; + } + + public void incrementKickCount() { + this.kickCount++; + } + + public void idle() { + this.setIdle(); + + if (this.getDanceType() != DanceType.NONE) { + this.setDance(DanceType.NONE); + } + + this.room.sendComposer(new SleepMessageComposer(this).compose()); + + WiredHandler.handle(WiredTriggerType.IDLES, this, this.room, new Object[]{this}); + } + + public void unIdle() { + this.resetIdleTicks(); + + this.room.sendComposer(new SleepMessageComposer(this).compose()); + + WiredHandler.handle(WiredTriggerType.UNIDLES, this, this.room, new Object[]{this}); + } + + public boolean isIdle() { + return this.idleTicks > Room.IDLE_CYCLES; + } + + public void setIdle() { + this.idleTicks = Room.IDLE_CYCLES + 1; + } + + public void incrementIdleTicks() { + this.idleTicks++; + } + + public void resetIdleTicks() { + this.idleTicks = 0; + } + + public RoomUnitType getRoomUnitType() { + return RoomUnitType.HABBO; + } + + @Override + public void clear() { + super.clear(); + this.cmdTeleportEnabled = false; + } +} 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 new file mode 100644 index 00000000..d06c8c81 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/entities/units/types/RoomPet.java @@ -0,0 +1,72 @@ +package com.eu.habbo.habbohotel.rooms.entities.units.types; + +import com.eu.habbo.habbohotel.pets.Pet; +import com.eu.habbo.habbohotel.pets.RideablePet; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +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 lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Getter +@Setter +@Accessors(chain = true) +public class RoomPet extends RoomUnit { + private Pet unit; + + public RoomPet() { + super(); + } + + @Override + public void cycle() { + if (!this.handleRider()) { + super.cycle(); + } + } + + /** + * Handles the interaction between a RideablePet unit and its rider (Habbo) in the virtual room. + * If the unit is a RideablePet and has a rider, this method updates the unit's position and status + * to reflect the rider's movement and actions. + * + * @return {@code true} if the interaction was successfully handled, {@code false} pet walks normally. + */ + public boolean handleRider() { + if (!(this.unit instanceof RideablePet rideablePet)) { + return false; + } + + Habbo rider = rideablePet.getRider(); + + if(rider == null) { + return false; + } + + RoomAvatar riderAvatar = rider.getRoomUnit(); + + if(this.getNextPosition() != null) { + this.setCurrentPosition(this.getNextPosition()); + this.setCurrentZ(this.getNextZ()); + } + + if(riderAvatar.isWalking()) { + this.addStatus(RoomUnitStatus.MOVE, riderAvatar.getNextPosition().getX() + "," + riderAvatar.getNextPosition().getY() + "," + (riderAvatar.getNextZ() - 1.0D)); + this.setNextPosition(riderAvatar.getNextPosition()); + this.setNextZ(riderAvatar.getNextZ() - 1.0D); + this.setRotation(riderAvatar.getBodyRotation()); + } else if(!riderAvatar.isWalking() && this.hasStatus(RoomUnitStatus.MOVE)) { + this.stopWalking(); + } + + return true; + } + + public RoomUnitType getRoomUnitType() { + return RoomUnitType.PET; + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/units/Unit.java b/src/main/java/com/eu/habbo/habbohotel/units/Unit.java new file mode 100644 index 00000000..aece2d88 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/units/Unit.java @@ -0,0 +1,11 @@ +package com.eu.habbo.habbohotel.units; + +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public abstract class Unit { + private RoomUnit roomUnit; +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/units/type/Avatar.java b/src/main/java/com/eu/habbo/habbohotel/units/type/Avatar.java new file mode 100644 index 00000000..becf31e0 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/units/type/Avatar.java @@ -0,0 +1,10 @@ +package com.eu.habbo.habbohotel.units.type; + +import com.eu.habbo.habbohotel.units.Unit; +import com.eu.habbo.messages.ISerialize; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public abstract class Avatar extends Unit implements ISerialize {} 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 9990c8ba..74fe2c3b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -5,11 +5,19 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.catalog.ClothItem; import com.eu.habbo.habbohotel.gameclients.GameClient; +import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.messenger.Messenger; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomChatMessage; +import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; +import com.eu.habbo.habbohotel.rooms.RoomUserAction; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; +import com.eu.habbo.habbohotel.units.type.Avatar; import com.eu.habbo.habbohotel.users.inventory.BadgesComponent; +import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.generic.alerts.*; import com.eu.habbo.messages.outgoing.inventory.*; import com.eu.habbo.messages.outgoing.rooms.FloodControlMessageComposer; @@ -22,7 +30,6 @@ import com.eu.habbo.plugin.events.users.UserGetIPAddressEvent; import com.eu.habbo.plugin.events.users.UserPointsEvent; import gnu.trove.TIntCollection; import gnu.trove.map.hash.THashMap; -import gnu.trove.set.hash.THashSet; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -30,11 +37,14 @@ import lombok.extern.slf4j.Slf4j; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.sql.ResultSet; +import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; @Slf4j -public class Habbo implements Runnable { +public class Habbo extends Avatar implements Runnable { + @Getter + private RoomHabbo roomUnit; @Getter private final HabboInfo habboInfo; @Getter @@ -46,15 +56,12 @@ public class Habbo implements Runnable { @Setter @Getter private GameClient client; - @Setter - @Getter - private RoomUnit roomUnit; private volatile boolean update; private volatile boolean disconnected = false; private volatile boolean disconnecting = false; - public Habbo(ResultSet set) { + public Habbo(ResultSet set) throws SQLException { this.client = null; this.habboInfo = new HabboInfo(set); this.habboStats = HabboStats.load(this.habboInfo); @@ -64,8 +71,9 @@ public class Habbo implements Runnable { this.messenger.loadFriends(this); this.messenger.loadFriendRequests(this); - this.roomUnit = new RoomUnit(); - this.roomUnit.setRoomUnitType(RoomUnitType.USER); + this.roomUnit = new RoomHabbo(); + this.roomUnit.setUnit(this); + this.update = false; } @@ -143,11 +151,11 @@ public class Habbo implements Runnable { this.disconnecting = true; try { - if (this.getHabboInfo().getCurrentRoom() != null) { - Emulator.getGameEnvironment().getRoomManager().leaveRoom(this, this.getHabboInfo().getCurrentRoom()); + if (this.getRoomUnit().getRoom() != null) { + Emulator.getGameEnvironment().getRoomManager().leaveRoom(this, this.getRoomUnit().getRoom()); } if (this.getHabboInfo().getRoomQueueId() > 0) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getHabboInfo().getRoomQueueId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.getHabboInfo().getRoomQueueId()); if (room != null) { room.removeFromQueue(this); @@ -189,28 +197,19 @@ public class Habbo implements Runnable { } public boolean canExecuteCommand(String key) { - return this.getHabboInfo().getPermissionGroup().canExecuteCommand(key, false); + return this.canExecuteCommand(key, false); } public boolean canExecuteCommand(String key, boolean hasRoomRights) { return this.getHabboInfo().getPermissionGroup().canExecuteCommand(key, hasRoomRights); } - public boolean hasCommand(String key) { - return this.hasCommand(key, false); + public boolean hasPermissionRight(String key) { + return this.hasPermissionRight(key, false); } - - public boolean hasCommand(String name, boolean hasRoomRights) { - return this.getHabboInfo().getPermissionGroup().hasCommand(name, hasRoomRights); - } - - public boolean hasRight(String key) { - return this.hasRight(key, false); - } - - public boolean hasRight(String key, boolean hasRoomRights) { - return this.getHabboInfo().getPermissionGroup().hasRight(key, hasRoomRights); + public boolean hasPermissionRight(String key, boolean hasRoomRights) { + return this.getHabboInfo().getPermissionGroup().hasPermissionRight(key, hasRoomRights); } @@ -280,7 +279,7 @@ public class Habbo implements Runnable { public void talk(String message, RoomChatMessageBubbles bubble) { if (this.getRoomUnit().isInRoom()) { - this.getHabboInfo().getCurrentRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)).compose()); + this.getRoomUnit().getRoom().sendComposer(new ChatMessageComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)).compose()); } } @@ -292,7 +291,7 @@ public class Habbo implements Runnable { public void shout(String message, RoomChatMessageBubbles bubble) { if (this.getRoomUnit().isInRoom()) { - this.getHabboInfo().getCurrentRoom().sendComposer(new ShoutMessageComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)).compose()); + this.getRoomUnit().getRoom().sendComposer(new ShoutMessageComposer(new RoomChatMessage(message, this.client.getHabbo().getRoomUnit(), bubble)).compose()); } } @@ -321,21 +320,14 @@ public class Habbo implements Runnable { } - public void addFurniture(HabboItem item) { + public void addFurniture(RoomItem item) { this.inventory.getItemsComponent().addItem(item); this.client.sendResponse(new UnseenItemsComposer(item)); this.client.sendResponse(new FurniListInvalidateComposer()); } - public void addFurniture(THashSet items) { - this.inventory.getItemsComponent().addItems(items); - this.client.sendResponse(new UnseenItemsComposer(items)); - this.client.sendResponse(new FurniListInvalidateComposer()); - } - - - public void removeFurniture(HabboItem item) { + public void removeFurniture(RoomItem item) { this.inventory.getItemsComponent().removeHabboItem(item); this.client.sendResponse(new FurniListRemoveComposer(item.getId())); } @@ -355,7 +347,7 @@ public class Habbo implements Runnable { public void deleteBot(Bot bot) { this.removeBot(bot); - bot.getRoom().removeBot(bot); + bot.getRoomUnit().getRoom().getRoomUnitManager().removeBot(bot); Emulator.getGameEnvironment().getBotManager().deleteBot(bot); } @@ -406,12 +398,12 @@ public class Habbo implements Runnable { return; } - if (!this.hasRight(Permission.ACC_NO_MUTE)) { + if (!this.hasPermissionRight(Permission.ACC_NO_MUTE)) { int remaining = this.habboStats.addMuteTime(seconds); this.client.sendResponse(new FloodControlMessageComposer(remaining)); this.client.sendResponse(new RemainingMutePeriodComposer(remaining)); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null && !isFlood) { room.sendComposer(new IgnoreResultMessageComposer(this, IgnoreResultMessageComposer.MUTED).compose()); } @@ -421,7 +413,7 @@ public class Habbo implements Runnable { public void unMute() { this.habboStats.unMute(); this.client.sendResponse(new FloodControlMessageComposer(3)); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { room.sendComposer(new IgnoreResultMessageComposer(this, IgnoreResultMessageComposer.UNIGNORED).compose()); } @@ -457,14 +449,14 @@ public class Habbo implements Runnable { target.getHabboStats().setRespectPointsReceived(target.getHabboStats().getRespectPointsReceived()+1); this.client.getHabbo().getHabboStats().setRespectPointsGiven(this.client.getHabbo().getHabboStats().getRespectPointsGiven()+1); this.client.getHabbo().getHabboStats().setRespectPointsToGive(this.client.getHabbo().getHabboStats().getRespectPointsToGive()-1); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RoomUserRespectComposer(target).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new ExpressionMessageComposer(this.client.getHabbo().getRoomUnit(), RoomUserAction.THUMB_UP).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new RoomUserRespectComposer(target).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new ExpressionMessageComposer(this.client.getHabbo().getRoomUnit(), RoomUserAction.THUMB_UP).compose()); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectGiven")); AchievementManager.progressAchievement(target, Emulator.getGameEnvironment().getAchievementManager().getAchievement("RespectEarned")); - this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(this.client.getHabbo()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().dance(this.client.getHabbo().getRoomUnit(), DanceType.NONE); + this.client.getHabbo().getRoomUnit().unIdle(); + this.client.getHabbo().getRoomUnit().setDance(DanceType.NONE); } } @@ -477,4 +469,34 @@ public class Habbo implements Runnable { .flatMap(c -> Arrays.stream(c).boxed()) .collect(Collectors.toSet()); } + + @Override + public void serialize(ServerMessage message) { + message.appendInt(this.habboInfo.getId()); + message.appendString(this.habboInfo.getUsername()); + message.appendString(this.habboInfo.getMotto()); + message.appendString(this.habboInfo.getLook()); + message.appendInt(this.roomUnit.getVirtualId()); + message.appendInt(this.roomUnit.getCurrentPosition().getX()); + message.appendInt(this.roomUnit.getCurrentPosition().getY()); + message.appendString(String.valueOf(this.roomUnit.getCurrentZ())); + message.appendInt(this.roomUnit.getBodyRotation().getValue()); + message.appendInt(1); + message.appendString(this.habboInfo.getGender().name().toUpperCase()); + message.appendInt(this.habboStats.getGuild() != 0 ? this.habboStats.getGuild() : -1); + message.appendInt(this.habboStats.getGuild() != 0 ? 1 : -1); + + String name = ""; + if (this.habboStats.getGuild() != 0) { + Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.habboStats.getGuild()); + + if (g != null) + name = g.getName(); + } + message.appendString(name); + + message.appendString(""); + message.appendInt(this.habboStats.getAchievementScore()); + message.appendBoolean(true); + } } 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 43aa908d..0affa40a 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,6 @@ 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.RoomUnit; -import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import gnu.trove.map.hash.TIntIntHashMap; import lombok.Getter; import lombok.Setter; @@ -26,100 +20,68 @@ import java.util.List; @Slf4j @Getter +@Setter +@Accessors(chain = true) public class HabboInfo implements Runnable { - - public boolean firstVisit = false; - @Setter + private final int id; private String username; - @Setter private String motto; - @Setter - @Accessors(chain = true) private String look; - @Setter private HabboGender gender; - @Setter private String mail; - @Setter private String sso; - @Setter private String ipRegister; - @Setter private String ipLogin; - private int id; - @Setter private int accountCreated; - @Setter private PermissionGroup permissionGroup; private int credits; - @Setter private int lastOnline; - @Setter private int homeRoom; - @Setter private boolean online; - @Setter - @Accessors(chain = true) - private int loadingRoom; - @Setter - private Room currentRoom; - @Setter private int roomQueueId; - @Setter - private RideablePet riding; - @Setter private Class currentGame; private TIntIntHashMap currencies; - @Setter private GamePlayer gamePlayer; - @Setter private int photoRoomId; - @Setter private int photoTimestamp; - @Setter private String photoURL; - @Setter private String photoJSON; - @Setter private int webPublishTimestamp; - @Setter private String machineID; private List savedSearches = new ArrayList<>(); private List messengerCategories = new ArrayList<>(); + public boolean firstVisit = false; - public HabboInfo(ResultSet set) { - try { - this.id = set.getInt("id"); - this.username = set.getString("username"); - this.motto = set.getString("motto"); - this.look = set.getString("look"); - this.gender = HabboGender.valueOf(set.getString("gender")); - this.mail = set.getString("mail"); - this.sso = set.getString("auth_ticket"); - this.ipRegister = set.getString("ip_register"); - this.ipLogin = set.getString("ip_current"); - this.permissionGroup = Emulator.getGameEnvironment().getPermissionsManager().getGroup(set.getInt("rank")); + public HabboInfo(ResultSet set) throws SQLException { + this.id = set.getInt("id"); + this.username = set.getString("username"); + this.motto = set.getString("motto"); + this.look = set.getString("look"); + this.gender = HabboGender.valueOf(set.getString("gender")); + this.mail = set.getString("mail"); + this.sso = set.getString("auth_ticket"); + this.ipRegister = set.getString("ip_register"); + this.ipLogin = set.getString("ip_current"); + this.permissionGroup = Emulator.getGameEnvironment().getPermissionsManager().getGroup(set.getInt("rank")); - if (this.permissionGroup == null) { - log.error("No existing rank found with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); - log.warn(this.username + " has an invalid rank with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); - this.permissionGroup = Emulator.getGameEnvironment().getPermissionsManager().getGroup(1); - } - - this.accountCreated = set.getInt("account_created"); - this.credits = set.getInt("credits"); - this.homeRoom = set.getInt("home_room"); - this.lastOnline = set.getInt("last_online"); - this.machineID = set.getString("machine_id"); - this.online = false; - this.currentRoom = null; - } catch (SQLException e) { - log.error("Caught SQL exception", e); + if (this.permissionGroup == null) { + log.error("No existing rank found with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); + log.warn(this.username + " has an invalid rank with id " + set.getInt("rank") + ". Make sure an entry in the permissions table exists."); + this.permissionGroup = Emulator.getGameEnvironment().getPermissionsManager().getGroup(1); } + this.accountCreated = set.getInt("account_created"); + this.credits = set.getInt("credits"); + this.homeRoom = set.getInt("home_room"); + this.lastOnline = set.getInt("last_online"); + this.machineID = set.getString("machine_id"); + this.online = false; + this.loadCurrencies(); this.loadSavedSearches(); this.loadMessengerCategories(); + + Emulator.getGameEnvironment().getHabboManager().getHabboInfoCache().getData().remove(this.id); } private void loadCurrencies() { @@ -304,45 +266,6 @@ public class HabboInfo implements Runnable { this.run(); } - public void dismountPet() { - this.dismountPet(false); - } - - public void dismountPet(boolean isRemoving) { - if (this.getRiding() == null) - return; - - Habbo habbo = this.getCurrentRoom().getHabbo(this.getId()); - if (habbo == null) - return; - - RideablePet riding = this.getRiding(); - - riding.setRider(null); - riding.setTask(PetTasks.FREE); - this.setRiding(null); - - Room room = this.getCurrentRoom(); - if (room != null) - room.giveEffect(habbo, 0, -1); - - RoomUnit roomUnit = habbo.getRoomUnit(); - if (roomUnit == null) - return; - - roomUnit.setZ(riding.getRoomUnit().getZ()); - roomUnit.setPreviousLocationZ(riding.getRoomUnit().getZ()); - roomUnit.stopWalking(); - if (room != null) - room.sendComposer(new UserUpdateComposer(roomUnit).compose()); - - List availableTiles = isRemoving ? new ArrayList<>() : this.getCurrentRoom().getLayout().getWalkableTilesAround(roomUnit.getCurrentLocation()); - - RoomTile tile = availableTiles.isEmpty() ? roomUnit.getCurrentLocation() : availableTiles.get(0); - roomUnit.setGoalLocation(tile); - roomUnit.statusUpdate(true); - } - public boolean isInGame() { return this.currentGame != null; } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java index f8a69995..9a786399 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ModToolBan; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.permissions.PermissionGroup; +import com.eu.habbo.habbohotel.users.cache.HabboInfoCache; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.catalog.*; import com.eu.habbo.messages.outgoing.catalog.marketplace.MarketplaceConfigurationComposer; @@ -25,27 +26,41 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; @Slf4j public class HabboManager { - //Configuration. Loaded from database & updated accordingly. public static String WELCOME_MESSAGE = ""; - public static boolean NAMECHANGE_ENABLED = false; @Getter private final ConcurrentHashMap onlineHabbos; + @Getter + private final HabboInfoCache habboInfoCache; + + public ScheduledFuture infoCacheTask; + public HabboManager() { long millis = System.currentTimeMillis(); this.onlineHabbos = new ConcurrentHashMap<>(); + this.habboInfoCache = new HabboInfoCache(); + log.info("Habbo Manager -> Loaded! (" + (System.currentTimeMillis() - millis) + " MS)"); + + this.infoCacheTask = Emulator.getThreading().getService().scheduleAtFixedRate(this.habboInfoCache, 500, 5, TimeUnit.MINUTES); } - public static HabboInfo getOfflineHabboInfo(int id) { + public HabboInfo getOfflineHabboInfo(int id) { + if(this.habboInfoCache.getData().containsKey(id)) { + return this.habboInfoCache.getData().get(id).getValue(); + } + HabboInfo info = null; + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE id = ? LIMIT 1")) { statement.setInt(1, id); try (ResultSet set = statement.executeQuery()) { @@ -57,10 +72,14 @@ public class HabboManager { log.error("Caught SQL exception", e); } + if(info != null) { + this.habboInfoCache.add(info); + } + return info; } - public static HabboInfo getOfflineHabboInfo(String username) { + public HabboInfo getOfflineHabboInfo(String username) { HabboInfo info = null; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE username = ? LIMIT 1")) { @@ -179,7 +198,7 @@ public class HabboManager { public void sendPacketToHabbosWithPermission(ServerMessage message, String perm) { synchronized (this.onlineHabbos) { for (Habbo habbo : this.onlineHabbos.values()) { - if (habbo.hasRight(perm)) { + if (habbo.hasPermissionRight(perm)) { habbo.getClient().sendResponse(message); } } @@ -187,11 +206,7 @@ public class HabboManager { } public synchronized void dispose() { - - -// - - + this.infoCacheTask.cancel(false); log.info("Habbo Manager -> Disposed!"); } @@ -264,7 +279,7 @@ public class HabboManager { habbo.getClient().sendResponse(new UserRightsMessageComposer(habbo)); habbo.getClient().sendResponse(new UserPerksComposer(habbo)); - if (habbo.hasRight(Permission.ACC_SUPPORTTOOL)) { + if (habbo.hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { habbo.getClient().sendResponse(new ModeratorInitMessageComposer(habbo)); } habbo.getHabboInfo().run(); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboInfoCache.java b/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboInfoCache.java new file mode 100644 index 00000000..9d4353fb --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/users/cache/HabboInfoCache.java @@ -0,0 +1,48 @@ +package com.eu.habbo.habbohotel.users.cache; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.users.HabboInfo; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.math3.util.Pair; + +import java.util.LinkedHashMap; +import java.util.Map; + +@Slf4j +@Getter +public class HabboInfoCache implements Runnable { + private static final long CACHE_DURATION = 10 * 60 * 1000; + private final LinkedHashMap> data; + + public HabboInfoCache() { + this.data = new LinkedHashMap>(16, 0.75f) { + @Override + protected boolean removeEldestEntry(Map.Entry> eldest) { + return cleanEntry(eldest); + } + }; + } + + public void add(HabboInfo habboInfo) { + long currentMillis = Emulator.getIntUnixTimestamp(); + this.data.put(habboInfo.getId(), new Pair<>(currentMillis, habboInfo)); + } + + private boolean cleanEntry(Map.Entry> entry) { + long currentMillis = Emulator.getIntUnixTimestamp(); + long entryTimestamp = entry.getValue().getKey(); + return entryTimestamp < currentMillis - CACHE_DURATION; + } + + public void verifyInfo(int userId) { + this.data.remove(userId); + } + + @Override + public void run() { + synchronized (this.data) { + this.data.entrySet().removeIf(this::cleanEntry); + } + } +} diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/BotsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BotsComponent.java index e97a3f5e..81e07d5a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/BotsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/BotsComponent.java @@ -25,7 +25,7 @@ public class BotsComponent { private void loadBots(Habbo habbo) { synchronized (this.bots) { - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON users.id = bots.user_id WHERE user_id = ? AND room_id = 0 ORDER BY id ASC")) { + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON users.id = bots.owner_id WHERE owner_id = ? AND room_id = 0 ORDER BY id ASC")) { statement.setInt(1, habbo.getHabboInfo().getId()); try (ResultSet set = statement.executeQuery()) { while (set.next()) { @@ -60,7 +60,7 @@ public class BotsComponent { public void dispose() { synchronized (this.bots) { for (Map.Entry map : this.bots.entrySet()) { - if (map.getValue().needsUpdate()) { + if (map.getValue().isSqlUpdateNeeded()) { Emulator.getThreading().run(map.getValue()); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java index 3ac89048..1f70dc16 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/EffectsComponent.java @@ -139,8 +139,8 @@ public class EffectsComponent { this.activatedEffect = effectId; - if (this.habbo.getHabboInfo().getCurrentRoom() != null) { - this.habbo.getHabboInfo().getCurrentRoom().giveEffect(this.habbo, effectId, effect.remainingTime()); + if (this.habbo.getRoomUnit().getRoom() != null) { + this.habbo.getRoomUnit().giveEffect(effectId, effect.remainingTime()); } this.habbo.getClient().sendResponse(new AvatarEffectActivatedMessageComposer(effect)); diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java index f9597b16..9aff218d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/ItemsComponent.java @@ -2,9 +2,9 @@ package com.eu.habbo.habbohotel.users.inventory; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInventory; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.plugin.events.inventory.InventoryItemAddedEvent; import com.eu.habbo.plugin.events.inventory.InventoryItemRemovedEvent; import com.eu.habbo.plugin.events.inventory.InventoryItemsAddedEvent; @@ -21,13 +21,14 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.HashSet; import java.util.NoSuchElementException; @Slf4j public class ItemsComponent { @Getter - private final TIntObjectMap items = TCollections.synchronizedMap(new TIntObjectHashMap<>()); + private final TIntObjectMap items = TCollections.synchronizedMap(new TIntObjectHashMap<>()); private final HabboInventory inventory; @@ -36,8 +37,8 @@ public class ItemsComponent { this.items.putAll(loadItems(habbo)); } - public static THashMap loadItems(Habbo habbo) { - THashMap itemsList = new THashMap<>(); + public static THashMap loadItems(Habbo habbo) { + THashMap itemsList = new THashMap<>(); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM items WHERE room_id = ? AND user_id = ?")) { statement.setInt(1, 0); @@ -45,7 +46,7 @@ public class ItemsComponent { try (ResultSet set = statement.executeQuery()) { while (set.next()) { try { - HabboItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set); + RoomItem item = Emulator.getGameEnvironment().getItemManager().loadHabboItem(set); if (item != null) { itemsList.put(set.getInt("id"), item); @@ -64,7 +65,7 @@ public class ItemsComponent { return itemsList; } - public void addItem(HabboItem item) { + public void addItem(RoomItem item) { if (item == null) { return; } @@ -79,14 +80,14 @@ public class ItemsComponent { } } - public void addItems(THashSet items) { + public void addItems(HashSet items) { InventoryItemsAddedEvent event = new InventoryItemsAddedEvent(this.inventory, items); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) { return; } synchronized (this.items) { - for (HabboItem item : event.items) { + for (RoomItem item : event.items) { if (item == null) { continue; } @@ -96,31 +97,31 @@ public class ItemsComponent { } } - public HabboItem getHabboItem(int itemId) { + public RoomItem getHabboItem(int itemId) { return this.items.get(Math.abs(itemId)); } - public HabboItem getAndRemoveHabboItem(final Item item) { - final HabboItem[] habboItem = {null}; + public RoomItem getAndRemoveHabboItem(final Item item) { + final RoomItem[] roomItem = {null}; synchronized (this.items) { this.items.forEachValue(object -> { if (object.getBaseItem() == item) { - habboItem[0] = object; + roomItem[0] = object; return false; } return true; }); } - this.removeHabboItem(habboItem[0]); - return habboItem[0]; + this.removeHabboItem(roomItem[0]); + return roomItem[0]; } public void removeHabboItem(int itemId) { this.items.remove(itemId); } - public void removeHabboItem(HabboItem item) { + public void removeHabboItem(RoomItem item) { InventoryItemRemovedEvent event = new InventoryItemRemovedEvent(this.inventory, item); if (Emulator.getPluginManager().fireEvent(event).isCancelled()) { return; @@ -131,8 +132,8 @@ public class ItemsComponent { } } - public THashSet getItemsAsValueCollection() { - THashSet items = new THashSet<>(); + public THashSet getItemsAsValueCollection() { + THashSet items = new THashSet<>(); items.addAll(this.items.valueCollection()); return items; @@ -144,7 +145,7 @@ public class ItemsComponent { public void dispose() { synchronized (this.items) { - TIntObjectIterator items = this.items.iterator(); + TIntObjectIterator items = this.items.iterator(); if (items == null) { log.error("Items is NULL!"); @@ -158,7 +159,8 @@ public class ItemsComponent { } catch (NoSuchElementException e) { break; } - if (items.value().needsUpdate()) + RoomItem roomItem = items.value(); + if (roomItem.isSqlUpdateNeeded()) Emulator.getThreading().run(items.value()); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/inventory/PetsComponent.java b/src/main/java/com/eu/habbo/habbohotel/users/inventory/PetsComponent.java index 76e6855c..2aed6703 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/inventory/PetsComponent.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/inventory/PetsComponent.java @@ -81,7 +81,7 @@ public class PetsComponent { } catch (NoSuchElementException e) { break; } - if (petIterator.value().isNeedsUpdate()) + if (petIterator.value().isSqlUpdateNeeded()) Emulator.getThreading().run(petIterator.value()); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java index f4a93859..89e48402 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/subscriptions/SubscriptionHabboClub.java @@ -164,8 +164,8 @@ public class SubscriptionHabboClub extends Subscription { habbo.getClient().sendResponse(new FigureUpdateComposer(habbo)); } - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); } } diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java index de585d1d..d03fd1f1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java @@ -1,6 +1,6 @@ package com.eu.habbo.habbohotel.wired; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -8,8 +8,8 @@ import lombok.Setter; @Getter @AllArgsConstructor public class WiredChangeDirectionSetting { - private final int item_id; + private final int itemId; private int rotation; - @Setter private RoomUserRotation direction; + @Setter private RoomRotation direction; } diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java index a05f7975..22d0aed4 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -7,17 +7,17 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredExtra; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredTriggerReset; import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectGiveReward; import com.eu.habbo.habbohotel.items.interactions.wired.effects.WiredEffectTriggerStacks; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraRandom; import com.eu.habbo.habbohotel.items.interactions.wired.extra.WiredExtraUnseen; +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.WiredTriggerReset; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.catalog.PurchaseOKMessageComposer; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; @@ -27,7 +27,7 @@ import com.eu.habbo.plugin.events.furniture.wired.WiredConditionFailedEvent; import com.eu.habbo.plugin.events.furniture.wired.WiredStackExecutedEvent; import com.eu.habbo.plugin.events.furniture.wired.WiredStackTriggeredEvent; import com.eu.habbo.plugin.events.users.UserWiredRewardReceivedEvent; -import com.google.gson.GsonBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; import gnu.trove.set.hash.THashSet; import lombok.extern.slf4j.Slf4j; @@ -41,52 +41,41 @@ import java.util.List; @Slf4j public class WiredHandler { - - //Configuration. Loaded from database & updated accordingly. public static int MAXIMUM_FURNI_SELECTION = 5; public static int TELEPORT_DELAY = 500; - - private static GsonBuilder gsonBuilder = null; + private static ObjectMapper objectMapper = null; public static boolean handle(WiredTriggerType triggerType, RoomUnit roomUnit, Room room, Object[] stuff) { - if (triggerType == WiredTriggerType.CUSTOM) return false; + if (triggerType == WiredTriggerType.CUSTOM || !Emulator.isReady || room == null || !room.isLoaded() || room.getRoomSpecialTypes() == null) { + return false; + } + + List triggers = room.getRoomSpecialTypes().getTriggers(triggerType); + + if (triggers == null || triggers.isEmpty()) { + return false; + } boolean talked = false; - - if (!Emulator.isReady) - return false; - - if (room == null) - return false; - - if (!room.isLoaded()) - return false; - - if (room.getRoomSpecialTypes() == null) - return false; - - THashSet triggers = room.getRoomSpecialTypes().getTriggers(triggerType); - - if (triggers == null || triggers.isEmpty()) - return false; - long millis = System.currentTimeMillis(); THashSet effectsToExecute = new THashSet<>(); - List triggeredTiles = new ArrayList<>(); - for (InteractionWiredTrigger trigger : triggers) { - RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY()); - if (triggeredTiles.contains(tile)) + for (InteractionWiredTrigger trigger : triggers) { + RoomTile tile = room.getLayout().getTile(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY()); + + if (triggeredTiles.contains(tile)) { continue; + } THashSet tEffectsToExecute = new THashSet<>(); if (handle(trigger, roomUnit, room, stuff, tEffectsToExecute)) { effectsToExecute.addAll(tEffectsToExecute); - if (triggerType.equals(WiredTriggerType.SAY_SOMETHING)) + if (triggerType.equals(WiredTriggerType.SAY_SOMETHING)) { talked = true; + } triggeredTiles.add(tile); } @@ -112,7 +101,7 @@ public class WiredHandler { if (room.getRoomSpecialTypes() == null) return false; - THashSet triggers = room.getRoomSpecialTypes().getTriggers(WiredTriggerType.CUSTOM); + List triggers = room.getRoomSpecialTypes().getTriggers(WiredTriggerType.CUSTOM); if (triggers == null || triggers.isEmpty()) return false; @@ -124,7 +113,7 @@ public class WiredHandler { for (InteractionWiredTrigger trigger : triggers) { if (trigger.getClass() != triggerType) continue; - RoomTile tile = room.getLayout().getTile(trigger.getX(), trigger.getY()); + RoomTile tile = room.getLayout().getTile(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY()); if (triggeredTiles.contains(tile)) continue; @@ -158,13 +147,18 @@ public class WiredHandler { } public static boolean handle(InteractionWiredTrigger trigger, final RoomUnit roomUnit, final Room room, final Object[] stuff, final THashSet effectsToExecute) { + if(!Emulator.isReady) { + return false; + } + long millis = System.currentTimeMillis(); - int roomUnitId = roomUnit != null ? roomUnit.getId() : -1; - if (Emulator.isReady && ((Emulator.getConfig().getBoolean("wired.custom.enabled", false) && (trigger.canExecute(millis) || roomUnitId > -1) && trigger.userCanExecute(roomUnitId, millis)) || (!Emulator.getConfig().getBoolean("wired.custom.enabled", false) && trigger.canExecute(millis))) && trigger.execute(roomUnit, room, stuff)) { + int roomUnitId = roomUnit != null ? roomUnit.getVirtualId() : -1; + if (((Emulator.getConfig().getBoolean("wired.custom.enabled", false) && (trigger.canExecute(millis) || roomUnitId > -1) && trigger.userCanExecute(roomUnitId, millis)) || (!Emulator.getConfig().getBoolean("wired.custom.enabled", false) && trigger.canExecute(millis))) && trigger.execute(roomUnit, room, stuff)) { + //DUNNO IF YOU HAVE TO SET EXTRADATA TO 1 IN HERE (In case of Repeaters) trigger.activateBox(room, roomUnit, millis); - THashSet conditions = room.getRoomSpecialTypes().getConditions(trigger.getX(), trigger.getY()); - THashSet effects = room.getRoomSpecialTypes().getEffects(trigger.getX(), trigger.getY()); + THashSet conditions = room.getRoomSpecialTypes().getConditions(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY()); + THashSet effects = room.getRoomSpecialTypes().getEffects(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY()); if (Emulator.getPluginManager().fireEvent(new WiredStackTriggeredEvent(room, roomUnit, trigger, effects, conditions)).isCancelled()) return false; @@ -188,9 +182,9 @@ public class WiredHandler { trigger.setCooldown(millis); - boolean hasExtraRandom = room.getRoomSpecialTypes().hasExtraType(trigger.getX(), trigger.getY(), WiredExtraRandom.class); - boolean hasExtraUnseen = room.getRoomSpecialTypes().hasExtraType(trigger.getX(), trigger.getY(), WiredExtraUnseen.class); - THashSet extras = room.getRoomSpecialTypes().getExtras(trigger.getX(), trigger.getY()); + boolean hasExtraRandom = room.getRoomSpecialTypes().hasExtraType(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY(), WiredExtraRandom.class); + boolean hasExtraUnseen = room.getRoomSpecialTypes().hasExtraType(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY(), WiredExtraUnseen.class); + THashSet extras = room.getRoomSpecialTypes().getExtras(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY()); for (InteractionWiredExtra extra : extras) { extra.activateBox(room, roomUnit, millis); @@ -204,9 +198,9 @@ public class WiredHandler { if (hasExtraUnseen) { - for (InteractionWiredExtra extra : room.getRoomSpecialTypes().getExtras(trigger.getX(), trigger.getY())) { + for (InteractionWiredExtra extra : room.getRoomSpecialTypes().getExtras(trigger.getCurrentPosition().getX(), trigger.getCurrentPosition().getY())) { if (extra instanceof WiredExtraUnseen) { - extra.setExtradata(extra.getExtradata().equals("1") ? "0" : "1"); + extra.setExtraData(extra.getExtraData().equals("1") ? "0" : "1"); InteractionWiredEffect effect = ((WiredExtraUnseen) extra).getUnseenEffect(effectList); effectsToExecute.add(effect); // triggerEffect(effect, roomUnit, room, stuff, millis); break; @@ -229,7 +223,7 @@ public class WiredHandler { private static boolean triggerEffect(InteractionWiredEffect effect, RoomUnit roomUnit, Room room, Object[] stuff, long millis) { boolean executed = false; - if (effect != null && (effect.canExecute(millis) || (roomUnit != null && effect.requiresTriggeringUser() && Emulator.getConfig().getBoolean("wired.custom.enabled", false) && effect.userCanExecute(roomUnit.getId(), millis)))) { + if (effect != null && (effect.canExecute(millis) || (roomUnit != null && effect.requiresTriggeringUser() && Emulator.getConfig().getBoolean("wired.custom.enabled", false) && effect.userCanExecute(roomUnit.getVirtualId(), millis)))) { executed = true; if (!effect.requiresTriggeringUser() || (roomUnit != null && effect.requiresTriggeringUser())) { Emulator.getThreading().run(() -> { @@ -243,27 +237,28 @@ public class WiredHandler { effect.activateBox(room, roomUnit, millis); } - }, effect.getDelay() * 500L); + }, effect.getWiredSettings().getDelay() * 500L); } } return executed; } - public static GsonBuilder getGsonBuilder() { - if(gsonBuilder == null) { - gsonBuilder = new GsonBuilder(); + public static ObjectMapper getObjectMapper() { + if(objectMapper == null) { + objectMapper = new ObjectMapper(); } - return gsonBuilder; + + return objectMapper; } public static boolean executeEffectsAtTiles(THashSet tiles, final RoomUnit roomUnit, final Room room, final Object[] stuff) { for (RoomTile tile : tiles) { if (room != null) { - THashSet items = room.getItemsAt(tile); + THashSet items = room.getRoomItemManager().getItemsAt(tile); long millis = room.getCycleTimestamp(); - for (final HabboItem item : items) { + for (final RoomItem item : items) { if (item instanceof InteractionWiredEffect && !(item instanceof WiredEffectTriggerStacks)) { triggerEffect((InteractionWiredEffect) item, roomUnit, room, stuff, millis); ((InteractionWiredEffect) item).setCooldown(millis); @@ -344,7 +339,7 @@ public class WiredHandler { } else if (rewardReceived.getType().equalsIgnoreCase("furni")) { Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem(Integer.parseInt(rewardReceived.getValue())); if (baseItem != null) { - HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), baseItem, 0, 0, ""); + RoomItem item = Emulator.getGameEnvironment().getItemManager().createItem(habbo.getHabboInfo().getId(), baseItem, 0, 0, ""); if (item != null) { habbo.getClient().sendResponse(new UnseenItemsComposer(item)); diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java index 2e45f17a..43a108b7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java @@ -1,17 +1,19 @@ package com.eu.habbo.habbohotel.wired; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor public class WiredMatchFurniSetting { - private final int item_id; - private final String state; - private final int rotation; - private final int x; - private final int y; + private int item_id; + private String state; + private int rotation; + private int x; + private int y; - public WiredMatchFurniSetting(int itemId, String state, int rotation, int x, int y) { - this.item_id = itemId; + public WiredMatchFurniSetting(int item_id, String state, int rotation, int x, int y) { + this.item_id = item_id; this.state = state.replace("\t\t\t", " "); this.rotation = rotation; this.x = x; diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/highscores/WiredHighscoreMidnightUpdater.java b/src/main/java/com/eu/habbo/habbohotel/wired/highscores/WiredHighscoreMidnightUpdater.java index 7b60b22c..00a70218 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/highscores/WiredHighscoreMidnightUpdater.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/highscores/WiredHighscoreMidnightUpdater.java @@ -3,7 +3,7 @@ package com.eu.habbo.habbohotel.wired.highscores; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredHighscore; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import gnu.trove.set.hash.THashSet; import java.time.LocalDateTime; @@ -19,8 +19,8 @@ public class WiredHighscoreMidnightUpdater implements Runnable { for (Room room : rooms) { if (room == null || room.getRoomSpecialTypes() == null) continue; - THashSet items = room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class); - for (HabboItem item : items) { + THashSet items = room.getRoomSpecialTypes().getItemsOfType(InteractionWiredHighscore.class); + for (RoomItem item : items) { ((InteractionWiredHighscore) item).reloadData(); room.updateItem(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertEvent.java b/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertEvent.java index 45dfd6b6..183cabae 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/ambassadors/AmbassadorAlertEvent.java @@ -12,14 +12,14 @@ import com.eu.habbo.plugin.events.support.SupportUserAlertedReason; public class AmbassadorAlertEvent extends MessageHandler { @Override public void handle() { - if (!this.client.getHabbo().hasRight(Permission.ACC_AMBASSADOR)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_AMBASSADOR)) { ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.alert").replace("%username%", client.getHabbo().getHabboInfo().getUsername()).replace("%message%", "${notification.ambassador.alert.warning.message}")); return; } int userId = this.packet.readInt(); - Habbo habbo = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(userId); + Habbo habbo = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboById(userId); if (habbo == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/ambassadors/FollowFriendEvent.java b/src/main/java/com/eu/habbo/messages/incoming/ambassadors/FollowFriendEvent.java index 4f3f7304..16a316fc 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/ambassadors/FollowFriendEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/ambassadors/FollowFriendEvent.java @@ -9,14 +9,14 @@ import com.eu.habbo.messages.outgoing.rooms.RoomForwardMessageComposer; public class FollowFriendEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_AMBASSADOR)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_AMBASSADOR)) { String username = this.packet.readString(); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(username); if (habbo != null) { - if (habbo.getHabboInfo().getCurrentRoom() != null) { - this.client.sendResponse(new RoomForwardMessageComposer(habbo.getHabboInfo().getCurrentRoom().getId())); + if (habbo.getRoomUnit().getRoom() != null) { + this.client.sendResponse(new RoomForwardMessageComposer(habbo.getRoomUnit().getRoom().getRoomInfo().getId())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/camera/PurchasePhotoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/camera/PurchasePhotoEvent.java index a0de9495..a96ce15f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/camera/PurchasePhotoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/camera/PurchasePhotoEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.camera; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.camera.CameraPurchaseOKMessageComposer; import com.eu.habbo.messages.outgoing.catalog.NotEnoughBalanceMessageComposer; @@ -32,15 +32,15 @@ public class PurchasePhotoEvent extends MessageHandler { if (!this.client.getHabbo().getHabboInfo().getPhotoJSON().contains(this.client.getHabbo().getHabboInfo().getPhotoTimestamp() + "")) return; - if (Emulator.getPluginManager().fireEvent(new UserPurchasePictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), this.client.getHabbo().getHabboInfo().getCurrentRoom().getId(), this.client.getHabbo().getHabboInfo().getPhotoTimestamp())).isCancelled()) { + if (Emulator.getPluginManager().fireEvent(new UserPurchasePictureEvent(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getPhotoURL(), this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId(), this.client.getHabbo().getHabboInfo().getPhotoTimestamp())).isCancelled()) { return; } - HabboItem photoItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), Emulator.getGameEnvironment().getItemManager().getItem(Emulator.getConfig().getInt("camera.item_id")), 0, 0, this.client.getHabbo().getHabboInfo().getPhotoJSON()); + RoomItem photoItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), Emulator.getGameEnvironment().getItemManager().getItem(Emulator.getConfig().getInt("camera.item_id")), 0, 0, this.client.getHabbo().getHabboInfo().getPhotoJSON()); if (photoItem != null) { - photoItem.setExtradata(photoItem.getExtradata().replace("%id%", photoItem.getId() + "")); - photoItem.needsUpdate(true); + photoItem.setExtraData(photoItem.getExtraData().replace("%id%", photoItem.getId() + "")); + photoItem.setSqlUpdateNeeded(true); this.client.getHabbo().getInventory().getItemsComponent().addItem(photoItem); diff --git a/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomEvent.java index 1207db74..bcb4d0ea 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomEvent.java @@ -10,7 +10,7 @@ import com.eu.habbo.util.crypto.ZIP; public class RenderRoomEvent extends MessageHandler { @Override public void handle() { - if (!this.client.getHabbo().hasRight(Permission.ACC_CAMERA)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_CAMERA)) { this.client.getHabbo().alert(Emulator.getTexts().getValue("camera.permission")); return; } @@ -21,12 +21,12 @@ public class RenderRoomEvent extends MessageHandler { byte[] data = this.packet.getBuffer().readBytes(this.packet.getBuffer().readableBytes()).array(); String content = new String(ZIP.inflate(data)); - CameraRenderImageComposer composer = new CameraRenderImageComposer(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getHabboInfo().getCurrentRoom().getBackgroundTonerColor().getRGB(), 320, 320, content); + CameraRenderImageComposer composer = new CameraRenderImageComposer(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getRoomUnit().getRoom().getBackgroundTonerColor().getRGB(), 320, 320, content); this.client.getHabbo().getHabboInfo().setPhotoJSON(Emulator.getConfig().getValue("camera.extradata").replace("%timestamp%", composer.timestamp + "")); this.client.getHabbo().getHabboInfo().setPhotoTimestamp(composer.timestamp); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - this.client.getHabbo().getHabboInfo().setPhotoRoomId(this.client.getHabbo().getHabboInfo().getCurrentRoom().getId()); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + this.client.getHabbo().getHabboInfo().setPhotoRoomId(this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId()); } Emulator.getCameraClient().sendMessage(composer); diff --git a/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomThumbnailEvent.java b/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomThumbnailEvent.java index 56931182..32bf44cd 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomThumbnailEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/camera/RenderRoomThumbnailEvent.java @@ -11,12 +11,12 @@ import com.eu.habbo.util.crypto.ZIP; public class RenderRoomThumbnailEvent extends MessageHandler { @Override public void handle() { - if (!this.client.getHabbo().hasRight(Permission.ACC_CAMERA)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_CAMERA)) { this.client.getHabbo().alert(Emulator.getTexts().getValue("camera.permission")); return; } - if (!this.client.getHabbo().getHabboInfo().getCurrentRoom().isOwner(this.client.getHabbo())) + if (!this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().isRoomOwner(this.client.getHabbo())) return; if (CameraClient.isLoggedIn) { @@ -24,7 +24,7 @@ public class RenderRoomThumbnailEvent extends MessageHandler { byte[] data = this.packet.getBuffer().readBytes(this.packet.getBuffer().readableBytes()).array(); String content = new String(ZIP.inflate(data)); - CameraRenderImageComposer composer = new CameraRenderImageComposer(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getHabboInfo().getCurrentRoom().getBackgroundTonerColor().getRGB(), 110, 110, content); + CameraRenderImageComposer composer = new CameraRenderImageComposer(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getRoomUnit().getRoom().getBackgroundTonerColor().getRGB(), 110, 110, content); this.client.getHabbo().getHabboInfo().setPhotoJSON(Emulator.getConfig().getValue("camera.extradata").replace("%timestamp%", composer.timestamp + "")); this.client.getHabbo().getHabboInfo().setPhotoTimestamp(composer.timestamp); diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseEvent.java index 508253eb..cd76b923 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseEvent.java @@ -19,10 +19,10 @@ public abstract class PurchaseEvent extends MessageHandler { if (this.client.getHabbo().getHabboInfo().getCredits() < totalCredits) return; - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_CREDITS)) + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_CREDITS)) this.client.getHabbo().giveCredits(-totalCredits); - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_POINTS)) + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_POINTS)) this.client.getHabbo().givePoints(deal.getPointsType(), -totalDuckets); diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogAsGiftEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogAsGiftEvent.java index 8d9a156a..0340d360 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogAsGiftEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogAsGiftEvent.java @@ -11,9 +11,9 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.*; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboBadge; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.*; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; @@ -192,7 +192,7 @@ public class PurchaseFromCatalogAsGiftEvent extends MessageHandler { limitedStack = limitedConfiguration.getTotalSet(); } - THashSet itemsList = new THashSet<>(); + THashSet itemsList = new THashSet<>(); boolean badgeFound = false; for (Item baseItem : item.getBaseItems()) { @@ -271,21 +271,21 @@ public class PurchaseFromCatalogAsGiftEvent extends MessageHandler { } if (baseItem.getInteractionType().getType() == InteractionTeleport.class || baseItem.getInteractionType().getType() == InteractionTeleportTile.class) { - HabboItem teleportOne = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); - HabboItem teleportTwo = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); + RoomItem teleportOne = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); + RoomItem teleportTwo = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); Emulator.getGameEnvironment().getItemManager().insertTeleportPair(teleportOne.getId(), teleportTwo.getId()); itemsList.add(teleportOne); itemsList.add(teleportTwo); } else if (baseItem.getInteractionType().getType() == InteractionHopper.class) { - HabboItem hopper = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedNumber, limitedNumber, extraData); + RoomItem hopper = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedNumber, limitedNumber, extraData); Emulator.getGameEnvironment().getItemManager().insertHopper(hopper); itemsList.add(hopper); } else if (baseItem.getInteractionType().getType() == InteractionGuildFurni.class || baseItem.getInteractionType().getType() == InteractionGuildGate.class) { InteractionGuildFurni habboItem = (InteractionGuildFurni) Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); - habboItem.setExtradata(""); - habboItem.needsUpdate(true); + habboItem.setExtraData(""); + habboItem.setSqlUpdateNeeded(true); int guildId; try { guildId = Integer.parseInt(extraData); @@ -298,8 +298,8 @@ public class PurchaseFromCatalogAsGiftEvent extends MessageHandler { Emulator.getGameEnvironment().getGuildManager().setGuild(habboItem, guildId); itemsList.add(habboItem); } else { - HabboItem habboItem = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); - itemsList.add(habboItem); + RoomItem roomItem = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, limitedStack, limitedNumber, extraData); + itemsList.add(roomItem); } } } else { @@ -312,13 +312,13 @@ public class PurchaseFromCatalogAsGiftEvent extends MessageHandler { StringBuilder giftData = new StringBuilder(itemsList.size() + "\t"); - for (HabboItem i : itemsList) { + for (RoomItem i : itemsList) { giftData.append(i.getId()).append("\t"); } giftData.append(color).append("\t").append(ribbonId).append("\t").append(showName ? "1" : "0").append("\t").append(message.replace("\t", "")).append("\t").append(this.client.getHabbo().getHabboInfo().getUsername()).append("\t").append(this.client.getHabbo().getHabboInfo().getLook()); - HabboItem gift = Emulator.getGameEnvironment().getItemManager().createGift(username, giftItem, giftData.toString(), 0, 0); + RoomItem gift = Emulator.getGameEnvironment().getItemManager().createGift(username, giftItem, giftData.toString(), 0, 0); if (gift == null) { this.client.sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR)); @@ -347,15 +347,15 @@ public class PurchaseFromCatalogAsGiftEvent extends MessageHandler { AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver")); } - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_CREDITS)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_CREDITS)) { if (totalCredits > 0) { this.client.getHabbo().giveCredits(-totalCredits); } } if (totalPoints > 0) { - if (item.getPointsType() == 0 && !this.client.getHabbo().hasRight(Permission.ACC_INFINITE_PIXELS)) { + if (item.getPointsType() == 0 && !this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_PIXELS)) { this.client.getHabbo().givePixels(-totalPoints); - } else if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_POINTS)) { + } else if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_POINTS)) { this.client.getHabbo().givePoints(item.getPointsType(), -totalPoints); } this.client.sendResponse(new HabboActivityPointNotificationMessageComposer(this.client.getHabbo().getHabboInfo().getCurrencyAmount(item.getPointsType()), -totalPoints, item.getPointsType())); diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogEvent.java index b0652399..7f4c5de9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/PurchaseFromCatalogEvent.java @@ -100,11 +100,11 @@ public class PurchaseFromCatalogEvent extends PurchaseEvent { return; } ((RoomBundleLayout) page).buyRoom(this.client.getHabbo()); - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_CREDITS)) { //if the player has this perm disabled + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_CREDITS)) { //if the player has this perm disabled this.client.getHabbo().getHabboInfo().addCredits(-roomBundleItem.getCredits()); // takes their credits away this.client.sendResponse(new CreditBalanceComposer(this.client.getHabbo())); // Sends the updated currency composer window } - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_POINTS)) { //if the player has this perm disabled + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_POINTS)) { //if the player has this perm disabled this.client.getHabbo().getHabboInfo().addCurrencyAmount(roomBundleItem.getPointsType(), -roomBundleItem.getPoints()); // takes their points away this.client.sendResponse(new ActivityPointsMessageComposer(this.client.getHabbo())); // Sends the updated currency composer window } @@ -172,13 +172,13 @@ public class PurchaseFromCatalogEvent extends PurchaseEvent { item = page.getCatalogItem(itemId); // temp patch, can a dev with better knowledge than me look into this asap pls. if (page instanceof BotsLayout) { - if (!this.client.getHabbo().hasRight(Permission.ACC_UNLIMITED_BOTS) && this.client.getHabbo().getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && this.client.getHabbo().getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) { this.client.getHabbo().alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", BotManager.MAXIMUM_BOT_INVENTORY_SIZE + "")); return; } } if (page instanceof PetsLayout) { // checks it's the petlayout - if (!this.client.getHabbo().hasRight(Permission.ACC_UNLIMITED_PETS) && this.client.getHabbo().getInventory().getPetsComponent().getPets().size() >= PetManager.MAXIMUM_PET_INVENTORY_SIZE) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_PETS) && this.client.getHabbo().getInventory().getPetsComponent().getPets().size() >= PetManager.MAXIMUM_PET_INVENTORY_SIZE) { this.client.getHabbo().alert(Emulator.getTexts().getValue("error.pets.max.inventory").replace("%amount%", PetManager.MAXIMUM_PET_INVENTORY_SIZE + "")); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/MakeOfferEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/MakeOfferEvent.java index 56495b1a..53a3d739 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/MakeOfferEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/marketplace/MakeOfferEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.catalog.marketplace; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.catalog.marketplace.MarketPlace; import com.eu.habbo.habbohotel.modtool.ScripterManager; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.PurchaseErrorMessageComposer; import com.eu.habbo.messages.outgoing.catalog.marketplace.MarketplaceMakeOfferResult; @@ -24,7 +24,7 @@ public class MakeOfferEvent extends MessageHandler { int unknown = this.packet.readInt(); int itemId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); if (item != null) { if (!item.getBaseItem().allowMarketplace()) { String message = Emulator.getTexts().getValue("scripter.warning.marketplace.forbidden").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%itemname%", item.getBaseItem().getName()).replace("%credits%", credits + ""); diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/PresentOpenEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/PresentOpenEvent.java index 262e8530..e609b5bd 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/PresentOpenEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/PresentOpenEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionGift; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; @@ -17,13 +17,14 @@ import com.eu.habbo.threading.runnables.OpenGift; public class PresentOpenEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { - HabboItem item = room.getHabboItem(this.packet.readInt()); + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + int id = this.packet.readInt(); + RoomItem item = room.getRoomItemManager().getRoomItemById(id); if (item == null) return; @@ -36,35 +37,35 @@ public class PresentOpenEvent extends MessageHandler { Emulator.getThreading().run(new OpenGift(item, this.client.getHabbo(), room), item.getBaseItem().getName().contains("present_wrap") ? 1000 : 0); } else { - if (item.getExtradata().length() == 0) { + if (item.getExtraData().length() == 0) { this.client.sendResponse(new WhisperMessageComposer(new RoomChatMessage(Emulator.getTexts().getValue("error.recycler.box.empty"), this.client.getHabbo(), this.client.getHabbo(), RoomChatMessageBubbles.BOT))); } else { - HabboItem reward = Emulator.getGameEnvironment().getItemManager().handleOpenRecycleBox(this.client.getHabbo(), item); + RoomItem reward = Emulator.getGameEnvironment().getItemManager().handleOpenRecycleBox(this.client.getHabbo(), item); if (reward != null) { this.client.getHabbo().getInventory().getItemsComponent().addItem(reward); this.client.sendResponse(new UnseenItemsComposer(reward)); this.client.sendResponse(new FurniListInvalidateComposer()); - this.client.sendResponse(new PresentOpenedMessageComposer(reward, item.getExtradata(), true)); + this.client.sendResponse(new PresentOpenedMessageComposer(reward, item.getExtraData(), true)); } } room.sendComposer(new RemoveFloorItemComposer(item).compose()); - room.removeHabboItem(item); + room.getRoomItemManager().removeRoomItem(item); } if (item.getRoomId() == 0) { - room.updateTile(room.getLayout().getTile(item.getX(), item.getY())); + room.updateTile(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); RoomLayout roomLayout = room.getLayout(); - short z = (short)room.getStackHeight(item.getX(), item.getY(), true); + short z = (short)room.getStackHeight(item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), true); if(roomLayout != null) { - RoomTile roomTile = roomLayout.getTile(item.getX(), item.getY()); + RoomTile roomTile = roomLayout.getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); if(roomTile != null) { z = roomTile.getZ(); } } - room.sendComposer(new HeightMapUpdateMessageComposer(item.getX(), item.getY(), z, room.getStackHeight(item.getX(), item.getY(), true)).compose()); + room.sendComposer(new HeightMapUpdateMessageComposer(item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), z, room.getStackHeight(item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), true)).compose()); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleItemsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleItemsEvent.java index 99796945..c08a44e2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleItemsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/recycler/RecycleItemsEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.catalog.recycler; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.items.ItemManager; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.PurchaseErrorMessageComposer; import com.eu.habbo.messages.outgoing.catalog.RecyclerFinishedComposer; @@ -24,13 +24,13 @@ public class RecycleItemsEvent extends MessageHandler { } if (Emulator.getGameEnvironment().getCatalogManager().ecotronItem != null && ItemManager.RECYCLER_ENABLED) { - THashSet items = new THashSet<>(); + THashSet items = new THashSet<>(); int count = this.packet.readInt(); if (count < Emulator.getConfig().getInt("recycler.value", 8)) return; for (int i = 0; i < count; i++) { - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); if (item == null) return; @@ -41,7 +41,7 @@ public class RecycleItemsEvent extends MessageHandler { } if (items.size() == count) { - for (HabboItem item : items) { + for (RoomItem item : items) { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.sendResponse(new FurniListRemoveComposer(item.getGiftAdjustedId())); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); @@ -51,7 +51,7 @@ public class RecycleItemsEvent extends MessageHandler { return; } - HabboItem reward = Emulator.getGameEnvironment().getItemManager().handleRecycle(this.client.getHabbo(), Emulator.getGameEnvironment().getCatalogManager().getRandomRecyclerPrize().getId() + ""); + RoomItem reward = Emulator.getGameEnvironment().getItemManager().handleRecycle(this.client.getHabbo(), Emulator.getGameEnvironment().getCatalogManager().getRandomRecyclerPrize().getId() + ""); if (reward == null) { this.client.sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR)); return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftEvent.java b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftEvent.java index 152f88ca..14abb152 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.crafting.CraftingAltar; import com.eu.habbo.habbohotel.crafting.CraftingRecipe; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.LimitedEditionSoldOutComposer; import com.eu.habbo.messages.outgoing.crafting.CraftingResultComposer; @@ -21,7 +21,7 @@ public class CraftEvent extends MessageHandler { @Override public void handle() { int craftingTable = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(craftingTable); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(craftingTable); CraftingAltar altar = Emulator.getGameEnvironment().getCraftingManager().getAltar(item.getBaseItem()); CraftingRecipe recipe = altar.getRecipe(this.packet.readString()); @@ -31,20 +31,20 @@ public class CraftEvent extends MessageHandler { return; } - TIntObjectHashMap toRemove = new TIntObjectHashMap<>(); + TIntObjectHashMap toRemove = new TIntObjectHashMap<>(); for (Map.Entry set : recipe.getIngredients().entrySet()) { for (int i = 0; i < set.getValue(); i++) { - HabboItem habboItem = this.client.getHabbo().getInventory().getItemsComponent().getAndRemoveHabboItem(set.getKey()); + RoomItem roomItem = this.client.getHabbo().getInventory().getItemsComponent().getAndRemoveHabboItem(set.getKey()); - if (habboItem == null) { + if (roomItem == null) { return; } - toRemove.put(habboItem.getId(), habboItem); + toRemove.put(roomItem.getId(), roomItem); } } - HabboItem rewardItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), recipe.getReward(), 0, 0, ""); + RoomItem rewardItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), recipe.getReward(), 0, 0, ""); if (rewardItem != null) { if (recipe.isLimited()) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftSecretEvent.java b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftSecretEvent.java index 68ac6b93..29b5143a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftSecretEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/crafting/CraftSecretEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.crafting.CraftingAltar; import com.eu.habbo.habbohotel.crafting.CraftingRecipe; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.LimitedEditionSoldOutComposer; import com.eu.habbo.messages.outgoing.crafting.CraftingResultComposer; @@ -25,30 +25,30 @@ public class CraftSecretEvent extends MessageHandler { int altarId = this.packet.readInt(); int count = this.packet.readInt(); - HabboItem craftingAltar = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(altarId); + RoomItem craftingAltar = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(altarId); if (craftingAltar != null) { CraftingAltar altar = Emulator.getGameEnvironment().getCraftingManager().getAltar(craftingAltar.getBaseItem()); if (altar != null) { - Set habboItems = new THashSet<>(); + Set roomItems = new THashSet<>(); Map items = new THashMap<>(); for (int i = 0; i < count; i++) { - HabboItem habboItem = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); + RoomItem roomItem = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); - if (habboItem == null) { + if (roomItem == null) { this.client.sendResponse(new CraftingResultComposer(null)); return; } - habboItems.add(habboItem); + roomItems.add(roomItem); - if (!items.containsKey(habboItem.getBaseItem())) { - items.put(habboItem.getBaseItem(), 0); + if (!items.containsKey(roomItem.getBaseItem())) { + items.put(roomItem.getBaseItem(), 0); } - items.put(habboItem.getBaseItem(), items.get(habboItem.getBaseItem()) + 1); + items.put(roomItem.getBaseItem(), items.get(roomItem.getBaseItem()) + 1); } CraftingRecipe recipe = altar.getRecipe(items); @@ -59,7 +59,7 @@ public class CraftSecretEvent extends MessageHandler { return; } - HabboItem rewardItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), recipe.getReward(), 0, 0, ""); + RoomItem rewardItem = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), recipe.getReward(), 0, 0, ""); if (rewardItem != null) { if (recipe.isLimited()) { @@ -77,7 +77,7 @@ public class CraftSecretEvent extends MessageHandler { } this.client.getHabbo().getInventory().getItemsComponent().addItem(rewardItem); this.client.sendResponse(new UnseenItemsComposer(rewardItem)); - for (HabboItem item : habboItems) { + for (RoomItem item : roomItems) { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.sendResponse(new FurniListRemoveComposer(item.getGiftAdjustedId())); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); diff --git a/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipeEvent.java b/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipeEvent.java index 8f7e5f0a..85515bfd 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipeEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipeEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.crafting; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.crafting.CraftingAltar; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.crafting.CraftableProductsComposer; @@ -10,7 +10,7 @@ public class GetCraftingRecipeEvent extends MessageHandler { @Override public void handle() { int itemId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item != null) { CraftingAltar altar = Emulator.getGameEnvironment().getCraftingManager().getAltar(item.getBaseItem()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipesAvailableEvent.java b/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipesAvailableEvent.java index d2ce560b..fd8044c1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipesAvailableEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/crafting/GetCraftingRecipesAvailableEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.crafting.CraftingAltar; import com.eu.habbo.habbohotel.crafting.CraftingRecipe; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.crafting.CraftingRecipesAvailableComposer; import gnu.trove.map.hash.THashMap; @@ -16,7 +16,7 @@ public class GetCraftingRecipesAvailableEvent extends MessageHandler { public void handle() { int altarId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(altarId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(altarId); CraftingAltar altar = Emulator.getGameEnvironment().getCraftingManager().getAltar(item.getBaseItem()); @@ -25,14 +25,14 @@ public class GetCraftingRecipesAvailableEvent extends MessageHandler { int count = this.packet.readInt(); for (int i = 0; i < count; i++) { - HabboItem habboItem = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); + RoomItem roomItem = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); - if (habboItem != null) { - if (!items.containsKey(habboItem.getBaseItem())) { - items.put(habboItem.getBaseItem(), 0); + if (roomItem != null) { + if (!items.containsKey(roomItem.getBaseItem())) { + items.put(roomItem.getBaseItem(), 0); } - items.put(habboItem.getBaseItem(), items.get(habboItem.getBaseItem()) + 1); + items.put(roomItem.getBaseItem(), items.get(roomItem.getBaseItem()) + 1); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetOccupiedTilesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetOccupiedTilesEvent.java index 4bc3e64a..9330f50a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetOccupiedTilesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetOccupiedTilesEvent.java @@ -6,9 +6,9 @@ import com.eu.habbo.messages.outgoing.floorplaneditor.RoomOccupiedTilesMessageCo public class GetOccupiedTilesEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - this.client.sendResponse(new RoomOccupiedTilesMessageComposer(this.client.getHabbo().getHabboInfo().getCurrentRoom())); + this.client.sendResponse(new RoomOccupiedTilesMessageComposer(this.client.getHabbo().getRoomUnit().getRoom())); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetRoomEntryTileEvent.java b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetRoomEntryTileEvent.java index 4d5c3f53..96144dbf 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetRoomEntryTileEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/floorplaneditor/GetRoomEntryTileEvent.java @@ -7,10 +7,10 @@ import com.eu.habbo.messages.outgoing.rooms.RoomFloorThicknessUpdatedComposer; public class GetRoomEntryTileEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - this.client.sendResponse(new RoomEntryTileMessageComposer(this.client.getHabbo().getHabboInfo().getCurrentRoom())); - this.client.sendResponse(new RoomFloorThicknessUpdatedComposer(this.client.getHabbo().getHabboInfo().getCurrentRoom())); + this.client.sendResponse(new RoomEntryTileMessageComposer(this.client.getHabbo().getRoomUnit().getRoom())); + this.client.sendResponse(new RoomFloorThicknessUpdatedComposer(this.client.getHabbo().getRoomUnit().getRoom())); } } 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 a6727ac1..b75b5ebf 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 @@ -23,17 +23,17 @@ public class UpdateFloorPropertiesEvent extends MessageHandler { @Override public void handle() { - if (!this.client.getHabbo().hasRight(Permission.ACC_FLOORPLAN_EDITOR)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_FLOORPLAN_EDITOR)) { this.client.sendResponse(new HabboBroadcastMessageComposer(Emulator.getTexts().getValue("floorplan.permission"))); return; } - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { StringJoiner errors = new StringJoiner("
"); String map = this.packet.readString(); map = map.replace("X", "x"); @@ -111,7 +111,7 @@ public class UpdateFloorPropertiesEvent extends MessageHandler { String square = String.valueOf(mapRows[y].charAt(x)); short height; - if (square.equalsIgnoreCase("x") && room.getTopItemAt(x, y) != null) { + if (square.equalsIgnoreCase("x") && room.getRoomItemManager().getTopItemAt(x, y) != null) { errors.add("${notification.floorplan_editor.error.message.change_blocked_by_room_item}"); break blockingRoomItemScan; } else { @@ -124,7 +124,7 @@ public class UpdateFloorPropertiesEvent extends MessageHandler { } } - if (tile != null && tile.getState() != RoomTileState.INVALID && height != tile.getZ() && room.getTopItemAt(x, y) != null) { + if (tile != null && tile.getState() != RoomTileState.INVALID && height != tile.getZ() && room.getRoomItemManager().getTopItemAt(x, y) != null) { errors.add("${notification.floorplan_editor.error.message.change_blocked_by_room_item}"); break blockingRoomItemScan; } @@ -155,7 +155,7 @@ public class UpdateFloorPropertiesEvent extends MessageHandler { if (layout.getDoorTile() == null) { this.client.getHabbo().alert("Error"); ((CustomRoomLayout) layout).needsUpdate(false); - Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); + room.dispose(); return; } ((CustomRoomLayout) layout).needsUpdate(true); @@ -165,18 +165,18 @@ public class UpdateFloorPropertiesEvent extends MessageHandler { } if (layout != null) { - room.setHasCustomLayout(true); + room.getRoomInfo().setModelOverridden(true); room.setNeedsUpdate(true); room.setLayout(layout); - room.setWallSize(wallSize); - room.setFloorSize(floorSize); - room.setWallHeight(wallHeight); + room.getRoomInfo().setWallThickness(wallSize); + room.getRoomInfo().setFloorThickness(floorSize); + room.getRoomInfo().setWallHeight(wallHeight); room.save(); - Collection habbos = new ArrayList<>(room.getUserCount()); - habbos.addAll(room.getHabbos()); - Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); - room = Emulator.getGameEnvironment().getRoomManager().loadRoom(room.getId()); - ServerMessage message = new RoomForwardMessageComposer(room.getId()).compose(); + Collection habbos = new ArrayList<>(room.getRoomUnitManager().getRoomHabbosCount()); + habbos.addAll(room.getRoomUnitManager().getCurrentHabbos().values()); + room.dispose(); + room = Emulator.getGameEnvironment().getRoomManager().getRoom(room.getRoomInfo().getId()); + ServerMessage message = new RoomForwardMessageComposer(room.getRoomInfo().getId()).compose(); for (Habbo habbo : habbos) { habbo.getClient().sendResponse(message); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/friends/AcceptFriendEvent.java b/src/main/java/com/eu/habbo/messages/incoming/friends/AcceptFriendEvent.java index 19b443a5..74c32cc7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/friends/AcceptFriendEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/friends/AcceptFriendEvent.java @@ -14,8 +14,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import static com.eu.habbo.habbohotel.users.HabboManager.getOfflineHabboInfo; - @Slf4j public class AcceptFriendEvent extends MessageHandler { @@ -38,7 +36,7 @@ public class AcceptFriendEvent extends MessageHandler { Habbo target = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if(target == null) { - HabboInfo habboInfo = getOfflineHabboInfo(userId); + HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(userId); if(habboInfo == null) { this.client.sendResponse(new MessengerErrorComposer(MessengerErrorComposer.TARGET_NOT_FOUND)); @@ -65,12 +63,12 @@ public class AcceptFriendEvent extends MessageHandler { continue; } - if(this.client.getHabbo().getMessenger().getFriends().size() >= this.client.getHabbo().getHabboStats().getMaxFriends() && !this.client.getHabbo().hasRight(Permission.ACC_INFINITE_FRIENDS)) { + if(this.client.getHabbo().getMessenger().getFriends().size() >= this.client.getHabbo().getHabboStats().getMaxFriends() && !this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_FRIENDS)) { this.client.sendResponse(new MessengerErrorComposer(MessengerErrorComposer.FRIEND_LIST_OWN_FULL)); break; } - if(target.getMessenger().getFriends().size() >= target.getHabboStats().getMaxFriends() && !target.hasRight(Permission.ACC_INFINITE_FRIENDS)) { + if(target.getMessenger().getFriends().size() >= target.getHabboStats().getMaxFriends() && !target.hasPermissionRight(Permission.ACC_INFINITE_FRIENDS)) { this.client.sendResponse(new MessengerErrorComposer(MessengerErrorComposer.FRIEND_LIST_TARGET_FULL)); continue; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/friends/FindNewFriendsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/friends/FindNewFriendsEvent.java index 82d9cab3..9bef5cd0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/friends/FindNewFriendsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/friends/FindNewFriendsEvent.java @@ -17,13 +17,13 @@ public class FindNewFriendsEvent extends MessageHandler { Collections.shuffle(roomCategories); for (RoomCategory category : roomCategories) { - List rooms = Emulator.getGameEnvironment().getRoomManager().getActiveRooms(category.getId()); + List rooms = Emulator.getGameEnvironment().getRoomManager().getActiveRoomsByCategoryId(category.getId()); if (!rooms.isEmpty()) { Room room = rooms.get(0); - if (room.getUserCount() > 0) { - this.client.sendResponse(new RoomForwardMessageComposer(room.getId())); + if (room.getRoomUnitManager().getRoomHabbosCount() > 0) { + this.client.sendResponse(new RoomForwardMessageComposer(room.getRoomInfo().getId())); return; } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/friends/RequestFriendEvent.java b/src/main/java/com/eu/habbo/messages/incoming/friends/RequestFriendEvent.java index a299ac62..eb969b52 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/friends/RequestFriendEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/friends/RequestFriendEvent.java @@ -64,13 +64,13 @@ public class RequestFriendEvent extends MessageHandler { } // You can only have x friends - if (this.client.getHabbo().getMessenger().getFriends().values().size() >= this.client.getHabbo().getHabboStats().getMaxFriends() && !this.client.getHabbo().hasRight(Permission.ACC_INFINITE_FRIENDS)) { + if (this.client.getHabbo().getMessenger().getFriends().values().size() >= this.client.getHabbo().getHabboStats().getMaxFriends() && !this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_FRIENDS)) { this.client.sendResponse(new MessengerErrorComposer(MessengerErrorComposer.FRIEND_LIST_OWN_FULL)); return; } // Check if targets friendlist is full - if (targetHabbo.getMessenger().getFriends().values().size() >= targetHabbo.getHabboStats().getMaxFriends() && !targetHabbo.hasRight(Permission.ACC_INFINITE_FRIENDS)) { + if (targetHabbo.getMessenger().getFriends().values().size() >= targetHabbo.getHabboStats().getMaxFriends() && !targetHabbo.hasPermissionRight(Permission.ACC_INFINITE_FRIENDS)) { this.client.sendResponse(new MessengerErrorComposer(MessengerErrorComposer.FRIEND_LIST_TARGET_FULL)); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/friends/VisitUserEvent.java b/src/main/java/com/eu/habbo/messages/incoming/friends/VisitUserEvent.java index fc7737b1..f3363673 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/friends/VisitUserEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/friends/VisitUserEvent.java @@ -30,18 +30,18 @@ public class VisitUserEvent extends MessageHandler { return; } - if (habbo.getHabboStats().isBlockFollowing() && !this.client.getHabbo().hasRight(Permission.ACC_CAN_STALK)) { + if (habbo.getHabboStats().isBlockFollowing() && !this.client.getHabbo().hasPermissionRight(Permission.ACC_CAN_STALK)) { this.client.sendResponse(new FollowFriendFailedComposer(FollowFriendFailedComposer.FRIEND_BLOCKED_STALKING)); return; } - if (habbo.getHabboInfo().getCurrentRoom() == null) { + if (habbo.getRoomUnit().getRoom() == null) { this.client.sendResponse(new FollowFriendFailedComposer(FollowFriendFailedComposer.FRIEND_NOT_IN_ROOM)); return; } - if (habbo.getHabboInfo().getCurrentRoom() != this.client.getHabbo().getHabboInfo().getCurrentRoom()) { - this.client.sendResponse(new RoomForwardMessageComposer(habbo.getHabboInfo().getCurrentRoom().getId())); + if (habbo.getRoomUnit().getRoom() != this.client.getHabbo().getRoomUnit().getRoom()) { + this.client.sendResponse(new RoomForwardMessageComposer(habbo.getRoomUnit().getRoom().getRoomInfo().getId())); } else { this.client.sendResponse(new WhisperMessageComposer(new RoomChatMessage(Emulator.getTexts().getValue("stalk.failed.same.room").replace("%user%", habbo.getHabboInfo().getUsername()), this.client.getHabbo(), this.client.getHabbo(), RoomChatMessageBubbles.ALERT))); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionGetRequesterRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionGetRequesterRoomEvent.java index 4302617f..9443eda8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionGetRequesterRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionGetRequesterRoomEvent.java @@ -11,7 +11,7 @@ public class GuideSessionGetRequesterRoomEvent extends MessageHandler { GuideTour tour = Emulator.getGameEnvironment().getGuideManager().getGuideTourByHelper(this.client.getHabbo()); if (tour != null) { - this.client.sendResponse(new GuideSessionRequesterRoomMessageComposer(tour.getNoob().getHabboInfo().getCurrentRoom())); + this.client.sendResponse(new GuideSessionRequesterRoomMessageComposer(tour.getNoob().getRoomUnit().getRoom())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionInviteRequesterEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionInviteRequesterEvent.java index 350577a9..d3427215 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionInviteRequesterEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionInviteRequesterEvent.java @@ -12,7 +12,7 @@ public class GuideSessionInviteRequesterEvent extends MessageHandler { GuideTour tour = Emulator.getGameEnvironment().getGuideManager().getGuideTourByHelper(this.client.getHabbo()); if (tour != null) { - ServerMessage message = new GuideSessionInvitedToGuideRoomMessageComposer(this.client.getHabbo().getHabboInfo().getCurrentRoom()).compose(); + ServerMessage message = new GuideSessionInvitedToGuideRoomMessageComposer(this.client.getHabbo().getRoomUnit().getRoom()).compose(); tour.getNoob().getClient().sendResponse(message); tour.getHelper().getClient().sendResponse(message); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionOnDutyUpdateEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionOnDutyUpdateEvent.java index a3a50337..f0ad7d85 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionOnDutyUpdateEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guides/GuideSessionOnDutyUpdateEvent.java @@ -15,13 +15,13 @@ public class GuideSessionOnDutyUpdateEvent extends MessageHandler { boolean helperRequests = this.packet.readBoolean(); boolean bullyReports = this.packet.readBoolean(); - if (!this.client.getHabbo().hasRight(Permission.ACC_HELPER_USE_GUIDE_TOOL)) + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_HELPER_USE_GUIDE_TOOL)) return; - if (helperRequests && !this.client.getHabbo().hasRight(Permission.ACC_HELPER_GIVE_GUIDE_TOURS)) + if (helperRequests && !this.client.getHabbo().hasPermissionRight(Permission.ACC_HELPER_GIVE_GUIDE_TOURS)) helperRequests = false; - if (bullyReports && !this.client.getHabbo().hasRight(Permission.ACC_HELPER_JUDGE_CHAT_REVIEWS)) + if (bullyReports && !this.client.getHabbo().hasPermissionRight(Permission.ACC_HELPER_JUDGE_CHAT_REVIEWS)) bullyReports = false; if (helperRequests) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/AddAdminRightsToMemberEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/AddAdminRightsToMemberEvent.java index a8c6faa6..fce7cd7d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/AddAdminRightsToMemberEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/AddAdminRightsToMemberEvent.java @@ -18,7 +18,7 @@ public class AddAdminRightsToMemberEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); - if (guild != null && (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN))) { + if (guild != null && (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN))) { Emulator.getGameEnvironment().getGuildManager().setAdmin(guild, userId); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); @@ -29,9 +29,11 @@ public class AddAdminRightsToMemberEvent extends MessageHandler { return; if (habbo != null) { - Room room = habbo.getHabboInfo().getCurrentRoom(); - if (room != null && room.getGuildId() == guildId) { - room.refreshRightsForHabbo(habbo); + Room room = habbo.getRoomUnit().getRoom(); + if (room != null) { + if (room.getRoomInfo().getGuild().getId() == guildId) { + room.getRoomRightsManager().refreshRightsForHabbo(habbo); + } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/ApproveMembershipRequestEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/ApproveMembershipRequestEvent.java index ff32b0d2..e1052a0f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/ApproveMembershipRequestEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/ApproveMembershipRequestEvent.java @@ -7,7 +7,6 @@ import com.eu.habbo.habbohotel.guilds.GuildRank; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.guilds.GuildMemberMgmtFailedMessageComposer; import com.eu.habbo.messages.outgoing.guilds.GuildMembershipRejectedMessageComposer; @@ -26,11 +25,11 @@ public class ApproveMembershipRequestEvent extends MessageHandler { GuildMember groupMember = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); - if (habbo == null) userInfo = HabboManager.getOfflineHabboInfo(userId); + if (habbo == null) userInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(userId); else userInfo = habbo.getHabboInfo(); - if (userInfo == null || groupMember == null || userId == this.client.getHabbo().getHabboInfo().getId() || (!this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN) && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId() && !groupMember.getRank().equals(GuildRank.ADMIN) && !groupMember.getRank().equals(GuildRank.OWNER))) + if (userInfo == null || groupMember == null || userId == this.client.getHabbo().getHabboInfo().getId() || (!this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN) && guild.getOwnerId() != this.client.getHabbo().getHabboInfo().getId() && !groupMember.getRank().equals(GuildRank.ADMIN) && !groupMember.getRank().equals(GuildRank.OWNER))) return; if (!userInfo.getHabboStats().hasGuild(guild.getId())) { @@ -56,9 +55,11 @@ public class ApproveMembershipRequestEvent extends MessageHandler { guild.increaseMemberCount(); this.client.sendResponse(new GuildMembershipRejectedMessageComposer(guild, userId)); - if (habbo != null && userInfo.isOnline() && userInfo.getCurrentRoom() != null && userInfo.getCurrentRoom().getGuildId() == guildId) { - habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId))); - userInfo.getCurrentRoom().refreshRightsForHabbo(habbo); + if (habbo != null && userInfo.isOnline() && habbo.getRoomUnit().getRoom() != null) { + if (habbo.getRoomUnit().getRoom().getRoomInfo().getGuild().getId() == guildId) { + habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId))); + habbo.getRoomUnit().getRoom().getRoomRightsManager().refreshRightsForHabbo(habbo); + } } } } 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 26945507..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 @@ -31,7 +31,7 @@ public class CreateGuildEvent extends GuildBadgeEvent { return; } - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_CREDITS)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_CREDITS)) { int guildPrice = Emulator.getConfig().getInt("catalog.guild.price"); if (this.client.getHabbo().getHabboInfo().getCredits() >= guildPrice) { this.client.getHabbo().giveCredits(-guildPrice); @@ -43,16 +43,16 @@ public class CreateGuildEvent extends GuildBadgeEvent { int roomId = this.packet.readInt(); - Room r = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room r = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (r != null) { - if (r.hasGuild()) { + if (r.getRoomInfo().hasGuild()) { this.client.sendResponse(new GuildEditFailedMessageComposer(GuildEditFailedMessageComposer.ROOM_ALREADY_IN_USE)); return; } - if (r.getOwnerId() == this.client.getHabbo().getHabboInfo().getId()) { - if (r.getGuildId() == 0) { + if (r.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId()) { + if (r.getRoomInfo().getGuild().getId() == 0) { int colorOne = this.packet.readInt(); int colorTwo = this.packet.readInt(); @@ -60,10 +60,10 @@ public class CreateGuildEvent extends GuildBadgeEvent { StringBuilder badge = createBadge(count); - Guild guild = Emulator.getGameEnvironment().getGuildManager().createGuild(this.client.getHabbo(), roomId, r.getName(), name, description, badge.toString(), colorOne, colorTwo); + Guild guild = Emulator.getGameEnvironment().getGuildManager().createGuild(this.client.getHabbo(), roomId, r.getRoomInfo().getName(), name, description, badge.toString(), colorOne, colorTwo); - r.setGuildId(guild.getId()); - r.removeAllRights(); + r.getRoomInfo().setGuild(guild); + r.getRoomRightsManager().removeAllRights(); //TODO Check if this is needed r.setNeedsUpdate(true); if (Emulator.getConfig().getBoolean("imager.internal.enabled")) { @@ -72,7 +72,7 @@ public class CreateGuildEvent extends GuildBadgeEvent { this.client.sendResponse(new PurchaseOKMessageComposer()); this.client.sendResponse(new GuildCreatedMessageComposer(guild)); - for (Habbo habbo : r.getHabbos()) { + for (Habbo habbo : r.getRoomUnitManager().getCurrentHabbos().values()) { habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, null)); } r.refreshGuild(guild); @@ -82,7 +82,7 @@ public class CreateGuildEvent extends GuildBadgeEvent { Emulator.getGameEnvironment().getGuildManager().addGuild(guild); } } else { - String message = Emulator.getTexts().getValue("scripter.warning.guild.buy.owner").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", r.getName().replace("%owner%", r.getOwnerName())); + String message = Emulator.getTexts().getValue("scripter.warning.guild.buy.owner").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", r.getRoomInfo().getName().replace("%owner%", r.getRoomInfo().getOwnerInfo().getUsername())); ScripterManager.scripterDetected(this.client, message); log.info(message); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/DeactivateGuildEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/DeactivateGuildEvent.java index 8e36cedf..98e5f5ba 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/DeactivateGuildEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/DeactivateGuildEvent.java @@ -20,24 +20,24 @@ public class DeactivateGuildEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (guild != null) { - if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) //TODO Add staff permission override. + if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) //TODO Add staff permission override. { THashSet members = Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild.getId()); for (GuildMember member : members) { Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(member.getUserId()); if (habbo != null) - if (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getRoomUnit() != null) - habbo.getHabboInfo().getCurrentRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(habbo.getRoomUnit(), null).compose()); + if (habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit() != null) + habbo.getRoomUnit().getRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(habbo.getRoomUnit(), null).compose()); } Emulator.getGameEnvironment().getGuildManager().deleteGuild(guild); Emulator.getPluginManager().fireEvent(new GuildDeletedEvent(guild, this.client.getHabbo())); - Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()).sendComposer(new HabboGroupDeactivatedMessageComposer(guildId).compose()); + Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()).sendComposer(new HabboGroupDeactivatedMessageComposer(guildId).compose()); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - if (guild.getRoomId() == this.client.getHabbo().getHabboInfo().getCurrentRoom().getId()) { - this.client.sendResponse(new GetGuestRoomResultComposer(this.client.getHabbo().getHabboInfo().getCurrentRoom(), this.client.getHabbo(), false, false)); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + if (guild.getRoomId() == this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId()) { + this.client.sendResponse(new GetGuestRoomResultComposer(this.client.getHabbo().getRoomUnit().getRoom(), this.client.getHabbo(), false, false)); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/DeselectFavouriteHabboGroupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/DeselectFavouriteHabboGroupEvent.java index de87760d..81d23d15 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/DeselectFavouriteHabboGroupEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/DeselectFavouriteHabboGroupEvent.java @@ -21,8 +21,8 @@ public class DeselectFavouriteHabboGroupEvent extends MessageHandler { this.client.getHabbo().getHabboStats().setGuild(0); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null && guild != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(this.client.getHabbo().getRoomUnit(), null).compose()); + if (this.client.getHabbo().getRoomUnit().getRoom() != null && guild != null) { + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(this.client.getHabbo().getRoomUnit(), null).compose()); } this.client.sendResponse(new ExtendedProfileMessageComposer(this.client.getHabbo(), this.client)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildCreationInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildCreationInfoEvent.java index 94ca7636..0c605d43 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildCreationInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildCreationInfoEvent.java @@ -16,7 +16,7 @@ public class GetGuildCreationInfoEvent extends MessageHandler { THashSet roomList = new THashSet<>(); for (Room room : rooms) { - if (room.getGuildId() == 0) + if (room.getRoomInfo().getGuild().getId() == 0) roomList.add(room); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildFurniContextMenuInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildFurniContextMenuInfoEvent.java index 7eeb9b4f..923d93d2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildFurniContextMenuInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildFurniContextMenuInfoEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.guilds; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.guilds.GuildFurniContextMenuInfoMessageComposer; @@ -12,8 +12,8 @@ public class GetGuildFurniContextMenuInfoEvent extends MessageHandler { int itemId = this.packet.readInt(); int guildId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (item != null && guild != null) diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildMembersEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildMembersEvent.java index 1fdfe6f4..5f284bb7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildMembersEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetGuildMembersEvent.java @@ -19,7 +19,7 @@ public class GetGuildMembersEvent extends MessageHandler { Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(groupId); if (g != null) { - boolean isAdmin = this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN); + boolean isAdmin = this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN); if (!isAdmin && this.client.getHabbo().getHabboStats().hasGuild(g.getId())) { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(g, this.client.getHabbo()); isAdmin = member != null && (member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetMemberGuildItemCountEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetMemberGuildItemCountEvent.java index 472001bb..f906d76d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/GetMemberGuildItemCountEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/GetMemberGuildItemCountEvent.java @@ -19,8 +19,8 @@ public class GetMemberGuildItemCountEvent extends MessageHandler { if (guild == null) return; GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); - if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || (member != null && (member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN))) || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(guild.getRoomId()); + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || (member != null && (member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN))) || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); int count = 0; if (room != null) { count = room.getUserFurniCount(userId); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/JoinHabboGroupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/JoinHabboGroupEvent.java index a01526fe..7471e5ff 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/JoinHabboGroupEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/JoinHabboGroupEvent.java @@ -29,11 +29,11 @@ public class JoinHabboGroupEvent extends MessageHandler { Emulator.getGameEnvironment().getGuildManager().joinGuild(guild, this.client, 0, false); this.client.sendResponse(new HabboGroupDetailsMessageComposer(guild, this.client, false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()))); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null || room.getGuildId() != guildId) + if (room == null || room.getRoomInfo().getGuild().getId() != guildId) return; - room.refreshRightsForHabbo(this.client.getHabbo()); + room.getRoomRightsManager().refreshRightsForHabbo(this.client.getHabbo()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/KickMemberEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/KickMemberEvent.java index ff80c26d..6223a6bd 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/KickMemberEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/KickMemberEvent.java @@ -24,7 +24,7 @@ public class KickMemberEvent extends MessageHandler { if (guild != null) { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); - if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN) || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.OWNER) || member.getRank().equals(GuildRank.ADMIN) || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); GuildRemovedMemberEvent removedMemberEvent = new GuildRemovedMemberEvent(guild, userId, habbo); Emulator.getPluginManager().fireEvent(removedMemberEvent); @@ -38,7 +38,7 @@ public class KickMemberEvent extends MessageHandler { this.client.sendResponse(new GuildMembershipRejectedMessageComposer(guild, userId)); } - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(guild.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); if (habbo != null) { habbo.getHabboStats().removeGuild(guild.getId()); @@ -46,18 +46,18 @@ public class KickMemberEvent extends MessageHandler { habbo.getHabboStats().setGuild(0); if (room != null) { - if (habbo.getHabboInfo().getCurrentRoom() != null && habbo.getRoomUnit() != null) - habbo.getHabboInfo().getCurrentRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(habbo.getRoomUnit(), null).compose()); - if (habbo.getHabboInfo().getCurrentRoom() == room) - room.refreshRightsForHabbo(habbo); + if (habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit() != null) + habbo.getRoomUnit().getRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(habbo.getRoomUnit(), null).compose()); + if (habbo.getRoomUnit().getRoom() == room) + room.getRoomRightsManager().refreshRightsForHabbo(habbo); } habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, null)); } if (room != null) { - if (room.getGuildId() == guildId) { - room.ejectUserFurni(userId); + if (room.getRoomInfo().getGuild().getId() == guildId) { + room.getRoomItemManager().ejectUserFurni(userId); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/RejectMembershipRequestEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/RejectMembershipRequestEvent.java index b2eb9cb4..6fae2b7d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/RejectMembershipRequestEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/RejectMembershipRequestEvent.java @@ -23,7 +23,7 @@ public class RejectMembershipRequestEvent extends MessageHandler { if (guild != null) { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, this.client.getHabbo()); - if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.ADMIN)|| member.getRank().equals(GuildRank.OWNER) || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { + if (userId == this.client.getHabbo().getHabboInfo().getId() || guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.ADMIN)|| member.getRank().equals(GuildRank.OWNER) || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { guild.decreaseRequestCount(); Emulator.getGameEnvironment().getGuildManager().removeMember(guild, userId); this.client.sendResponse(new GuildMembersComposer(guild, Emulator.getGameEnvironment().getGuildManager().getGuildMembers(guild, 0, 0, ""), this.client.getHabbo(), 0, 0, "", true, Emulator.getGameEnvironment().getGuildManager().getGuildMembersCount(guild, 0, ""))); @@ -33,9 +33,9 @@ public class RejectMembershipRequestEvent extends MessageHandler { Emulator.getPluginManager().fireEvent(new GuildDeclinedMembershipEvent(guild, userId, habbo, this.client.getHabbo())); if (habbo != null) { - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); if (room != null) { - if (room.getGuildId() == guildId) { + if (room.getRoomInfo().getGuild().getId() == guildId) { habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, habbo.getClient(), false, null)); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/RemoveAdminRightsFromMemberEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/RemoveAdminRightsFromMemberEvent.java index 81a38874..8eb4c250 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/RemoveAdminRightsFromMemberEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/RemoveAdminRightsFromMemberEvent.java @@ -19,10 +19,10 @@ public class RemoveAdminRightsFromMemberEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (guild != null) { - if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { + if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { int userId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); GuildRemovedAdminEvent removedAdminEvent = new GuildRemovedAdminEvent(guild, userId, habbo); @@ -36,7 +36,8 @@ public class RemoveAdminRightsFromMemberEvent extends MessageHandler { if (habbo != null) { habbo.getClient().sendResponse(new HabboGroupDetailsMessageComposer(guild, this.client, false, Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild.getId(), userId))); - if (room != null && habbo.getHabboInfo().getCurrentRoom() != null && habbo.getHabboInfo().getCurrentRoom() == room) room.refreshRightsForHabbo(habbo); + if (room != null && habbo.getRoomUnit().getRoom() != null && habbo.getRoomUnit().getRoom() == room) + room.getRoomRightsManager().refreshRightsForHabbo(habbo); } GuildMember guildMember = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, userId); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/SelectFavouriteHabboGroupEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/SelectFavouriteHabboGroupEvent.java index 6834ebef..2e927171 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/SelectFavouriteHabboGroupEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/SelectFavouriteHabboGroupEvent.java @@ -24,10 +24,10 @@ public class SelectFavouriteHabboGroupEvent extends MessageHandler { this.client.getHabbo().getHabboStats().setGuild(guildId); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { if (guild != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new HabboAddGroupBadgesMessageComposer(guild).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(this.client.getHabbo().getRoomUnit(), guild).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new HabboAddGroupBadgesMessageComposer(guild).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new FavoriteMembershipUpdateMessageComposer(this.client.getHabbo().getRoomUnit(), guild).compose()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildBadgeEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildBadgeEvent.java index 434857b9..e1ddab4f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildBadgeEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildBadgeEvent.java @@ -13,10 +13,10 @@ public class UpdateGuildBadgeEvent extends GuildBadgeEvent { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (guild != null) { - if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); + if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); - if (room == null || room.getId() != guild.getRoomId()) + if (room == null || room.getRoomInfo().getId() != guild.getRoomId()) return; int count = this.packet.readInt(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildColorsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildColorsEvent.java index 37bc64e6..7df79c8b 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildColorsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildColorsEvent.java @@ -15,7 +15,7 @@ public class UpdateGuildColorsEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (guild != null) { - if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { + if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { GuildChangedColorsEvent colorsEvent = new GuildChangedColorsEvent(guild, this.packet.readInt(), this.packet.readInt()); Emulator.getPluginManager().fireEvent(colorsEvent); @@ -26,12 +26,14 @@ public class UpdateGuildColorsEvent extends MessageHandler { guild.setColorOne(colorsEvent.getColorOne()); guild.setColorTwo(colorsEvent.getColorTwo()); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); - if (room != null && room.getUserCount() > 0) { - room.refreshGuild(guild); + if (room != null) { + if (room.getRoomUnitManager().getRoomHabbosCount() > 0) { + room.refreshGuild(guild); - room.refreshGuildColors(guild); + room.refreshGuildColors(guild); + } } guild.needsUpdate = true; Emulator.getThreading().run(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 3e89e0e1..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 @@ -15,7 +15,7 @@ public class UpdateGuildIdentityEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (guild != null) { - if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { + if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { GuildChangedNameEvent nameEvent = new GuildChangedNameEvent(guild, this.packet.readString(), this.packet.readString()); Emulator.getPluginManager().fireEvent(nameEvent); @@ -33,10 +33,12 @@ public class UpdateGuildIdentityEvent extends MessageHandler { guild.needsUpdate = true; guild.run(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); - if (room != null && !room.getCurrentHabbos().isEmpty()) { - room.refreshGuild(guild); + if (room != null) { + if (!room.getRoomUnitManager().getCurrentHabbos().values().isEmpty()) { + room.refreshGuild(guild); + } } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildSettingsEvent.java index 5edff097..ffa95de7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildSettingsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/UpdateGuildSettingsEvent.java @@ -16,7 +16,7 @@ public class UpdateGuildSettingsEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); if (guild != null) { - if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN)) { + if (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN)) { GuildChangedSettingsEvent settingsEvent = new GuildChangedSettingsEvent(guild, this.packet.readInt(), this.packet.readInt() == 0); Emulator.getPluginManager().fireEvent(settingsEvent); @@ -26,7 +26,7 @@ public class UpdateGuildSettingsEvent extends MessageHandler { guild.setState(GuildState.valueOf(settingsEvent.getState())); guild.setRights(settingsEvent.isRights()); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(guild.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(guild.getRoomId()); if(room != null) { room.refreshGuild(guild); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GetMessagesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GetMessagesEvent.java index 81b7c012..e6c6f8fd 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GetMessagesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/GetMessagesEvent.java @@ -27,7 +27,7 @@ public class GetMessagesEvent extends MessageHandler { Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(guildId); ForumThread thread = ForumThread.getById(threadId); - boolean hasStaffPermissions = this.client.getHabbo().hasRight(Permission.ACC_MODTOOL_TICKET_Q); + boolean hasStaffPermissions = this.client.getHabbo().hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q); if (guild == null || thread == null) { this.client.sendResponse(new ErrorReportComposer(404)); return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateMessageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateMessageEvent.java index 5a23932d..66d8074a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateMessageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateMessageEvent.java @@ -37,7 +37,7 @@ public class ModerateMessageEvent extends MessageHandler { return; } - boolean hasStaffPermissions = this.client.getHabbo().hasRight(Permission.ACC_MODTOOL_TICKET_Q); + boolean hasStaffPermissions = this.client.getHabbo().hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q); GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); if (member == null) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateThreadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateThreadEvent.java index fa36ff78..a53e4c5f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateThreadEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/ModerateThreadEvent.java @@ -33,7 +33,7 @@ public class ModerateThreadEvent extends MessageHandler { } GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); - boolean hasStaffPerms = this.client.getHabbo().hasRight(Permission.ACC_MODTOOL_TICKET_Q); // check for if they have staff perm + boolean hasStaffPerms = this.client.getHabbo().hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q); // check for if they have staff perm boolean isGuildAdmin = (guild.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || member.getRank().equals(GuildRank.ADMIN)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/PostMessageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/PostMessageEvent.java index 90723b3d..915dcd38 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/PostMessageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/PostMessageEvent.java @@ -39,7 +39,7 @@ public class PostMessageEvent extends MessageHandler { return; } - boolean isStaff = this.client.getHabbo().hasRight(Permission.ACC_MODTOOL_TICKET_Q); + boolean isStaff = this.client.getHabbo().hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q); GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/UpdateThreadEvent.java b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/UpdateThreadEvent.java index 9f3b433b..10f5d877 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/UpdateThreadEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/guilds/forums/UpdateThreadEvent.java @@ -30,7 +30,7 @@ public class UpdateThreadEvent extends MessageHandler { return; } - boolean isStaff = this.client.getHabbo().hasRight(Permission.ACC_MODTOOL_TICKET_Q); + boolean isStaff = this.client.getHabbo().hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q); GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guildId, this.client.getHabbo().getHabboInfo().getId()); if (member == null) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SSOTicketEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SSOTicketEvent.java index 7b4ddfdb..1b5694c9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SSOTicketEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SSOTicketEvent.java @@ -217,7 +217,7 @@ public class SSOTicketEvent extends MessageHandler { messages.add(new ScrSendUserInfoComposer(this.client.getHabbo(), SubscriptionHabboClub.HABBO_CLUB, ScrSendUserInfoComposer.RESPONSE_TYPE_LOGIN).compose()); - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { messages.add(new ModeratorInitMessageComposer(this.client.getHabbo()).compose()); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/hotelview/QuitEvent.java b/src/main/java/com/eu/habbo/messages/incoming/hotelview/QuitEvent.java index 7c59c7b2..6a90397e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/hotelview/QuitEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/hotelview/QuitEvent.java @@ -2,20 +2,23 @@ package com.eu.habbo.messages.incoming.hotelview; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.hotelview.CloseConnectionMessageComposer; public class QuitEvent extends MessageHandler { @Override public void handle() { - this.client.getHabbo().getHabboInfo().setLoadingRoom(0); + RoomHabbo roomHabbo = this.client.getHabbo().getRoomUnit(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - Emulator.getGameEnvironment().getRoomManager().leaveRoom(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getCurrentRoom()); + roomHabbo.setLoadingRoom(null); + + if (roomHabbo.getRoom() != null) { + Emulator.getGameEnvironment().getRoomManager().leaveRoom(this.client.getHabbo(), roomHabbo.getRoom()); } if (this.client.getHabbo().getHabboInfo().getRoomQueueId() != 0) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.client.getHabbo().getHabboInfo().getRoomQueueId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.client.getHabbo().getHabboInfo().getRoomQueueId()); if (room != null) { room.removeFromQueue(this.client.getHabbo()); @@ -25,9 +28,6 @@ public class QuitEvent extends MessageHandler { this.client.sendResponse(new CloseConnectionMessageComposer()); } - if (this.client.getHabbo().getRoomUnit() != null) { - this.client.getHabbo().getRoomUnit().clearWalking(); - this.client.getHabbo().getRoomUnit().setInRoom(false); - } + roomHabbo.clear(); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestFurniInventoryWhenNotInRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestFurniInventoryWhenNotInRoomEvent.java index e4db03f4..977c1c80 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestFurniInventoryWhenNotInRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/inventory/RequestFurniInventoryWhenNotInRoomEvent.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.incoming.inventory; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.inventory.FurniListComposer; import gnu.trove.iterator.TIntObjectIterator; @@ -29,9 +29,9 @@ public class RequestFurniInventoryWhenNotInRoomEvent extends MessageHandler { } synchronized (this.client.getHabbo().getInventory().getItemsComponent().getItems()) { - TIntObjectMap items = new TIntObjectHashMap<>(); + TIntObjectMap items = new TIntObjectHashMap<>(); - TIntObjectIterator iterator = this.client.getHabbo().getInventory().getItemsComponent().getItems().iterator(); + TIntObjectIterator iterator = this.client.getHabbo().getInventory().getItemsComponent().getItems().iterator(); int count = 0; int fragmentNumber = 0; diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpEvent.java index 35393c6f..4cd0f8f2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpEvent.java @@ -27,7 +27,7 @@ public class CallForHelpEvent extends MessageHandler { int roomId = this.packet.readInt(); int messageCount = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); List issues = Emulator.getGameEnvironment().getModToolManager().openTicketsForHabbo(this.client.getHabbo()); if (!issues.isEmpty()) { //this.client.sendResponse(new GenericAlertComposer("You've got still a pending ticket. Wait till the moderators are done reviewing your ticket.")); @@ -87,7 +87,7 @@ public class CallForHelpEvent extends MessageHandler { } } } else { - ModToolIssue issue = new ModToolIssue(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getHabboInfo().getUsername(), room != null ? room.getOwnerId() : 0, room != null ? room.getOwnerName() : "", roomId, message, ModToolTicketType.ROOM); + ModToolIssue issue = new ModToolIssue(this.client.getHabbo().getHabboInfo().getId(), this.client.getHabbo().getHabboInfo().getUsername(), room != null ? room.getRoomInfo().getOwnerInfo().getId() : 0, room != null ? room.getRoomInfo().getOwnerInfo().getUsername() : "", roomId, message, ModToolTicketType.ROOM); issue.category = topic; new InsertModToolIssue(issue).run(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromIMEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromIMEvent.java index 895d49f8..533299ff 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromIMEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromIMEvent.java @@ -6,7 +6,6 @@ import com.eu.habbo.habbohotel.modtool.ModToolIssue; import com.eu.habbo.habbohotel.modtool.ModToolTicketType; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.CallForHelpDisabledNotifyMessageComposer; import com.eu.habbo.threading.runnables.InsertModToolIssue; @@ -32,7 +31,7 @@ public class CallForHelpFromIMEvent extends MessageHandler { if (target != null) { info = target.getHabboInfo(); } else { - info = HabboManager.getOfflineHabboInfo(userId); + info = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(userId); } if (info == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromPhotoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromPhotoEvent.java index f6bef706..c0bf448c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromPhotoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/CallForHelpFromPhotoEvent.java @@ -6,8 +6,8 @@ import com.eu.habbo.habbohotel.modtool.CfhTopic; import com.eu.habbo.habbohotel.modtool.ModToolIssue; import com.eu.habbo.habbohotel.modtool.ModToolTicketType; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.CallForHelpResultMessageComposer; import com.eu.habbo.threading.runnables.InsertModToolIssue; @@ -32,15 +32,15 @@ public class CallForHelpFromPhotoEvent extends MessageHandler { if (topic == null) return; - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (!(item instanceof InteractionExternalImage)) return; - HabboInfo photoOwner = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(item.getUserId()); + HabboInfo photoOwner = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(item.getOwnerInfo().getId()); if (photoOwner == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ChatReviewSessionCreateEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ChatReviewSessionCreateEvent.java index a4aaf565..66e9d0fb 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ChatReviewSessionCreateEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ChatReviewSessionCreateEvent.java @@ -26,10 +26,10 @@ public class ChatReviewSessionCreateEvent extends MessageHandler { return; } - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { - Habbo habbo = room.getHabbo(userId); + Habbo habbo = room.getRoomUnitManager().getRoomHabboById(userId); if (habbo != null) { GuardianTicket ticket = Emulator.getGameEnvironment().getGuideManager().getOpenReportedHabboTicket(habbo); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssueDefaultActionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssueDefaultActionEvent.java index 50458749..8801cc1d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssueDefaultActionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssueDefaultActionEvent.java @@ -9,7 +9,7 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class CloseIssueDefaultActionEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int issueId = this.packet.readInt(); int unknown = this.packet.readInt(); int category = this.packet.readInt(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssuesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssuesEvent.java index 48b78115..e31d03b1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssuesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/CloseIssuesEvent.java @@ -10,7 +10,7 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class CloseIssuesEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int state = this.packet.readInt(); int something = this.packet.readInt(); int ticketId = this.packet.readInt(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetCfhChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetCfhChatlogEvent.java index d8bfa94f..e7c525b3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetCfhChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetCfhChatlogEvent.java @@ -15,7 +15,7 @@ import java.util.stream.Collectors; public class GetCfhChatlogEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { ModToolIssue issue = Emulator.getGameEnvironment().getModToolManager().getTicket(this.packet.readInt()); if (issue != null) { @@ -61,11 +61,11 @@ public class GetCfhChatlogEvent extends MessageHandler { } } - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(issue.roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(issue.roomId); String roomName = ""; if (room != null) { - roomName = room.getName(); + roomName = room.getRoomInfo().getName(); } this.client.sendResponse(new CfhChatlogComposer(issue, chatlog, roomName, chatlogType)); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorRoomInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorRoomInfoEvent.java index 06b9e539..1ab7715a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorRoomInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorRoomInfoEvent.java @@ -10,10 +10,10 @@ import com.eu.habbo.messages.outgoing.modtool.ModeratorRoomInfoComposer; public class GetModeratorRoomInfoEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { this.client.sendResponse(new ModeratorRoomInfoComposer(room)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorUserInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorUserInfoEvent.java index 5b234a01..f0f0f3ef 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorUserInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetModeratorUserInfoEvent.java @@ -9,7 +9,7 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class GetModeratorUserInfoEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { ModToolManager.requestUserInfo(this.client, this.packet); } else { ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.userinfo").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomChatlogEvent.java index 827fcd57..739a07c6 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomChatlogEvent.java @@ -10,12 +10,12 @@ import com.eu.habbo.messages.outgoing.modtool.RoomChatlogComposer; public class GetRoomChatlogEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.packet.readInt()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.packet.readInt()); if (room != null) - this.client.sendResponse(new RoomChatlogComposer(room, Emulator.getGameEnvironment().getModToolManager().getRoomChatlog(room.getId()))); + this.client.sendResponse(new RoomChatlogComposer(room, Emulator.getGameEnvironment().getModToolManager().getRoomChatlog(room.getRoomInfo().getId()))); } else { ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.chatlog").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomVisitsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomVisitsEvent.java index 449df7c5..03dd2445 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomVisitsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetRoomVisitsEvent.java @@ -9,7 +9,7 @@ import com.eu.habbo.messages.outgoing.modtool.RoomVisitsComposer; public class GetRoomVisitsEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int userId = this.packet.readInt(); HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(userId); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetUserChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetUserChatlogEvent.java index 355ae337..dd684925 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/GetUserChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/GetUserChatlogEvent.java @@ -3,16 +3,15 @@ package com.eu.habbo.messages.incoming.modtool; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.modtool.UserChatlogComposer; public class GetUserChatlogEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int userId = this.packet.readInt(); - String username = HabboManager.getOfflineHabboInfo(userId).getUsername(); + String username = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(userId).getUsername(); this.client.sendResponse(new UserChatlogComposer(Emulator.getGameEnvironment().getModToolManager().getUserRoomVisitsAndChatlogs(userId), userId, username)); } else { diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModAlertEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModAlertEvent.java index 99df9398..65b030b4 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModAlertEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModAlertEvent.java @@ -18,7 +18,7 @@ public class ModAlertEvent extends MessageHandler { String message = this.packet.readString(); int cfhTopic = this.packet.readInt(); - if (!this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) return; + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) return; Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo == null) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModBanEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModBanEvent.java index 8e3ec701..fe872516 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModBanEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModBanEvent.java @@ -52,7 +52,7 @@ public class ModBanEvent extends MessageHandler { case BAN_AVATAR_ONLY_100_YEARS: duration = Emulator.getIntUnixTimestamp(); } - if (!this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { ScripterManager.scripterDetected(this.client, Emulator.getTexts().getValue("scripter.warning.modtools.ban").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername())); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMessageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMessageEvent.java index 6b041f63..73c795d1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMessageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMessageEvent.java @@ -10,7 +10,7 @@ import com.eu.habbo.plugin.events.support.SupportUserAlertedReason; public class ModMessageEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { Habbo alertedUser = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.packet.readInt()); if (alertedUser != null) diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMuteEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMuteEvent.java index 4bca6e02..f83917c4 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMuteEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModMuteEvent.java @@ -20,7 +20,7 @@ public class ModMuteEvent extends MessageHandler { String message = this.packet.readString(); int cfhTopic = this.packet.readInt(); - if (!this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) return; + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) return; Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo == null) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java index 6bfdaa56..d98d76ea 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolRequestRoomUserChatlogEvent.java @@ -11,16 +11,16 @@ import com.eu.habbo.messages.outgoing.modtool.RoomChatlogComposer; public class ModToolRequestRoomUserChatlogEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int userId = this.packet.readInt(); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo != null) { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - this.client.sendResponse(new RoomChatlogComposer(room, Emulator.getGameEnvironment().getModToolManager().getRoomChatlog(room.getId()))); + this.client.sendResponse(new RoomChatlogComposer(room, Emulator.getGameEnvironment().getModToolManager().getRoomChatlog(room.getRoomInfo().getId()))); } } } else { diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionEvent.java index a9c62836..df40a20c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolSanctionEvent.java @@ -9,7 +9,7 @@ import com.eu.habbo.threading.runnables.UpdateModToolIssue; public class ModToolSanctionEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int ticketId = this.packet.readInt(); int unknownInt = this.packet.readInt(); int categoryId = this.packet.readInt(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java index ee1e38aa..6d0e3224 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModToolWarnEvent.java @@ -10,7 +10,7 @@ import com.eu.habbo.plugin.events.support.SupportUserAlertedReason; public class ModToolWarnEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { Habbo alertedUser = Emulator.getGameEnvironment().getHabboManager().getHabbo(this.packet.readInt()); if (alertedUser != null) diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModTradingLockEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModTradingLockEvent.java index 2a0fbf6f..0f0f649a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModTradingLockEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModTradingLockEvent.java @@ -19,7 +19,7 @@ public class ModTradingLockEvent extends MessageHandler { int duration = this.packet.readInt(); int cfhTopic = this.packet.readInt(); - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(userId); if (habbo != null) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModerateRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModerateRoomEvent.java index 7d08216d..8ee92553 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModerateRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModerateRoomEvent.java @@ -9,8 +9,8 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class ModerateRoomEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.packet.readInt()); + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.packet.readInt()); if (room != null) { final boolean lockDoor = this.packet.readInt() == 1; diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModeratorActionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModeratorActionEvent.java index a9c7171e..7437889d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ModeratorActionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ModeratorActionEvent.java @@ -9,10 +9,10 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class ModeratorActionEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int type = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { room.alert(this.packet.readString()); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/PickIssuesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/PickIssuesEvent.java index df10877e..832298f1 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/PickIssuesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/PickIssuesEvent.java @@ -13,7 +13,7 @@ public class PickIssuesEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { this.packet.readInt(); ModToolIssue issue = Emulator.getGameEnvironment().getModToolManager().getTicket(this.packet.readInt()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/modtool/ReleaseIssuesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReleaseIssuesEvent.java index 2a832cfc..a6554ea5 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/modtool/ReleaseIssuesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/modtool/ReleaseIssuesEvent.java @@ -10,7 +10,7 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class ReleaseIssuesEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_SUPPORTTOOL)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_SUPPORTTOOL)) { int count = this.packet.readInt(); while (count != 0) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/CreateFlatEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/CreateFlatEvent.java index b8eb6de7..94596eda 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/CreateFlatEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/CreateFlatEvent.java @@ -45,11 +45,11 @@ public class CreateFlatEvent extends MessageHandler { if (description.length() > 128 || !Emulator.getGameEnvironment().getWordFilter().filter(description, this.client.getHabbo()).equals(description)) return; - int count = Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(this.client.getHabbo()).size(); - int max = this.client.getHabbo().getHabboStats().hasActiveClub() ? RoomManager.MAXIMUM_ROOMS_HC : RoomManager.MAXIMUM_ROOMS_USER; + int totalRoomsCount = Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(this.client.getHabbo()).size(); + int maxRoomsCount = this.client.getHabbo().getHabboStats().hasActiveClub() ? RoomManager.MAXIMUM_ROOMS_HC : RoomManager.MAXIMUM_ROOMS_USER; - if (count >= max) { - this.client.sendResponse(new CanCreateRoomComposer(count, max)); + if (totalRoomsCount >= maxRoomsCount) { + this.client.sendResponse(new CanCreateRoomComposer(totalRoomsCount, maxRoomsCount)); return; } 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 7ec78be7..25cf6167 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 @@ -2,7 +2,6 @@ package com.eu.habbo.messages.incoming.navigator; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.RideablePet; @@ -27,94 +26,84 @@ public class DeleteRoomEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); - if (room != null) { - if (room.isOwner(this.client.getHabbo())) { - if (room.getId() == this.client.getHabbo().getHabboInfo().getHomeRoom()) { - return; + if(room == null) { + return; + } + + if(!room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { + String message = Emulator.getTexts().getValue("scripter.warning.room.delete").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", room.getRoomInfo().getName()).replace("%roomowner%", room.getRoomInfo().getOwnerInfo().getUsername()); + ScripterManager.scripterDetected(this.client, message); + log.info(message); + return; + } + + if (room.getRoomInfo().getId() == this.client.getHabbo().getHabboInfo().getHomeRoom()) { + return; + } + + if (Emulator.getPluginManager().fireEvent(new NavigatorRoomDeletedEvent(this.client.getHabbo(), room)).isCancelled()) { + return; + } + + room.getRoomItemManager().ejectAllFurni(); + room.getRoomItemManager().ejectUserFurni(room.getRoomInfo().getOwnerInfo().getId()); + + 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().getCurrentPets().values()); + for (Pet pet : pets) { + if (pet instanceof RideablePet rideablePet) { + if (rideablePet.getRider() != null) { + rideablePet.getRider().getRoomUnit().dismountPet(true); } - - if (Emulator.getPluginManager().fireEvent(new NavigatorRoomDeletedEvent(this.client.getHabbo(), room)).isCancelled()) { - return; - } - - room.ejectAll(); - room.ejectUserFurni(room.getOwnerId()); - - List bots = new ArrayList<>(room.getCurrentBots().valueCollection()); - for (Bot bot : bots) { - Emulator.getGameEnvironment().getBotManager().pickUpBot(bot, null); - } - - List pets = new ArrayList<>(room.getCurrentPets().valueCollection()); - for (Pet pet : pets) { - if (pet instanceof RideablePet rideablePet) { - if (rideablePet.getRider() != null) { - rideablePet.getRider().getHabboInfo().dismountPet(true); - } - } - - pet.removeFromRoom(); - Emulator.getThreading().run(pet); - - Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); - - if (owner != null) { - owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); - owner.getInventory().getPetsComponent().addPet(pet); - } - } - - if (room.getGuildId() > 0) { - Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(room.getGuildId()); - - if (guild != null) { - Emulator.getGameEnvironment().getGuildManager().deleteGuild(guild); - } - } - - room.preventUnloading = false; - room.dispose(); - Emulator.getGameEnvironment().getRoomManager().uncacheRoom(room); - - try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { - try (PreparedStatement statement = connection.prepareStatement("DELETE FROM rooms WHERE id = ? LIMIT 1")) { - statement.setInt(1, roomId); - statement.execute(); - } - - if (room.hasCustomLayout()) { - try (PreparedStatement stmt = connection.prepareStatement("DELETE FROM room_models_custom WHERE id = ? LIMIT 1")) { - stmt.setInt(1, roomId); - stmt.execute(); - } - } - - Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); - - try (PreparedStatement rights = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ?")) { - rights.setInt(1, roomId); - rights.execute(); - } - - try (PreparedStatement votes = connection.prepareStatement("DELETE FROM room_votes WHERE room_id = ?")) { - votes.setInt(1, roomId); - votes.execute(); - } - - try (PreparedStatement filter = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ?")) { - filter.setInt(1, roomId); - filter.execute(); - } - } catch (SQLException e) { - log.error("Caught SQL exception", e); - } - } else { - String message = Emulator.getTexts().getValue("scripter.warning.room.delete").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", room.getName()).replace("%roomowner%", room.getOwnerName()); - ScripterManager.scripterDetected(this.client, message); - log.info(message); } + + pet.removeFromRoom(); + Emulator.getThreading().run(pet); + + Habbo owner = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); + + if (owner != null) { + owner.getClient().sendResponse(new PetAddedToInventoryComposer(pet)); + owner.getInventory().getPetsComponent().addPet(pet); + } + } + + if (room.getRoomInfo().hasGuild()) { + Emulator.getGameEnvironment().getGuildManager().deleteGuild(room.getRoomInfo().getGuild()); + } + + room.preventUnloading = false; + + room.getRoomRightsManager().removeAllRights(); + room.getRoomWordFilterManager().removeAllWords(); + room.dispose(); + Emulator.getGameEnvironment().getRoomManager().uncacheRoom(room); + + try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { + try (PreparedStatement statement = connection.prepareStatement("DELETE FROM rooms WHERE id = ? LIMIT 1")) { + statement.setInt(1, roomId); + statement.execute(); + } + + if (room.getRoomInfo().isModelOverridden()) { + try (PreparedStatement stmt = connection.prepareStatement("DELETE FROM room_models_custom WHERE id = ? LIMIT 1")) { + stmt.setInt(1, roomId); + stmt.execute(); + } + } + + try (PreparedStatement votes = connection.prepareStatement("DELETE FROM room_votes WHERE room_id = ?")) { + votes.setInt(1, roomId); + votes.execute(); + } + } catch (SQLException e) { + log.error("Caught SQL exception", e); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/ForwardToSomeRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/ForwardToSomeRoomEvent.java index abb96fdb..e7411786 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/ForwardToSomeRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/ForwardToSomeRoomEvent.java @@ -6,7 +6,6 @@ import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.RoomForwardMessageComposer; import com.eu.habbo.messages.outgoing.users.NavigatorSettingsComposer; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -19,7 +18,7 @@ public class ForwardToSomeRoomEvent extends MessageHandler { List rooms = Emulator.getGameEnvironment().getRoomManager().getActiveRooms(); if (!rooms.isEmpty()) { Collections.shuffle(rooms); - this.client.sendResponse(new RoomForwardMessageComposer(rooms.get(0).getId())); + this.client.sendResponse(new RoomForwardMessageComposer(rooms.get(0).getRoomInfo().getId())); } } else if (data.equalsIgnoreCase("predefined_noob_lobby")) { this.client.sendResponse(new RoomForwardMessageComposer(Emulator.getConfig().getInt("hotel.room.nooblobby"))); diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/NewNavigatorSearchEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/NewNavigatorSearchEvent.java index e58b2b30..dc5b6117 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/NewNavigatorSearchEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/NewNavigatorSearchEvent.java @@ -124,11 +124,11 @@ public class NewNavigatorSearchEvent extends MessageHandler { for (SearchResultList li : resultLists) { for (Room room : li.getRooms()) { - searchRooms.put(room.getId(), room); + searchRooms.put(room.getRoomInfo().getId(), room); } } - SearchResultList list = new SearchResultList(0, "query", "", SearchAction.NONE, ListMode.LIST, DisplayMode.VISIBLE, new ArrayList<>(searchRooms.values()), true, this.client.getHabbo().hasRight(Permission.ACC_ENTERANYROOM) || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER), DisplayOrder.ACTIVITY, -1); + SearchResultList list = new SearchResultList(0, "query", "", SearchAction.NONE, ListMode.LIST, DisplayMode.VISIBLE, new ArrayList<>(searchRooms.values()), true, this.client.getHabbo().hasPermissionRight(Permission.ACC_ENTERANYROOM) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER), DisplayOrder.ACTIVITY, -1); nList.add(list); return nList; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/navigator/PopularRoomsSearchEvent.java b/src/main/java/com/eu/habbo/messages/incoming/navigator/PopularRoomsSearchEvent.java index f6734d32..1330cd06 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/navigator/PopularRoomsSearchEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/navigator/PopularRoomsSearchEvent.java @@ -7,6 +7,6 @@ import com.eu.habbo.messages.outgoing.navigator.GuestRoomSearchResultComposer; public class PopularRoomsSearchEvent extends MessageHandler { @Override public void handle() { - this.client.sendResponse(new GuestRoomSearchResultComposer(Emulator.getGameEnvironment().getRoomManager().getActiveRooms(-1))); + this.client.sendResponse(new GuestRoomSearchResultComposer(Emulator.getGameEnvironment().getRoomManager().getActiveRoomsByCategoryId(-1))); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/polls/AnswerPollEvent.java b/src/main/java/com/eu/habbo/messages/incoming/polls/AnswerPollEvent.java index 33ef0cff..b2e2770c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/polls/AnswerPollEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/polls/AnswerPollEvent.java @@ -29,7 +29,7 @@ public class AnswerPollEvent extends MessageHandler { if(answer.length() <= 0) return; if (pollId == 0 && questionId <= 0) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().handleWordQuiz(this.client.getHabbo(), answer.toString()); + this.client.getHabbo().getRoomUnit().getRoom().handleWordQuiz(this.client.getHabbo(), answer.toString()); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/AddFavouriteRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/AddFavouriteRoomEvent.java index 726cb9cd..d0513d23 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/AddFavouriteRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/AddFavouriteRoomEvent.java @@ -10,7 +10,7 @@ public class AddFavouriteRoomEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); boolean added = true; if (room != null) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/DeleteFavouriteRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/DeleteFavouriteRoomEvent.java index ae943e23..47a2e66f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/DeleteFavouriteRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/DeleteFavouriteRoomEvent.java @@ -10,7 +10,7 @@ public class DeleteFavouriteRoomEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { if (this.client.getHabbo().getHabboStats().hasFavoriteRoom(roomId)) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetBannedUsersFromRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetBannedUsersFromRoomEvent.java index 4918cf88..80852fbc 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetBannedUsersFromRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetBannedUsersFromRoomEvent.java @@ -11,7 +11,7 @@ public class GetBannedUsersFromRoomEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { this.client.sendResponse(new BannedUsersFromRoomComposer(room)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetCustomRoomFilterEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetCustomRoomFilterEvent.java index b1339c5e..29c75138 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetCustomRoomFilterEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetCustomRoomFilterEvent.java @@ -9,9 +9,9 @@ import com.eu.habbo.messages.outgoing.rooms.RoomFilterSettingsMessageComposer; public class GetCustomRoomFilterEvent extends MessageHandler { @Override public void handle() { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.packet.readInt()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.packet.readInt()); - if (room != null && room.hasRights(this.client.getHabbo())) { + if (room != null && room.getRoomRightsManager().hasRights(this.client.getHabbo())) { this.client.sendResponse(new RoomFilterSettingsMessageComposer(room)); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("SelfModRoomFilterSeen")); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetFlatControllersEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetFlatControllersEvent.java index 6054e8f9..d02b8377 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetFlatControllersEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetFlatControllersEvent.java @@ -8,12 +8,12 @@ import com.eu.habbo.messages.outgoing.rooms.FlatControllersComposer; public class GetFlatControllersEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { this.client.sendResponse(new FlatControllersComposer(room)); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetGuestRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetGuestRoomEvent.java index ffaddec2..69f26dbb 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetGuestRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetGuestRoomEvent.java @@ -8,14 +8,15 @@ import com.eu.habbo.messages.outgoing.rooms.GetGuestRoomResultComposer; public class GetGuestRoomEvent extends MessageHandler { @Override public void handle() { - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(this.packet.readInt()); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.packet.readInt()); int something = this.packet.readInt(); int something2 = this.packet.readInt(); + if (room != null) { boolean unknown = something != 0 || something2 != 1; - //this.client.getHabbo().getHabboInfo().getCurrentRoom() != room + //this.client.getHabbo().getRoomUnit().getRoom() != room this.client.sendResponse(new GetGuestRoomResultComposer(room, this.client.getHabbo(), true, unknown)); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomEntryDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomEntryDataEvent.java index bab4015c..4a4cfd2a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomEntryDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomEntryDataEvent.java @@ -9,8 +9,8 @@ import com.eu.habbo.messages.outgoing.rooms.HeightMapComposer; public class GetRoomEntryDataEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getLoadingRoom() > 0) { - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(this.client.getHabbo().getHabboInfo().getLoadingRoom()); + if (this.client.getHabbo().getRoomUnit().isLoadingRoom()) { + Room room = this.client.getHabbo().getRoomUnit().getLoadingRoom(); if (room != null && room.getLayout() != null) { this.client.sendResponse(new HeightMapComposer(room)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomSettingsEvent.java index b9c450f4..418ded5e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomSettingsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/GetRoomSettingsEvent.java @@ -10,7 +10,7 @@ public class GetRoomSettingsEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) this.client.sendResponse(new RoomSettingsDataComposer(room)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/LetUserInEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/LetUserInEvent.java index 74a5f0e7..2804975f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/LetUserInEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/LetUserInEvent.java @@ -10,23 +10,25 @@ import com.eu.habbo.messages.outgoing.rooms.FlatAccessibleMessageComposer; public class LetUserInEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null && this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) { + if (this.client.getHabbo().getRoomUnit().getRoom() != null && this.client.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(this.client.getHabbo())) { String username = this.packet.readString(); boolean accepted = this.packet.readBoolean(); Habbo habbo = Emulator.getGameServer().getGameClientManager().getHabbo(username); - if (habbo != null && habbo.getHabboInfo().getRoomQueueId() == this.client.getHabbo().getHabboInfo().getCurrentRoom().getId()) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().removeFromQueue(habbo); + if (habbo != null) { + if (habbo.getHabboInfo().getRoomQueueId() == this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId()) { + this.client.getHabbo().getRoomUnit().getRoom().removeFromQueue(habbo); - if (accepted) { - habbo.getClient().sendResponse(new FlatAccessibleMessageComposer("")); - Emulator.getGameEnvironment().getRoomManager().enterRoom(habbo, this.client.getHabbo().getHabboInfo().getCurrentRoom().getId(), "", true); - } else { - habbo.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); - habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); + if (accepted) { + habbo.getClient().sendResponse(new FlatAccessibleMessageComposer("")); + Emulator.getGameEnvironment().getRoomManager().enterRoom(habbo, this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId(), "", true); + } else { + habbo.getClient().sendResponse(new FlatAccessDeniedMessageComposer("")); + habbo.getClient().sendResponse(new CloseConnectionMessageComposer()); + } + habbo.getHabboInfo().setRoomQueueId(0); } - habbo.getHabboInfo().setRoomQueueId(0); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/MuteAllInRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/MuteAllInRoomEvent.java index 8711ef77..35576d89 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/MuteAllInRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/MuteAllInRoomEvent.java @@ -7,10 +7,10 @@ import com.eu.habbo.messages.outgoing.rooms.MuteAllInRoomComposer; public class MuteAllInRoomEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - if (room.isOwner(this.client.getHabbo())) { + if (room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { room.setMuted(!room.isMuted()); this.client.sendResponse(new MuteAllInRoomComposer(room)); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/OpenFlatConnectionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/OpenFlatConnectionEvent.java index 5787a41d..c669084b 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/OpenFlatConnectionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/OpenFlatConnectionEvent.java @@ -3,30 +3,33 @@ package com.eu.habbo.messages.incoming.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class OpenFlatConnectionEvent extends MessageHandler { + /** + * When user clicks to enter a room + */ @Override public void handle() { int roomId = this.packet.readInt(); String password = this.packet.readString(); - if (this.client.getHabbo().getHabboInfo().getLoadingRoom() == 0 && this.client.getHabbo().getHabboStats().roomEnterTimestamp + 1000 < System.currentTimeMillis()) { + if (!this.client.getHabbo().getRoomUnit().isLoadingRoom() && this.client.getHabbo().getHabboStats().roomEnterTimestamp + 1000 < System.currentTimeMillis()) { + Room previousRoom = this.client.getHabbo().getRoomUnit().getRoom(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - if (room != null) { + if (previousRoom != null) { Emulator.getGameEnvironment().getRoomManager().logExit(this.client.getHabbo()); - - room.removeHabbo(this.client.getHabbo(), true); - - this.client.getHabbo().getHabboInfo().setCurrentRoom(null); + previousRoom.getRoomUnitManager().removeHabbo(this.client.getHabbo(), true); + this.client.getHabbo().getRoomUnit().setPreviousRoom(previousRoom); } - if (this.client.getHabbo().getRoomUnit() != null && this.client.getHabbo().getRoomUnit().isTeleporting()) { + if (this.client.getHabbo().getRoomUnit().isTeleporting()) { this.client.getHabbo().getRoomUnit().setTeleporting(false); } - Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password); + Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password, false); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RateFlatEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RateFlatEvent.java index 683e5a18..45ce93a0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RateFlatEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RateFlatEvent.java @@ -6,6 +6,6 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class RateFlatEvent extends MessageHandler { @Override public void handle() { - Emulator.getGameEnvironment().getRoomManager().voteForRoom(this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getCurrentRoom()); + Emulator.getGameEnvironment().getRoomManager().voteForRoom(this.client.getHabbo(), this.client.getHabbo().getRoomUnit().getRoom()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveAllRightsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveAllRightsEvent.java index 1a96ec8b..a2b43d4d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveAllRightsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveAllRightsEvent.java @@ -12,25 +12,23 @@ import com.eu.habbo.messages.outgoing.rooms.users.NoSuchFlatComposer; public class RemoveAllRightsEvent extends MessageHandler { @Override public void handle() { - final Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + final Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null || room.getId() != this.packet.readInt()) + if (room == null || room.getRoomInfo().getId() != this.packet.readInt()) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { - room.getRights().forEach(value -> { - Habbo habbo = room.getHabbo(value); + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + room.getRoomRightsManager().getRights().forEach(value -> { + Habbo habbo = room.getRoomUnitManager().getRoomHabboById(value); if (habbo != null) { room.sendComposer(new NoSuchFlatComposer(room, value).compose()); habbo.getRoomUnit().removeStatus(RoomUnitStatus.FLAT_CONTROL); habbo.getClient().sendResponse(new YouAreControllerMessageComposer(RoomRightLevels.NONE)); } - - return true; }); - room.removeAllRights(); + room.getRoomRightsManager().removeAllRights(); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveOwnRoomRightsRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveOwnRoomRightsRoomEvent.java index b5bace40..fef6a27e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveOwnRoomRightsRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RemoveOwnRoomRightsRoomEvent.java @@ -1,6 +1,7 @@ package com.eu.habbo.messages.incoming.rooms; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; public class RemoveOwnRoomRightsRoomEvent extends MessageHandler { @@ -8,6 +9,7 @@ public class RemoveOwnRoomRightsRoomEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Emulator.getGameEnvironment().getRoomManager().getRoom(roomId).removeRights(this.client.getHabbo().getHabboInfo().getId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); + room.getRoomRightsManager().removeRights(this.client.getHabbo().getHabboInfo().getId()); } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestHeightmapEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestHeightmapEvent.java index e40258eb..6b11663b 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestHeightmapEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestHeightmapEvent.java @@ -7,12 +7,11 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class RequestHeightmapEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getLoadingRoom() > 0) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.client.getHabbo().getHabboInfo().getLoadingRoom()); + if (this.client.getHabbo().getRoomUnit().isLoadingRoom()) { + Room room = this.client.getHabbo().getRoomUnit().getLoadingRoom(); if (room != null) { Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), room); - } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomPropertySet.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomPropertySet.java index 5809d1fd..44dfe13d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomPropertySet.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/RequestRoomPropertySet.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.inventory.FurniListRemoveComposer; import com.eu.habbo.messages.outgoing.rooms.RoomPropertyMessageComposer; @@ -12,14 +12,14 @@ import com.eu.habbo.messages.outgoing.rooms.RoomPropertyMessageComposer; public class RequestRoomPropertySet extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || room.hasRights(this.client.getHabbo()) || this.client.getHabbo().hasRight(Permission.ACC_PLACEFURNI)) { + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || room.getRoomRightsManager().hasRights(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_PLACEFURNI)) { int itemId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); if (item == null) { this.client.sendResponse(new FurniListRemoveComposer(itemId)); @@ -28,17 +28,17 @@ public class RequestRoomPropertySet extends MessageHandler { switch (item.getBaseItem().getName()) { case "floor": - room.setFloorPaint(item.getExtradata()); + room.getRoomInfo().setFloorPaint(item.getExtraData()); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoFloor")); break; case "wallpaper": - room.setWallPaint(item.getExtradata()); + room.getRoomInfo().setWallPaint(item.getExtraData()); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoWallpaper")); break; case "landscape": - room.setBackgroundPaint(item.getExtradata()); + room.getRoomInfo().setLandscapePaint(item.getExtraData()); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("RoomDecoLandscape")); break; @@ -48,8 +48,8 @@ public class RequestRoomPropertySet extends MessageHandler { this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); room.setNeedsUpdate(true); - room.sendComposer(new RoomPropertyMessageComposer(item.getBaseItem().getName(), item.getExtradata()).compose()); - item.needsDelete(true); + room.sendComposer(new RoomPropertyMessageComposer(item.getBaseItem().getName(), item.getExtraData()).compose()); + item.setSqlDeleteNeeded(true); Emulator.getThreading().run(item); this.client.sendResponse(new FurniListRemoveComposer(itemId)); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/SaveRoomSettingsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/SaveRoomSettingsEvent.java index c0b93562..2dd9e688 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/SaveRoomSettingsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/SaveRoomSettingsEvent.java @@ -20,19 +20,19 @@ public class SaveRoomSettingsEvent extends MessageHandler { public void handle() { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { - if (room.isOwner(this.client.getHabbo())) { + if (room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { String name = this.packet.readString(); if (name.trim().isEmpty() || name.length() > 60) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.ROOM_NAME_MISSING, "")); + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.ROOM_NAME_MISSING, "")); return; } if (!Emulator.getGameEnvironment().getWordFilter().filter(name, this.client.getHabbo()).equals(name)) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.ROOM_NAME_BADWORDS, "")); + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.ROOM_NAME_BADWORDS, "")); return; } @@ -43,15 +43,15 @@ public class SaveRoomSettingsEvent extends MessageHandler { } if (!Emulator.getGameEnvironment().getWordFilter().filter(description, this.client.getHabbo()).equals(description)) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.ROOM_DESCRIPTION_BADWORDS, "")); + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.ROOM_DESCRIPTION_BADWORDS, "")); return; } RoomState state = RoomState.values()[this.packet.readInt() % RoomState.values().length]; String password = this.packet.readString(); - if (state == RoomState.PASSWORD && password.isEmpty() && (room.getPassword() == null || room.getPassword().isEmpty())) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.PASSWORD_REQUIRED, "")); + if (state == RoomState.PASSWORD && password.isEmpty() && (room.getRoomInfo().getPassword() == null || room.getRoomInfo().getPassword().isEmpty())) { + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.PASSWORD_REQUIRED, "")); return; } @@ -64,7 +64,7 @@ public class SaveRoomSettingsEvent extends MessageHandler { String tag = this.packet.readString(); if (tag.length() > 15) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.TAGS_TOO_LONG, "")); + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.TAGS_TOO_LONG, "")); return; } if(!uniqueTags.contains(tag)) { @@ -74,7 +74,7 @@ public class SaveRoomSettingsEvent extends MessageHandler { } if (!Emulator.getGameEnvironment().getWordFilter().filter(tags.toString(), this.client.getHabbo()).equals(tags.toString())) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.ROOM_TAGS_BADWWORDS, "")); + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.ROOM_TAGS_BADWWORDS, "")); return; } @@ -82,21 +82,21 @@ public class SaveRoomSettingsEvent extends MessageHandler { if (tags.length() > 0) { for (String s : Emulator.getConfig().getValue("hotel.room.tags.staff").split(";")) { if (tags.toString().contains(s)) { - this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getId(), RoomSettingsSaveErrorComposer.RESTRICTED_TAGS, "1")); + this.client.sendResponse(new RoomSettingsSaveErrorComposer(room.getRoomInfo().getId(), RoomSettingsSaveErrorComposer.RESTRICTED_TAGS, "1")); return; } } } - room.setName(name); - room.setDescription(description); - room.setState(state); - if (!password.isEmpty()) room.setPassword(password); - room.setUsersMax(usersMax); + room.getRoomInfo().setName(name); + room.getRoomInfo().setDescription(description); + room.getRoomInfo().setState(state); + if (!password.isEmpty()) room.getRoomInfo().setPassword(password); + room.getRoomInfo().setMaxUsers(usersMax); if (Emulator.getGameEnvironment().getRoomManager().hasCategory(categoryId, this.client.getHabbo())) - room.setCategory(categoryId); + room.getRoomInfo().setCategory(Emulator.getGameEnvironment().getRoomManager().getCategory(categoryId)); else { RoomCategory category = Emulator.getGameEnvironment().getRoomManager().getCategory(categoryId); @@ -113,22 +113,39 @@ public class SaveRoomSettingsEvent extends MessageHandler { } - room.setTags(tags.toString()); - room.setTradeMode(this.packet.readInt()); - room.setAllowPets(this.packet.readBoolean()); - room.setAllowPetsEat(this.packet.readBoolean()); - room.setAllowWalkthrough(this.packet.readBoolean()); - room.setHideWall(this.packet.readBoolean()); - room.setWallSize(this.packet.readInt()); - room.setFloorSize(this.packet.readInt()); - room.setMuteOption(this.packet.readInt()); - room.setKickOption(this.packet.readInt()); - room.setBanOption(this.packet.readInt()); - room.setChatMode(this.packet.readInt()); - room.setChatWeight(this.packet.readInt()); - room.setChatSpeed(this.packet.readInt()); - room.setChatDistance(Math.abs(this.packet.readInt())); - room.setChatProtection(this.packet.readInt()); + room.getRoomInfo().setTags(tags.toString()); + int tradeMode = this.packet.readInt(); + room.getRoomInfo().setTradeMode(tradeMode); + room.getRoomInfo().setAllowPets(this.packet.readBoolean()); + + if(!room.getRoomInfo().isAllowPets()) { + room.getRoomUnitManager().removeAllPetsExceptRoomOwner(); + } + + boolean allowPetsEat = this.packet.readBoolean(); + room.getRoomInfo().setAllowPetsEat(allowPetsEat); + boolean allowWalkthrough = this.packet.readBoolean(); + room.getRoomInfo().setAllowWalkthrough(allowWalkthrough); + boolean hideWall = this.packet.readBoolean(); + room.getRoomInfo().setHideWalls(hideWall); + room.getRoomInfo().setWallThickness(this.packet.readInt()); + room.getRoomInfo().setFloorThickness(this.packet.readInt()); + int muteOption = this.packet.readInt(); + room.getRoomInfo().setWhoCanMuteOption(muteOption); + int kickOption = this.packet.readInt(); + room.getRoomInfo().setWhoCanKickOption(kickOption); + int banOption = this.packet.readInt(); + room.getRoomInfo().setWhoCanBanOption(banOption); + int chatMode = this.packet.readInt(); + room.getRoomInfo().setChatMode(chatMode); + int chatWeight = this.packet.readInt(); + room.getRoomInfo().setChatWeight(chatWeight); + int chatSpeed = this.packet.readInt(); + room.getRoomInfo().setChatSpeed(chatSpeed); + int chatDistance = Math.abs(this.packet.readInt()); + room.getRoomInfo().setChatDistance(chatDistance); + int chatProtection = this.packet.readInt(); + room.getRoomInfo().setChatProtection(chatProtection); room.setNeedsUpdate(true); room.sendComposer(new RoomVisualizationSettingsComposer(room).compose()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/SetRoomBackgroundColorDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/SetRoomBackgroundColorDataEvent.java index 25f7df27..de92ddba 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/SetRoomBackgroundColorDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/SetRoomBackgroundColorDataEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.plugin.events.furniture.FurnitureRoomTonerEvent; @@ -12,12 +12,12 @@ public class SetRoomBackgroundColorDataEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.hasRights(this.client.getHabbo()) || this.client.getHabbo().hasRight(Permission.ACC_PLACEFURNI)) { - HabboItem item = room.getHabboItem(itemId); + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_PLACEFURNI)) { + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item == null) return; @@ -35,8 +35,8 @@ public class SetRoomBackgroundColorDataEvent extends MessageHandler { saturation = event.getSaturation() % 256; brightness = event.getBrightness() % 256; - item.setExtradata(item.getExtradata().split(":")[0] + ":" + hue + ":" + saturation + ":" + brightness); - item.needsUpdate(true); + item.setExtraData(item.getExtraData().split(":")[0] + ":" + hue + ":" + saturation + ":" + brightness); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); room.updateItem(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/SubmitRoomToCompetitionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/SubmitRoomToCompetitionEvent.java index d2e40610..6fd1c161 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/SubmitRoomToCompetitionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/SubmitRoomToCompetitionEvent.java @@ -12,18 +12,19 @@ import com.eu.habbo.messages.outgoing.rooms.GetGuestRoomResultComposer; public class SubmitRoomToCompetitionEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().hasRight(Permission.ACC_STAFF_PICK)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_STAFF_PICK)) { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { - room.setStaffPromotedRoom(!room.isStaffPromotedRoom()); + boolean staffPromotedRoom = !room.getRoomInfo().isStaffPicked(); + room.getRoomInfo().setStaffPicked(staffPromotedRoom); room.setNeedsUpdate(true); NavigatorPublicCategory publicCategory = Emulator.getGameEnvironment().getNavigatorManager().publicCategories.get(Emulator.getConfig().getInt("hotel.navigator.staffpicks.categoryid")); - if (room.isStaffPromotedRoom()) { - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(room.getOwnerId()); + if (room.getRoomInfo().isStaffPicked()) { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(room.getRoomInfo().getOwnerInfo().getId()); if (habbo != null) { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("Spr")); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/ToggleStaffPickEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/ToggleStaffPickEvent.java index af162d35..4cafbafe 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/ToggleStaffPickEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/ToggleStaffPickEvent.java @@ -12,18 +12,19 @@ import com.eu.habbo.messages.outgoing.rooms.GetGuestRoomResultComposer; public class ToggleStaffPickEvent extends MessageHandler { @Override public void handle() throws Exception { - if (this.client.getHabbo().hasRight(Permission.ACC_STAFF_PICK)) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_STAFF_PICK)) { int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { - room.setStaffPromotedRoom(!room.isStaffPromotedRoom()); + boolean staffPromotedRoom = !room.getRoomInfo().isStaffPicked(); + room.getRoomInfo().setStaffPicked(staffPromotedRoom); room.setNeedsUpdate(true); NavigatorPublicCategory publicCategory = Emulator.getGameEnvironment().getNavigatorManager().publicCategories.get(Emulator.getConfig().getInt("hotel.navigator.staffpicks.categoryid")); - if (room.isStaffPromotedRoom()) { - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(room.getOwnerId()); + if (room.getRoomInfo().isStaffPicked()) { + Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(room.getRoomInfo().getOwnerInfo().getId()); if (habbo != null) { AchievementManager.progressAchievement(habbo, Emulator.getGameEnvironment().getAchievementManager().getAchievement("Spr")); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/UpdateRoomFilterEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/UpdateRoomFilterEvent.java index b8df73ab..f9eb118e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/UpdateRoomFilterEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/UpdateRoomFilterEvent.java @@ -16,22 +16,22 @@ public class UpdateRoomFilterEvent extends MessageHandler { } // Get current room of user. - final Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - if (room == null || room.getId() != roomId) { + final Room room = this.client.getHabbo().getRoomUnit().getRoom(); + if (room == null || room.getRoomInfo().getId() != roomId) { return; } // Check if owner. - if (!room.isOwner(this.client.getHabbo())) { + if (!room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { ScripterManager.scripterDetected(this.client, String.format("User (%s) tried to change wordfilter for a not owned room.", this.client.getHabbo().getHabboInfo().getUsername())); return; } // Modify word filter. if (add) { - room.addToWordFilter(word); + room.getRoomWordFilterManager().addWord(word); } else { - room.removeFromWordFilter(word); + room.getRoomWordFilterManager().removeWord(word); } } } 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 91d18c51..08befe11 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 @@ -8,7 +8,6 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer; -import com.eu.habbo.messages.outgoing.rooms.users.DanceMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserNameChangedMessageComposer; import com.eu.habbo.plugin.events.bots.BotSavedChatEvent; @@ -21,18 +20,19 @@ import java.util.ArrayList; public class CommandBotEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { int botId = this.packet.readInt(); - Bot bot = room.getBot(Math.abs(botId)); + Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); - if (bot == null) + if (bot == null) { return; + } int settingId = this.packet.readInt(); @@ -45,10 +45,10 @@ public class CommandBotEvent extends MessageHandler { Emulator.getPluginManager().fireEvent(lookEvent); if (lookEvent.isCancelled()) break; + bot.setFigure(lookEvent.getNewLook()); bot.setGender(lookEvent.getGender()); bot.setEffect(lookEvent.getEffect(), -1); - bot.needsUpdate(true); } case 2 -> { String messageString = this.packet.readString(); @@ -74,7 +74,7 @@ public class CommandBotEvent extends MessageHandler { String result = Emulator.getGameEnvironment().getWordFilter().filter(s, this.client.getHabbo()); if (!result.isEmpty()) { - if (!this.client.getHabbo().hasRight(Permission.ACC_CHAT_NO_FILTER)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_CHAT_NO_FILTER)) { result = Emulator.getGameEnvironment().getWordFilter().filter(result, this.client.getHabbo()); } @@ -102,16 +102,15 @@ public class CommandBotEvent extends MessageHandler { bot.setChatDelay((short) chatEvent.getChatDelay()); bot.clearChat(); bot.addChatLines(chat); - bot.needsUpdate(true); + bot.setSqlUpdateNeeded(true); } case 3 -> { - bot.setCanWalk(!bot.canWalk()); - bot.needsUpdate(true); + bot.getRoomUnit().setCanWalk(!bot.getRoomUnit().isCanWalk()); + bot.setSqlUpdateNeeded(true); } case 4 -> { - bot.getRoomUnit().setDanceType(DanceType.values()[(bot.getRoomUnit().getDanceType().getType() + 1) % DanceType.values().length]); - room.sendComposer(new DanceMessageComposer(bot.getRoomUnit()).compose()); - bot.needsUpdate(true); + bot.getRoomUnit().setDance(DanceType.values()[(bot.getRoomUnit().getDanceType().getType() + 1) % DanceType.values().length]); + bot.setSqlUpdateNeeded(true); } case 5 -> { String name = this.packet.readString(); @@ -128,8 +127,8 @@ public class CommandBotEvent extends MessageHandler { break; bot.setName(nameEvent.getName()); - bot.needsUpdate(true); - room.sendComposer(new UserNameChangedMessageComposer(bot.getRoomUnit().getId(), bot.getRoomUnit().getId(), nameEvent.getName()).compose()); + bot.setSqlUpdateNeeded(true); + room.sendComposer(new UserNameChangedMessageComposer(bot.getRoomUnit().getVirtualId(), bot.getRoomUnit().getVirtualId(), nameEvent.getName()).compose()); } } if (invalidName) { @@ -140,12 +139,11 @@ public class CommandBotEvent extends MessageHandler { String motto = this.packet.readString(); if (motto.length() > Emulator.getConfig().getInt("motto.max_length", 38)) break; bot.setMotto(motto); - bot.needsUpdate(true); room.sendComposer(new RoomUsersComposer(bot).compose()); } } - if (bot.needsUpdate()) { + if (bot.isSqlUpdateNeeded()) { Emulator.getThreading().run(bot); } } 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 1945016b..7c9f337b 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 @@ -9,15 +9,15 @@ import com.eu.habbo.messages.outgoing.rooms.BotCommandConfigurationComposer; public class GetBotCommandConfigurationDataEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + 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.getBot(Math.abs(botId)); + Bot bot = room.getRoomUnitManager().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 ed6cea2d..3e81a536 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 @@ -1,6 +1,5 @@ package com.eu.habbo.messages.incoming.rooms.bots; -import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -8,19 +7,21 @@ import com.eu.habbo.messages.incoming.MessageHandler; public class PlaceBotEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null) + if (room == null) { return; + } Bot bot = this.client.getHabbo().getInventory().getBotsComponent().getBot(this.packet.readInt()); - if (bot == null) + if (bot == null) { return; + } int x = this.packet.readInt(); int y = this.packet.readInt(); - Emulator.getGameEnvironment().getBotManager().placeBot(bot, this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getCurrentRoom(), room.getLayout().getTile((short) x, (short) y)); + room.getRoomUnitManager().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 87189997..d55a372a 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 @@ -1,6 +1,6 @@ package com.eu.habbo.messages.incoming.rooms.bots; -import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -9,11 +9,20 @@ public class RemoveBotFromFlatEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null) + if (room == null) { return; + } - Emulator.getGameEnvironment().getBotManager().pickUpBot(this.packet.readInt(), this.client.getHabbo()); + int botId = this.packet.readInt(); + + Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId)); + + if(bot == null) { + return; + } + + room.getRoomUnitManager().pickUpBot(bot, this.client.getHabbo()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/AddSpamWallPostItEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/AddSpamWallPostItEvent.java index 0e4fea1d..5e216071 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/AddSpamWallPostItEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/AddSpamWallPostItEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.PostItColor; import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import lombok.extern.slf4j.Slf4j; @@ -22,7 +22,7 @@ public class AddSpamWallPostItEvent extends MessageHandler { this.packet.readString(); String color = this.packet.readString(); if (itemId == -1234) { - if (this.client.getHabbo().hasCommand("cmd_multi")) { + if (this.client.getHabbo().canExecuteCommand("cmd_multi")) { String[] commands = this.packet.readString().split("\r"); Arrays.stream(commands) @@ -34,11 +34,11 @@ public class AddSpamWallPostItEvent extends MessageHandler { } else { String text = this.packet.readString(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - HabboItem sticky = room.getHabboItem(itemId); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + RoomItem sticky = room.getRoomItemManager().getRoomItemById(itemId); - if (sticky != null && sticky.getUserId() == this.client.getHabbo().getHabboInfo().getId()) { - sticky.setUserId(room.getOwnerId()); + if (sticky != null && sticky.getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId()) { + sticky.setOwnerInfo(room.getRoomInfo().getOwnerInfo()); if (color.equalsIgnoreCase(PostItColor.YELLOW.hexColor)) { color = PostItColor.randomColorNotYellow().hexColor; @@ -47,9 +47,9 @@ public class AddSpamWallPostItEvent extends MessageHandler { text = InteractionPostIt.STICKYPOLE_PREFIX_TEXT.replace("\\r", "\r").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%timestamp%", LocalDate.now().toString()) + text; } - sticky.setUserId(room.getOwnerId()); - sticky.setExtradata(color + " " + text); - sticky.needsUpdate(true); + sticky.setOwnerInfo(room.getRoomInfo().getOwnerInfo()); + sticky.setExtraData(color + " " + text); + sticky.setSqlUpdateNeeded(true); room.updateItem(sticky); Emulator.getThreading().run(sticky); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CreditFurniRedeemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CreditFurniRedeemEvent.java index bb577502..2ee0e584 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CreditFurniRedeemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CreditFurniRedeemEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.HeightMapUpdateMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; @@ -20,12 +20,12 @@ public class CreditFurniRedeemEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); - if (item != null && this.client.getHabbo().getHabboInfo().getId() == item.getUserId()) { + if (item != null && this.client.getHabbo().getHabboInfo().getId() == item.getOwnerInfo().getId()) { boolean furnitureRedeemEventRegistered = Emulator.getPluginManager().isRegistered(FurnitureRedeemedEvent.class, true); FurnitureRedeemedEvent furniRedeemEvent = new FurnitureRedeemedEvent(item, this.client.getHabbo(), 0, FurnitureRedeemedEvent.CREDITS); @@ -93,15 +93,15 @@ public class CreditFurniRedeemEvent extends MessageHandler { if (furniRedeemEvent.amount < 1) return; - if (room.getHabboItem(item.getId()) == null) // plugins may cause a lag between which time the item can be removed from the room + if (room.getRoomItemManager().getRoomItemById(item.getId()) == null) // plugins may cause a lag between which time the item can be removed from the room return; - room.removeHabboItem(item); + room.getRoomItemManager().removeRoomItem(item); room.sendComposer(new RemoveFloorItemComposer(item).compose()); - RoomTile t = room.getLayout().getTile(item.getX(), item.getY()); - t.setStackHeight(room.getStackHeight(item.getX(), item.getY(), false)); + RoomTile t = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + t.setStackHeight(room.getStackHeight(item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), false)); room.updateTile(t); - room.sendComposer(new HeightMapUpdateMessageComposer(item.getX(), item.getY(), t.getZ(), t.relativeHeight()).compose()); + room.sendComposer(new HeightMapUpdateMessageComposer(item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), t.getZ(), t.relativeHeight()).compose()); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); switch (furniRedeemEvent.currencyID) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CustomizeAvatarWithFurniEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CustomizeAvatarWithFurniEvent.java index 937aae78..b507f0b8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CustomizeAvatarWithFurniEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/CustomizeAvatarWithFurniEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.catalog.ClothItem; import com.eu.habbo.habbohotel.items.interactions.InteractionClothing; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -26,22 +26,23 @@ public class CustomizeAvatarWithFurniEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null && - this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) { - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + if (this.client.getHabbo().getRoomUnit().getRoom() != null && this.client.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(this.client.getHabbo())) { + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); - if (item != null && item.getUserId() == this.client.getHabbo().getHabboInfo().getId()) { + if (item != null && item.getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId()) { if (item instanceof InteractionClothing) { ClothItem clothing = Emulator.getGameEnvironment().getCatalogManager().getClothing(item.getBaseItem().getName()); if (clothing != null) { if (!this.client.getHabbo().getInventory().getWardrobeComponent().getClothing().contains(clothing.getId())) { + //Deprecated item.setRoomId(0); - RoomTile tile = this.client.getHabbo().getHabboInfo().getCurrentRoom().getLayout().getTile(item.getX(), item.getY()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item); - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTile(tile); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new HeightMapUpdateMessageComposer(tile.getX(), tile.getY(), tile.getZ(), tile.relativeHeight()).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item, true).compose()); + item.setRoom(null); + RoomTile tile = this.client.getHabbo().getRoomUnit().getRoom().getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().removeRoomItem(item); + this.client.getHabbo().getRoomUnit().getRoom().updateTile(tile); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new HeightMapUpdateMessageComposer(tile.getX(), tile.getY(), tile.getZ(), tile.relativeHeight()).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new RemoveFloorItemComposer(item, true).compose()); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO users_clothing (user_id, clothing_id) VALUES (?, ?)")) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/DiceOffEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/DiceOffEvent.java index 6fda922f..1da05b08 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/DiceOffEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/DiceOffEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionDice; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class DiceOffEvent extends MessageHandler { @@ -13,19 +13,19 @@ public class DiceOffEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item != null) { if (item instanceof InteractionDice) { - if (RoomLayout.tilesAdjecent(room.getLayout().getTile(item.getX(), item.getY()), this.client.getHabbo().getRoomUnit().getCurrentLocation())) { - if (!item.getExtradata().equals("-1")) { - item.setExtradata("0"); - item.needsUpdate(true); + if (RoomLayout.tilesAdjecent(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), this.client.getHabbo().getRoomUnit().getCurrentPosition())) { + if (!item.getExtraData().equals("-1")) { + item.setExtraData("0"); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); room.updateItem(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/EnterOneWayDoorEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/EnterOneWayDoorEvent.java index 9c3dc5e5..ba4452ba 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/EnterOneWayDoorEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/EnterOneWayDoorEvent.java @@ -1,26 +1,26 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionOneWayGate; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class EnterOneWayDoorEvent extends MessageHandler { @Override public void handle() throws Exception { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; int itemId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item == null) return; if (item instanceof InteractionOneWayGate) { - if (!item.getExtradata().equals("0") || this.client.getHabbo().getRoomUnit().isTeleporting()) + if (!item.getExtraData().equals("0") || this.client.getHabbo().getRoomUnit().isTeleporting()) return; - item.onClick(this.client, this.client.getHabbo().getHabboInfo().getCurrentRoom(), null); + item.onClick(this.client, this.client.getHabbo().getRoomUnit().getRoom(), null); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/GetItemDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/GetItemDataEvent.java index d78c2b42..83599fa7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/GetItemDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/GetItemDataEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.ItemDataUpdateMessageComposer; @@ -11,10 +11,10 @@ public class GetItemDataEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionPostIt) { this.client.sendResponse(new ItemDataUpdateMessageComposer((InteractionPostIt) item)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveObjectEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveObjectEvent.java index a2dd1bf2..bc81c26d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveObjectEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveObjectEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -12,28 +12,28 @@ import com.eu.habbo.messages.outgoing.rooms.items.ObjectUpdateMessageComposer; public class MoveObjectEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null) + if (room == null) { return; + } - int furniId = this.packet.readInt(); - HabboItem item = room.getHabboItem(furniId); - if (item == null) return; + int itemId = this.packet.readInt(); + + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); + + if (item == null) { + return; + } int x = this.packet.readInt(); int y = this.packet.readInt(); int rotation = this.packet.readInt(); + RoomTile tile = room.getLayout().getTile((short) x, (short) y); - FurnitureMovementError error = room.canPlaceFurnitureAt(item, this.client.getHabbo(), tile, rotation); - if (!error.equals(FurnitureMovementError.NONE)) { - this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), error.getErrorCode())); - this.client.sendResponse(new ObjectUpdateMessageComposer(item)); - return; - } + FurnitureMovementError error = room.getRoomItemManager().moveItemTo(item, tile, rotation, this.client.getHabbo()); - error = room.moveFurniTo(item, tile, rotation, this.client.getHabbo()); if (!error.equals(FurnitureMovementError.NONE)) { this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), error.getErrorCode())); this.client.sendResponse(new ObjectUpdateMessageComposer(item)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveWallItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveWallItemEvent.java index 62609bfc..185c3c1b 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveWallItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MoveWallItemEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomRightLevels; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -12,14 +12,16 @@ import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageCo public class MoveWallItemEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (!room.hasRights(this.client.getHabbo()) && !this.client.getHabbo().hasRight(Permission.ACC_PLACEFURNI) && !(room.getGuildId() > 0 && room.getGuildRightLevel(this.client.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { - this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode())); - return; + if (!room.getRoomRightsManager().hasRights(this.client.getHabbo()) && !this.client.getHabbo().hasPermissionRight(Permission.ACC_PLACEFURNI)) { + if (!(room.getRoomInfo().getGuild().getId() > 0 && room.getGuildRightLevel(this.client.getHabbo()).isEqualOrGreaterThan(RoomRightLevels.GUILD_RIGHTS))) { + this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode())); + return; + } } int itemId = this.packet.readInt(); @@ -28,13 +30,13 @@ public class MoveWallItemEvent extends MessageHandler { if (itemId <= 0 || wallPosition.length() <= 13) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item == null) return; item.setWallPosition(wallPosition); - item.needsUpdate(true); + item.setSqlUpdateNeeded(true); room.updateItem(item); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PickupObjectEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PickupObjectEvent.java index 162fd074..4f6da343 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PickupObjectEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PickupObjectEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class PickupObjectEvent extends MessageHandler { @@ -12,30 +12,33 @@ public class PickupObjectEvent extends MessageHandler { int category = this.packet.readInt(); //10 = floorItem and 20 = wallItem int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null) + if (room == null) { return; + } - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); - if (item == null) + if (item == null || item instanceof InteractionPostIt) { return; + } - if (item instanceof InteractionPostIt) - return; - - if (item.getUserId() == this.client.getHabbo().getHabboInfo().getId()) { - room.pickUpItem(item, this.client.getHabbo()); + if (item.getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId()) { + room.getRoomItemManager().pickUpItem(item, this.client.getHabbo()); } else { - if (room.hasRights(this.client.getHabbo())) { - if (this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { - item.setUserId(this.client.getHabbo().getHabboInfo().getId()); - } else if (this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId() && item.getUserId() == room.getOwnerId()) { - return; + if (room.getRoomRightsManager().hasRights(this.client.getHabbo())) { + if (this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + item.setOwnerInfo(this.client.getHabbo().getHabboInfo()); + } else { + if (!room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { + if (item.getOwnerInfo().getId() == room.getRoomInfo().getOwnerInfo().getId()) { + return; + } + } } - room.ejectUserItem(item); + room.getRoomItemManager().ejectUserItem(item); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlaceObjectEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlaceObjectEvent.java index 5ba6485e..776acf3e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlaceObjectEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlaceObjectEvent.java @@ -7,7 +7,7 @@ import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -16,42 +16,33 @@ import com.eu.habbo.messages.outgoing.inventory.FurniListRemoveComposer; public class PlaceObjectEvent extends MessageHandler { @Override public void handle() { - String[] values = this.packet.readString().split(" "); - - int itemId = -1; - - if (values.length != 0) itemId = Integer.parseInt(values[0]); - if (!this.client.getHabbo().getRoomUnit().isInRoom()) { this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode())); return; } - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + if (room == null) { return; } - HabboItem rentSpace = null; - if (this.client.getHabbo().getHabboStats().isRentingSpace()) { - rentSpace = room.getHabboItem(this.client.getHabbo().getHabboStats().getRentedItemId()); + String[] values = this.packet.readString().split(" "); + + int itemId = -1; + + if (values.length != 0) { + itemId = Integer.parseInt(values[0]); } - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); - if (item == null || item.getBaseItem().getInteractionType().getType() == InteractionPostIt.class) - return; - - if (room.getId() != item.getRoomId() && item.getRoomId() != 0) - return; - - //TODO move this to canStackAt() though find a way to handle the different bubble alert keys - if (item instanceof InteractionMoodLight && !room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class).isEmpty()) { - this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.MAX_DIMMERS.getErrorCode())); + //PostIts have their own event + if (item == null || item.getBaseItem().getInteractionType().getType() == InteractionPostIt.class) { return; } - if (item instanceof InteractionJukeBox && !room.getRoomSpecialTypes().getItemsOfType(InteractionJukeBox.class).isEmpty()) { - this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.MAX_SOUNDFURNI.getErrorCode())); + + if (room.getRoomInfo().getId() != item.getRoomId() && item.getRoomId() != 0) { return; } @@ -65,19 +56,26 @@ public class PlaceObjectEvent extends MessageHandler { if(tile == null) { String userName = this.client.getHabbo().getHabboInfo().getUsername(); - int roomId = room.getId(); + int roomId = room.getRoomInfo().getId(); ScripterManager.scripterDetected(this.client, "User [" + userName + "] tried to place a furni with itemId [" + itemId + "] at a tile which is not existing in room [" + roomId + "], tile: [" + x + "," + y + "]"); return; } - HabboItem buildArea = null; - for (HabboItem area : room.getRoomSpecialTypes().getItemsOfType(InteractionBuildArea.class)) { + RoomItem buildArea = null; + + for (RoomItem area : room.getRoomSpecialTypes().getItemsOfType(InteractionBuildArea.class)) { if (((InteractionBuildArea) area).inSquare(tile)) { buildArea = area; } } - if ((rentSpace != null || buildArea != null) && !room.hasRights(this.client.getHabbo())) { + RoomItem rentSpace = null; + + if (this.client.getHabbo().getHabboStats().isRentingSpace()) { + rentSpace = room.getRoomItemManager().getRoomItemById(this.client.getHabbo().getHabboStats().getRentedItemId()); + } + + if ((rentSpace != null || buildArea != null) && !room.getRoomRightsManager().hasRights(this.client.getHabbo())) { if (item instanceof InteractionRoller || item instanceof InteractionStackHelper || item instanceof InteractionWired || @@ -89,25 +87,21 @@ public class PlaceObjectEvent extends MessageHandler { this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode())); return; } - if (rentSpace != null && !RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getX(), rentSpace.getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(x, y, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation))) { + if (rentSpace != null && !RoomLayout.squareInSquare(RoomLayout.getRectangle(rentSpace.getCurrentPosition().getX(), rentSpace.getCurrentPosition().getY(), rentSpace.getBaseItem().getWidth(), rentSpace.getBaseItem().getLength(), rentSpace.getRotation()), RoomLayout.getRectangle(x, y, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation))) { this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode())); return; } } - FurnitureMovementError error = room.canPlaceFurnitureAt(item, this.client.getHabbo(), tile, rotation); + + FurnitureMovementError error = room.getRoomItemManager().placeFloorItemAt(item, tile, rotation, this.client.getHabbo()); if (!error.equals(FurnitureMovementError.NONE)) { this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), error.getErrorCode())); return; } - error = room.placeFloorFurniAt(item, tile, rotation, this.client.getHabbo()); - if (!error.equals(FurnitureMovementError.NONE)) { - this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), error.getErrorCode())); - return; - } } else { - FurnitureMovementError error = room.placeWallFurniAt(item, values[1] + " " + values[2] + " " + values[3], this.client.getHabbo()); + FurnitureMovementError error = room.getRoomItemManager().placeWallItemAt(item, values[1] + " " + values[2] + " " + values[3], this.client.getHabbo()); if (!error.equals(FurnitureMovementError.NONE)) { this.client.sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), error.getErrorCode())); return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlacePostItEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlacePostItEvent.java index 1f6eee07..c2d610ae 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlacePostItEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/PlacePostItEvent.java @@ -6,7 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; import com.eu.habbo.habbohotel.items.interactions.InteractionStickyPole; import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -19,28 +19,30 @@ public class PlacePostItEvent extends MessageHandler { int itemId = this.packet.readInt(); String location = this.packet.readString(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - if (room.hasRights(this.client.getHabbo()) || !room.getRoomSpecialTypes().getItemsOfType(InteractionStickyPole.class).isEmpty()) { - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || !room.getRoomSpecialTypes().getItemsOfType(InteractionStickyPole.class).isEmpty()) { + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(itemId); if (item instanceof InteractionPostIt) { if (room.getPostItNotes().size() < Room.MAXIMUM_POSTITNOTES) { - room.addHabboItem(item); - item.setExtradata("FFFF33"); - item.setRoomId(this.client.getHabbo().getHabboInfo().getCurrentRoom().getId()); + room.getRoomItemManager().addRoomItem(item); + item.setExtraData("FFFF33"); + //Deprecated + item.setRoomId(this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getId()); + item.setRoom(this.client.getHabbo().getRoomUnit().getRoom()); item.setWallPosition(location); - item.setUserId(this.client.getHabbo().getHabboInfo().getId()); - item.needsUpdate(true); + item.setOwnerInfo(this.client.getHabbo().getHabboInfo()); + item.setSqlUpdateNeeded(true); room.sendComposer(new ItemAddMessageComposer(item, this.client.getHabbo().getHabboInfo().getUsername()).compose()); this.client.getHabbo().getInventory().getItemsComponent().removeHabboItem(item); this.client.sendResponse(new FurniListRemoveComposer(item.getGiftAdjustedId())); item.setFromGift(false); Emulator.getThreading().run(item); - if (room.getOwnerId() != this.client.getHabbo().getHabboInfo().getId()) { - AchievementManager.progressAchievement(room.getOwnerId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("NotesReceived")); + if (room.getRoomInfo().getOwnerInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) { + AchievementManager.progressAchievement(room.getRoomInfo().getOwnerInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("NotesReceived")); AchievementManager.progressAchievement(this.client.getHabbo().getHabboInfo().getId(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("NotesLeft")); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RemoveItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RemoveItemEvent.java index 44b57ac3..879979aa 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RemoveItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RemoveItemEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionExternalImage; import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.ItemRemoveMessageComposer; import com.eu.habbo.threading.runnables.QueryDeleteHabboItem; @@ -15,17 +15,19 @@ public class RemoveItemEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionPostIt || item instanceof InteractionExternalImage) { - if (item.getUserId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (item.getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + //Deprecated item.setRoomId(0); - room.removeHabboItem(item); + item.setRoom(null); + room.getRoomItemManager().removeRoomItem(item); room.sendComposer(new ItemRemoveMessageComposer(item).compose()); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerChangeStateEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerChangeStateEvent.java index 2ba8cb82..927803b8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerChangeStateEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerChangeStateEvent.java @@ -5,22 +5,23 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionMoodLight; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomMoodlightData; import com.eu.habbo.habbohotel.rooms.RoomRightLevels; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; +import gnu.trove.map.TIntObjectMap; public class RoomDimmerChangeStateEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if ((room.getGuildId() > 0 && room.getGuildRightLevel(this.client.getHabbo()).isLessThan(RoomRightLevels.GUILD_RIGHTS)) && !room.hasRights(this.client.getHabbo())) + if ((room.getRoomInfo().getGuild().getId() > 0 && room.getGuildRightLevel(this.client.getHabbo()).isLessThan(RoomRightLevels.GUILD_RIGHTS)) && !room.getRoomRightsManager().hasRights(this.client.getHabbo())) return; - for (HabboItem moodLight : room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class)) { + for (RoomItem moodLight : room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class)) { // enabled ? 2 : 1, preset id, background only ? 2 : 1, color, intensity String extradata = "2,1,2,#FF00FF,255"; - for (RoomMoodlightData data : room.getMoodlightData().valueCollection()) { + for (RoomMoodlightData data : ((TIntObjectMap) room.getRoomInfo().getMoodLightData()).valueCollection()) { if (data.isEnabled()) { extradata = data.toString(); break; @@ -28,10 +29,10 @@ public class RoomDimmerChangeStateEvent extends MessageHandler { } RoomMoodlightData adjusted = RoomMoodlightData.fromString(extradata); - if (RoomMoodlightData.fromString(moodLight.getExtradata()).isEnabled()) adjusted.disable(); - moodLight.setExtradata(adjusted.toString()); + if (RoomMoodlightData.fromString(moodLight.getExtraData()).isEnabled()) adjusted.disable(); + moodLight.setExtraData(adjusted.toString()); - moodLight.needsUpdate(true); + moodLight.setSqlUpdateNeeded(true); room.updateItem(moodLight); Emulator.getThreading().run(moodLight); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerGetPresetsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerGetPresetsEvent.java index fbfb8fb5..0a2016d7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerGetPresetsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerGetPresetsEvent.java @@ -1,12 +1,14 @@ package com.eu.habbo.messages.incoming.rooms.items; +import com.eu.habbo.habbohotel.rooms.RoomMoodlightData; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.RoomDimmerPresetsComposer; +import gnu.trove.map.TIntObjectMap; public class RoomDimmerGetPresetsEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) - this.client.sendResponse(new RoomDimmerPresetsComposer(this.client.getHabbo().getHabboInfo().getCurrentRoom().getMoodlightData())); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) + this.client.sendResponse(new RoomDimmerPresetsComposer((TIntObjectMap) this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getMoodLightData())); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerSavePresetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerSavePresetEvent.java index 122f0902..499ca932 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerSavePresetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/RoomDimmerSavePresetEvent.java @@ -6,9 +6,10 @@ import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomMoodlightData; import com.eu.habbo.habbohotel.rooms.RoomRightLevels; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.RoomDimmerPresetsComposer; +import gnu.trove.map.TIntObjectMap; import java.util.Arrays; import java.util.List; @@ -19,9 +20,9 @@ public class RoomDimmerSavePresetEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if ((room.getGuildId() <= 0 && room.getGuildRightLevel(this.client.getHabbo()).isLessThan(RoomRightLevels.GUILD_RIGHTS)) && !room.hasRights(this.client.getHabbo())) + if ((room.getRoomInfo().getGuild().getId() <= 0 && room.getGuildRightLevel(this.client.getHabbo()).isLessThan(RoomRightLevels.GUILD_RIGHTS)) && !room.getRoomRightsManager().hasRights(this.client.getHabbo())) return; int id = this.packet.readInt(); @@ -40,16 +41,16 @@ public class RoomDimmerSavePresetEvent extends MessageHandler { return; } - for (RoomMoodlightData data : room.getMoodlightData().valueCollection()) { + for (RoomMoodlightData data : ((TIntObjectMap) room.getRoomInfo().getMoodLightData()).valueCollection()) { if (data.getId() == id) { data.setBackgroundOnly(backgroundOnly == 2); data.setColor(color); data.setIntensity(brightness); if (apply) data.enable(); - for (HabboItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class)) { - item.setExtradata(data.toString()); - item.needsUpdate(true); + for (RoomItem item : room.getRoomSpecialTypes().getItemsOfType(InteractionMoodLight.class)) { + item.setExtraData(data.toString()); + item.setSqlUpdateNeeded(true); room.updateItem(item); Emulator.getThreading().run(item); } @@ -59,6 +60,6 @@ public class RoomDimmerSavePresetEvent extends MessageHandler { } room.setNeedsUpdate(true); - this.client.sendResponse(new RoomDimmerPresetsComposer(room.getMoodlightData())); + this.client.sendResponse(new RoomDimmerPresetsComposer((TIntObjectMap) room.getRoomInfo().getMoodLightData())); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetClothingChangeDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetClothingChangeDataEvent.java index 5820a0f2..f2fec1cc 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetClothingChangeDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetClothingChangeDataEvent.java @@ -2,18 +2,19 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.games.football.InteractionFootballGate; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class SetClothingChangeDataEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId()) + if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getRoomInfo().getOwnerInfo().getId()) return; - HabboItem item = room.getHabboItem(this.packet.readInt()); + int id = this.packet.readInt(); + RoomItem item = room.getRoomItemManager().getRoomItemById(id); if (!(item instanceof InteractionFootballGate)) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetCustomStackingHeightEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetCustomStackingHeightEvent.java index 0dfc6682..2774d8e9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetCustomStackingHeightEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetCustomStackingHeightEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionStackHelper; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.HeightMapUpdateMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.UpdateStackHeightTileHeightComposer; @@ -14,15 +14,15 @@ public class SetCustomStackingHeightEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - if (this.client.getHabbo().getHabboInfo().getId() == this.client.getHabbo().getHabboInfo().getCurrentRoom().getOwnerId() || this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) { - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + if (this.client.getHabbo().getHabboInfo().getId() == this.client.getHabbo().getRoomUnit().getRoom().getRoomInfo().getOwnerInfo().getId() || this.client.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(this.client.getHabbo())) { + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionStackHelper) { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - RoomTile itemTile = room.getLayout().getTile(item.getX(), item.getY()); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + RoomTile itemTile = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); double stackerHeight = this.packet.readInt(); THashSet tiles = room.getLayout().getTilesAt(itemTile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation()); @@ -46,13 +46,14 @@ public class SetCustomStackingHeightEvent extends MessageHandler { tile.setStackHeight(height); } - item.setZ(height); - item.setExtradata((int) (height * 100) + ""); - item.needsUpdate(true); - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateItem(item); - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(tiles); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new HeightMapUpdateMessageComposer (room, tiles).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightTileHeightComposer(item, (int) ((height) * 100)).compose()); + item.setCurrentZ(height); + item.setExtraData(String.valueOf((int) (height * 100))); + item.setSqlUpdateNeeded(true); + + this.client.getHabbo().getRoomUnit().getRoom().updateItem(item); + this.client.getHabbo().getRoomUnit().getRoom().updateTiles(tiles); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new HeightMapUpdateMessageComposer (room, tiles).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UpdateStackHeightTileHeightComposer(item, (int) ((height) * 100)).compose()); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetItemDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetItemDataEvent.java index f7d649ff..853af0dc 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetItemDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetItemDataEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.items.PostItColor; import com.eu.habbo.habbohotel.items.interactions.InteractionPostIt; import com.eu.habbo.habbohotel.modtool.ScripterManager; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import java.util.Arrays; @@ -29,30 +29,30 @@ public class SetItemDataEvent extends MessageHandler { return; } - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (!(item instanceof InteractionPostIt)) return; - if (!color.equalsIgnoreCase(PostItColor.YELLOW.hexColor) && !room.hasRights(this.client.getHabbo())) { - if (!text.startsWith(item.getExtradata().replace(item.getExtradata().split(" ")[0], ""))) { + if (!color.equalsIgnoreCase(PostItColor.YELLOW.hexColor) && !room.getRoomRightsManager().hasRights(this.client.getHabbo())) { + if (!text.startsWith(item.getExtraData().replace(item.getExtraData().split(" ")[0], ""))) { return; } } else { - if (!room.hasRights(this.client.getHabbo())) + if (!room.getRoomRightsManager().hasRights(this.client.getHabbo())) return; } if (color.isEmpty()) color = PostItColor.YELLOW.hexColor; - item.setExtradata(color + " " + text); - item.needsUpdate(true); + item.setExtraData(color + " " + text); + item.setSqlUpdateNeeded(true); room.updateItem(item); Emulator.getThreading().run(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinFigureEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinFigureEvent.java index 0e924d12..66ac6978 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinFigureEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinFigureEvent.java @@ -2,24 +2,25 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; public class SetMannequinFigureEvent extends MessageHandler { @Override public void handle() { Habbo habbo = this.client.getHabbo(); - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); - if (room == null || !room.isOwner(habbo)) + if (room == null || !room.getRoomInfo().isRoomOwner(habbo)) return; - HabboItem item = room.getHabboItem(this.packet.readInt()); + int id = this.packet.readInt(); + RoomItem item = room.getRoomItemManager().getRoomItemById(id); if (item == null) return; - String[] data = item.getExtradata().split(":"); + String[] data = item.getExtraData().split(":"); //TODO: Only clothing not whole body part. StringBuilder look = new StringBuilder(); @@ -35,12 +36,12 @@ public class SetMannequinFigureEvent extends MessageHandler { } if (data.length == 3) { - item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]); + item.setExtraData(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]); } else { - item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + habbo.getHabboInfo().getUsername() + "'s look."); + item.setExtraData(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + habbo.getHabboInfo().getUsername() + "'s look."); } - item.needsUpdate(true); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); room.updateItem(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinNameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinNameEvent.java index 825d2649..892d2d68 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinNameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetMannequinNameEvent.java @@ -2,21 +2,22 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class SetMannequinNameEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - if (room == null || !room.isOwner(this.client.getHabbo())) + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + if (room == null || !room.getRoomInfo().isRoomOwner(this.client.getHabbo())) return; - HabboItem item = room.getHabboItem(this.packet.readInt()); + int id = this.packet.readInt(); + RoomItem item = room.getRoomItemManager().getRoomItemById(id); if (item == null) return; - String[] data = item.getExtradata().split(":"); + String[] data = item.getExtraData().split(":"); String name = this.packet.readString(); if (name.length() < 3 || name.length() > 15) { @@ -24,11 +25,11 @@ public class SetMannequinNameEvent extends MessageHandler { } if (data.length == 3) { - item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toUpperCase() + ":" + data[1] + ":" + name); + item.setExtraData(this.client.getHabbo().getHabboInfo().getGender().name().toUpperCase() + ":" + data[1] + ":" + name); } else { - item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toUpperCase() + ":" + this.client.getHabbo().getHabboInfo().getLook() + ":" + name); + item.setExtraData(this.client.getHabbo().getHabboInfo().getGender().name().toUpperCase() + ":" + this.client.getHabbo().getHabboInfo().getLook() + ":" + name); } - item.needsUpdate(true); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); room.updateItem(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetObjectDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetObjectDataEvent.java index cca723e6..7ee64b0c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetObjectDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetObjectDataEvent.java @@ -5,25 +5,26 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionCustomValues; import com.eu.habbo.habbohotel.items.interactions.InteractionRoomAds; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import gnu.trove.map.hash.THashMap; public class SetObjectDataEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (!room.hasRights(this.client.getHabbo())) + if (!room.getRoomRightsManager().hasRights(this.client.getHabbo())) return; - HabboItem item = room.getHabboItem(this.packet.readInt()); + int id = this.packet.readInt(); + RoomItem item = room.getRoomItemManager().getRoomItemById(id); if (item == null) return; - if (item instanceof InteractionRoomAds && !this.client.getHabbo().hasRight(Permission.ACC_ADS_BACKGROUND)) { + if (item instanceof InteractionRoomAds && !this.client.getHabbo().hasPermissionRight(Permission.ACC_ADS_BACKGROUND)) { this.client.getHabbo().alert(Emulator.getTexts().getValue("hotel.error.roomads.nopermission")); return; } @@ -41,8 +42,8 @@ public class SetObjectDataEvent extends MessageHandler { ((InteractionCustomValues) item).values.put(key, value); } - item.setExtradata(((InteractionCustomValues) item).toExtraData()); - item.needsUpdate(true); + item.setExtraData(((InteractionCustomValues) item).toExtraData()); + item.setSqlUpdateNeeded(true); Emulator.getThreading().run(item); room.updateItem(item); ((InteractionCustomValues) item).onCustomValuesSaved(room, this.client, oldValues); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetRandomStateEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetRandomStateEvent.java index 9ffa42ef..2055f5b8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetRandomStateEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SetRandomStateEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionRandomState; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import lombok.extern.slf4j.Slf4j; @@ -15,9 +15,9 @@ public class SetRandomStateEvent extends MessageHandler { int itemId = this.packet.readInt(); int state = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (!(item instanceof InteractionRandomState randomStateItem)) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SpinWheelOfFortuneEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SpinWheelOfFortuneEvent.java index 77142088..a753cfed 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SpinWheelOfFortuneEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/SpinWheelOfFortuneEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionColorWheel; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class SpinWheelOfFortuneEvent extends MessageHandler { @@ -10,12 +10,12 @@ public class SpinWheelOfFortuneEvent extends MessageHandler { public void handle() throws Exception { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionColorWheel) { item.onClick(this.client, room, null); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java index f04ddc35..ea6ef3fa 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/ThrowDiceEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionDice; import com.eu.habbo.habbohotel.items.interactions.InteractionSpinningBottle; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomLayout; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class ThrowDiceEvent extends MessageHandler { @@ -12,17 +12,17 @@ public class ThrowDiceEvent extends MessageHandler { public void handle() throws Exception { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) { return; } - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item != null) { if (item instanceof InteractionDice || item instanceof InteractionSpinningBottle) { - if (RoomLayout.tilesAdjecent(room.getLayout().getTile(item.getX(), item.getY()), this.client.getHabbo().getRoomUnit().getCurrentLocation())) { + if (RoomLayout.tilesAdjecent(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), this.client.getHabbo().getRoomUnit().getCurrentPosition())) { item.onClick(this.client, room, new Object[]{}); } } 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 e500c8c7..67f4e111 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 @@ -3,11 +3,10 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionDice; import com.eu.habbo.habbohotel.items.interactions.InteractionSpinningBottle; -import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionMonsterPlantSeed; import com.eu.habbo.habbohotel.pets.MonsterplantPet; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; import com.eu.habbo.messages.outgoing.rooms.pets.OpenPetPackageRequestedMessageComposer; @@ -27,7 +26,7 @@ public class UseFurnitureEvent extends MessageHandler { @Override public void handle() { try { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; @@ -35,7 +34,7 @@ public class UseFurnitureEvent extends MessageHandler { int itemId = this.packet.readInt(); int state = this.packet.readInt(); - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item == null || item instanceof InteractionDice || item instanceof InteractionSpinningBottle) return; @@ -50,33 +49,31 @@ public class UseFurnitureEvent extends MessageHandler { if (handleMonsterPlantSeed(room, item)) return; - if (PET_PRESENTS.contains(item.getBaseItem().getName().toLowerCase()) && room.getCurrentPets().size() < Room.MAXIMUM_PETS) { - this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item)); - return; + if (PET_PRESENTS.contains(item.getBaseItem().getName().toLowerCase())) { + if (room.getRoomUnitManager().getCurrentPets().size() < Room.MAXIMUM_PETS) { + this.client.sendResponse(new OpenPetPackageRequestedMessageComposer(item)); + return; + } } item.onClick(this.client, room, new Object[]{state}); - - if (item instanceof InteractionWired) { - this.client.getHabbo().getRoomUnit().setGoalLocation(this.client.getHabbo().getRoomUnit().getCurrentLocation()); - } } catch (Exception e) { log.error("Caught exception", e); } } - private boolean handleMonsterPlantSeed(Room room, HabboItem item) { + private boolean handleMonsterPlantSeed(Room room, RoomItem item) { if (item instanceof InteractionMonsterPlantSeed) { Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); boolean isRare = item.getBaseItem().getName().contains("rare"); int rarity = getRarity(item, isRare); - MonsterplantPet pet = Emulator.getGameEnvironment().getPetManager().createMonsterplant(room, this.client.getHabbo(), isRare, room.getLayout().getTile(item.getX(), item.getY()), rarity); + MonsterplantPet pet = Emulator.getGameEnvironment().getPetManager().createMonsterplant(room, this.client.getHabbo(), isRare, room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), rarity); room.sendComposer(new RemoveFloorItemComposer(item, true).compose()); - room.removeHabboItem(item); - room.updateTile(room.getLayout().getTile(item.getX(), item.getY())); - room.placePet(pet, item.getX(), item.getY(), item.getZ()); + room.getRoomItemManager().removeRoomItem(item); + room.updateTile(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); + room.getRoomUnitManager().placePet(pet, room, item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), item.getCurrentZ()); pet.cycle(); room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); return true; @@ -84,12 +81,12 @@ public class UseFurnitureEvent extends MessageHandler { return false; } - private int getRarity(HabboItem item, boolean isRare) { - if (item.getExtradata().isEmpty() || Integer.parseInt(item.getExtradata()) - 1 < 0) { + private int getRarity(RoomItem item, boolean isRare) { + if (item.getExtraData().isEmpty() || Integer.parseInt(item.getExtraData()) - 1 < 0) { return isRare ? InteractionMonsterPlantSeed.randomGoldenRarityLevel() : InteractionMonsterPlantSeed.randomRarityLevel(); } else { try { - return Integer.parseInt(item.getExtradata()) - 1; + return Integer.parseInt(item.getExtraData()) - 1; } catch (Exception ignored) { return 0; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseWallItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseWallItemEvent.java index a59b3232..6d1ca0e8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseWallItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/UseWallItemEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.plugin.Event; import com.eu.habbo.plugin.events.furniture.FurnitureToggleEvent; @@ -10,7 +10,7 @@ import com.eu.habbo.plugin.events.furniture.FurnitureToggleEvent; public class UseWallItemEvent extends MessageHandler { @Override public void handle() throws Exception { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; @@ -18,7 +18,7 @@ public class UseWallItemEvent extends MessageHandler { int itemId = this.packet.readInt(); int state = this.packet.readInt(); - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (item == null) return; @@ -32,7 +32,7 @@ public class UseWallItemEvent extends MessageHandler { if (item.getBaseItem().getName().equalsIgnoreCase("poster")) return; - item.needsUpdate(true); + item.setSqlUpdateNeeded(true); item.onClick(this.client, room, new Object[]{state}); room.updateItem(item); Emulator.getThreading().run(item); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/AddJukeboxDiskEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/AddJukeboxDiskEvent.java index 402281f6..a477037a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/AddJukeboxDiskEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/AddJukeboxDiskEvent.java @@ -1,14 +1,14 @@ package com.eu.habbo.messages.incoming.rooms.items.jukebox; import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; public class AddJukeboxDiskEvent extends MessageHandler { @Override public void handle() { - if (!this.client.getHabbo().getHabboInfo().getCurrentRoom().hasRights(this.client.getHabbo())) return; + if (!this.client.getHabbo().getRoomUnit().getRoom().getRoomRightsManager().hasRights(this.client.getHabbo())) return; int itemId = this.packet.readInt(); int slotId = this.packet.readInt(); @@ -16,10 +16,10 @@ public class AddJukeboxDiskEvent extends MessageHandler { Habbo habbo = this.client.getHabbo(); if (habbo != null) { - HabboItem item = habbo.getInventory().getItemsComponent().getHabboItem(itemId); + RoomItem item = habbo.getInventory().getItemsComponent().getHabboItem(itemId); if (item instanceof InteractionMusicDisc interactionMusicDisc && item.getRoomId() == 0) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().addSong(interactionMusicDisc, habbo); + this.client.getHabbo().getRoomUnit().getRoom().getRoomTraxManager().addSong(interactionMusicDisc, habbo); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetJukeboxPlayListEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetJukeboxPlayListEvent.java index 6368a05e..49d556eb 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetJukeboxPlayListEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetJukeboxPlayListEvent.java @@ -1,10 +1,5 @@ package com.eu.habbo.messages.incoming.rooms.items.jukebox; -import com.eu.habbo.habbohotel.rooms.TraxManager; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeboxSongDisksMessageComposer; -import com.eu.habbo.messages.outgoing.rooms.items.jukebox.UserSongDisksInventoryMessageComposer; - public class GetJukeboxPlayListEvent extends JukeboxEvent { @Override public void handle() { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetNowPlayingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetNowPlayingEvent.java index 4659c61d..ce2bacba 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetNowPlayingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/GetNowPlayingEvent.java @@ -1,10 +1,5 @@ package com.eu.habbo.messages.incoming.rooms.items.jukebox; -import com.eu.habbo.habbohotel.rooms.TraxManager; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeboxSongDisksMessageComposer; -import com.eu.habbo.messages.outgoing.rooms.items.jukebox.UserSongDisksInventoryMessageComposer; - public class GetNowPlayingEvent extends JukeboxEvent { @Override public void handle() { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeBoxEventOne.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeBoxEventOne.java index 8d2ada31..161cbf9d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeBoxEventOne.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeBoxEventOne.java @@ -1,10 +1,5 @@ package com.eu.habbo.messages.incoming.rooms.items.jukebox; -import com.eu.habbo.habbohotel.rooms.TraxManager; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeboxSongDisksMessageComposer; -import com.eu.habbo.messages.outgoing.rooms.items.jukebox.UserSongDisksInventoryMessageComposer; - public class JukeBoxEventOne extends JukeboxEvent { @Override public void handle() { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeboxEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeboxEvent.java index bef71287..cbd3d700 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeboxEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/JukeboxEvent.java @@ -1,15 +1,15 @@ package com.eu.habbo.messages.incoming.rooms.items.jukebox; -import com.eu.habbo.habbohotel.rooms.TraxManager; +import com.eu.habbo.habbohotel.rooms.RoomTraxManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.jukebox.JukeboxSongDisksMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.jukebox.UserSongDisksInventoryMessageComposer; public abstract class JukeboxEvent extends MessageHandler { protected void updateHabboWithCurrentPlaying() { - TraxManager traxManager = this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager(); - this.client.sendResponse(new JukeboxSongDisksMessageComposer(traxManager.getSongs(), traxManager.totalLength())); - this.client.sendResponse(new UserSongDisksInventoryMessageComposer(traxManager.myList(this.client.getHabbo()))); - this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().updateCurrentPlayingSong(this.client.getHabbo()); + RoomTraxManager roomTraxManager = this.client.getHabbo().getRoomUnit().getRoom().getRoomTraxManager(); + this.client.sendResponse(new JukeboxSongDisksMessageComposer(roomTraxManager.getSongs(), roomTraxManager.totalLength())); + this.client.sendResponse(new UserSongDisksInventoryMessageComposer(roomTraxManager.myList(this.client.getHabbo()))); + this.client.getHabbo().getRoomUnit().getRoom().getRoomTraxManager().updateCurrentPlayingSong(this.client.getHabbo()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/RemoveJukeboxDiskEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/RemoveJukeboxDiskEvent.java index 7902048d..47ded455 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/RemoveJukeboxDiskEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/jukebox/RemoveJukeboxDiskEvent.java @@ -8,10 +8,10 @@ public class RemoveJukeboxDiskEvent extends MessageHandler { public void handle() { int index = this.packet.readInt(); - InteractionMusicDisc musicDisc = this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().getSongs().get(index); + InteractionMusicDisc musicDisc = this.client.getHabbo().getRoomUnit().getRoom().getRoomTraxManager().getSongs().get(index); if (musicDisc != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().getTraxManager().removeSong(musicDisc.getId()); + this.client.getHabbo().getRoomUnit().getRoom().getRoomTraxManager().removeSong(musicDisc.getId()); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/lovelock/FriendFurniConfirmLockEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/lovelock/FriendFurniConfirmLockEvent.java index 98313948..a8950b2e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/lovelock/FriendFurniConfirmLockEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/lovelock/FriendFurniConfirmLockEvent.java @@ -1,8 +1,8 @@ package com.eu.habbo.messages.incoming.rooms.items.lovelock; import com.eu.habbo.habbohotel.items.interactions.InteractionLoveLock; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.lovelock.FriendFurniCancelLockMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.lovelock.FriendFurniOtherLockConfirmedMessageComposer; @@ -13,10 +13,10 @@ public class FriendFurniConfirmLockEvent extends MessageHandler { int itemId = this.packet.readInt(); if (this.packet.readBoolean()) { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item == null) return; @@ -31,7 +31,7 @@ public class FriendFurniConfirmLockEvent extends MessageHandler { } if (userId > 0) { - Habbo habbo = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(userId); + Habbo habbo = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboById(userId); if (habbo != null) { habbo.getClient().sendResponse(new FriendFurniOtherLockConfirmedMessageComposer((InteractionLoveLock) item)); @@ -39,7 +39,7 @@ public class FriendFurniConfirmLockEvent extends MessageHandler { habbo.getClient().sendResponse(new FriendFurniCancelLockMessageComposer((InteractionLoveLock) item)); this.client.sendResponse(new FriendFurniCancelLockMessageComposer((InteractionLoveLock) item)); - ((InteractionLoveLock) item).lock(habbo, this.client.getHabbo(), this.client.getHabbo().getHabboInfo().getCurrentRoom()); + ((InteractionLoveLock) item).lock(habbo, this.client.getHabbo(), this.client.getHabbo().getRoomUnit().getRoom()); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceCancelRentEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceCancelRentEvent.java index b4e97674..6c9547eb 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceCancelRentEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceCancelRentEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items.rentablespace; import com.eu.habbo.habbohotel.items.interactions.InteractionRentableSpace; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class RentableSpaceCancelRentEvent extends MessageHandler { @@ -11,15 +11,15 @@ public class RentableSpaceCancelRentEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || - this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || + this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { if (item instanceof InteractionRentableSpace) { ((InteractionRentableSpace) item).endRent(); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceRentEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceRentEvent.java index 5dc6abb7..4e300bd2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceRentEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/rentablespace/RentableSpaceRentEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.incoming.rooms.items.rentablespace; import com.eu.habbo.habbohotel.items.interactions.InteractionRentableSpace; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class RentableSpaceRentEvent extends MessageHandler { @@ -10,12 +10,12 @@ public class RentableSpaceRentEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = room.getHabboItem(itemId); + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); if (!(item instanceof InteractionRentableSpace)) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/ControlYoutubeDisplayPlaybackEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/ControlYoutubeDisplayPlaybackEvent.java index b6b5805a..e373ea29 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/ControlYoutubeDisplayPlaybackEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/ControlYoutubeDisplayPlaybackEvent.java @@ -2,11 +2,9 @@ package com.eu.habbo.messages.incoming.rooms.items.youtube; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionYoutubeTV; -import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.youtube.YoutubeControlVideoMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.youtube.YoutubeDisplayVideoMessageComposer; import com.eu.habbo.threading.runnables.YoutubeAdvanceVideo; @@ -47,8 +45,8 @@ public class ControlYoutubeDisplayPlaybackEvent extends YoutubeEvent { if(!validate(habbo)) return; - Room room = habbo.getHabboInfo().getCurrentRoom(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + Room room = habbo.getRoomUnit().getRoom(); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (!(item instanceof InteractionYoutubeTV tv)) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/GetYoutubeDisplayStatusEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/GetYoutubeDisplayStatusEvent.java index 4dfc7fd1..ceb1e91c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/GetYoutubeDisplayStatusEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/GetYoutubeDisplayStatusEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.incoming.rooms.items.youtube; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.YoutubeManager; import com.eu.habbo.habbohotel.items.interactions.InteractionYoutubeTV; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.handshake.ErrorReportComposer; import com.eu.habbo.messages.outgoing.rooms.items.youtube.YoutubeDisplayPlaylistsComposer; @@ -19,8 +19,8 @@ public class GetYoutubeDisplayStatusEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionYoutubeTV tv) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/SetYoutubeDisplayPlaylistEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/SetYoutubeDisplayPlaylistEvent.java index 7f9fbeca..2e5c6193 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/SetYoutubeDisplayPlaylistEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/SetYoutubeDisplayPlaylistEvent.java @@ -3,11 +3,9 @@ package com.eu.habbo.messages.incoming.rooms.items.youtube; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.YoutubeManager; import com.eu.habbo.habbohotel.items.interactions.InteractionYoutubeTV; -import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.youtube.YoutubeDisplayVideoMessageComposer; import com.eu.habbo.threading.runnables.YoutubeAdvanceVideo; @@ -23,10 +21,10 @@ public class SetYoutubeDisplayPlaylistEvent extends YoutubeEvent { if (!validate(habbo)) return; - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (!(item instanceof InteractionYoutubeTV)) return; @@ -45,7 +43,7 @@ public class SetYoutubeDisplayPlaylistEvent extends YoutubeEvent { room.sendComposer(new YoutubeDisplayVideoMessageComposer(itemId, video, true, 0).compose()); ((InteractionYoutubeTV) item).autoAdvance = Emulator.getThreading().run(new YoutubeAdvanceVideo((InteractionYoutubeTV) item), video.getDuration() * 1000L); - item.needsUpdate(true); + item.setSqlUpdateNeeded(true); } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/YoutubeEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/YoutubeEvent.java index c7e43781..ab8e8a34 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/YoutubeEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/youtube/YoutubeEvent.java @@ -12,12 +12,12 @@ public abstract class YoutubeEvent extends MessageHandler { return false; } - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); if (room == null) { return false; } - if (!room.isOwner(habbo) && !habbo.hasRight(Permission.ACC_ANYROOMOWNER)) { + if (!room.getRoomInfo().isRoomOwner(habbo) && !habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { return false; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/BreedPetsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/BreedPetsEvent.java index 016aafba..2d022131 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/BreedPetsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/BreedPetsEvent.java @@ -10,8 +10,10 @@ public class BreedPetsEvent extends MessageHandler { int unknownInt = this.packet.readInt(); //Something state. 2 = accept if (unknownInt == 0) { - Pet petOne = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(this.packet.readInt()); - Pet petTwo = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(this.packet.readInt()); + int petId1 = this.packet.readInt(); + Pet petOne = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId1); + int petId = this.packet.readInt(); + Pet petTwo = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId); if (petOne == null || petTwo == null || petOne == petTwo) { //TODO Add error diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CancelPetBreedingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CancelPetBreedingEvent.java index 58b0dc53..a6532b0e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CancelPetBreedingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CancelPetBreedingEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetBreedingNest; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class CancelPetBreedingEvent extends MessageHandler { @@ -9,7 +9,7 @@ public class CancelPetBreedingEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionPetBreedingNest) { ((InteractionPetBreedingNest) item).stopBreeding(this.client.getHabbo()); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostPlantEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostPlantEvent.java index f024f092..db1054fe 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostPlantEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CompostPlantEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.pets.MonsterplantPet; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.ObjectAddMessageComposer; import lombok.extern.slf4j.Slf4j; @@ -22,8 +22,8 @@ public class CompostPlantEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - Pet pet = room.getPet(petId); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + Pet pet = room.getRoomUnitManager().getRoomPetById(petId); if (pet != null) { if (pet instanceof MonsterplantPet) { @@ -32,12 +32,13 @@ public class CompostPlantEvent extends MessageHandler { Item baseItem = Emulator.getGameEnvironment().getItemManager().getItem("mnstr_compost"); if (baseItem != null) { - HabboItem compost = Emulator.getGameEnvironment().getItemManager().createItem(pet.getUserId(), baseItem, 0, 0, ""); - compost.setX(pet.getRoomUnit().getX()); - compost.setY(pet.getRoomUnit().getY()); - compost.setZ(pet.getRoomUnit().getZ()); + RoomItem compost = Emulator.getGameEnvironment().getItemManager().createItem(pet.getUserId(), baseItem, 0, 0, "");; + + compost.setCurrentPosition(pet.getRoomUnit().getCurrentPosition()); + compost.setCurrentZ(pet.getRoomUnit().getCurrentZ()); compost.setRotation(pet.getRoomUnit().getBodyRotation().getValue()); - room.addHabboItem(compost); + + room.getRoomItemManager().addRoomItem(compost); room.sendComposer(new ObjectAddMessageComposer(compost, this.client.getHabbo().getHabboInfo().getUsername()).compose()); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ConfirmPetBreedingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ConfirmPetBreedingEvent.java index bc0c0fbf..d5023547 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ConfirmPetBreedingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/ConfirmPetBreedingEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.habbohotel.items.interactions.pets.InteractionPetBreedingNest; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class ConfirmPetBreedingEvent extends MessageHandler { @@ -13,7 +13,7 @@ public class ConfirmPetBreedingEvent extends MessageHandler { int petOneId = this.packet.readInt(); int petTwoId = this.packet.readInt(); - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item instanceof InteractionPetBreedingNest) { ((InteractionPetBreedingNest) item).breed(this.client.getHabbo(), name); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CustomizePetWithFurniEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CustomizePetWithFurniEvent.java index 87d1d190..96361b73 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CustomizePetWithFurniEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/CustomizePetWithFurniEvent.java @@ -7,7 +7,7 @@ import com.eu.habbo.habbohotel.pets.MonsterplantPet; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; import com.eu.habbo.messages.outgoing.rooms.pets.PetFigureUpdateComposer; @@ -20,17 +20,17 @@ public class CustomizePetWithFurniEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - HabboItem item = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboItem(itemId); + RoomItem item = this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().getRoomItemById(itemId); if (item == null) return; int petId = this.packet.readInt(); - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + Pet pet = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId); if (pet instanceof HorsePet) { if (item.getBaseItem().getName().toLowerCase().startsWith("horse_dye")) { @@ -44,7 +44,7 @@ public class CustomizePetWithFurniEvent extends MessageHandler { raceType = 0; pet.setRace(raceType); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); } else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_hairdye")) { int splittedHairdye = Integer.parseInt(item.getBaseItem().getName().toLowerCase().split("_")[2]); int newHairdye = 48; @@ -60,7 +60,7 @@ public class CustomizePetWithFurniEvent extends MessageHandler { } ((HorsePet) pet).setHairColor(newHairdye); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); } else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_hairstyle")) { int splittedHairstyle = Integer.parseInt(item.getBaseItem().getName().toLowerCase().split("_")[2]); int newHairstyle = 100; @@ -72,35 +72,37 @@ public class CustomizePetWithFurniEvent extends MessageHandler { } ((HorsePet) pet).setHairStyle(newHairstyle); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); } else if (item.getBaseItem().getName().toLowerCase().startsWith("horse_saddle")) { ((HorsePet) pet).hasSaddle(true); ((HorsePet) pet).setSaddleItemId(item.getBaseItem().getId()); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); } - if (pet.isNeedsUpdate()) { + if (pet.isSqlUpdateNeeded()) { Emulator.getThreading().run(pet); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetFigureUpdateComposer((HorsePet) pet).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new PetFigureUpdateComposer((HorsePet) pet).compose()); - room.removeHabboItem(item); + room.getRoomItemManager().removeRoomItem(item); room.sendComposer(new RemoveFloorItemComposer(item, true).compose()); + //Deprecated item.setRoomId(0); + item.setRoom(null); Emulator.getGameEnvironment().getItemManager().deleteItem(item); } } else if (pet instanceof MonsterplantPet) { if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_revival")) { if (((MonsterplantPet) pet).isDead()) { ((MonsterplantPet) pet).setDeathTimestamp(Emulator.getIntUnixTimestamp() + MonsterplantPet.TIME_TO_LIVE); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "rev"); + pet.getRoomUnit().clearStatuses(); + pet.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, "rev"); pet.setPacketUpdate(true); - this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); + this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().removeRoomItem(item); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); + this.client.getHabbo().getRoomUnit().getRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("MonsterPlantHealer")); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); @@ -108,15 +110,15 @@ public class CustomizePetWithFurniEvent extends MessageHandler { } else if (item.getBaseItem().getName().equalsIgnoreCase("mnstr_fert")) { if (!((MonsterplantPet) pet).isFullyGrown()) { pet.setCreated(pet.getCreated() - MonsterplantPet.GROW_TIME); - pet.getRoomUnit().clearStatus(); + pet.getRoomUnit().clearStatuses(); pet.cycle(); - pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "spd"); - pet.getRoomUnit().setStatus(RoomUnitStatus.fromString("grw" + ((MonsterplantPet) pet).getGrowthStage()), ""); - this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); + pet.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, "spd"); + pet.getRoomUnit().addStatus(RoomUnitStatus.fromString("grw" + ((MonsterplantPet) pet).getGrowthStage()), ""); + this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().removeRoomItem(item); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); + this.client.getHabbo().getRoomUnit().getRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); pet.cycle(); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); @@ -131,14 +133,14 @@ public class CustomizePetWithFurniEvent extends MessageHandler { { ((MonsterplantPet) pet).setCanBreed(true); - pet.getRoomUnit().clearStatus(); - pet.getRoomUnit().setStatus(RoomUnitStatus.GESTURE, "reb"); + pet.getRoomUnit().clearStatuses(); + pet.getRoomUnit().addStatus(RoomUnitStatus.GESTURE, "reb"); - this.client.getHabbo().getHabboInfo().getCurrentRoom().removeHabboItem(item); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); - this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getX(), item.getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); + this.client.getHabbo().getRoomUnit().getRoom().getRoomItemManager().removeRoomItem(item); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new RemoveFloorItemComposer(item).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new PetStatusUpdateComposer(pet).compose()); + this.client.getHabbo().getRoomUnit().getRoom().updateTiles(room.getLayout().getTilesAt(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()), item.getBaseItem().getWidth(), item.getBaseItem().getLength(), item.getRotation())); pet.getRoomUnit().removeStatus(RoomUnitStatus.GESTURE); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetCommandsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetCommandsEvent.java index e3dbf722..dcc9ea99 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetCommandsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetCommandsEvent.java @@ -9,10 +9,10 @@ public class GetPetCommandsEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + Pet pet = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId); if (pet != null) this.client.sendResponse(new PetTrainingPanelComposer(pet)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetInfoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetInfoEvent.java index f357f711..bf5b49a9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetInfoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/GetPetInfoEvent.java @@ -10,12 +10,12 @@ public class GetPetInfoEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - Pet pet = room.getPet(petId); + Pet pet = room.getRoomUnitManager().getRoomPetById(petId); if (pet != null) { this.client.sendResponse(new PetInfoMessageComposer(pet, room, this.client.getHabbo())); 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 eeab20d1..fa1996e0 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 @@ -16,38 +16,45 @@ public class MountPetEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); Habbo habbo = this.client.getHabbo(); - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); - if (room == null) - return; - - Pet pet = room.getPet(petId); - - if (!(pet instanceof RideablePet rideablePet)) - return; - - //dismount - if (habbo.getHabboInfo().getRiding() != null) { - habbo.getHabboInfo().dismountPet(); + if (room == null) { return; } - // someone is already on it - if (rideablePet.getRider() != null) - return; + Pet pet = room.getRoomUnitManager().getRoomPetById(petId); - // check if able to ride - if (!rideablePet.anyoneCanRide() && habbo.getHabboInfo().getId() != rideablePet.getUserId()) + if (!(pet instanceof RideablePet rideablePet)) { return; + } - List availableTiles = room.getLayout().getWalkableTilesAround(pet.getRoomUnit().getCurrentLocation()); + if (habbo.getRoomUnit().isRiding()) { + boolean mountAnotherPet = petId != habbo.getRoomUnit().getRidingPet().getId(); + habbo.getRoomUnit().dismountPet(false); + + if(!mountAnotherPet) { + return; + } + } + + if (rideablePet.getRider() != null) { + return; + } + + 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().walkTo(goalTile); + habbo.getRoomUnit().setRideLocked(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/MovePetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MovePetEvent.java index 3a1337e8..9f8b0342 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MovePetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/MovePetEvent.java @@ -3,18 +3,19 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; public class MovePetEvent extends MessageHandler { @Override public void handle() { - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(this.packet.readInt()); + int petId = this.packet.readInt(); + Pet pet = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId); if (pet != null) { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - if (room != null && room.hasRights(this.client.getHabbo())) { + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + if (room != null && room.getRoomRightsManager().hasRights(this.client.getHabbo())) { if (pet.getRoomUnit() != null) { int x = this.packet.readInt(); int y = this.packet.readInt(); @@ -23,12 +24,10 @@ public class MovePetEvent extends MessageHandler { if (tile != null) { pet.getRoomUnit().setLocation(tile); - pet.getRoomUnit().setPreviousLocation(tile); - pet.getRoomUnit().setZ(tile.getZ()); - pet.getRoomUnit().setRotation(RoomUserRotation.fromValue(this.packet.readInt())); - pet.getRoomUnit().setPreviousLocationZ(pet.getRoomUnit().getZ()); + pet.getRoomUnit().setCurrentZ(tile.getZ()); + pet.getRoomUnit().setRotation(RoomRotation.fromValue(this.packet.readInt())); room.sendComposer(new UserUpdateComposer(pet.getRoomUnit()).compose()); - pet.setNeedsUpdate(true); + pet.setSqlUpdateNeeded(true); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java index 0e001ca5..e82a68e8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/OpenPetPackageEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.catalog.PurchaseErrorMessageComposer; import com.eu.habbo.messages.outgoing.rooms.HeightMapUpdateMessageComposer; @@ -18,11 +18,11 @@ public class OpenPetPackageEvent extends MessageHandler { int itemId = this.packet.readInt(); String name = this.packet.readString(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - HabboItem item = room.getHabboItem(itemId); - if (item != null && item.getUserId() == this.client.getHabbo().getHabboInfo().getId()) { + RoomItem item = room.getRoomItemManager().getRoomItemById(itemId); + if (item != null && item.getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId()) { if (!name.matches("^[a-zA-Z0-9]*$")) { this.client.sendResponse(new PerkAllowancesComposer(itemId, PerkAllowancesComposer.CONTAINS_INVALID_CHARS, name.replaceAll("^[a-zA-Z0-9]*$", ""))); return; @@ -55,18 +55,18 @@ public class OpenPetPackageEvent extends MessageHandler { } if (pet != null) { - room.placePet(pet, item.getX(), item.getY(), item.getZ()); + room.getRoomUnitManager().placePet(pet, room, item.getCurrentPosition().getX(), item.getCurrentPosition().getY(), item.getCurrentZ()); pet.setUserId(this.client.getHabbo().getHabboInfo().getId()); - pet.setNeedsUpdate(true); - pet.getRoomUnit().setLocation(room.getLayout().getTile(item.getX(), item.getY())); - pet.getRoomUnit().setZ(item.getZ()); + pet.setSqlUpdateNeeded(true); + pet.getRoomUnit().setLocation(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); + pet.getRoomUnit().setCurrentZ(item.getCurrentZ()); Emulator.getThreading().run(new QueryDeleteHabboItem(item.getId())); - room.removeHabboItem(item); + room.getRoomItemManager().removeRoomItem(item); room.sendComposer(new RemoveFloorItemComposer(item).compose()); - RoomTile tile = room.getLayout().getTile(item.getX(), item.getY()); - room.updateTile(room.getLayout().getTile(item.getX(), item.getY())); + RoomTile tile = room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()); + room.updateTile(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY())); room.sendComposer(new HeightMapUpdateMessageComposer(tile.getX(), tile.getY(), tile.getZ(), tile.relativeHeight()).compose()); - item.setUserId(0); + item.setOwnerInfo(null); } else { this.client.sendResponse(new PurchaseErrorMessageComposer(PurchaseErrorMessageComposer.SERVER_ERROR)); } 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 e99af933..fa9df07b 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 @@ -3,7 +3,11 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.*; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.PetPlacingErrorComposer; import com.eu.habbo.messages.outgoing.inventory.PetRemovedFromInventoryComposer; @@ -12,14 +16,17 @@ import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; public class PlacePetEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + //TODO Improve This + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId() && !room.isAllowPets() && !(this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasRight(Permission.ACC_PLACEFURNI))) { - this.client.sendResponse(new PetPlacingErrorComposer(PetPlacingErrorComposer.ROOM_ERROR_PETS_FORBIDDEN_IN_FLAT)); - return; + if (this.client.getHabbo().getHabboInfo().getId() != room.getRoomInfo().getOwnerInfo().getId()) { + if (!room.getRoomInfo().isAllowPets() && !(this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasPermissionRight(Permission.ACC_PLACEFURNI))) { + this.client.sendResponse(new PetPlacingErrorComposer(PetPlacingErrorComposer.ROOM_ERROR_PETS_FORBIDDEN_IN_FLAT)); + return; + } } int petId = this.packet.readInt(); @@ -29,7 +36,7 @@ public class PlacePetEvent extends MessageHandler { if (pet == null) { return; } - if (room.getCurrentPets().size() >= Room.MAXIMUM_PETS && !this.client.getHabbo().hasRight(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; } @@ -38,11 +45,11 @@ public class PlacePetEvent extends MessageHandler { int y = this.packet.readInt(); RoomTile tile; - RoomTile playerTile = this.client.getHabbo().getRoomUnit().getCurrentLocation(); + RoomTile playerTile = this.client.getHabbo().getRoomUnit().getCurrentPosition(); - if ((x == 0 && y == 0) || !room.isOwner(this.client.getHabbo())) { + if ((x == 0 && y == 0) || !room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { //Place the pet in front of the player. - tile = room.getLayout().getTileInFront(this.client.getHabbo().getRoomUnit().getCurrentLocation(), this.client.getHabbo().getRoomUnit().getBodyRotation().getValue()); + tile = room.getLayout().getTileInFront(this.client.getHabbo().getRoomUnit().getCurrentPosition(), this.client.getHabbo().getRoomUnit().getBodyRotation().getValue()); if (tile == null || !tile.isWalkable()) { this.client.sendResponse(new PetPlacingErrorComposer(PetPlacingErrorComposer.ROOM_ERROR_PETS_NO_FREE_TILES)); @@ -66,26 +73,31 @@ public class PlacePetEvent extends MessageHandler { return; } + //TODO REMOVE THIS pet.setRoom(room); - RoomUnit roomUnit = pet.getRoomUnit(); - if (roomUnit == null) { - roomUnit = new RoomUnit(); - } + RoomPet roomPet = pet.getRoomUnit(); - roomUnit.setPathFinderRoom(room); + roomPet.setRoom(room); + + roomPet.setLocation(tile); + roomPet.setCurrentZ(tile.getStackHeight()); + + roomPet.addStatus(RoomUnitStatus.SIT, "0"); + + //TODO I dont think I need this anymore + roomPet.setRoomUnitType(RoomUnitType.PET); - roomUnit.setLocation(tile); - roomUnit.setZ(tile.getStackHeight()); - roomUnit.setStatus(RoomUnitStatus.SIT, "0"); - roomUnit.setRoomUnitType(RoomUnitType.PET); if (playerTile != null) { - roomUnit.lookAtPoint(playerTile); + roomPet.lookAtPoint(playerTile); } - pet.setRoomUnit(roomUnit); - room.addPet(pet); - pet.setNeedsUpdate(true); + + room.getRoomUnitManager().addRoomUnit(pet); + + //This to update room on DB + pet.setSqlUpdateNeeded(true); Emulator.getThreading().run(pet); + room.sendComposer(new RoomPetComposer(pet).compose()); this.client.getHabbo().getInventory().getPetsComponent().removePet(pet); this.client.sendResponse(new PetRemovedFromInventoryComposer(pet)); 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 3ed3c6a4..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 @@ -15,23 +15,23 @@ public class RemovePetFromFlatEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - Pet pet = room.getPet(petId); + Pet pet = room.getRoomUnitManager().getRoomPetById(petId); if (pet != null) { - if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId() || room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { - if (!this.client.getHabbo().hasRight(Permission.ACC_UNLIMITED_PETS) && this.client.getHabbo().getInventory().getPetsComponent().getPets().size() >= PetManager.MAXIMUM_PET_INVENTORY_SIZE) { + if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId() || room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_UNLIMITED_PETS) && this.client.getHabbo().getInventory().getPetsComponent().getPets().size() >= PetManager.MAXIMUM_PET_INVENTORY_SIZE) { this.client.getHabbo().alert(Emulator.getTexts().getValue("error.pets.max.inventory").replace("%amount%", PetManager.MAXIMUM_PET_INVENTORY_SIZE + "")); return; } if (pet instanceof RideablePet rideablePet) { if (rideablePet.getRider() != null) { - rideablePet.getRider().getHabboInfo().dismountPet(true); + rideablePet.getRider().getRoomUnit().dismountPet(true); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemoveSaddleFromPetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemoveSaddleFromPetEvent.java index 51fe2603..c0030713 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemoveSaddleFromPetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RemoveSaddleFromPetEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.pets.HorsePet; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; @@ -23,8 +23,9 @@ public class RemoveSaddleFromPetEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - Pet pet = room.getPet(this.packet.readInt()); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); + int petId = this.packet.readInt(); + Pet pet = room.getRoomUnitManager().getRoomPetById(petId); if (!(pet instanceof HorsePet horse) || pet.getUserId() != this.client.getHabbo().getHabboInfo().getId()) return; @@ -52,11 +53,11 @@ public class RemoveSaddleFromPetEvent extends MessageHandler { if (saddleItem == null) return; horse.hasSaddle(false); - horse.setNeedsUpdate(true); + horse.setSqlUpdateNeeded(true); Emulator.getThreading().run(pet); - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new PetFigureUpdateComposer(horse).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new PetFigureUpdateComposer(horse).compose()); - HabboItem saddle = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), saddleItem, 0, 0, ""); + RoomItem saddle = Emulator.getGameEnvironment().getItemManager().createItem(this.client.getHabbo().getHabboInfo().getId(), saddleItem, 0, 0, ""); this.client.getHabbo().getInventory().getItemsComponent().addItem(saddle); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java index 23ea7f00..76ef0283 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/RespectPetEvent.java @@ -3,11 +3,11 @@ package com.eu.habbo.messages.incoming.rooms.pets; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.pets.MonsterplantPet; import com.eu.habbo.habbohotel.pets.Pet; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; +import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.messages.incoming.MessageHandler; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import java.util.ArrayList; import java.util.List; @@ -21,10 +21,10 @@ public class RespectPetEvent extends MessageHandler { final Habbo habbo = this.client.getHabbo(); if (habbo == null) { return; } - final Room room = habbo.getHabboInfo().getCurrentRoom(); + final Room room = habbo.getRoomUnit().getRoom(); if (room == null) { return; } - final Pet pet = room.getPet(petId); + final Pet pet = room.getRoomUnitManager().getRoomPetById(petId); if (pet == null) { return; } if (habbo.getHabboStats().getPetRespectPointsToGive() > 0 || pet instanceof MonsterplantPet) { @@ -35,9 +35,9 @@ public class RespectPetEvent extends MessageHandler { Emulator.getThreading().run(pet); }); - RoomTile tile = habbo.getRoomUnit().getClosestAdjacentTile(pet.getRoomUnit().getX(), pet.getRoomUnit().getY(), true); + RoomTile tile = habbo.getRoomUnit().getClosestAdjacentTile(pet.getRoomUnit().getCurrentPosition().getX(), pet.getRoomUnit().getCurrentPosition().getY(), true); if(tile != null) { - habbo.getRoomUnit().setGoalLocation(tile); + habbo.getRoomUnit().walkTo(tile); } Emulator.getThreading().run(new RoomUnitWalkToLocation(habbo.getRoomUnit(), tile, room, tasks, tasks)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetBreedingPermissionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetBreedingPermissionEvent.java index 45633ef4..be729dab 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetBreedingPermissionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/pets/TogglePetBreedingPermissionEvent.java @@ -9,7 +9,7 @@ public class TogglePetBreedingPermissionEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + Pet pet = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId); if (pet != null) { if (pet.getUserId() == this.client.getHabbo().getHabboInfo().getId()) { 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 ac7087ef..7de47b2e 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 @@ -11,19 +11,19 @@ public class TogglePetRidingPermissionEvent extends MessageHandler { public void handle() { int petId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - Pet pet = this.client.getHabbo().getHabboInfo().getCurrentRoom().getPet(petId); + Pet pet = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomPetById(petId); if (pet == null || pet.getUserId() != this.client.getHabbo().getHabboInfo().getId() || !(pet instanceof RideablePet rideablePet)) return; rideablePet.setAnyoneCanRide(!rideablePet.anyoneCanRide()); - rideablePet.setNeedsUpdate(true); + rideablePet.setSqlUpdateNeeded(true); if (!rideablePet.anyoneCanRide() && rideablePet.getRider() != null && rideablePet.getRider().getHabboInfo().getId() != this.client.getHabbo().getHabboInfo().getId()) { - rideablePet.getRider().getHabboInfo().dismountPet(); + rideablePet.getRider().getRoomUnit().dismountPet(false); } if (pet instanceof HorsePet) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/EditEventEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/EditEventEvent.java index f6a10972..177e3b06 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/EditEventEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/EditEventEvent.java @@ -17,9 +17,9 @@ public class EditEventEvent extends MessageHandler { String promotionName = this.packet.readString(); String promotionDescription = this.packet.readString(); - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(id); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(id); - if (room == null || room.getOwnerId() != this.client.getHabbo().getHabboInfo().getId() || !this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room == null || room.getRoomInfo().getOwnerInfo().getId() != this.client.getHabbo().getHabboInfo().getId() || !this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/PurchaseRoomAdEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/PurchaseRoomAdEvent.java index e622e071..b1797e73 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/PurchaseRoomAdEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/promotions/PurchaseRoomAdEvent.java @@ -36,9 +36,9 @@ public class PurchaseRoomAdEvent extends MessageHandler { CatalogItem item = page.getCatalogItem(itemId); if (item != null) { if (this.client.getHabbo().getHabboInfo().canBuy(item)) { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); - if (!(room.isOwner(this.client.getHabbo()) || room.hasRights(this.client.getHabbo()) || room.getGuildRightLevel(this.client.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) { + if (!(room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || room.getRoomRightsManager().hasRights(this.client.getHabbo()) || room.getGuildRightLevel(this.client.getHabbo()).equals(RoomRightLevels.GUILD_ADMIN))) { return; } @@ -49,11 +49,11 @@ public class PurchaseRoomAdEvent extends MessageHandler { } if (room.isPromoted()) { - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_CREDITS)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_CREDITS)) { this.client.getHabbo().giveCredits(-item.getCredits()); } - if (!this.client.getHabbo().hasRight(Permission.ACC_INFINITE_POINTS)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_INFINITE_POINTS)) { this.client.getHabbo().givePoints(item.getPointsType(), -item.getPoints()); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AssignRightsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AssignRightsEvent.java index c905c207..9198050c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AssignRightsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AssignRightsEvent.java @@ -11,25 +11,26 @@ import com.eu.habbo.plugin.events.users.UserRightsGivenEvent; public class AssignRightsEvent extends MessageHandler { @Override public void handle() { - int userId = this.packet.readInt(); + int targetId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null) + if (room == null) { return; + } - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { - Habbo target = room.getHabbo(userId); + if (room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { + Habbo target = room.getRoomUnitManager().getRoomHabboById(targetId); if (target != null) { if (!Emulator.getPluginManager().fireEvent(new UserRightsGivenEvent(this.client.getHabbo(), target)).isCancelled()) { - room.giveRights(target); + room.getRoomRightsManager().giveRights(target); } } else { - MessengerBuddy buddy = this.client.getHabbo().getMessenger().getFriend(userId); + MessengerBuddy buddy = this.client.getHabbo().getMessenger().getFriend(targetId); if (buddy != null) { - room.giveRights(userId); + room.getRoomRightsManager().giveRights(buddy); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AvatarExpressionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AvatarExpressionEvent.java index c3dffc03..cb01fb1c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AvatarExpressionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/AvatarExpressionEvent.java @@ -11,7 +11,7 @@ import com.eu.habbo.plugin.events.users.UserIdleEvent; public class AvatarExpressionEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) { return; } @@ -21,7 +21,7 @@ public class AvatarExpressionEvent extends MessageHandler { if (this.client.getHabbo().getRoomUnit().getCacheable().get("control") != null) { habbo = (Habbo) this.client.getHabbo().getRoomUnit().getCacheable().get("control"); - if (habbo.getHabboInfo().getCurrentRoom() != room) { + if (habbo.getRoomUnit().getRoom() != room) { habbo.getRoomUnit().getCacheable().remove("controller"); this.client.getHabbo().getRoomUnit().getCacheable().remove("control"); habbo = this.client.getHabbo(); @@ -36,9 +36,9 @@ public class AvatarExpressionEvent extends MessageHandler { if (!event.isCancelled()) { if (event.isIdle()) { - room.idle(habbo); + habbo.getRoomUnit().idle(); } else { - room.unIdle(habbo); + habbo.getRoomUnit().unIdle(); } } } else { @@ -46,7 +46,7 @@ public class AvatarExpressionEvent extends MessageHandler { Emulator.getPluginManager().fireEvent(event); if (!event.isCancelled() && !event.isIdle()) { - room.unIdle(habbo); + habbo.getRoomUnit().unIdle(); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/CancelTypingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/CancelTypingEvent.java index dc309636..c98ddddc 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/CancelTypingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/CancelTypingEvent.java @@ -6,7 +6,7 @@ import com.eu.habbo.messages.outgoing.rooms.users.UserTypingMessageComposer; public class CancelTypingEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) { + if (this.client.getHabbo().getRoomUnit().getRoom() == null) { return; } @@ -14,6 +14,6 @@ public class CancelTypingEvent extends MessageHandler { return; } - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserTypingMessageComposer(this.client.getHabbo().getRoomUnit(), false).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserTypingMessageComposer(this.client.getHabbo().getRoomUnit(), false).compose()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChangePostureEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChangePostureEvent.java index f71580fa..94fac702 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChangePostureEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChangePostureEvent.java @@ -7,18 +7,19 @@ import com.eu.habbo.plugin.events.users.UserIdleEvent; public class ChangePostureEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { if (this.client.getHabbo().getRoomUnit().isWalking()) { this.client.getHabbo().getRoomUnit().stopWalking(); } - this.client.getHabbo().getHabboInfo().getCurrentRoom().makeSit(this.client.getHabbo()); + + this.client.getHabbo().getRoomUnit().makeSit(); UserIdleEvent event = new UserIdleEvent(this.client.getHabbo(), UserIdleEvent.IdleReason.WALKED, false); Emulator.getPluginManager().fireEvent(event); if (!event.isCancelled()) { if (!event.isIdle()) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(this.client.getHabbo()); + this.client.getHabbo().getRoomUnit().unIdle(); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChatEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChatEvent.java index 8a095856..8d2b7028 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChatEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ChatEvent.java @@ -16,7 +16,7 @@ public class ChatEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DanceEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DanceEvent.java index 58dec5ae..15c8834c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DanceEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DanceEvent.java @@ -10,7 +10,7 @@ import com.eu.habbo.plugin.events.users.UserIdleEvent; public class DanceEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; int danceId = this.packet.readInt(); @@ -22,7 +22,7 @@ public class DanceEvent extends MessageHandler { if (this.client.getHabbo().getRoomUnit().getCacheable().get("control") != null) { habbo = (Habbo) this.client.getHabbo().getRoomUnit().getCacheable().get("control"); - if (habbo.getHabboInfo().getCurrentRoom() != this.client.getHabbo().getHabboInfo().getCurrentRoom()) { + if (habbo.getRoomUnit().getRoom() != this.client.getHabbo().getRoomUnit().getRoom()) { habbo.getRoomUnit().getCacheable().remove("controller"); this.client.getHabbo().getRoomUnit().getCacheable().remove("control"); habbo = this.client.getHabbo(); @@ -36,11 +36,11 @@ public class DanceEvent extends MessageHandler { if (!event.isCancelled()) { if (!event.isIdle()) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(habbo); + this.client.getHabbo().getRoomUnit().unIdle(); } } - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new DanceMessageComposer(habbo.getRoomUnit()).compose()); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DropCarryItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DropCarryItemEvent.java index 5f87c859..83b4d64d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DropCarryItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/DropCarryItemEvent.java @@ -7,10 +7,10 @@ import com.eu.habbo.messages.outgoing.rooms.users.CarryObjectMessageComposer; public class DropCarryItemEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); this.client.getHabbo().getRoomUnit().setHandItem(0); if (room != null) { - room.unIdle(this.client.getHabbo()); + this.client.getHabbo().getRoomUnit().unIdle(); room.sendComposer(new CarryObjectMessageComposer(this.client.getHabbo().getRoomUnit()).compose()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/GetUserTagsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/GetUserTagsEvent.java index 0e485506..7283013c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/GetUserTagsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/GetUserTagsEvent.java @@ -9,8 +9,8 @@ public class GetUserTagsEvent extends MessageHandler { public void handle() { int roomUnitId = this.packet.readInt(); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - Habbo habbo = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabboByRoomUnitId(roomUnitId); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + Habbo habbo = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getHabboByVirtualId(roomUnitId); if (habbo != null) { this.client.sendResponse(new UserTagsMessageComposer(habbo)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreUserEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreUserEvent.java index 9dab2387..1897dfa8 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreUserEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/IgnoreUserEvent.java @@ -10,12 +10,12 @@ import com.eu.habbo.messages.outgoing.rooms.users.IgnoreResultMessageComposer; public class IgnoreUserEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { String username = this.packet.readString(); - Habbo habbo = room.getHabbo(username); + Habbo habbo = room.getRoomUnitManager().getRoomHabboByUsername(username); if (habbo != null) { if (habbo == this.client.getHabbo()) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/LookToEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/LookToEvent.java index 819463d3..d49b8b54 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/LookToEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/LookToEvent.java @@ -2,15 +2,15 @@ package com.eu.habbo.messages.incoming.rooms.users; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.incoming.MessageHandler; public class LookToEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; @@ -19,39 +19,38 @@ public class LookToEvent extends MessageHandler { if (habbo.getRoomUnit().getCacheable().get("control") != null) { habbo = (Habbo) this.client.getHabbo().getRoomUnit().getCacheable().get("control"); - if (habbo.getHabboInfo().getCurrentRoom() != this.client.getHabbo().getHabboInfo().getCurrentRoom()) { + if (habbo.getRoomUnit().getRoom() != this.client.getHabbo().getRoomUnit().getRoom()) { habbo.getRoomUnit().getCacheable().remove("controller"); this.client.getHabbo().getRoomUnit().getCacheable().remove("control"); habbo = this.client.getHabbo(); } } - RoomUnit roomUnit = habbo.getRoomUnit(); + RoomHabbo roomHabbo = habbo.getRoomUnit(); - if (!roomUnit.canWalk()) + if (!roomHabbo.isCanWalk()) return; - if (roomUnit.isWalking() || roomUnit.hasStatus(RoomUnitStatus.MOVE)) + if (roomHabbo.isWalking() || roomHabbo.hasStatus(RoomUnitStatus.MOVE)) return; - if (roomUnit.isCmdLay() || roomUnit.hasStatus(RoomUnitStatus.LAY)) + if (roomHabbo.isCmdLayEnabled() || roomHabbo.hasStatus(RoomUnitStatus.LAY)) return; - if (roomUnit.isIdle()) + if (roomHabbo.isIdle()) return; int x = this.packet.readInt(); int y = this.packet.readInt(); - if (x == roomUnit.getX() && y == roomUnit.getY()) - return; + if (x == roomHabbo.getCurrentPosition().getX()) { + if (y == roomHabbo.getCurrentPosition().getY()) return; + } - RoomTile tile = habbo.getHabboInfo().getCurrentRoom().getLayout().getTile((short) x, (short) y); + RoomTile tile = habbo.getRoomUnit().getRoom().getLayout().getTile((short) x, (short) y); if (tile != null) { - roomUnit.lookAtPoint(tile); - roomUnit.statusUpdate(true); - //room.sendComposer(new RoomUserStatusComposer(roomUnit).compose()); + roomHabbo.lookAtPoint(tile); } } } 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 88c83947..499fafa5 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 @@ -1,23 +1,14 @@ package com.eu.habbo.messages.incoming.rooms.users; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.pets.PetTasks; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.rooms.users.RoomUnitOnRollerComposer; -import com.eu.habbo.plugin.events.users.UserIdleEvent; -import gnu.trove.set.hash.THashSet; import lombok.extern.slf4j.Slf4j; @Slf4j public class MoveAvatarEvent extends MessageHandler { - - @Override public int getRatelimit() { return 500; @@ -25,130 +16,54 @@ public class MoveAvatarEvent extends MessageHandler { @Override public void handle() throws Exception { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - int x = this.packet.readInt(); // Position X - int y = this.packet.readInt(); // Position Y + int x = this.packet.readInt(); + int y = this.packet.readInt(); - // Get Habbo object - Habbo habbo = this.client.getHabbo(); + Habbo habbo = this.client.getHabbo(); - // Get Room Habbo object (Unique GUID?) - RoomUnit roomUnit = this.client.getHabbo().getRoomUnit(); + if(habbo == null) { + return; + } - // If habbo is teleporting, dont calculate a new path - if (roomUnit.isTeleporting()) + RoomHabbo roomHabbo = this.client.getHabbo().getRoomUnit(); + + if(roomHabbo == null) { + return; + } + + Room room = habbo.getRoomUnit().getRoom(); + + if (room == null || room.getLayout() == null) { + return; + } + + if (roomHabbo.getCurrentPosition().equals(x,y) && roomHabbo.isAtGoal()) { + return; + } + + if (roomHabbo.getCacheable().get("control") != null) { + habbo = (Habbo) roomHabbo.getCacheable().get("control"); + + if (habbo.getRoomUnit().getRoom() != room) { + habbo.getRoomUnit().getCacheable().remove("controller"); + this.client.getHabbo().getRoomUnit().getCacheable().remove("control"); + habbo = this.client.getHabbo(); + } + } + + roomHabbo = habbo.getRoomUnit(); + + if (roomHabbo != null && roomHabbo.isInRoom() && roomHabbo.isCanWalk()) { + RoomTile tile = room.getLayout().getTile((short) x, (short) y); + + if (tile == null) { return; - - // If habbo is being kicked dont calculate a new path - if (roomUnit.isKicked()) - return; - - // If habbo has control (im assuming admin, do something else, but we dont care about this part here) - if (roomUnit.getCacheable().get("control") != null) { - habbo = (Habbo) roomUnit.getCacheable().get("control"); - - if (habbo.getHabboInfo().getCurrentRoom() != this.client.getHabbo().getHabboInfo().getCurrentRoom()) { - habbo.getRoomUnit().getCacheable().remove("controller"); - this.client.getHabbo().getRoomUnit().getCacheable().remove("control"); - habbo = this.client.getHabbo(); - } } - // Get room unit? - roomUnit = habbo.getRoomUnit(); + //STANKMAN EASTER EGG + roomHabbo.setTemporalFastWalkEnabled(roomHabbo.getTargetPosition() != null && roomHabbo.getTargetPosition().equals(tile)); - // Get the room the habbo is in - Room room = habbo.getHabboInfo().getCurrentRoom(); - - // If our room unit is not nullptr and we are in a room and we can walk, then calculate a new path - if (roomUnit != null && roomUnit.isInRoom() && roomUnit.canWalk()) { - // If we are not teleporting calcualte a new path - if (!roomUnit.isCmdTeleport()) { - // Don't calculate a new path if we are on a horse - if (habbo.getHabboInfo().getRiding() != null && habbo.getHabboInfo().getRiding().getTask() != null && habbo.getHabboInfo().getRiding().getTask().equals(PetTasks.JUMP)) - return; - - // Don't calulcate a new path if are already at the end position - if (x == roomUnit.getX() && y == roomUnit.getY()) - return; - - if (room == null || room.getLayout() == null) - return; - - // Reset idle status - if (roomUnit.isIdle()) { - UserIdleEvent event = new UserIdleEvent(habbo, UserIdleEvent.IdleReason.WALKED, false); - Emulator.getPluginManager().fireEvent(event); - - if (!event.isCancelled()) { - if (!event.isIdle()) { - if (roomUnit.getRoom() != null) roomUnit.getRoom().unIdle(habbo); - roomUnit.resetIdleTimer(); - } - } - } - - // Get room height map - RoomTile tile = room.getLayout().getTile((short) x, (short) y); - - // this should never happen, if it does it would be a design flaw - if (tile == null) { - return; - } - - // Don't care - if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY)) { - if (room.getLayout().getTilesInFront(habbo.getRoomUnit().getCurrentLocation(), habbo.getRoomUnit().getBodyRotation().getValue(), 2).contains(tile)) - return; - } - if (room.canLayAt(tile.getX(), tile.getY())) { - HabboItem bed = room.getTopItemAt(tile.getX(), tile.getY()); - - if (bed != null && bed.getBaseItem().allowLay()) { - room.getLayout().getTile(bed.getX(), bed.getY()); - RoomTile pillow = switch (bed.getRotation()) { - case 0, 4 -> room.getLayout().getTile((short) x, bed.getY()); - case 2, 8 -> room.getLayout().getTile(bed.getX(), (short) y); - default -> room.getLayout().getTile(bed.getX(), bed.getY()); - }; - - if (pillow != null && room.canLayAt(pillow.getX(), pillow.getY())) { - roomUnit.setGoalLocation(pillow); - return; - } - } - } - - THashSet items = room.getItemsAt(tile); - - if (items.size() > 0) { - for (HabboItem item : items) { - RoomTile overriddenTile = item.getOverrideGoalTile(roomUnit, room, tile); - - if (overriddenTile == null) { - return; // null cancels the entire event - } - - if (!overriddenTile.equals(tile) && overriddenTile.isWalkable()) { - tile = overriddenTile; - break; - } - } - } - - // This is where we set the end location and begin finding a path - if (tile.isWalkable() || room.canSitOrLayAt(tile.getX(), tile.getY())) { - roomUnit.setGoalLocation(tile); - } - } else { - RoomTile t = room.getLayout().getTile((short) x, (short) y); - room.sendComposer(new RoomUnitOnRollerComposer(roomUnit, t, room).compose()); - - if (habbo.getHabboInfo().getRiding() != null) { - room.sendComposer(new RoomUnitOnRollerComposer(habbo.getHabboInfo().getRiding().getRoomUnit(), t, room).compose()); - } - } - } + roomHabbo.walkTo(tile); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/PassCarryItemEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/PassCarryItemEvent.java index ef606c0b..a817be2d 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/PassCarryItemEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/PassCarryItemEvent.java @@ -15,15 +15,15 @@ public class PassCarryItemEvent extends MessageHandler { public void handle() { int userId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - Habbo target = room.getHabbo(userId); + Habbo target = room.getRoomUnitManager().getRoomHabboById(userId); if (target != null) { List executable = new ArrayList<>(); executable.add(new HabboGiveHandItemToHabbo(this.client.getHabbo(), target)); - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.client.getHabbo().getRoomUnit(), target.getRoomUnit(), this.client.getHabbo().getHabboInfo().getCurrentRoom(), executable, executable)); + Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.client.getHabbo().getRoomUnit(), target.getRoomUnit(), this.client.getHabbo().getRoomUnit().getRoom(), executable, executable)); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RemoveRightsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RemoveRightsEvent.java index 3399e52e..43adff72 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RemoveRightsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RemoveRightsEvent.java @@ -9,16 +9,16 @@ public class RemoveRightsEvent extends MessageHandler { public void handle() { int amount = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; - if (room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER)) { + if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) { for (int i = 0; i < amount; i++) { int userId = this.packet.readInt(); - room.removeRights(userId); + room.getRoomRightsManager().removeRights(userId); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RespectUserEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RespectUserEvent.java index e0211d32..178465a9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RespectUserEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RespectUserEvent.java @@ -14,7 +14,7 @@ public class RespectUserEvent extends MessageHandler { return; } if (this.client.getHabbo().getHabboStats().getRespectPointsToGive() > 0) { - Habbo target = this.client.getHabbo().getHabboInfo().getCurrentRoom().getHabbo(userId); + Habbo target = this.client.getHabbo().getRoomUnit().getRoom().getRoomUnitManager().getRoomHabboById(userId); if (Emulator.getPluginManager().isRegistered(UserRespectedEvent.class, false)) { if (Emulator.getPluginManager().fireEvent(new UserRespectedEvent(target, this.client.getHabbo())).isCancelled()) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserKickEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserKickEvent.java index 4dac9cb0..a6689aa9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserKickEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserKickEvent.java @@ -14,24 +14,24 @@ import com.eu.habbo.plugin.events.users.UserKickEvent; public class RoomUserKickEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room == null) return; int userId = this.packet.readInt(); - Habbo target = room.getHabbo(userId); + Habbo target = room.getRoomUnitManager().getRoomHabboById(userId); if (target == null) return; - if (target.hasRight(Permission.ACC_UNKICKABLE)) { + if (target.hasPermissionRight(Permission.ACC_UNKICKABLE)) { this.client.sendResponse(new WhisperMessageComposer(new RoomChatMessage(Emulator.getTexts().getValue("commands.error.cmd_kick.unkickable").replace("%username%", target.getHabboInfo().getUsername()), this.client.getHabbo(), this.client.getHabbo(), RoomChatMessageBubbles.ALERT))); return; } - if (room.isOwner(target)) { + if (room.getRoomInfo().isRoomOwner(target)) { return; } @@ -41,8 +41,8 @@ public class RoomUserKickEvent extends MessageHandler { if (event.isCancelled()) return; - if (room.hasRights(this.client.getHabbo()) || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasRight(Permission.ACC_AMBASSADOR)) { - if (target.hasRight(Permission.ACC_UNKICKABLE)) return; + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasPermissionRight(Permission.ACC_AMBASSADOR)) { + if (target.hasPermissionRight(Permission.ACC_UNKICKABLE)) return; room.kickHabbo(target, true); AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("SelfModKickSeen")); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserMuteEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserMuteEvent.java index 3b737e69..b238cdad 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserMuteEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/RoomUserMuteEvent.java @@ -15,11 +15,11 @@ public class RoomUserMuteEvent extends MessageHandler { int roomId = this.packet.readInt(); int minutes = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { - if (room.hasRights(this.client.getHabbo()) || this.client.getHabbo().hasCommand("cmd_mute") || this.client.getHabbo().hasRight(Permission.ACC_AMBASSADOR)) { - Habbo habbo = room.getHabbo(userId); + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || this.client.getHabbo().canExecuteCommand("cmd_mute") || this.client.getHabbo().hasPermissionRight(Permission.ACC_AMBASSADOR)) { + Habbo habbo = room.getRoomUnitManager().getRoomHabboById(userId); if (habbo != null) { room.muteHabbo(habbo, minutes); diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ShoutEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ShoutEvent.java index 40c2b46f..569495b2 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ShoutEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/ShoutEvent.java @@ -13,7 +13,7 @@ public class ShoutEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; if (!this.client.getHabbo().getHabboStats().allowTalk()) @@ -27,7 +27,7 @@ public class ShoutEvent extends MessageHandler { return; } - this.client.getHabbo().getHabboInfo().getCurrentRoom().talk(this.client.getHabbo(), message, RoomChatType.SHOUT); + this.client.getHabbo().getRoomUnit().getRoom().talk(this.client.getHabbo(), message, RoomChatType.SHOUT); if (!message.isCommand) { if (RoomChatMessage.SAVE_ROOM_CHATS) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/SignEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/SignEvent.java index 9e38ba84..55119bf7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/SignEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/SignEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionVoteCounter; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.plugin.events.users.UserSignEvent; @@ -13,20 +13,21 @@ public class SignEvent extends MessageHandler { public void handle() { int signId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); - if (room == null) + if (room == null) { return; + } UserSignEvent event = new UserSignEvent(this.client.getHabbo(), signId); + if (!Emulator.getPluginManager().fireEvent(event).isCancelled()) { - this.client.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.SIGN, event.getSign() + ""); - this.client.getHabbo().getHabboInfo().getCurrentRoom().unIdle(this.client.getHabbo()); + this.client.getHabbo().getRoomUnit().addStatus(RoomUnitStatus.SIGN, String.valueOf(event.getSign())); + this.client.getHabbo().getRoomUnit().unIdle(); if(signId <= 10) { - int userId = this.client.getHabbo().getHabboInfo().getId(); - for (HabboItem item : room.getFloorItems()) { + for (RoomItem item : room.getRoomItemManager().getFloorItems().values()) { if (item instanceof InteractionVoteCounter) { ((InteractionVoteCounter)item).vote(room, userId, signId); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/StartTypingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/StartTypingEvent.java index deda8e53..f352f238 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/StartTypingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/StartTypingEvent.java @@ -6,7 +6,7 @@ import com.eu.habbo.messages.outgoing.rooms.users.UserTypingMessageComposer; public class StartTypingEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) { + if (this.client.getHabbo().getRoomUnit().getRoom() == null) { return; } @@ -14,6 +14,6 @@ public class StartTypingEvent extends MessageHandler { return; } - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserTypingMessageComposer(this.client.getHabbo().getRoomUnit(), true).compose()); + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserTypingMessageComposer(this.client.getHabbo().getRoomUnit(), true).compose()); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnbanUserFromRoomEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnbanUserFromRoomEvent.java index 3c1560f9..0741b6d0 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnbanUserFromRoomEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnbanUserFromRoomEvent.java @@ -10,10 +10,10 @@ public class UnbanUserFromRoomEvent extends MessageHandler { int userId = this.packet.readInt(); int roomId = this.packet.readInt(); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(roomId); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId); if (room != null) { - if (room.isOwner(this.client.getHabbo())) { + if (room.getRoomInfo().isRoomOwner(this.client.getHabbo())) { room.unbanHabbo(userId); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnignoreUserEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnignoreUserEvent.java index 81c3773b..bdc1b240 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnignoreUserEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/UnignoreUserEvent.java @@ -8,12 +8,12 @@ import com.eu.habbo.messages.outgoing.rooms.users.IgnoreResultMessageComposer; public class UnignoreUserEvent extends MessageHandler { @Override public void handle() { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { String username = this.packet.readString(); - Habbo habbo = room.getHabbo(username); + Habbo habbo = room.getRoomUnitManager().getRoomHabboByUsername(username); if (habbo != null) { if (habbo.getHabboStats().allowTalk()) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/WhisperEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/WhisperEvent.java index 910faaee..6a6fcd1c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/users/WhisperEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/users/WhisperEvent.java @@ -13,7 +13,7 @@ public class WhisperEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; RoomChatMessage chatMessage = new RoomChatMessage(this); @@ -26,7 +26,7 @@ public class WhisperEvent extends MessageHandler { return; } - this.client.getHabbo().getHabboInfo().getCurrentRoom().talk(this.client.getHabbo(), chatMessage, RoomChatType.WHISPER, true); + this.client.getHabbo().getRoomUnit().getRoom().talk(this.client.getHabbo(), chatMessage, RoomChatType.WHISPER, true); if (RoomChatMessage.SAVE_ROOM_CHATS) { Emulator.getThreading().run(chatMessage); diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/AcceptTradingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/AcceptTradingEvent.java index 85870b34..708facba 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/AcceptTradingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/AcceptTradingEvent.java @@ -9,10 +9,10 @@ public class AcceptTradingEvent extends MessageHandler { public void handle() { Habbo habbo = this.client.getHabbo(); - if (habbo == null || habbo.getHabboInfo() == null || habbo.getHabboInfo().getCurrentRoom() == null) + if (habbo == null || habbo.getHabboInfo() == null || habbo.getRoomUnit().getRoom() == null) return; - RoomTrade trade = habbo.getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(habbo); + RoomTrade trade = habbo.getRoomUnit().getRoom().getActiveTradeForHabbo(habbo); if (trade == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemToTradeEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemToTradeEvent.java index 233fdec7..f3c16d65 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemToTradeEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemToTradeEvent.java @@ -1,21 +1,21 @@ package com.eu.habbo.messages.incoming.trading; import com.eu.habbo.habbohotel.rooms.RoomTrade; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class AddItemToTradeEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - RoomTrade trade = this.client.getHabbo().getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(this.client.getHabbo()); + RoomTrade trade = this.client.getHabbo().getRoomUnit().getRoom().getActiveTradeForHabbo(this.client.getHabbo()); if (trade == null) return; - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); if (item == null || !item.getBaseItem().allowTrade()) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemsToTradeEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemsToTradeEvent.java index 716eff81..4adcc2d7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemsToTradeEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/AddItemsToTradeEvent.java @@ -1,26 +1,26 @@ package com.eu.habbo.messages.incoming.trading; import com.eu.habbo.habbohotel.rooms.RoomTrade; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import gnu.trove.set.hash.THashSet; public class AddItemsToTradeEvent extends MessageHandler { @Override public void handle() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() == null) + if (this.client.getHabbo().getRoomUnit().getRoom() == null) return; - RoomTrade trade = this.client.getHabbo().getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(this.client.getHabbo()); + RoomTrade trade = this.client.getHabbo().getRoomUnit().getRoom().getActiveTradeForHabbo(this.client.getHabbo()); if (trade == null) return; - THashSet items = new THashSet<>(); + THashSet items = new THashSet<>(); int count = this.packet.readInt(); for (int i = 0; i < count; i++) { - HabboItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); + RoomItem item = this.client.getHabbo().getInventory().getItemsComponent().getHabboItem(this.packet.readInt()); if (item != null && item.getBaseItem().allowTrade()) { items.add(item); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/ConfirmAcceptTradingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/ConfirmAcceptTradingEvent.java index c75d62bd..1a17b345 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/ConfirmAcceptTradingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/ConfirmAcceptTradingEvent.java @@ -8,7 +8,7 @@ public class ConfirmAcceptTradingEvent extends MessageHandler { @Override public void handle() { Habbo habbo = this.client.getHabbo(); - RoomTrade trade = habbo.getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(habbo); + RoomTrade trade = habbo.getRoomUnit().getRoom().getActiveTradeForHabbo(habbo); if (trade == null || !trade.getRoomTradeUserForHabbo(habbo).isAccepted()) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/OpenTradingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/OpenTradingEvent.java index b0661bdc..9973b33e 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/OpenTradingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/OpenTradingEvent.java @@ -16,19 +16,19 @@ public class OpenTradingEvent extends MessageHandler { this.client.getHabbo().getHabboStats().setLastTradeTimestamp(Emulator.getIntUnixTimestamp()); int userId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - if (userId >= 0 && userId != this.client.getHabbo().getRoomUnit().getId()) { - Habbo targetUser = room.getHabboByRoomUnitId(userId); + if (userId >= 0 && userId != this.client.getHabbo().getRoomUnit().getVirtualId()) { + Habbo targetUser = room.getRoomUnitManager().getHabboByVirtualId(userId); - boolean tradeAnywhere = this.client.getHabbo().hasRight(Permission.ACC_TRADE_ANYWHERE); + boolean tradeAnywhere = this.client.getHabbo().hasPermissionRight(Permission.ACC_TRADE_ANYWHERE); if (!RoomTrade.TRADING_ENABLED && !tradeAnywhere) { this.client.sendResponse(new TradingOpenFailedComposer(TradingOpenFailedComposer.HOTEL_TRADING_NOT_ALLOWED)); return; } - if ((room.getTradeMode() == 0 || (room.getTradeMode() == 1 && this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId())) && !tradeAnywhere) { + if ((room.getRoomInfo().getTradeMode() == 0 || (room.getRoomInfo().getTradeMode() == 1 && this.client.getHabbo().getHabboInfo().getId() != room.getRoomInfo().getOwnerInfo().getId())) && !tradeAnywhere) { this.client.sendResponse(new TradingOpenFailedComposer(TradingOpenFailedComposer.ROOM_TRADING_NOT_ALLOWED)); return; } diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/RemoveItemFromTradeEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/RemoveItemFromTradeEvent.java index ee8245f1..e3213a64 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/RemoveItemFromTradeEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/RemoveItemFromTradeEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.incoming.trading; import com.eu.habbo.habbohotel.rooms.RoomTrade; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; public class RemoveItemFromTradeEvent extends MessageHandler { @@ -9,9 +9,9 @@ public class RemoveItemFromTradeEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - RoomTrade trade = this.client.getHabbo().getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(this.client.getHabbo()); + RoomTrade trade = this.client.getHabbo().getRoomUnit().getRoom().getActiveTradeForHabbo(this.client.getHabbo()); if (trade != null) { - HabboItem item = trade.getRoomTradeUserForHabbo(this.client.getHabbo()).getItem(itemId); + RoomItem item = trade.getRoomTradeUserForHabbo(this.client.getHabbo()).getItem(itemId); if (!trade.getRoomTradeUserForHabbo(this.client.getHabbo()).isAccepted() && item != null) { trade.removeItem(this.client.getHabbo(), item); diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/TradingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/TradingEvent.java index a2fb005a..188da4d9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/TradingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/TradingEvent.java @@ -7,7 +7,7 @@ import com.eu.habbo.messages.incoming.MessageHandler; public abstract class TradingEvent extends MessageHandler { protected void stopTrade(Habbo habbo) { - Room room = habbo.getHabboInfo().getCurrentRoom(); + Room room = habbo.getRoomUnit().getRoom(); if (room == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/trading/UnacceptTradingEvent.java b/src/main/java/com/eu/habbo/messages/incoming/trading/UnacceptTradingEvent.java index ac788b39..d5d3db0c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/trading/UnacceptTradingEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/trading/UnacceptTradingEvent.java @@ -8,7 +8,7 @@ public class UnacceptTradingEvent extends MessageHandler { @Override public void handle() { Habbo habbo = this.client.getHabbo(); - RoomTrade trade = habbo.getHabboInfo().getCurrentRoom().getActiveTradeForHabbo(habbo); + RoomTrade trade = habbo.getRoomUnit().getRoom().getActiveTradeForHabbo(habbo); if (trade == null) return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/AvatarEffectSelectedEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/AvatarEffectSelectedEvent.java index 7146433a..03834112 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/AvatarEffectSelectedEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/AvatarEffectSelectedEvent.java @@ -14,8 +14,8 @@ public class AvatarEffectSelectedEvent extends MessageHandler { } else { this.client.getHabbo().getInventory().getEffectsComponent().setActivatedEffect(0); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().giveEffect(this.client.getHabbo().getRoomUnit(), 0, -1); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + this.client.getHabbo().getRoomUnit().giveEffect(0, -1); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/ChangeMottoEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/ChangeMottoEvent.java index 6d2405e5..aceeab5f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/ChangeMottoEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/ChangeMottoEvent.java @@ -21,8 +21,8 @@ public class ChangeMottoEvent extends MessageHandler { this.client.getHabbo().getHabboInfo().run(); } - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(this.client.getHabbo()).compose()); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(this.client.getHabbo()).compose()); } else { this.client.sendResponse(new UserChangeMessageComposer(this.client.getHabbo())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/ChangeUserNameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/ChangeUserNameEvent.java index 241ac1c9..0d24bd23 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/ChangeUserNameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/ChangeUserNameEvent.java @@ -1,12 +1,11 @@ package com.eu.habbo.messages.incoming.users; import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.rooms.users.ChangeUserNameResultMessageEvent; -import com.eu.habbo.habbohotel.achievements.AchievementManager; import com.eu.habbo.messages.outgoing.rooms.users.UserNameChangedMessageComposer; import com.eu.habbo.messages.outgoing.users.CheckUserNameResultMessageComposer; import com.eu.habbo.messages.outgoing.users.UserObjectComposer; @@ -41,7 +40,7 @@ public class ChangeUserNameEvent extends MessageHandler { } if (name.equals(this.client.getHabbo().getHabboStats().getChangeNameChecked())) { - HabboInfo habboInfo = HabboManager.getOfflineHabboInfo(name); + HabboInfo habboInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(name); if (habboInfo == null) { synchronized (changingUsernames) { @@ -58,7 +57,6 @@ public class ChangeUserNameEvent extends MessageHandler { Emulator.getPluginManager().fireEvent(new UserNameChangedEvent(this.client.getHabbo(), oldName)); for (Room room : Emulator.getGameEnvironment().getRoomManager().getRoomsForHabbo(this.client.getHabbo())) { - room.setOwnerName(name); room.setNeedsUpdate(true); room.save(); } @@ -69,13 +67,13 @@ public class ChangeUserNameEvent extends MessageHandler { this.client.sendResponse(new ChangeUserNameResultMessageEvent(this.client.getHabbo())); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserNameChangedMessageComposer(this.client.getHabbo()).compose()); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserNameChangedMessageComposer(this.client.getHabbo()).compose()); } else { this.client.sendResponse(new UserNameChangedMessageComposer(this.client.getHabbo()).compose()); } - this.client.getHabbo().getMessenger().connectionChanged(this.client.getHabbo(), true, this.client.getHabbo().getHabboInfo().getCurrentRoom() != null); + this.client.getHabbo().getMessenger().connectionChanged(this.client.getHabbo(), true, this.client.getHabbo().getRoomUnit().getRoom() != null); this.client.getHabbo().getClient().sendResponse(new UserObjectComposer(this.client.getHabbo())); try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO namechange_log (user_id, old_name, new_name, timestamp) VALUES (?, ?, ?, ?) ")) { diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/CheckUserNameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/CheckUserNameEvent.java index ca79760b..61d5e9d9 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/CheckUserNameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/CheckUserNameEvent.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.incoming.users; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.users.CheckUserNameResultMessageComposer; @@ -25,7 +24,7 @@ public class CheckUserNameEvent extends MessageHandler { errorCode = CheckUserNameResultMessageComposer.TOO_SHORT; } else if (name.length() > 15) { errorCode = CheckUserNameResultMessageComposer.TOO_LONG; - } else if (name.equalsIgnoreCase(this.client.getHabbo().getHabboInfo().getUsername()) || HabboManager.getOfflineHabboInfo(name) != null || ChangeUserNameEvent.changingUsernames.contains(name.toLowerCase())) { + } else if (name.equalsIgnoreCase(this.client.getHabbo().getHabboInfo().getUsername()) || Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(name) != null || ChangeUserNameEvent.changingUsernames.contains(name.toLowerCase())) { errorCode = CheckUserNameResultMessageComposer.TAKEN_WITH_SUGGESTIONS; suggestions.add(name + Emulator.getRandom().nextInt(9999)); suggestions.add(name + Emulator.getRandom().nextInt(9999)); diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/GetExtendedProfileEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/GetExtendedProfileEvent.java index 9203d35c..369c6167 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/GetExtendedProfileEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/GetExtendedProfileEvent.java @@ -15,6 +15,6 @@ public class GetExtendedProfileEvent extends MessageHandler { if (habbo != null) this.client.sendResponse(new ExtendedProfileMessageComposer(habbo, this.client)); else - this.client.sendResponse(new ExtendedProfileMessageComposer(HabboManager.getOfflineHabboInfo(habboId), this.client)); + this.client.sendResponse(new ExtendedProfileMessageComposer(Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(habboId), this.client)); } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/GetIgnoredUsersEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/GetIgnoredUsersEvent.java index a3bc41b3..653a7848 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/GetIgnoredUsersEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/GetIgnoredUsersEvent.java @@ -3,7 +3,6 @@ package com.eu.habbo.messages.incoming.users; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.unknown.IgnoredUsersMessageComposer; import gnu.trove.list.array.TIntArrayList; @@ -26,7 +25,7 @@ public class GetIgnoredUsersEvent extends MessageHandler { int userId = ignoredUsersId.iterator().next(); HabboInfo user = Emulator.getGameEnvironment().getHabboManager().getHabboInfo(userId); - if(user == null) user = HabboManager.getOfflineHabboInfo(userId); + if(user == null) user = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(userId); if(user != null) ignoredUsernames.add(user.getUsername()); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/SetActivatedBadgesEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/SetActivatedBadgesEvent.java index c7509697..e798c4b7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/SetActivatedBadgesEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/SetActivatedBadgesEvent.java @@ -35,8 +35,8 @@ public class SetActivatedBadgesEvent extends MessageHandler { } } - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserBadgesComposer(updatedBadges, this.client.getHabbo().getHabboInfo().getId()).compose()); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserBadgesComposer(updatedBadges, this.client.getHabbo().getHabboInfo().getId()).compose()); } else { this.client.sendResponse(new UserBadgesComposer(updatedBadges, this.client.getHabbo().getHabboInfo().getId())); } diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/SetChatStylePreferenceEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/SetChatStylePreferenceEvent.java index ed7add4e..c8ec2257 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/SetChatStylePreferenceEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/SetChatStylePreferenceEvent.java @@ -10,7 +10,7 @@ public class SetChatStylePreferenceEvent extends MessageHandler { public void handle() { int chatBubble = this.packet.readInt(); - if (!this.client.getHabbo().hasRight(Permission.ACC_ANYCHATCOLOR)) { + if (!this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYCHATCOLOR)) { for (String s : Emulator.getConfig().getValue("commands.cmd_chatcolor.banned_numbers").split(";")) { if (Integer.parseInt(s) == chatBubble) { return; diff --git a/src/main/java/com/eu/habbo/messages/incoming/users/UpdateFigureDataEvent.java b/src/main/java/com/eu/habbo/messages/incoming/users/UpdateFigureDataEvent.java index d2e1b78d..2e1dbbd7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/users/UpdateFigureDataEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/users/UpdateFigureDataEvent.java @@ -39,8 +39,8 @@ public class UpdateFigureDataEvent extends MessageHandler { this.client.getHabbo().getHabboInfo().setGender(lookEvent.getGender()); Emulator.getThreading().run(this.client.getHabbo().getHabboInfo()); this.client.sendResponse(new FigureUpdateComposer(this.client.getHabbo())); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != null) { - this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(this.client.getHabbo()).compose()); + if (this.client.getHabbo().getRoomUnit().getRoom() != null) { + this.client.getHabbo().getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(this.client.getHabbo()).compose()); } AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("AvatarLooks")); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java index 5f9aebd7..1d5534f5 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/ApplySnapshotEvent.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.rooms.FurnitureMovementError; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomTileState; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer; @@ -35,19 +35,19 @@ public class ApplySnapshotEvent extends MessageHandler { return; } - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); // Executing Habbo should be able to edit wireds - if (room == null || (!room.hasRights(this.client.getHabbo()) && !room.isOwner(this.client.getHabbo()))) { + if (room == null || (!room.getRoomRightsManager().hasRights(this.client.getHabbo()) && !room.getRoomInfo().isRoomOwner(this.client.getHabbo()))) { return; } - List wireds = new ArrayList<>(); + List wireds = new ArrayList<>(); wireds.addAll(room.getRoomSpecialTypes().getConditions()); wireds.addAll(room.getRoomSpecialTypes().getEffects()); // Find the item with the given ID in the room - Optional item = wireds.stream() + Optional item = wireds.stream() .filter(wired -> wired.getId() == itemId) .findFirst(); @@ -56,37 +56,38 @@ public class ApplySnapshotEvent extends MessageHandler { return; } - HabboItem wiredItem = item.get(); + RoomItem wiredItem = item.get(); // The item should have settings to match furni state, position and rotation if (wiredItem instanceof InteractionWiredMatchFurniSettings wired) { // Try to apply the set settings to each item - wired.getMatchFurniSettings().forEach(setting -> { - HabboItem matchItem = room.getHabboItem(setting.getItem_id()); + wired.getMatchSettings().forEach(setting -> { + RoomItem matchItem = room.getRoomItemManager().getRoomItemById(setting.getItem_id()); // Match state - if (wired.shouldMatchState() && matchItem.allowWiredResetState() && !setting.getState().equals(" ") && !matchItem.getExtradata().equals(setting.getState())) { - matchItem.setExtradata(setting.getState()); + if (wired.shouldMatchState() && matchItem.allowWiredResetState() && !setting.getState().equals(" ") && !matchItem.getExtraData().equals(setting.getState())) { + matchItem.setExtraData(setting.getState()); room.updateItemState(matchItem); } - RoomTile oldLocation = room.getLayout().getTile(matchItem.getX(), matchItem.getY()); - double oldZ = matchItem.getZ(); + RoomTile oldLocation = room.getLayout().getTile(matchItem.getCurrentPosition().getX(), matchItem.getCurrentPosition().getY()); + double oldZ = matchItem.getCurrentZ(); // Match Position & Rotation if (wired.shouldMatchRotation() && !wired.shouldMatchPosition()) { - if (matchItem.getRotation() != setting.getRotation() && room.furnitureFitsAt(oldLocation, matchItem, setting.getRotation(), false) == FurnitureMovementError.NONE) { - room.moveFurniTo(matchItem, oldLocation, setting.getRotation(), null, true); + if (matchItem.getRotation() != setting.getRotation() && room.getRoomItemManager().furnitureFitsAt(oldLocation, matchItem, setting.getRotation(), false) == FurnitureMovementError.NONE) { + room.getRoomItemManager().moveItemTo(matchItem, oldLocation, setting.getRotation(), null, true, true); } } else if (wired.shouldMatchPosition()) { boolean slideAnimation = !wired.shouldMatchRotation() || matchItem.getRotation() == setting.getRotation(); RoomTile newLocation = room.getLayout().getTile((short) setting.getX(), (short) setting.getY()); int newRotation = wired.shouldMatchRotation() ? setting.getRotation() : matchItem.getRotation(); - if (newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != matchItem.getRotation()) - && room.furnitureFitsAt(newLocation, matchItem, newRotation, true) == FurnitureMovementError.NONE - && room.moveFurniTo(matchItem, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE && slideAnimation) { - room.sendComposer(new FloorItemOnRollerComposer(matchItem, null, oldLocation, oldZ, newLocation, matchItem.getZ(), 0, room).compose()); + if (newLocation != null && newLocation.getState() != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != matchItem.getRotation()) && room.getRoomItemManager().furnitureFitsAt(newLocation, matchItem, newRotation, true) == FurnitureMovementError.NONE) { + boolean sendUpdates = !slideAnimation; + if (room.getRoomItemManager().moveItemTo(matchItem, newLocation, newRotation, null, sendUpdates, true) == FurnitureMovementError.NONE && slideAnimation) { + room.sendComposer(new FloorItemOnRollerComposer(matchItem, null, oldLocation, oldZ, newLocation, matchItem.getCurrentZ(), 0, room).compose()); + } } } }); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java index ba66ade6..e7b0fc5a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateActionEvent.java @@ -1,9 +1,7 @@ package com.eu.habbo.messages.incoming.wired; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -15,24 +13,23 @@ public class UpdateActionEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - if (room.hasRights(this.client.getHabbo()) || room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasRight(Permission.ACC_MOVEROTATE)) { + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasPermissionRight(Permission.ACC_MOVEROTATE)) { + //TODO Check SUPER WIRED PERMISSIONS TOO + InteractionWiredEffect effect = room.getRoomSpecialTypes().getEffect(itemId); try { - if (effect == null) + if (effect == null) { throw new WiredSaveException(String.format("Wired effect with item id %s not found in room", itemId)); - - WiredSettings settings = InteractionWired.readSettings(this.packet, true); - if (effect.saveData(settings, this.client)) { - this.client.sendResponse(new WiredSavedComposer()); - effect.needsUpdate(true); - Emulator.getThreading().run(effect); } - + effect.saveWiredSettings(this.packet, room); + this.client.sendResponse(new WiredSavedComposer()); + effect.setSqlUpdateNeeded(true); + Emulator.getThreading().run(effect); } catch (WiredSaveException e) { this.client.sendResponse(new WiredValidationErrorComposer(e.getMessage())); diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java index 47aa0d8a..49cf8f8a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateConditionEvent.java @@ -1,9 +1,7 @@ package com.eu.habbo.messages.incoming.wired; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -15,25 +13,24 @@ public class UpdateConditionEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - if (room.hasRights(this.client.getHabbo()) || room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasRight(Permission.ACC_MOVEROTATE)) { + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasPermissionRight(Permission.ACC_MOVEROTATE)) { InteractionWiredCondition condition = room.getRoomSpecialTypes().getCondition(itemId); - if (condition != null) { - WiredSettings settings = InteractionWired.readSettings(this.packet, false); - - if (condition.saveData(settings)) { - this.client.sendResponse(new WiredSavedComposer()); - - condition.needsUpdate(true); - - Emulator.getThreading().run(condition); - } else { - this.client.sendResponse(new WiredValidationErrorComposer("There was an error while saving that condition")); + try { + if (condition == null) { + throw new WiredSaveException(String.format("Wired condition with item id %s not found in room", itemId)); } + condition.saveWiredSettings(this.packet, room); + this.client.sendResponse(new WiredSavedComposer()); + condition.setSqlUpdateNeeded(true); + Emulator.getThreading().run(condition); + } + catch (WiredSaveException e) { + this.client.sendResponse(new WiredValidationErrorComposer(e.getMessage())); } } } diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java index 57859f62..e8a375f5 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/UpdateTriggerEvent.java @@ -1,9 +1,7 @@ package com.eu.habbo.messages.incoming.wired; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.items.interactions.InteractionWired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; -import com.eu.habbo.habbohotel.items.interactions.wired.WiredSettings; import com.eu.habbo.habbohotel.permissions.Permission; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.incoming.MessageHandler; @@ -15,24 +13,24 @@ public class UpdateTriggerEvent extends MessageHandler { public void handle() { int itemId = this.packet.readInt(); - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Room room = this.client.getHabbo().getRoomUnit().getRoom(); if (room != null) { - if (room.hasRights(this.client.getHabbo()) || room.getOwnerId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasRight(Permission.ACC_MOVEROTATE)) { + if (room.getRoomRightsManager().hasRights(this.client.getHabbo()) || room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER) || this.client.getHabbo().hasPermissionRight(Permission.ACC_MOVEROTATE)) { InteractionWiredTrigger trigger = room.getRoomSpecialTypes().getTrigger(itemId); - if (trigger != null) { - WiredSettings settings = InteractionWired.readSettings(this.packet, false); - - if (trigger.saveData(settings)) { - this.client.sendResponse(new WiredSavedComposer()); - - trigger.needsUpdate(true); - - Emulator.getThreading().run(trigger); - } else { - this.client.sendResponse(new WiredValidationErrorComposer("There was an error while saving that trigger")); + try { + if (trigger == null) { + throw new WiredSaveException(String.format("Wired trigger with item id %s not found in room", itemId)); } + + trigger.saveWiredSettings(this.packet, room); + this.client.sendResponse(new WiredSavedComposer()); + trigger.setSqlUpdateNeeded(true); + Emulator.getThreading().run(trigger); + } + catch (WiredSaveException e) { + this.client.sendResponse(new WiredValidationErrorComposer(e.getMessage())); } } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/catalog/CatalogPagesListComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/catalog/CatalogPagesListComposer.java index ed282c32..3c838951 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/catalog/CatalogPagesListComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/catalog/CatalogPagesListComposer.java @@ -21,7 +21,7 @@ public class CatalogPagesListComposer extends MessageComposer { public CatalogPagesListComposer(Habbo habbo, String mode) { this.habbo = habbo; this.mode = mode; - this.hasPermission = this.habbo.hasRight(Permission.ACC_CATALOG_IDS); + this.hasPermission = this.habbo.hasPermissionRight(Permission.ACC_CATALOG_IDS); } @Override diff --git a/src/main/java/com/eu/habbo/messages/outgoing/friends/MessengerInitComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/friends/MessengerInitComposer.java index 1e6125fa..17388e1f 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/friends/MessengerInitComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/friends/MessengerInitComposer.java @@ -19,7 +19,7 @@ public class MessengerInitComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.messengerInitComposer); - if (this.habbo.hasRight(Permission.ACC_INFINITE_FRIENDS)) { + if (this.habbo.hasPermissionRight(Permission.ACC_INFINITE_FRIENDS)) { this.response.appendInt(Integer.MAX_VALUE); this.response.appendInt(1337); this.response.appendInt(Integer.MAX_VALUE); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionInvitedToGuideRoomMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionInvitedToGuideRoomMessageComposer.java index 0db1cc67..f044aea3 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionInvitedToGuideRoomMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionInvitedToGuideRoomMessageComposer.java @@ -15,8 +15,8 @@ public class GuideSessionInvitedToGuideRoomMessageComposer extends MessageCompos @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.guideSessionInvitedToGuideRoomMessageComposer); - this.response.appendInt(this.room != null ? this.room.getId() : 0); - this.response.appendString(this.room != null ? this.room.getName() : ""); + this.response.appendInt(this.room != null ? this.room.getRoomInfo().getId() : 0); + this.response.appendString(this.room != null ? this.room.getRoomInfo().getName() : ""); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionRequesterRoomMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionRequesterRoomMessageComposer.java index bcce411b..61d95616 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionRequesterRoomMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guides/GuideSessionRequesterRoomMessageComposer.java @@ -12,7 +12,7 @@ public class GuideSessionRequesterRoomMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.guideSessionRequesterRoomMessageComposer); - this.response.appendInt(this.room != null ? this.room.getId() : 0); + this.response.appendInt(this.room != null ? this.room.getRoomInfo().getId() : 0); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/FavoriteMembershipUpdateMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/FavoriteMembershipUpdateMessageComposer.java index 28b34815..72aad389 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/FavoriteMembershipUpdateMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/FavoriteMembershipUpdateMessageComposer.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.outgoing.guilds; import com.eu.habbo.habbohotel.guilds.Guild; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -16,7 +16,7 @@ public class FavoriteMembershipUpdateMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.favoriteMembershipUpdateMessageComposer); - this.response.appendInt(this.roomUnit.getId()); + this.response.appendInt(this.roomUnit.getVirtualId()); this.response.appendInt(this.guild != null ? this.guild.getId() : 0); this.response.appendInt(this.guild != null ? this.guild.getState().getState() : 3); this.response.appendString(this.guild != null ? this.guild.getName() : ""); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildCreationInfoMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildCreationInfoMessageComposer.java index 670715c3..2edf2412 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildCreationInfoMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildCreationInfoMessageComposer.java @@ -18,8 +18,8 @@ public class GuildCreationInfoMessageComposer extends MessageComposer { this.response.appendInt(this.rooms.size()); for (Room room : this.rooms) { - this.response.appendInt(room.getId()); - this.response.appendString(room.getName()); + this.response.appendInt(room.getRoomInfo().getId()); + this.response.appendString(room.getRoomInfo().getName()); this.response.appendBoolean(false); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildFurniContextMenuInfoMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildFurniContextMenuInfoMessageComposer.java index 3fc033e8..ff968a33 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildFurniContextMenuInfoMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/GuildFurniContextMenuInfoMessageComposer.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.outgoing.guilds; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -13,7 +13,7 @@ import lombok.AllArgsConstructor; public class GuildFurniContextMenuInfoMessageComposer extends MessageComposer { private final Habbo habbo; private final Guild guild; - private final HabboItem item; + private final RoomItem item; @Override protected ServerMessage composeInternal() { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/HabboGroupDetailsMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/HabboGroupDetailsMessageComposer.java index 84fb7bbe..62385357 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/HabboGroupDetailsMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/HabboGroupDetailsMessageComposer.java @@ -23,7 +23,7 @@ public class HabboGroupDetailsMessageComposer extends MessageComposer { private final GuildMember member; @Override protected ServerMessage composeInternal() { - boolean adminPermissions = this.client.getHabbo().getHabboStats().hasGuild(this.guild.getId()) && this.client.getHabbo().hasRight(Permission.ACC_GUILD_ADMIN) || Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(this.client.getHabbo().getHabboInfo().getId()) != null; + boolean adminPermissions = this.client.getHabbo().getHabboStats().hasGuild(this.guild.getId()) && this.client.getHabbo().hasPermissionRight(Permission.ACC_GUILD_ADMIN) || Emulator.getGameEnvironment().getGuildManager().getOnlyAdmins(guild).get(this.client.getHabbo().getHabboInfo().getId()) != null; this.response.init(Outgoing.habboGroupDetailsMessageComposer); this.response.appendInt(this.guild.getId()); this.response.appendBoolean(true); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ForumDataMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ForumDataMessageComposer.java index 840a9e1b..b71b7f56 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ForumDataMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/guilds/forums/ForumDataMessageComposer.java @@ -107,7 +107,7 @@ public class ForumDataMessageComposer extends MessageComposer { GuildMember member = Emulator.getGameEnvironment().getGuildManager().getGuildMember(guild, habbo); boolean isAdmin = member != null && (member.getRank().getType() < GuildRank.MEMBER.getType() || guild.getOwnerId() == this.habbo.getHabboInfo().getId()); - boolean isStaff = this.habbo.hasRight(Permission.ACC_MODTOOL_TICKET_Q); + boolean isStaff = this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q); String errorRead = ""; String errorPost = ""; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListAddOrUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListAddOrUpdateComposer.java index 34809b06..4ba9cb7f 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListAddOrUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListAddOrUpdateComposer.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.outgoing.inventory; import com.eu.habbo.habbohotel.items.FurnitureType; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -9,43 +9,43 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class FurniListAddOrUpdateComposer extends MessageComposer { - private final HabboItem habboItem; + private final RoomItem roomItem; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.furniListAddOrUpdateComposer); - this.response.appendInt(this.habboItem.getGiftAdjustedId()); - this.response.appendString(this.habboItem.getBaseItem().getType().code); - this.response.appendInt(this.habboItem.getId()); - this.response.appendInt(this.habboItem.getBaseItem().getSpriteId()); + this.response.appendInt(this.roomItem.getGiftAdjustedId()); + this.response.appendString(this.roomItem.getBaseItem().getType().code); + this.response.appendInt(this.roomItem.getId()); + this.response.appendInt(this.roomItem.getBaseItem().getSpriteId()); - switch (this.habboItem.getBaseItem().getName()) { + switch (this.roomItem.getBaseItem().getName()) { case "landscape" -> this.response.appendInt(4); case "floor" -> this.response.appendInt(3); case "wallpaper" -> this.response.appendInt(2); case "poster" -> this.response.appendInt(6); } - if (this.habboItem.isLimited()) { + if (this.roomItem.isLimited()) { this.response.appendInt(1); this.response.appendInt(256); - this.response.appendString(this.habboItem.getExtradata()); - this.response.appendInt(this.habboItem.getLimitedSells()); - this.response.appendInt(this.habboItem.getLimitedStack()); + this.response.appendString(this.roomItem.getExtraData()); + this.response.appendInt(this.roomItem.getLimitedSells()); + this.response.appendInt(this.roomItem.getLimitedStack()); } else { this.response.appendInt(1); this.response.appendInt(0); - this.response.appendString(this.habboItem.getExtradata()); + this.response.appendString(this.roomItem.getExtraData()); } - this.response.appendBoolean(this.habboItem.getBaseItem().allowRecyle()); - this.response.appendBoolean(this.habboItem.getBaseItem().allowTrade()); - this.response.appendBoolean(!this.habboItem.isLimited() && this.habboItem.getBaseItem().allowInventoryStack()); - this.response.appendBoolean(this.habboItem.getBaseItem().allowMarketplace()); + this.response.appendBoolean(this.roomItem.getBaseItem().allowRecyle()); + this.response.appendBoolean(this.roomItem.getBaseItem().allowTrade()); + this.response.appendBoolean(!this.roomItem.isLimited() && this.roomItem.getBaseItem().allowInventoryStack()); + this.response.appendBoolean(this.roomItem.getBaseItem().allowMarketplace()); this.response.appendInt(-1); this.response.appendBoolean(false); this.response.appendInt(-1); - if (this.habboItem.getBaseItem().getType() == FurnitureType.FLOOR) { + if (this.roomItem.getBaseItem().getType() == FurnitureType.FLOOR) { this.response.appendString(""); //slotId this.response.appendInt(0); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListComposer.java index 9def2fb0..0b9e9301 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/FurniListComposer.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.outgoing.inventory; import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.items.interactions.InteractionGift; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -16,11 +16,11 @@ import java.util.List; @Slf4j @AllArgsConstructor -public class FurniListComposer extends MessageComposer implements TIntObjectProcedure { +public class FurniListComposer extends MessageComposer implements TIntObjectProcedure { private final int fragmentNumber; private final int totalFragments; - private final TIntObjectMap items; + private final TIntObjectMap items; @Override @@ -41,14 +41,14 @@ public class FurniListComposer extends MessageComposer implements TIntObjectProc } @Override - public boolean execute(int a, HabboItem habboItem) { - this.response.appendInt(habboItem.getGiftAdjustedId()); - this.response.appendString(habboItem.getBaseItem().getType().code); - this.response.appendInt(habboItem.getId()); - this.response.appendInt(habboItem.getBaseItem().getSpriteId()); + public boolean execute(int a, RoomItem roomItem) { + this.response.appendInt(roomItem.getGiftAdjustedId()); + this.response.appendString(roomItem.getBaseItem().getType().code); + this.response.appendInt(roomItem.getId()); + this.response.appendInt(roomItem.getBaseItem().getSpriteId()); - if (habboItem.getBaseItem().getName().equals("floor") || habboItem.getBaseItem().getName().equals("song_disk") || habboItem.getBaseItem().getName().equals("landscape") || habboItem.getBaseItem().getName().equals("wallpaper") || habboItem.getBaseItem().getName().equals("poster")) { - switch (habboItem.getBaseItem().getName()) { + if (roomItem.getBaseItem().getName().equals("floor") || roomItem.getBaseItem().getName().equals("song_disk") || roomItem.getBaseItem().getName().equals("landscape") || roomItem.getBaseItem().getName().equals("wallpaper") || roomItem.getBaseItem().getName().equals("poster")) { + switch (roomItem.getBaseItem().getName()) { case "landscape" -> this.response.appendInt(4); case "floor" -> this.response.appendInt(3); case "wallpaper" -> this.response.appendInt(2); @@ -57,39 +57,39 @@ public class FurniListComposer extends MessageComposer implements TIntObjectProc } this.response.appendInt(0); - this.response.appendString(habboItem.getExtradata()); + this.response.appendString(roomItem.getExtraData()); } else { - if (habboItem.getBaseItem().getName().equals("gnome_box")) + if (roomItem.getBaseItem().getName().equals("gnome_box")) this.response.appendInt(13); else - this.response.appendInt(habboItem instanceof InteractionGift ? ((((InteractionGift) habboItem).getColorId() * 1000) + ((InteractionGift) habboItem).getRibbonId()) : 1); + this.response.appendInt(roomItem instanceof InteractionGift ? ((((InteractionGift) roomItem).getColorId() * 1000) + ((InteractionGift) roomItem).getRibbonId()) : 1); - habboItem.serializeExtradata(this.response); + roomItem.serializeExtradata(this.response); } - this.response.appendBoolean(habboItem.getBaseItem().allowRecyle()); - this.response.appendBoolean(habboItem.getBaseItem().allowTrade()); - this.response.appendBoolean(!habboItem.isLimited() && habboItem.getBaseItem().allowInventoryStack()); - this.response.appendBoolean(habboItem.getBaseItem().allowMarketplace()); + this.response.appendBoolean(roomItem.getBaseItem().allowRecyle()); + this.response.appendBoolean(roomItem.getBaseItem().allowTrade()); + this.response.appendBoolean(!roomItem.isLimited() && roomItem.getBaseItem().allowInventoryStack()); + this.response.appendBoolean(roomItem.getBaseItem().allowMarketplace()); this.response.appendInt(-1); this.response.appendBoolean(true); this.response.appendInt(-1); - if (habboItem.getBaseItem().getType() == FurnitureType.FLOOR) { + if (roomItem.getBaseItem().getType() == FurnitureType.FLOOR) { this.response.appendString(""); - if(habboItem.getBaseItem().getName().equals("song_disk")) { - List extraDataAsList = Arrays.asList(habboItem.getExtradata().split("\n")); + if(roomItem.getBaseItem().getName().equals("song_disk")) { + List extraDataAsList = Arrays.asList(roomItem.getExtraData().split("\n")); this.response.appendInt(Integer.valueOf(extraDataAsList.get(extraDataAsList.size() - 1))); return true; } - this.response.appendInt(habboItem instanceof InteractionGift ? ((((InteractionGift) habboItem).getColorId() * 1000) + ((InteractionGift) habboItem).getRibbonId()) : 1); + this.response.appendInt(roomItem instanceof InteractionGift ? ((((InteractionGift) roomItem).getColorId() * 1000) + ((InteractionGift) roomItem).getRibbonId()) : 1); } return true; } - public void addExtraDataToResponse(HabboItem habboItem) { + public void addExtraDataToResponse(RoomItem roomItem) { this.response.appendInt(0); - this.response.appendString(habboItem.getExtradata()); + this.response.appendString(roomItem.getExtraData()); } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/inventory/UnseenItemsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/inventory/UnseenItemsComposer.java index 670f204e..b5116f3b 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/inventory/UnseenItemsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/inventory/UnseenItemsComposer.java @@ -1,27 +1,27 @@ package com.eu.habbo.messages.outgoing.inventory; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; -import gnu.trove.set.hash.THashSet; +import java.util.HashSet; import java.util.List; import java.util.Map; public class UnseenItemsComposer extends MessageComposer { - private THashSet itemsList; - private HabboItem item; + private HashSet itemsList; + private RoomItem item; private int[] ids; private AddHabboItemCategory category; private Map> entries; - public UnseenItemsComposer(THashSet itemsList) { + public UnseenItemsComposer(HashSet itemsList) { this.itemsList = itemsList; this.category = AddHabboItemCategory.OWNED_FURNI; } - public UnseenItemsComposer(HabboItem item) { + public UnseenItemsComposer(RoomItem item) { this.item = item; this.category = AddHabboItemCategory.OWNED_FURNI; } @@ -67,8 +67,8 @@ public class UnseenItemsComposer extends MessageComposer { this.response.appendInt(1); this.response.appendInt(1); this.response.appendInt(this.itemsList.size()); - for (HabboItem habboItem : this.itemsList) { - this.response.appendInt(habboItem.getId()); + for (RoomItem roomItem : this.itemsList) { + this.response.appendInt(roomItem.getId()); } } else { this.response.appendInt(1); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/CfhChatlogComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/CfhChatlogComposer.java index ff356e02..d4e763d2 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/CfhChatlogComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/CfhChatlogComposer.java @@ -73,8 +73,8 @@ public class CfhChatlogComposer extends MessageComposer { this.response.appendInt(this.issue.roomId); ModToolChatRecordDataContext.GROUP_ID.append(this.response); - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.issue.roomId); - this.response.appendInt(room == null ? 0 : room.getGuildId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.issue.roomId); + this.response.appendInt(room == null ? 0 : room.getRoomInfo().getGuild().getId()); } this.response.appendShort(this.chatlog.size()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorInitMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorInitMessageComposer.java index 5ae705f4..08cb98fb 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorInitMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/ModeratorInitMessageComposer.java @@ -24,7 +24,7 @@ public class ModeratorInitMessageComposer extends MessageComposer implements TOb protected ServerMessage composeInternal() { this.response.init(Outgoing.moderatorInitMessageComposer); - if (this.habbo.hasRight(Permission.ACC_MODTOOL_TICKET_Q)) { + if (this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q)) { THashSet openTickets = new THashSet<>(); THashMap tickets = Emulator.getGameEnvironment().getModToolManager().getTickets(); @@ -62,13 +62,13 @@ public class ModeratorInitMessageComposer extends MessageComposer implements TOb Emulator.getGameEnvironment().getModToolManager().getCategory().forEachValue(this); - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_TICKET_Q)); //ticketQueueueuhuehuehuehue - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_USER_LOGS)); //user chatlogs - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_USER_ALERT)); //can send caution - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_USER_KICK)); //can send kick - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_USER_BAN)); //can send ban - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_ROOM_INFO)); //room info ??Not sure - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_MODTOOL_ROOM_LOGS)); //room chatlogs ??Not sure + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_TICKET_Q)); //ticketQueueueuhuehuehuehue + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_USER_LOGS)); //user chatlogs + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_USER_ALERT)); //can send caution + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_USER_KICK)); //can send kick + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_USER_BAN)); //can send ban + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_ROOM_INFO)); //room info ??Not sure + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_MODTOOL_ROOM_LOGS)); //room chatlogs ??Not sure synchronized (Emulator.getGameEnvironment().getModToolManager().getPresets()) { this.response.appendInt(Emulator.getGameEnvironment().getModToolManager().getPresets().get("room").size()); 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 4e05d6f0..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 @@ -13,17 +13,17 @@ public class ModeratorRoomInfoComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.moderatorRoomInfoComposer); - this.response.appendInt(this.room.getId()); - this.response.appendInt(this.room.getCurrentHabbos().size()); - this.response.appendBoolean(this.room.getHabbo(this.room.getOwnerId()) != null); - this.response.appendInt(this.room.getOwnerId()); - this.response.appendString(this.room.getOwnerName()); + this.response.appendInt(this.room.getRoomInfo().getId()); + 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()); this.response.appendBoolean(true); - this.response.appendString(this.room.getName()); - this.response.appendString(this.room.getDescription()); - this.response.appendInt(this.room.getTags().split(";").length); - for (int i = 0; i < this.room.getTags().split(";").length; i++) { - this.response.appendString(this.room.getTags().split(";")[i]); + this.response.appendString(this.room.getRoomInfo().getName()); + this.response.appendString(this.room.getRoomInfo().getDescription()); + this.response.appendInt(this.room.getRoomInfo().getTags().split(";").length); + for (int i = 0; i < this.room.getRoomInfo().getTags().split(";").length; i++) { + this.response.appendString(this.room.getRoomInfo().getTags().split(";")[i]); } return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/modtool/RoomChatlogComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/modtool/RoomChatlogComposer.java index e7118bda..1d16b565 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/modtool/RoomChatlogComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/modtool/RoomChatlogComposer.java @@ -23,10 +23,10 @@ public class RoomChatlogComposer extends MessageComposer { this.response.appendShort(2); this.response.appendString("roomName"); this.response.appendByte(2); - this.response.appendString(this.room.getName()); + this.response.appendString(this.room.getRoomInfo().getName()); this.response.appendString("roomId"); this.response.appendByte(1); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); SimpleDateFormat formatDate = new SimpleDateFormat("HH:mm"); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/navigator/FlatCreatedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/navigator/FlatCreatedComposer.java index 5b7ebaf1..04e32e6c 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/navigator/FlatCreatedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/navigator/FlatCreatedComposer.java @@ -13,8 +13,8 @@ public class FlatCreatedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.flatCreatedComposer); - this.response.appendInt(this.room.getId()); - this.response.appendString(this.room.getName()); + this.response.appendInt(this.room.getRoomInfo().getId()); + this.response.appendString(this.room.getRoomInfo().getName()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/BannedUsersFromRoomComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/BannedUsersFromRoomComposer.java index c09508f2..7e7eaded 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/BannedUsersFromRoomComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/BannedUsersFromRoomComposer.java @@ -39,7 +39,7 @@ public class BannedUsersFromRoomComposer extends MessageComposer { return null; this.response.init(Outgoing.bannedUsersFromRoomComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendInt(roomBans.size()); for (RoomBan ban : roomBans) { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerAddedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerAddedComposer.java index 8534955a..99fd4b5d 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerAddedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerAddedComposer.java @@ -15,7 +15,7 @@ public class FlatControllerAddedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.flatControllerAddedComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendInt(this.userId); this.response.appendString(this.userName); return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerRemovedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerRemovedComposer.java index 4300380c..3c2d73c9 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerRemovedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllerRemovedComposer.java @@ -15,7 +15,7 @@ public class FlatControllerRemovedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.flatControllerRemovedComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendInt(this.userId); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllersComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllersComposer.java index 079357f7..264d923e 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllersComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FlatControllersComposer.java @@ -4,9 +4,9 @@ import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; -import gnu.trove.map.hash.THashMap; import lombok.AllArgsConstructor; +import java.util.HashMap; import java.util.Map; @AllArgsConstructor @@ -16,9 +16,9 @@ public class FlatControllersComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.flatControllersComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); - THashMap rightsMap = this.room.getUsersWithRights(); + HashMap rightsMap = this.room.getRoomRightsManager().getUsersWithRights(); this.response.appendInt(rightsMap.size()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FloorHeightMapComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FloorHeightMapComposer.java index 253b4ee0..321a481f 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/FloorHeightMapComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/FloorHeightMapComposer.java @@ -14,7 +14,7 @@ public class FloorHeightMapComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.floorHeightMapComposer); this.response.appendBoolean(true); - this.response.appendInt(this.room.getWallHeight()); //FixedWallsHeight + this.response.appendInt(this.room.getRoomInfo().getWallThickness()); //FixedWallsHeight this.response.appendString(this.room.getLayout().getRelativeMap()); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/GamePlayerValueMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/GamePlayerValueMessageComposer.java index 14017806..96ecebbe 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/GamePlayerValueMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/GamePlayerValueMessageComposer.java @@ -13,7 +13,7 @@ public class GamePlayerValueMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.gamePlayerValueMessageComposer); - this.response.appendInt(this.gamePlayer.getHabbo().getRoomUnit().getId()); + this.response.appendInt(this.gamePlayer.getHabbo().getRoomUnit().getVirtualId()); this.response.appendInt(this.gamePlayer.getLives()); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java index 24f06ade..1948ced2 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/GetGuestRoomResultComposer.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.guilds.Guild; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; @@ -20,89 +19,31 @@ public class GetGuestRoomResultComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.getGuestRoomResultComposer); this.response.appendBoolean(this.enterRoom); - this.response.appendInt(this.room.getId()); - this.response.appendString(this.room.getName()); - if (this.room.isPublicRoom()) { - this.response.appendInt(0); - this.response.appendString(""); - } else { - this.response.appendInt(this.room.getOwnerId()); - this.response.appendString(this.room.getOwnerName()); - } - this.response.appendInt(this.room.getState().getState()); - this.response.appendInt(this.room.getUserCount()); - this.response.appendInt(this.room.getUsersMax()); - this.response.appendString(this.room.getDescription()); - this.response.appendInt(this.room.getTradeMode()); - this.response.appendInt(this.room.getScore()); - this.response.appendInt(2);//Top rated room rank - this.response.appendInt(this.room.getCategory()); - if (!this.room.getTags().isEmpty()) { - String[] tags = this.room.getTags().split(";"); - this.response.appendInt(tags.length); - for (String s : tags) { - this.response.appendString(s); - } - } else { - this.response.appendInt(0); - } - - int base = 0; - - if (this.room.getGuildId() > 0) { - base = base | 2; - } - - if (!this.room.isPublicRoom()) { - base = base | 8; - } - - if (this.room.isPromoted()) { - base = base | 4; - } - - if (this.room.isAllowPets()) { - base = base | 16; - } - - this.response.appendInt(base); - - if (this.room.getGuildId() > 0) { - Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.room.getGuildId()); - if (g != null) { - this.response.appendInt(g.getId()); - this.response.appendString(g.getName()); - this.response.appendString(g.getBadge()); - } else { - this.response.appendInt(0); - this.response.appendString(""); - this.response.appendString(""); - } - } - - if (this.room.isPromoted()) { - this.response.appendString(this.room.getPromotion().getTitle()); - this.response.appendString(this.room.getPromotion().getDescription()); - this.response.appendInt((this.room.getPromotion().getEndTimestamp() - Emulator.getIntUnixTimestamp()) / 60); - } + this.response.append(this.room); this.response.appendBoolean(this.roomForward); - this.response.appendBoolean(this.room.isStaffPromotedRoom()); // staffpicked - this.response.appendBoolean(this.room.hasGuild() && Emulator.getGameEnvironment().getGuildManager().getGuildMember(this.room.getGuildId(), this.habbo.getHabboInfo().getId()) != null); // is group member + this.response.appendBoolean(this.room.getRoomInfo().isStaffPicked()); // staffpicked + + if(this.room.getRoomInfo().hasGuild()) { + this.response.appendBoolean(Emulator.getGameEnvironment().getGuildManager().getGuildMember(this.room.getRoomInfo().getGuild().getId(), this.habbo.getHabboInfo().getId()) != null); + } else { + this.response.appendBoolean(false); + } + this.response.appendBoolean(this.room.isMuted()); // isroommuted - this.response.appendInt(this.room.getMuteOption()); - this.response.appendInt(this.room.getKickOption()); - this.response.appendInt(this.room.getBanOption()); + this.response.appendInt(this.room.getRoomInfo().getWhoCanMuteOption()); + this.response.appendInt(this.room.getRoomInfo().getWhoCanKickOption()); + this.response.appendInt(this.room.getRoomInfo().getWhoCanBanOption()); - this.response.appendBoolean(this.room.hasRights(this.habbo)); //mute all button + this.response.appendBoolean(this.room.getRoomRightsManager().hasRights(this.habbo)); //mute all button - this.response.appendInt(this.room.getChatMode()); - this.response.appendInt(this.room.getChatWeight()); - this.response.appendInt(this.room.getChatSpeed()); - this.response.appendInt(this.room.getChatDistance()); - this.response.appendInt(this.room.getChatProtection()); + this.response.appendInt(this.room.getRoomInfo().getChatMode()); + this.response.appendInt(this.room.getRoomInfo().getChatWeight()); + this.response.appendInt(this.room.getRoomInfo().getChatSpeed()); + this.response.appendInt(this.room.getRoomInfo().getChatDistance()); + this.response.appendInt(this.room.getRoomInfo().getChatProtection()); return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomChatSettingsMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomChatSettingsMessageComposer.java index 0f51fb6a..d73702f8 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomChatSettingsMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomChatSettingsMessageComposer.java @@ -13,11 +13,11 @@ public class RoomChatSettingsMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomChatSettingsMessageComposer); - this.response.appendInt(this.room.getChatMode()); - this.response.appendInt(this.room.getChatWeight()); - this.response.appendInt(this.room.getChatSpeed()); - this.response.appendInt(this.room.getChatDistance()); - this.response.appendInt(this.room.getChatProtection()); + this.response.appendInt(this.room.getRoomInfo().getChatMode()); + this.response.appendInt(this.room.getRoomInfo().getChatWeight()); + this.response.appendInt(this.room.getRoomInfo().getChatSpeed()); + this.response.appendInt(this.room.getRoomInfo().getChatDistance()); + this.response.appendInt(this.room.getRoomInfo().getChatProtection()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoComposer.java index b236b606..74e1ee07 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoComposer.java @@ -13,8 +13,8 @@ public class RoomEntryInfoComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomEntryInfoComposer); - this.response.appendInt(this.room.getId()); - this.response.appendString(this.room.getOwnerName()); + this.response.appendInt(this.room.getRoomInfo().getId()); + this.response.appendString(this.room.getRoomInfo().getOwnerInfo().getUsername()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoMessageComposer.java index cad2f54f..254611a9 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomEntryInfoMessageComposer.java @@ -14,7 +14,7 @@ public class RoomEntryInfoMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomEntryInfoMessageComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendBoolean(this.roomOwner); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFilterSettingsMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFilterSettingsMessageComposer.java index 96d0ad1c..0c808f8b 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFilterSettingsMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFilterSettingsMessageComposer.java @@ -14,9 +14,9 @@ public class RoomFilterSettingsMessageComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.roomFilterSettingsMessageComposer); - this.response.appendInt(this.room.getWordFilterWords().size()); + this.response.appendInt(this.room.getRoomWordFilterManager().getFilteredWords().size()); - for (String string : this.room.getWordFilterWords()) { + for (String string : this.room.getRoomWordFilterManager().getFilteredWords()) { this.response.appendString(string); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFloorThicknessUpdatedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFloorThicknessUpdatedComposer.java index f123933c..a5475d47 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFloorThicknessUpdatedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomFloorThicknessUpdatedComposer.java @@ -13,9 +13,9 @@ public class RoomFloorThicknessUpdatedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomFloorThicknessUpdatedComposer); - this.response.appendBoolean(this.room.isHideWall()); //Hide walls? - this.response.appendInt(this.room.getFloorSize()); //Floor Thickness - this.response.appendInt(this.room.getWallSize()); //Wall Thickness + this.response.appendBoolean(this.room.getRoomInfo().isHideWalls()); + this.response.appendInt(this.room.getRoomInfo().getFloorThickness()); + this.response.appendInt(this.room.getRoomInfo().getWallThickness()); return this.response; } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomInfoUpdatedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomInfoUpdatedComposer.java index 77ed4d97..a0e2e673 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomInfoUpdatedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomInfoUpdatedComposer.java @@ -13,7 +13,7 @@ public class RoomInfoUpdatedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomInfoUpdatedComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomReadyMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomReadyMessageComposer.java index d57b2c22..641e07c8 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomReadyMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomReadyMessageComposer.java @@ -14,7 +14,7 @@ public class RoomReadyMessageComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.roomReadyMessageComposer); this.response.appendString(this.room.getLayout().getName()); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java index 6520ae16..84ff0674 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsDataComposer.java @@ -12,17 +12,17 @@ public class RoomSettingsDataComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomSettingsDataComposer); - this.response.appendInt(this.room.getId()); - this.response.appendString(this.room.getName()); - this.response.appendString(this.room.getDescription()); - this.response.appendInt(this.room.getState().getState()); - this.response.appendInt(this.room.getCategory()); - this.response.appendInt(this.room.getUsersMax()); - this.response.appendInt(this.room.getUsersMax()); + this.response.appendInt(this.room.getRoomInfo().getId()); + this.response.appendString(this.room.getRoomInfo().getName()); + this.response.appendString(this.room.getRoomInfo().getDescription()); + this.response.appendInt(this.room.getRoomInfo().getState().ordinal()); + this.response.appendInt(this.room.getRoomInfo().getCategory().getId()); + this.response.appendInt(this.room.getRoomInfo().getMaxUsers()); + this.response.appendInt(this.room.getRoomInfo().getMaxUsers()); - if (!this.room.getTags().isEmpty()) { - this.response.appendInt(this.room.getTags().split(";").length); - for (String tag : this.room.getTags().split(";")) { + if (!this.room.getRoomInfo().getTags().isEmpty()) { + this.response.appendInt(this.room.getRoomInfo().getTags().split(";").length); + for (String tag : this.room.getRoomInfo().getTags().split(";")) { this.response.appendString(tag); } } else { @@ -30,25 +30,25 @@ public class RoomSettingsDataComposer extends MessageComposer { } //this.response.appendInt(this.room.getRights().size()); - this.response.appendInt(this.room.getTradeMode()); //Trade Mode - this.response.appendInt(this.room.isAllowPets() ? 1 : 0); - this.response.appendInt(this.room.isAllowPetsEat() ? 1 : 0); - this.response.appendInt(this.room.isAllowWalkthrough() ? 1 : 0); - this.response.appendInt(this.room.isHideWall() ? 1 : 0); - this.response.appendInt(this.room.getWallSize()); - this.response.appendInt(this.room.getFloorSize()); + this.response.appendInt(this.room.getRoomInfo().getTradeMode()); //Trade Mode + this.response.appendInt(this.room.getRoomInfo().isAllowPets() ? 1 : 0); + this.response.appendInt(this.room.getRoomInfo().isAllowPetsEat() ? 1 : 0); + this.response.appendInt(this.room.getRoomInfo().isAllowWalkthrough() ? 1 : 0); + this.response.appendInt(this.room.getRoomInfo().isHideWalls() ? 1 : 0); + this.response.appendInt(this.room.getRoomInfo().getWallThickness()); + this.response.appendInt(this.room.getRoomInfo().getFloorThickness()); - this.response.appendInt(this.room.getChatMode()); - this.response.appendInt(this.room.getChatWeight()); - this.response.appendInt(this.room.getChatSpeed()); - this.response.appendInt(this.room.getChatDistance()); - this.response.appendInt(this.room.getChatProtection()); + this.response.appendInt(this.room.getRoomInfo().getChatMode()); + this.response.appendInt(this.room.getRoomInfo().getChatWeight()); + this.response.appendInt(this.room.getRoomInfo().getChatSpeed()); + this.response.appendInt(this.room.getRoomInfo().getChatDistance()); + this.response.appendInt(this.room.getRoomInfo().getChatProtection()); this.response.appendBoolean(false); //IDK? - this.response.appendInt(this.room.getMuteOption()); - this.response.appendInt(this.room.getKickOption()); - this.response.appendInt(this.room.getBanOption()); + this.response.appendInt(this.room.getRoomInfo().getWhoCanMuteOption()); + this.response.appendInt(this.room.getRoomInfo().getWhoCanKickOption()); + this.response.appendInt(this.room.getRoomInfo().getWhoCanBanOption()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsSavedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsSavedComposer.java index 5ebf1aa1..6240dde0 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsSavedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomSettingsSavedComposer.java @@ -13,7 +13,7 @@ public class RoomSettingsSavedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomSettingsSavedComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomVisualizationSettingsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomVisualizationSettingsComposer.java index 4982e0db..a434684c 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomVisualizationSettingsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/RoomVisualizationSettingsComposer.java @@ -13,9 +13,9 @@ public class RoomVisualizationSettingsComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomVisualizationSettingsComposer); - this.response.appendBoolean(this.room.isHideWall()); - this.response.appendInt(this.room.getWallSize()); - this.response.appendInt(this.room.getFloorSize()); + this.response.appendBoolean(this.room.getRoomInfo().isHideWalls()); + this.response.appendInt(this.room.getRoomInfo().getWallThickness()); + this.response.appendInt(this.room.getRoomInfo().getFloorThickness()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/FloorItemOnRollerComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/FloorItemOnRollerComposer.java index 40629d13..18db005c 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/FloorItemOnRollerComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/FloorItemOnRollerComposer.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.outgoing.rooms.items; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -12,8 +12,8 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class FloorItemOnRollerComposer extends MessageComposer { // THIS IS WRONG SlideObjectBundleMessageComposer - private final HabboItem item; - private final HabboItem roller; + private final RoomItem item; + private final RoomItem roller; private final RoomTile oldLocation; private final double oldZ; private final RoomTile newLocation; @@ -21,7 +21,7 @@ public class FloorItemOnRollerComposer extends MessageComposer { private final double heightOffset; private final Room room; - public FloorItemOnRollerComposer(HabboItem item, HabboItem roller, RoomTile newLocation, double heightOffset, Room room) { + public FloorItemOnRollerComposer(RoomItem item, RoomItem roller, RoomTile newLocation, double heightOffset, Room room) { this.item = item; this.roller = roller; this.newLocation = newLocation; @@ -35,31 +35,31 @@ public class FloorItemOnRollerComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { - short oldX = this.item.getX(); - short oldY = this.item.getY(); + short oldX = this.item.getCurrentPosition().getX(); + short oldY = this.item.getCurrentPosition().getY(); this.response.init(Outgoing.slideObjectBundleMessageComposer); - this.response.appendInt(this.oldLocation != null ? this.oldLocation.getX() : this.item.getX()); - this.response.appendInt(this.oldLocation != null ? this.oldLocation.getY() : this.item.getY()); + this.response.appendInt(this.oldLocation != null ? this.oldLocation.getX() : this.item.getCurrentPosition().getX()); + this.response.appendInt(this.oldLocation != null ? this.oldLocation.getY() : this.item.getCurrentPosition().getY()); this.response.appendInt(this.newLocation.getX()); this.response.appendInt(this.newLocation.getY()); this.response.appendInt(1); this.response.appendInt(this.item.getId()); - this.response.appendString(Double.toString(this.oldLocation != null ? this.oldZ : this.item.getZ())); - this.response.appendString(Double.toString(this.oldLocation != null ? this.newZ : (this.item.getZ() + this.heightOffset))); + this.response.appendString(Double.toString(this.oldLocation != null ? this.oldZ : this.item.getCurrentZ())); + this.response.appendString(Double.toString(this.oldLocation != null ? this.newZ : (this.item.getCurrentZ() + this.heightOffset))); this.response.appendInt(this.roller != null ? this.roller.getId() : -1); if(this.oldLocation == null) { - this.item.onMove(this.room, this.room.getLayout().getTile(this.item.getX(), this.item.getY()), this.newLocation); - this.item.setX(this.newLocation.getX()); - this.item.setY(this.newLocation.getY()); - this.item.setZ(this.item.getZ() + this.heightOffset); - this.item.needsUpdate(true); + this.item.onMove(this.room, this.room.getLayout().getTile(this.item.getCurrentPosition().getX(), this.item.getCurrentPosition().getY()), this.newLocation); + + this.item.setCurrentPosition(this.newLocation); + this.item.setCurrentZ(this.item.getCurrentZ() + this.heightOffset); + this.item.setSqlUpdateNeeded(true); //TODO This is bad // THashSet tiles = this.room.getLayout().getTilesAt(this.room.getLayout().getTile(oldX, oldY), this.item.getBaseItem().getWidth(), this.item.getBaseItem().getLength(), this.item.getRotation()); - tiles.addAll(this.room.getLayout().getTilesAt(this.room.getLayout().getTile(this.item.getX(), this.item.getY()), this.item.getBaseItem().getWidth(), this.item.getBaseItem().getLength(), this.item.getRotation())); + tiles.addAll(this.room.getLayout().getTilesAt(this.room.getLayout().getTile(this.item.getCurrentPosition().getX(), this.item.getCurrentPosition().getY()), this.item.getBaseItem().getWidth(), this.item.getBaseItem().getLength(), this.item.getRotation())); this.room.updateTiles(tiles); //this.room.sendComposer(new UpdateStackHeightComposer(oldX, oldY, this.room.getStackHeight(oldX, oldY, true)).compose()); // diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemAddMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemAddMessageComposer.java index 88325771..84d63be3 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemAddMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemAddMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class ItemAddMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; private final String itemOwnerName; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemDataUpdateMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemDataUpdateMessageComposer.java index 54962305..674093b7 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemDataUpdateMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemDataUpdateMessageComposer.java @@ -13,13 +13,13 @@ public class ItemDataUpdateMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { - if (this.postIt.getExtradata().isEmpty() || this.postIt.getExtradata().length() < 6) { - this.postIt.setExtradata("FFFF33"); + if (this.postIt.getExtraData().isEmpty() || this.postIt.getExtraData().length() < 6) { + this.postIt.setExtraData("FFFF33"); } this.response.init(Outgoing.itemDataUpdateMessageComposer); this.response.appendString(this.postIt.getId() + ""); - this.response.appendString(this.postIt.getExtradata()); + this.response.appendString(this.postIt.getExtraData()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemRemoveMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemRemoveMessageComposer.java index 50fa9538..dadb1f62 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemRemoveMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemRemoveMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,13 +8,13 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class ItemRemoveMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.itemRemoveMessageComposer); this.response.appendString(this.item.getId() + ""); - this.response.appendInt(this.item.getUserId()); + this.response.appendInt(this.item.getOwnerInfo().getId()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemUpdateMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemUpdateMessageComposer.java index d2b3ecf0..daedf355 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemUpdateMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemUpdateMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,14 +8,14 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class ItemUpdateMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.itemUpdateMessageComposer); this.item.serializeWallData(this.response); - this.response.appendString(this.item.getUserId() + ""); + this.response.appendString(String.valueOf(this.item.getOwnerInfo().getId())); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java index 13ff6004..cfefa0e5 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsComposer.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.outgoing.rooms.items; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -10,7 +10,7 @@ import gnu.trove.map.TIntObjectMap; import gnu.trove.map.hash.THashMap; import lombok.AllArgsConstructor; -import java.util.List; +import java.util.Collection; import java.util.Map; import java.util.NoSuchElementException; @@ -18,7 +18,6 @@ import java.util.NoSuchElementException; public class ItemsComposer extends MessageComposer { private final Room room; - @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.itemsComposer); @@ -42,10 +41,10 @@ public class ItemsComposer extends MessageComposer { this.response.appendString(set.getValue()); } - List items = this.room.getWallItems(); + Collection items = this.room.getRoomItemManager().getWallItems().values(); this.response.appendInt(items.size()); - for (HabboItem item : items) { + for (RoomItem item : items) { item.serializeWallData(this.response); } return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsDataUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsDataUpdateComposer.java index 76359e60..0777a895 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsDataUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ItemsDataUpdateComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -10,14 +10,14 @@ import java.util.Set; @AllArgsConstructor public class ItemsDataUpdateComposer extends MessageComposer { - private final Set items; + private final Set items; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.objectsDataUpdateMessageComposer); this.response.appendInt(this.items.size()); - for (HabboItem item : this.items) { + for (RoomItem item : this.items) { this.response.appendInt(item.getId()); item.serializeExtradata(this.response); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectAddMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectAddMessageComposer.java index 6f89621e..246cd2cf 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectAddMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectAddMessageComposer.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.outgoing.rooms.items; import com.eu.habbo.habbohotel.items.interactions.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -9,7 +9,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class ObjectAddMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; private final String itemOwnerName; @@ -21,7 +21,7 @@ public class ObjectAddMessageComposer extends MessageComposer { this.item.serializeExtradata(this.response); this.response.appendInt(-1); this.response.appendInt(this.item instanceof InteractionTeleport || this.item instanceof InteractionSwitch || this.item instanceof InteractionSwitchRemoteControl || this.item instanceof InteractionVendingMachine || this.item instanceof InteractionInformationTerminal || this.item instanceof InteractionPostIt || this.item instanceof InteractionSpinningBottle || this.item instanceof InteractionPuzzleBox ? 2 : this.item.isUsable() ? 1 : 0); - this.response.appendInt(this.item.getUserId()); + this.response.appendInt(this.item.getOwnerInfo().getId()); this.response.appendString(this.itemOwnerName); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectDataUpdateMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectDataUpdateMessageComposer.java index 76b98b6f..08e461bb 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectDataUpdateMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectDataUpdateMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class ObjectDataUpdateMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override protected ServerMessage composeInternal() { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectUpdateMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectUpdateMessageComposer.java index 9f48b749..419717bb 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectUpdateMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectUpdateMessageComposer.java @@ -2,7 +2,7 @@ package com.eu.habbo.messages.outgoing.rooms.items; import com.eu.habbo.habbohotel.items.interactions.InteractionGift; import com.eu.habbo.habbohotel.items.interactions.InteractionMusicDisc; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -10,7 +10,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class ObjectUpdateMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override @@ -21,7 +21,7 @@ public class ObjectUpdateMessageComposer extends MessageComposer { this.item.serializeExtradata(this.response); this.response.appendInt(-1); this.response.appendInt(0); - this.response.appendInt(this.item.getUserId()); + this.response.appendInt(this.item.getOwnerInfo().getId()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectsMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectsMessageComposer.java index 797533a0..901e289c 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectsMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/ObjectsMessageComposer.java @@ -1,7 +1,7 @@ package com.eu.habbo.messages.outgoing.rooms.items; import com.eu.habbo.habbohotel.items.interactions.*; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -15,7 +15,7 @@ import java.util.NoSuchElementException; @AllArgsConstructor public class ObjectsMessageComposer extends MessageComposer { private final TIntObjectMap furniOwnerNames; - private final THashSet items; + private final THashSet items; @Override @@ -37,13 +37,13 @@ public class ObjectsMessageComposer extends MessageComposer { this.response.appendInt(this.items.size()); - for (HabboItem item : this.items) { + for (RoomItem item : this.items) { item.serializeFloorData(this.response); this.response.appendInt(item instanceof InteractionGift ? ((((InteractionGift) item).getColorId() * 1000) + ((InteractionGift) item).getRibbonId()) : (item instanceof InteractionMusicDisc ? ((InteractionMusicDisc) item).getSongId() : 1)); item.serializeExtradata(this.response); this.response.appendInt(-1); this.response.appendInt(item instanceof InteractionTeleport || item instanceof InteractionSwitch || item instanceof InteractionSwitchRemoteControl || item instanceof InteractionVendingMachine || item instanceof InteractionInformationTerminal || item instanceof InteractionPostIt || item instanceof InteractionSpinningBottle || item instanceof InteractionPuzzleBox ? 2 : item.isUsable() ? 1 : 0); - this.response.appendInt(item.getUserId()); + this.response.appendInt(item.getOwnerInfo().getId()); } return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/OneWayDoorStatusMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/OneWayDoorStatusMessageComposer.java index dfaa9c36..8f02ff06 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/OneWayDoorStatusMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/OneWayDoorStatusMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,14 +8,14 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class OneWayDoorStatusMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.oneWayDoorStatusMessageComposer); this.response.appendInt(this.item.getId()); try { - int state = Integer.parseInt(this.item.getExtradata()); + int state = Integer.parseInt(this.item.getExtraData()); this.response.appendInt(state); } catch (Exception e) { this.response.appendInt(0); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentOpenedMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentOpenedMessageComposer.java index 21e5773a..11ade4fa 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentOpenedMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/PresentOpenedMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class PresentOpenedMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; private final String text; private final boolean unknown; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RemoveFloorItemComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RemoveFloorItemComposer.java index 724b51a6..c9e90cdc 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RemoveFloorItemComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RemoveFloorItemComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,10 +8,10 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class RemoveFloorItemComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; private final boolean noUser; - public RemoveFloorItemComposer(HabboItem item) { + public RemoveFloorItemComposer(RoomItem item) { this.item = item; this.noUser = false; } @@ -23,7 +23,7 @@ public class RemoveFloorItemComposer extends MessageComposer { this.response.appendString(this.item.getId() + ""); this.response.appendBoolean(false); - this.response.appendInt(this.noUser ? 0 : this.item.getUserId()); + this.response.appendInt(this.noUser ? 0 : this.item.getOwnerInfo().getId()); this.response.appendInt(0); return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RequestSpamWallPostItMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RequestSpamWallPostItMessageComposer.java index f3016dd0..fb230aee 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RequestSpamWallPostItMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/RequestSpamWallPostItMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class RequestSpamWallPostItMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override protected ServerMessage composeInternal() { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/UpdateStackHeightTileHeightComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/UpdateStackHeightTileHeightComposer.java index c9c07747..749d9580 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/UpdateStackHeightTileHeightComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/UpdateStackHeightTileHeightComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.items; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class UpdateStackHeightTileHeightComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; private final int height; @Override diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/rentablespaces/RentableSpaceStatusMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/rentablespaces/RentableSpaceStatusMessageComposer.java index 0061c9a6..4a130394 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/rentablespaces/RentableSpaceStatusMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/items/rentablespaces/RentableSpaceStatusMessageComposer.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.outgoing.rooms.items.rentablespaces; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionRentableSpace; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -27,7 +27,7 @@ public class RentableSpaceStatusMessageComposer extends MessageComposer { //:test 194 b:1 i:101 i:1 s:Admin i:10 i:10 private final Habbo habbo; - private final HabboItem item; + private final RoomItem item; private int errorCode = 0; @Override diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/OpenPetPackageRequestedMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/OpenPetPackageRequestedMessageComposer.java index d360906a..f72de30a 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/OpenPetPackageRequestedMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/OpenPetPackageRequestedMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.pets; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class OpenPetPackageRequestedMessageComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetExperienceComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetExperienceComposer.java index 63a0d18b..9822184e 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetExperienceComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetExperienceComposer.java @@ -16,7 +16,7 @@ public class PetExperienceComposer extends MessageComposer { protected ServerMessage composeInternal() { this.response.init(Outgoing.petExperienceComposer); this.response.appendInt(this.pet.getId()); - this.response.appendInt(this.pet.getRoomUnit().getId()); + this.response.appendInt(this.pet.getRoomUnit().getVirtualId()); this.response.appendInt(this.amount); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetFigureUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetFigureUpdateComposer.java index f393d9e2..392d5203 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetFigureUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetFigureUpdateComposer.java @@ -14,7 +14,7 @@ public class PetFigureUpdateComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.petFigureUpdateComposer); - this.response.appendInt(this.pet.getRoomUnit().getId()); + this.response.appendInt(this.pet.getRoomUnit().getVirtualId()); this.response.appendInt(this.pet.getId()); this.response.appendInt(this.pet.getPetData().getType()); this.response.appendInt(this.pet.getRace()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetLevelUpdatedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetLevelUpdatedComposer.java index 01583576..dbcc7382 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetLevelUpdatedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetLevelUpdatedComposer.java @@ -14,7 +14,7 @@ public class PetLevelUpdatedComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.petLevelUpdateComposer); - this.response.appendInt(this.pet.getRoomUnit().getId()); + this.response.appendInt(this.pet.getRoomUnit().getVirtualId()); this.response.appendInt(this.pet.getId()); this.response.appendInt(this.pet.getLevel()); return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java index 0b4c7408..5f5b065a 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/PetStatusUpdateComposer.java @@ -15,7 +15,7 @@ public class PetStatusUpdateComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.petStatusUpdateComposer); - this.response.appendInt(this.pet.getRoomUnit().getId()); + this.response.appendInt(this.pet.getRoomUnit().getVirtualId()); this.response.appendInt(this.pet instanceof RideablePet && ((RideablePet) this.pet).anyoneCanRide() ? 1 : 0); this.response.appendBoolean((this.pet instanceof MonsterplantPet && ((MonsterplantPet) this.pet).canBreed())); //unknown 1 this.response.appendBoolean((this.pet instanceof MonsterplantPet && !((MonsterplantPet) this.pet).isFullyGrown())); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java index 2d942965..b5285772 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/pets/RoomPetComposer.java @@ -4,17 +4,16 @@ import com.eu.habbo.habbohotel.pets.*; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; -import gnu.trove.map.TIntObjectMap; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.procedure.TIntObjectProcedure; import lombok.AllArgsConstructor; +import java.util.concurrent.ConcurrentHashMap; + @AllArgsConstructor -public class RoomPetComposer extends MessageComposer implements TIntObjectProcedure { - private final TIntObjectMap pets; +public class RoomPetComposer extends MessageComposer { + private final ConcurrentHashMap pets; public RoomPetComposer(Pet pet) { - this.pets = new TIntObjectHashMap<>(); + this.pets = new ConcurrentHashMap<>(); this.pets.put(pet.getId(), pet); } @@ -23,11 +22,10 @@ public class RoomPetComposer extends MessageComposer implements TIntObjectProced protected ServerMessage composeInternal() { this.response.init(Outgoing.usersComposer); this.response.appendInt(this.pets.size()); - this.pets.forEachEntry(this); + this.pets.forEach((a, p) -> this.execute(a, p)); return this.response; } - @Override public boolean execute(int a, Pet pet) { this.response.appendInt(pet.getId()); this.response.appendString(pet.getName()); @@ -38,10 +36,10 @@ public class RoomPetComposer extends MessageComposer implements TIntObjectProced // TODO: It will never be a type of MonsterplantPet in this scenario? this.response.appendString(pet.getPetData().getType() + " " + pet.getRace() + " " + pet.getColor() + " " + ((pet instanceof HorsePet ? (((HorsePet) pet).hasSaddle() ? "3" : "2") + " 2 " + ((HorsePet) pet).getHairStyle() + " " + ((HorsePet) pet).getHairColor() + " 3 " + ((HorsePet) pet).getHairStyle() + " " + ((HorsePet) pet).getHairColor() + (((HorsePet) pet).hasSaddle() ? " 4 9 0" : "") : pet instanceof MonsterplantPet ? (((MonsterplantPet) pet).look.isEmpty() ? "2 1 8 6 0 -1 -1" : ((MonsterplantPet) pet).look) : "2 2 -1 0 3 -1 0"))); } - this.response.appendInt(pet.getRoomUnit().getId()); - this.response.appendInt(pet.getRoomUnit().getX()); - this.response.appendInt(pet.getRoomUnit().getY()); - this.response.appendString(pet.getRoomUnit().getZ() + ""); + this.response.appendInt(pet.getRoomUnit().getVirtualId()); + this.response.appendInt(pet.getRoomUnit().getCurrentPosition().getX()); + this.response.appendInt(pet.getRoomUnit().getCurrentPosition().getY()); + this.response.appendString(pet.getRoomUnit().getCurrentZ() + ""); this.response.appendInt(0); this.response.appendInt(2); this.response.appendInt(pet.getPetData().getType()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomAdPurchaseInfoComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomAdPurchaseInfoComposer.java index 437f05dd..7d75dc76 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomAdPurchaseInfoComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomAdPurchaseInfoComposer.java @@ -24,8 +24,8 @@ public class RoomAdPurchaseInfoComposer extends MessageComposer { this.response.appendBoolean(true); this.response.appendInt(this.rooms.size()); for (Room room : this.rooms) { - this.response.appendInt(room.getId()); - this.response.appendString(room.getName()); + this.response.appendInt(room.getRoomInfo().getId()); + this.response.appendString(room.getRoomInfo().getName()); this.response.appendBoolean(true); //IDK what the fuck this is. } return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomEventComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomEventComposer.java index 0f5f1ebd..5d0a6cd1 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomEventComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/promotions/RoomEventComposer.java @@ -30,11 +30,11 @@ public class RoomEventComposer extends MessageComposer { this.response.appendInt(0); this.response.appendInt(0); } else { - this.response.appendInt(this.room.getId()); // promotion id - this.response.appendInt(this.room.getOwnerId()); - this.response.appendString(this.room.getOwnerName()); + this.response.appendInt(this.room.getRoomInfo().getId()); // promotion id + this.response.appendInt(this.room.getRoomInfo().getOwnerInfo().getId()); + this.response.appendString(this.room.getRoomInfo().getOwnerInfo().getUsername()); - this.response.appendInt(this.room.getId()); // room id + this.response.appendInt(this.room.getRoomInfo().getId()); // room id this.response.appendInt(1); // "type" this.response.appendString(this.roomPromotion.getTitle()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/AvatarEffectMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/AvatarEffectMessageComposer.java index 3004bd7b..41926d47 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/AvatarEffectMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/AvatarEffectMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,11 +8,11 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class AvatarEffectMessageComposer extends MessageComposer { - private final RoomUnit roomUnit; + private final RoomAvatar roomAvatar; private final int effectId; - public AvatarEffectMessageComposer(RoomUnit roomUnit) { - this.roomUnit = roomUnit; + public AvatarEffectMessageComposer(RoomAvatar roomAvatar) { + this.roomAvatar = roomAvatar; this.effectId = -1; } @@ -20,8 +20,8 @@ public class AvatarEffectMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.avatarEffectMessageComposer); - this.response.appendInt(this.roomUnit.getId()); - this.response.appendInt(this.effectId == -1 ? this.roomUnit.getEffectId() : this.effectId); + this.response.appendInt(this.roomAvatar.getVirtualId()); + this.response.appendInt(this.effectId == -1 ? this.roomAvatar.getEffectId() : this.effectId); this.response.appendInt(0); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/CarryObjectMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/CarryObjectMessageComposer.java index 5d3e1947..31171227 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/CarryObjectMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/CarryObjectMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,14 +8,14 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class CarryObjectMessageComposer extends MessageComposer { - private final RoomUnit roomUnit; + private final RoomAvatar roomAvatar; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.carryObjectMessageComposer); - this.response.appendInt(this.roomUnit.getId()); - this.response.appendInt(this.roomUnit.getHandItem()); + this.response.appendInt(this.roomAvatar.getVirtualId()); + this.response.appendInt(this.roomAvatar.getHandItem()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java index 5da8c5b0..92a28ac1 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/DanceMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,14 +8,14 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class DanceMessageComposer extends MessageComposer { - private final RoomUnit roomUnit; + private final RoomAvatar roomAvatar; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.danceMessageComposer); - this.response.appendInt(this.roomUnit.getId()); - this.response.appendInt(this.roomUnit.getDanceType().getType()); + this.response.appendInt(this.roomAvatar.getVirtualId()); + this.response.appendInt(this.roomAvatar.getDanceType().getType()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/ExpressionMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/ExpressionMessageComposer.java index e4a3aef5..370c450f 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/ExpressionMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/ExpressionMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUserAction; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -15,7 +15,7 @@ public class ExpressionMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.expressionMessageComposer); - this.response.appendInt(this.roomUnit.getId()); + this.response.appendInt(this.roomUnit.getVirtualId()); this.response.appendInt(this.action.getAction()); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/HandItemReceivedMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/HandItemReceivedMessageComposer.java index aa9914e5..7774d2b3 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/HandItemReceivedMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/HandItemReceivedMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -14,7 +14,7 @@ public class HandItemReceivedMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.handItemReceivedMessageComposer); - this.response.appendInt(this.from.getId()); + this.response.appendInt(this.from.getVirtualId()); this.response.appendInt(this.handItem); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/NoSuchFlatComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/NoSuchFlatComposer.java index 559cbc76..cf6fad8f 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/NoSuchFlatComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/NoSuchFlatComposer.java @@ -15,7 +15,7 @@ public class NoSuchFlatComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.noSuchFlatComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendInt(this.habboId); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java index 36d8ee4e..ffa13289 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUnitOnRollerComposer.java @@ -4,8 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionRoller; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -18,7 +18,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { // THIS IS WRONG SlideObjectBundleMessageComposer private static final Logger LOGGER = LoggerFactory.getLogger(RoomUnitOnRollerComposer.class); private final RoomUnit roomUnit; - private final HabboItem roller; + private final RoomItem roller; private final RoomTile oldLocation; private final double oldZ; private final RoomTile newLocation; @@ -26,9 +26,9 @@ public class RoomUnitOnRollerComposer extends MessageComposer { private final Room room; private int x; private int y; - private final HabboItem oldTopItem; + private final RoomItem oldTopItem; - public RoomUnitOnRollerComposer(RoomUnit roomUnit, HabboItem roller, RoomTile oldLocation, double oldZ, RoomTile newLocation, double newZ, Room room) { + public RoomUnitOnRollerComposer(RoomUnit roomUnit, RoomItem roller, RoomTile oldLocation, double oldZ, RoomTile newLocation, double newZ, Room room) { this.roomUnit = roomUnit; this.roller = roller; this.oldLocation = oldLocation; @@ -36,14 +36,14 @@ public class RoomUnitOnRollerComposer extends MessageComposer { this.newLocation = newLocation; this.newZ = newZ; this.room = room; - oldTopItem = this.room.getTopItemAt(oldLocation.getX(), oldLocation.getY()); + oldTopItem = this.room.getRoomItemManager().getTopItemAt(oldLocation.getX(), oldLocation.getY()); } public RoomUnitOnRollerComposer(RoomUnit roomUnit, RoomTile newLocation, Room room) { this.roomUnit = roomUnit; this.roller = null; - this.oldLocation = this.roomUnit.getCurrentLocation(); - this.oldZ = this.roomUnit.getZ(); + this.oldLocation = this.roomUnit.getCurrentPosition(); + this.oldZ = this.roomUnit.getCurrentZ(); this.newLocation = newLocation; this.newZ = this.newLocation.getStackHeight(); this.room = room; @@ -63,15 +63,15 @@ public class RoomUnitOnRollerComposer extends MessageComposer { this.response.appendInt(0); this.response.appendInt(this.roller == null ? 0 : this.roller.getId()); this.response.appendInt(2); - this.response.appendInt(this.roomUnit.getId()); + this.response.appendInt(this.roomUnit.getVirtualId()); this.response.appendString(this.oldZ + ""); this.response.appendString(this.newZ + ""); if (this.roller != null && room.getLayout() != null) { Emulator.getThreading().run(() -> { - if(!this.roomUnit.isWalking() && this.roomUnit.getCurrentLocation() == this.oldLocation) { - HabboItem topItem = this.room.getTopItemAt(this.oldLocation.getX(), this.oldLocation.getY()); - HabboItem topItemNewLocation = this.room.getTopItemAt(this.newLocation.getX(), this.newLocation.getY()); + if(!this.roomUnit.isWalking() && this.roomUnit.getCurrentPosition() == this.oldLocation) { + RoomItem topItem = this.room.getRoomItemManager().getTopItemAt(this.oldLocation.getX(), this.oldLocation.getY()); + RoomItem topItemNewLocation = this.room.getRoomItemManager().getTopItemAt(this.newLocation.getX(), this.newLocation.getY()); if (topItem != null && (oldTopItem == null || oldTopItem != topItemNewLocation)) { try { @@ -82,8 +82,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { } this.roomUnit.setLocation(this.newLocation); - this.roomUnit.setZ(this.newLocation.getStackHeight()); - this.roomUnit.setPreviousLocationZ(this.newLocation.getStackHeight()); + this.roomUnit.setCurrentZ(this.newLocation.getStackHeight()); if (topItemNewLocation != null && topItemNewLocation != roller && oldTopItem != topItemNewLocation) { try { @@ -93,7 +92,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { } } } - }, this.room.getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY); + }, this.room.getRoomInfo().getRollerSpeed() == 0 ? 250 : InteractionRoller.DELAY); /* RoomTile rollerTile = room.getLayout().getTile(this.roller.getX(), this.roller.getY()); Emulator.getThreading().run(() -> { @@ -117,7 +116,7 @@ public class RoomUnitOnRollerComposer extends MessageComposer { */ } else { this.roomUnit.setLocation(this.newLocation); - this.roomUnit.setZ(this.newZ); + this.roomUnit.setCurrentZ(this.newZ); } return this.response; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUsersComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUsersComposer.java index 10225e60..4a1be99d 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUsersComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/RoomUsersComposer.java @@ -1,153 +1,36 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.bots.Bot; -import com.eu.habbo.habbohotel.guilds.Guild; -import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.units.type.Avatar; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; import java.util.Collection; +import java.util.List; public class RoomUsersComposer extends MessageComposer { - private Habbo habbo; - private Collection habbos; - private Bot bot; - private Collection bots; + private final Collection avatars; - public RoomUsersComposer(Habbo habbo) { - this.habbo = habbo; + public RoomUsersComposer(Avatar avatar) { + this.avatars = List.of(avatar); } - public RoomUsersComposer(Collection habbos) { - this.habbos = habbos; - } - - public RoomUsersComposer(Bot bot) { - this.bot = bot; - } - - public RoomUsersComposer(Collection bots, boolean isBot) { - this.bots = bots; + public RoomUsersComposer(Collection avatars) { + this.avatars = avatars; } @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.usersComposer); - if (this.habbo != null) { - this.response.appendInt(1); - this.response.appendInt(this.habbo.getHabboInfo().getId()); - this.response.appendString(this.habbo.getHabboInfo().getUsername()); - this.response.appendString(this.habbo.getHabboInfo().getMotto()); - this.response.appendString(this.habbo.getHabboInfo().getLook()); - this.response.appendInt(this.habbo.getRoomUnit().getId()); //Room Unit ID - this.response.appendInt(this.habbo.getRoomUnit().getX()); - this.response.appendInt(this.habbo.getRoomUnit().getY()); - this.response.appendString(this.habbo.getRoomUnit().getZ() + ""); - this.response.appendInt(this.habbo.getRoomUnit().getBodyRotation().getValue()); - this.response.appendInt(1); - this.response.appendString(this.habbo.getHabboInfo().getGender().name().toUpperCase()); - this.response.appendInt(this.habbo.getHabboStats().getGuild() != 0 ? this.habbo.getHabboStats().getGuild() : -1); - this.response.appendInt(this.habbo.getHabboStats().getGuild() != 0 ? 1 : -1); - - String name = ""; - if (this.habbo.getHabboStats().getGuild() != 0) { - Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.habbo.getHabboStats().getGuild()); - - if (g != null) - name = g.getName(); - } - this.response.appendString(name); - - this.response.appendString(""); - this.response.appendInt(this.habbo.getHabboStats().getAchievementScore()); - this.response.appendBoolean(true); - } else if (this.habbos != null) { - this.response.appendInt(this.habbos.size()); - for (Habbo habbo : this.habbos) { - if (habbo != null) { - this.response.appendInt(habbo.getHabboInfo().getId()); - this.response.appendString(habbo.getHabboInfo().getUsername()); - this.response.appendString(habbo.getHabboInfo().getMotto()); - this.response.appendString(habbo.getHabboInfo().getLook()); - this.response.appendInt(habbo.getRoomUnit().getId()); //Room Unit ID - this.response.appendInt(habbo.getRoomUnit().getX()); - this.response.appendInt(habbo.getRoomUnit().getY()); - this.response.appendString(habbo.getRoomUnit().getZ() + ""); - this.response.appendInt(habbo.getRoomUnit().getBodyRotation().getValue()); - this.response.appendInt(1); - this.response.appendString(habbo.getHabboInfo().getGender().name().toUpperCase()); - this.response.appendInt(habbo.getHabboStats().getGuild() != 0 ? habbo.getHabboStats().getGuild() : -1); - this.response.appendInt(habbo.getHabboStats().getGuild() != 0 ? habbo.getHabboStats().getGuild() : -1); - String name = ""; - if (habbo.getHabboStats().getGuild() != 0) { - Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(habbo.getHabboStats().getGuild()); - - if (g != null) - name = g.getName(); - } - this.response.appendString(name); - this.response.appendString(""); - this.response.appendInt(habbo.getHabboStats().getAchievementScore()); - this.response.appendBoolean(true); + if (this.avatars != null) { + this.response.appendInt(this.avatars.size()); + for (Avatar avatar : this.avatars) { + if (avatar != null) { + avatar.serialize(this.response); } } - } else if (this.bot != null) { - this.response.appendInt(1); - this.response.appendInt(-this.bot.getId()); - this.response.appendString(this.bot.getName()); - this.response.appendString(this.bot.getMotto()); - this.response.appendString(this.bot.getFigure()); - this.response.appendInt(this.bot.getRoomUnit().getId()); - this.response.appendInt(this.bot.getRoomUnit().getX()); - this.response.appendInt(this.bot.getRoomUnit().getY()); - this.response.appendString(this.bot.getRoomUnit().getZ() + ""); - this.response.appendInt(this.bot.getRoomUnit().getBodyRotation().getValue()); - this.response.appendInt(4); - this.response.appendString(this.bot.getGender().name().toUpperCase()); - this.response.appendInt(this.bot.getOwnerId()); - this.response.appendString(this.bot.getOwnerName()); - this.response.appendInt(10); - this.response.appendShort(0); - this.response.appendShort(1); - this.response.appendShort(2); - this.response.appendShort(3); - this.response.appendShort(4); - this.response.appendShort(5); - this.response.appendShort(6); - this.response.appendShort(7); - this.response.appendShort(8); - this.response.appendShort(9); - } else if (this.bots != null) { - this.response.appendInt(this.bots.size()); - for (Bot bot : this.bots) { - this.response.appendInt(-bot.getId()); - this.response.appendString(bot.getName()); - this.response.appendString(bot.getMotto()); - this.response.appendString(bot.getFigure()); - this.response.appendInt(bot.getRoomUnit().getId()); - this.response.appendInt(bot.getRoomUnit().getX()); - this.response.appendInt(bot.getRoomUnit().getY()); - this.response.appendString(bot.getRoomUnit().getZ() + ""); - this.response.appendInt(bot.getRoomUnit().getBodyRotation().getValue()); - this.response.appendInt(4); - this.response.appendString(bot.getGender().name().toUpperCase()); - this.response.appendInt(bot.getOwnerId()); - this.response.appendString(bot.getOwnerName()); - this.response.appendInt(10); - this.response.appendShort(0); - this.response.appendShort(1); - this.response.appendShort(2); - this.response.appendShort(3); - this.response.appendShort(4); - this.response.appendShort(5); - this.response.appendShort(6); - this.response.appendShort(7); - this.response.appendShort(8); - this.response.appendShort(9); - } } + return this.response; } -} +} \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/SleepMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/SleepMessageComposer.java index 778f4fc0..ef7e00d6 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/SleepMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/SleepMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,14 +8,13 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class SleepMessageComposer extends MessageComposer { - private final RoomUnit roomUnit; - + private final RoomHabbo roomHabbo; @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.sleepMessageComposer); - this.response.appendInt(this.roomUnit.getId()); - this.response.appendBoolean(this.roomUnit.isIdle()); + this.response.appendInt(this.roomHabbo.getVirtualId()); + this.response.appendBoolean(this.roomHabbo.isIdle()); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserChangeMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserChangeMessageComposer.java index d35c7dbb..1eee6ba2 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserChangeMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserChangeMessageComposer.java @@ -13,7 +13,7 @@ public class UserChangeMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.userChangeMessageComposer); - this.response.appendInt(this.habbo.getRoomUnit() == null ? -1 : this.habbo.getRoomUnit().getId()); + this.response.appendInt(this.habbo.getRoomUnit() == null ? -1 : this.habbo.getRoomUnit().getVirtualId()); this.response.appendString(this.habbo.getHabboInfo().getLook()); this.response.appendString(this.habbo.getHabboInfo().getGender().name() + ""); this.response.appendString(this.habbo.getHabboInfo().getMotto()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserNameChangedMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserNameChangedMessageComposer.java index 80d4a998..83d43b65 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserNameChangedMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserNameChangedMessageComposer.java @@ -20,7 +20,7 @@ public class UserNameChangedMessageComposer extends MessageComposer { public UserNameChangedMessageComposer(Habbo habbo, boolean includePrefix) { this.userId = habbo.getHabboInfo().getId(); - this.roomId = habbo.getRoomUnit().getId(); + this.roomId = habbo.getRoomUnit().getVirtualId(); this.name = (includePrefix ? Room.PREFIX_FORMAT.replace("%color%", habbo.getHabboInfo().getPermissionGroup().getPrefixColor()).replace("%prefix%", habbo.getHabboInfo().getPermissionGroup().getPrefix()) : "") + habbo.getHabboInfo().getUsername(); } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserRemoveMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserRemoveMessageComposer.java index b1bb08b8..b846b460 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserRemoveMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserRemoveMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -13,7 +13,7 @@ public class UserRemoveMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.userRemoveMessageComposer); - this.response.appendString(this.roomUnit.getId() + ""); + this.response.appendString(String.valueOf(this.roomUnit.getVirtualId())); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTagsMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTagsMessageComposer.java index 72a1482a..d23e22b2 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTagsMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTagsMessageComposer.java @@ -13,7 +13,7 @@ public class UserTagsMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.userTagsMessageComposer); - this.response.appendInt(this.habbo.getRoomUnit().getId()); + this.response.appendInt(this.habbo.getRoomUnit().getVirtualId()); this.response.appendInt(this.habbo.getHabboStats().getTags().length); for (String tag : this.habbo.getHabboStats().getTags()) { diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTypingMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTypingMessageComposer.java index f9e91566..b7da4c61 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTypingMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserTypingMessageComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -14,7 +14,7 @@ public class UserTypingMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.userTypingMessageComposer); - this.response.appendInt(this.roomUnit.getId()); + this.response.appendInt(this.roomUnit.getVirtualId()); this.response.appendInt(this.typing ? 1 : 0); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUnbannedFromRoomComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUnbannedFromRoomComposer.java index 917b0ebc..5aa02593 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUnbannedFromRoomComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUnbannedFromRoomComposer.java @@ -14,7 +14,7 @@ public class UserUnbannedFromRoomComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.userUnbannedFromRoomComposer); - this.response.appendInt(this.room.getId()); + this.response.appendInt(this.room.getRoomInfo().getId()); this.response.appendInt(this.userId); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java index e1f23e2b..45dd404e 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/rooms/users/UserUpdateComposer.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.outgoing.rooms.users; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; @@ -9,7 +8,6 @@ import com.eu.habbo.messages.outgoing.Outgoing; import gnu.trove.set.hash.THashSet; import java.util.Collection; -import java.util.Map; public class UserUpdateComposer extends MessageComposer { private Collection habbos; @@ -40,43 +38,30 @@ public class UserUpdateComposer extends MessageComposer { if (this.roomUnits != null) { this.response.appendInt(this.roomUnits.size()); for (RoomUnit roomUnit : this.roomUnits) { - this.response.appendInt(roomUnit.getId()); - this.response.appendInt(roomUnit.getPreviousLocation().getX()); - this.response.appendInt(roomUnit.getPreviousLocation().getY()); - this.response.appendString((this.overrideZ != -1 ? this.overrideZ : roomUnit.getPreviousLocationZ()) + ""); - + this.response.appendInt(roomUnit.getVirtualId()); + this.response.appendInt(roomUnit.getCurrentPosition().getX()); + this.response.appendInt(roomUnit.getCurrentPosition().getY()); + this.response.appendString(String.valueOf(this.overrideZ != -1 ? this.overrideZ : roomUnit.getCurrentZ())); this.response.appendInt(roomUnit.getHeadRotation().getValue()); this.response.appendInt(roomUnit.getBodyRotation().getValue()); - StringBuilder status = new StringBuilder("/"); - for (Map.Entry entry : roomUnit.getStatus().entrySet()) { - status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); - } - - this.response.appendString(status.toString()); - roomUnit.setPreviousLocation(roomUnit.getCurrentLocation()); + this.response.appendString(roomUnit.getCurrentStatuses()); } } else { synchronized (this.habbos) { this.response.appendInt(this.habbos.size()); for (Habbo habbo : this.habbos) { - this.response.appendInt(habbo.getRoomUnit().getId()); - this.response.appendInt(habbo.getRoomUnit().getPreviousLocation().getX()); - this.response.appendInt(habbo.getRoomUnit().getPreviousLocation().getY()); - this.response.appendString(habbo.getRoomUnit().getPreviousLocationZ() + ""); + this.response.appendInt(habbo.getRoomUnit().getVirtualId()); + this.response.appendInt(habbo.getRoomUnit().getCurrentPosition().getX()); + this.response.appendInt(habbo.getRoomUnit().getCurrentPosition().getY()); + this.response.appendString(String.valueOf(habbo.getRoomUnit().getCurrentZ())); this.response.appendInt(habbo.getRoomUnit().getHeadRotation().getValue()); this.response.appendInt(habbo.getRoomUnit().getBodyRotation().getValue()); - StringBuilder status = new StringBuilder("/"); - - for (Map.Entry entry : habbo.getRoomUnit().getStatus().entrySet()) { - status.append(entry.getKey()).append(" ").append(entry.getValue()).append("/"); - } - this.response.appendString(status.toString()); - habbo.getRoomUnit().setPreviousLocation(habbo.getRoomUnit().getCurrentLocation()); + this.response.appendString(habbo.getRoomUnit().getCurrentStatuses()); } } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/trading/TradingItemListComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/trading/TradingItemListComposer.java index f0ecff94..d21a0231 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/trading/TradingItemListComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/trading/TradingItemListComposer.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.outgoing.trading; import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.rooms.RoomTrade; import com.eu.habbo.habbohotel.rooms.RoomTradeUser; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -20,7 +20,7 @@ public class TradingItemListComposer extends MessageComposer { this.response.appendInt(roomTradeUser.getUserId()); this.response.appendInt(roomTradeUser.getItems().size()); - for (HabboItem item : roomTradeUser.getItems()) { + for (RoomItem item : roomTradeUser.getItems()) { this.response.appendInt(item.getId()); this.response.appendString(item.getBaseItem().getType().code); this.response.appendInt(item.getId()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/unknown/PostItPlacedComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/unknown/PostItPlacedComposer.java index c4bf530a..718bb50d 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/unknown/PostItPlacedComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/unknown/PostItPlacedComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.unknown; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class PostItPlacedComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; private final int unknownInt; @Override diff --git a/src/main/java/com/eu/habbo/messages/outgoing/unknown/RoomMessageNotificationMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/unknown/RoomMessageNotificationMessageComposer.java index 9b74bbd7..06f34882 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/unknown/RoomMessageNotificationMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/unknown/RoomMessageNotificationMessageComposer.java @@ -15,8 +15,8 @@ public class RoomMessageNotificationMessageComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.roomMessageNotificationMessageComposer); - this.response.appendInt(this.room.getId()); - this.response.appendString(this.room.getName()); + this.response.appendInt(this.room.getRoomInfo().getId()); + this.response.appendString(this.room.getRoomInfo().getName()); this.response.appendInt(this.count); return this.response; } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/users/UserPerksComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/users/UserPerksComposer.java index e6f88c7e..9d1ef4d4 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/users/UserPerksComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/users/UserPerksComposer.java @@ -17,16 +17,16 @@ public class UserPerksComposer extends MessageComposer { this.response.appendString("USE_GUIDE_TOOL"); this.response.appendString("requirement.unfulfilled.helper_level_4"); - this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasRight(Permission.ACC_HELPER_USE_GUIDE_TOOL, false)); + this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasPermissionRight(Permission.ACC_HELPER_USE_GUIDE_TOOL, false)); this.response.appendString("GIVE_GUIDE_TOURS"); this.response.appendString(""); - this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasRight(Permission.ACC_HELPER_GIVE_GUIDE_TOURS, false)); + this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasPermissionRight(Permission.ACC_HELPER_GIVE_GUIDE_TOURS, false)); this.response.appendString("JUDGE_CHAT_REVIEWS"); this.response.appendString("requirement.unfulfilled.helper_level_6"); - this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasRight(Permission.ACC_HELPER_JUDGE_CHAT_REVIEWS, false)); + this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasPermissionRight(Permission.ACC_HELPER_JUDGE_CHAT_REVIEWS, false)); this.response.appendString("VOTE_IN_COMPETITIONS"); this.response.appendString("requirement.unfulfilled.helper_level_2"); @@ -46,7 +46,7 @@ public class UserPerksComposer extends MessageComposer { this.response.appendString("HEIGHTMAP_EDITOR_BETA"); this.response.appendString("requirement.unfulfilled.feature_disabled"); - this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasRight(Permission.ACC_FLOORPLAN_EDITOR, false)); + this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasPermissionRight(Permission.ACC_FLOORPLAN_EDITOR, false)); this.response.appendString("BUILDER_AT_WORK"); this.response.appendString(""); @@ -58,7 +58,7 @@ public class UserPerksComposer extends MessageComposer { this.response.appendString("CAMERA"); this.response.appendString(""); - this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasRight(Permission.ACC_CAMERA, false)); + this.response.appendBoolean(this.habbo.getHabboInfo().getPermissionGroup().hasPermissionRight(Permission.ACC_CAMERA, false)); this.response.appendString("NAVIGATOR_PHASE_TWO_2014"); this.response.appendString(""); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/users/UserRightsMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/users/UserRightsMessageComposer.java index 087f293f..b3e763c3 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/users/UserRightsMessageComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/users/UserRightsMessageComposer.java @@ -21,7 +21,7 @@ public class UserRightsMessageComposer extends MessageComposer { this.response.init(Outgoing.userRightsMessageComposer); this.response.appendInt(this.clubLevel); this.response.appendInt(this.habbo.getHabboInfo().getPermissionGroup().getLevel()); - this.response.appendBoolean(this.habbo.hasRight(Permission.ACC_AMBASSADOR)); + this.response.appendBoolean(this.habbo.hasPermissionRight(Permission.ACC_AMBASSADOR)); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/wired/OpenComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/wired/OpenComposer.java index 1fb6f4ee..1885bf52 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/wired/OpenComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/wired/OpenComposer.java @@ -1,6 +1,6 @@ package com.eu.habbo.messages.outgoing.wired; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -8,7 +8,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor public class OpenComposer extends MessageComposer { - private final HabboItem item; + private final RoomItem item; @Override diff --git a/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredConditionDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredConditionDataComposer.java index a3265514..8ce80a87 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredConditionDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredConditionDataComposer.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.outgoing.wired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -15,8 +16,28 @@ public class WiredConditionDataComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.wiredConditionDataComposer); - this.condition.serializeWiredData(this.response, this.room); - this.condition.needsUpdate(true); + + this.response.appendBoolean(false); + this.response.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); + this.response.appendInt(this.condition.getWiredSettings().getItemIds().size()); + + for (int itemId : this.condition.getWiredSettings().getItemIds()) { + this.response.appendInt(itemId); + } + + this.response.appendInt(this.condition.getBaseItem().getSpriteId()); + this.response.appendInt(this.condition.getId()); + this.response.appendString(this.condition.getWiredSettings().getStringParam()); + this.response.appendInt(this.condition.getWiredSettings().getIntegerParams().size()); + + for (int param : this.condition.getWiredSettings().getIntegerParams()) { + this.response.appendInt(param); + } + + this.response.appendInt(this.condition.getWiredSettings().getSelectionType()); + this.response.appendInt(this.condition.getType().getCode()); + + this.condition.setSqlUpdateNeeded(true); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredEffectDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredEffectDataComposer.java index 0b0757cc..07301e81 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredEffectDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredEffectDataComposer.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.outgoing.wired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -15,8 +16,36 @@ public class WiredEffectDataComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.wiredEffectDataComposer); - this.effect.serializeWiredData(this.response, this.room); - this.effect.needsUpdate(true); + + this.response.appendBoolean(false); + this.response.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); + this.response.appendInt(this.effect.getWiredSettings().getItemIds().size()); + + for (int itemId : this.effect.getWiredSettings().getItemIds()) { + this.response.appendInt(itemId); + } + + this.response.appendInt(this.effect.getBaseItem().getSpriteId()); + this.response.appendInt(this.effect.getId()); + this.response.appendString(this.effect.getWiredSettings().getStringParam()); + this.response.appendInt(this.effect.getWiredSettings().getIntegerParams().size()); + + for (int param : this.effect.getWiredSettings().getIntegerParams()) { + this.response.appendInt(param); + } + + this.response.appendInt(this.effect.getWiredSettings().getSelectionType()); + this.response.appendInt(this.effect.getType().getCode()); + this.response.appendInt(this.effect.getWiredSettings().getDelay()); + + this.response.appendInt(this.effect.getBlockedTriggers(this.room).size()); + + for(int blockedTrigger : this.effect.getBlockedTriggers(this.room)) { + this.response.appendInt(blockedTrigger); + } + + this.effect.setSqlUpdateNeeded(true); + return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredTriggerDataComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredTriggerDataComposer.java index bea9262c..ce5b7d03 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredTriggerDataComposer.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/wired/WiredTriggerDataComposer.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.outgoing.wired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.MessageComposer; import com.eu.habbo.messages.outgoing.Outgoing; @@ -15,8 +16,33 @@ public class WiredTriggerDataComposer extends MessageComposer { @Override protected ServerMessage composeInternal() { this.response.init(Outgoing.wiredTriggerDataComposer); - this.trigger.serializeWiredData(this.response, this.room); - this.trigger.needsUpdate(true); + + this.response.appendBoolean(false); + this.response.appendInt(WiredHandler.MAXIMUM_FURNI_SELECTION); + this.response.appendInt(this.trigger.getWiredSettings().getItemIds().size()); + + for (int itemId : this.trigger.getWiredSettings().getItemIds()) { + this.response.appendInt(itemId); + } + + this.response.appendInt(this.trigger.getBaseItem().getSpriteId()); + this.response.appendInt(this.trigger.getId()); + this.response.appendString(this.trigger.getWiredSettings().getStringParam()); + this.response.appendInt(this.trigger.getWiredSettings().getIntegerParams().size()); + + for (int param : this.trigger.getWiredSettings().getIntegerParams()) { + this.response.appendInt(param); + } + + this.response.appendInt(this.trigger.getWiredSettings().getSelectionType()); + this.response.appendInt(this.trigger.getType().getCode()); + this.response.appendInt(this.trigger.getBlockedEffects(this.room).size()); + + for(int blockedTrigger : this.trigger.getBlockedEffects(this.room)) { + this.response.appendInt(blockedTrigger); + } + + this.trigger.setSqlUpdateNeeded(true); return this.response; } } diff --git a/src/main/java/com/eu/habbo/messages/rcon/ChangeRoomOwner.java b/src/main/java/com/eu/habbo/messages/rcon/ChangeRoomOwner.java index 262b60be..d5bf751e 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/ChangeRoomOwner.java +++ b/src/main/java/com/eu/habbo/messages/rcon/ChangeRoomOwner.java @@ -2,6 +2,7 @@ package com.eu.habbo.messages.rcon; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.users.Habbo; import com.google.gson.Gson; public class ChangeRoomOwner extends RCONMessage { @@ -11,15 +12,22 @@ public class ChangeRoomOwner extends RCONMessage { @Override public void handle(Gson gson, JSON json) { - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(json.room_id); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(json.room_id); - if (room != null) { - room.setOwnerId(json.user_id); - room.setOwnerName(json.username); - room.setNeedsUpdate(true); - room.save(); - Emulator.getGameEnvironment().getRoomManager().unloadRoom(room); + if(room == null) { + return; } + + Habbo newOwner = Emulator.getGameEnvironment().getHabboManager().getHabbo(json.user_id); + + if(newOwner == null) { + return; + } + + room.getRoomInfo().setOwnerInfo(newOwner.getHabboInfo()); + room.setNeedsUpdate(true); + room.save(); + room.dispose(); } static class JSON { diff --git a/src/main/java/com/eu/habbo/messages/rcon/ForwardUser.java b/src/main/java/com/eu/habbo/messages/rcon/ForwardUser.java index 62629656..af576538 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/ForwardUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/ForwardUser.java @@ -17,11 +17,11 @@ public class ForwardUser extends RCONMessage { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(object.user_id); if (habbo != null) { - Room room = Emulator.getGameEnvironment().getRoomManager().loadRoom(object.room_id); + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(object.room_id); if (room != null) { - if (habbo.getHabboInfo().getCurrentRoom() != null) { - Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, habbo.getHabboInfo().getCurrentRoom()); + if (habbo.getRoomUnit().getRoom() != null) { + Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, habbo.getRoomUnit().getRoom()); } habbo.getClient().sendResponse(new RoomForwardMessageComposer(object.room_id)); diff --git a/src/main/java/com/eu/habbo/messages/rcon/FriendRequest.java b/src/main/java/com/eu/habbo/messages/rcon/FriendRequest.java index aac25f42..e8b0dece 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/FriendRequest.java +++ b/src/main/java/com/eu/habbo/messages/rcon/FriendRequest.java @@ -4,7 +4,6 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.messenger.Messenger; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.eu.habbo.messages.outgoing.friends.NewFriendRequestComposer; import com.google.gson.Gson; @@ -25,7 +24,7 @@ public class FriendRequest extends RCONMessage { if (from != null) { target.getClient().sendResponse(new NewFriendRequestComposer(from.getHabboInfo())); } else { - final HabboInfo info = HabboManager.getOfflineHabboInfo(json.user_id); + final HabboInfo info = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(json.user_id); if (info != null) { target.getClient().sendResponse(new NewFriendRequestComposer(info)); diff --git a/src/main/java/com/eu/habbo/messages/rcon/SendGift.java b/src/main/java/com/eu/habbo/messages/rcon/SendGift.java index 450e0b38..051c706c 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/SendGift.java +++ b/src/main/java/com/eu/habbo/messages/rcon/SendGift.java @@ -3,7 +3,7 @@ package com.eu.habbo.messages.rcon; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; @@ -70,7 +70,7 @@ public class SendGift extends RCONMessage { return; } - HabboItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, 0, 0, ""); + RoomItem item = Emulator.getGameEnvironment().getItemManager().createItem(0, baseItem, 0, 0, ""); Item giftItem = Emulator.getGameEnvironment().getItemManager().getItem((Integer) Emulator.getGameEnvironment().getCatalogManager().giftFurnis.values().toArray()[Emulator.getRandom().nextInt(Emulator.getGameEnvironment().getCatalogManager().giftFurnis.size())]); String extraData = "1\t" + item.getId(); diff --git a/src/main/java/com/eu/habbo/messages/rcon/SendRoomBundle.java b/src/main/java/com/eu/habbo/messages/rcon/SendRoomBundle.java index 25b276ac..074133db 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/SendRoomBundle.java +++ b/src/main/java/com/eu/habbo/messages/rcon/SendRoomBundle.java @@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.catalog.CatalogPage; import com.eu.habbo.habbohotel.catalog.layouts.RoomBundleLayout; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboInfo; -import com.eu.habbo.habbohotel.users.HabboManager; import com.google.gson.Gson; public class SendRoomBundle extends RCONMessage { @@ -23,7 +22,7 @@ public class SendRoomBundle extends RCONMessage { if (habbo != null) { ((RoomBundleLayout) page).buyRoom(habbo); } else { - HabboInfo info = HabboManager.getOfflineHabboInfo(json.user_id); + HabboInfo info = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(json.user_id); if (info != null) { ((RoomBundleLayout) page).buyRoom(null, json.user_id, info.getUsername()); diff --git a/src/main/java/com/eu/habbo/messages/rcon/SetMotto.java b/src/main/java/com/eu/habbo/messages/rcon/SetMotto.java index ec83db61..ffd0bc14 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/SetMotto.java +++ b/src/main/java/com/eu/habbo/messages/rcon/SetMotto.java @@ -23,7 +23,7 @@ public class SetMotto extends RCONMessage { if (habbo != null) { habbo.getHabboInfo().setMotto(json.motto); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + habbo.getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); } else { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection()) { try (PreparedStatement statement = connection.prepareStatement("UPDATE users SET motto = ? WHERE id = ? LIMIT 1")) { diff --git a/src/main/java/com/eu/habbo/messages/rcon/StalkUser.java b/src/main/java/com/eu/habbo/messages/rcon/StalkUser.java index 3e2a61fb..9a47fe13 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/StalkUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/StalkUser.java @@ -23,7 +23,7 @@ public class StalkUser extends RCONMessage { return; } - if (target.getHabboInfo().getCurrentRoom() == null) { + if (target.getRoomUnit().getRoom() == null) { this.message = Emulator.getTexts().getValue("commands.error.cmd_stalk.not_room").replace("%user%", json.user_id + ""); this.status = STATUS_ERROR; return; @@ -35,14 +35,14 @@ public class StalkUser extends RCONMessage { return; } - if (target.getHabboInfo().getCurrentRoom() == habbo.getHabboInfo().getCurrentRoom()) { + if (target.getRoomUnit().getRoom() == habbo.getRoomUnit().getRoom()) { this.message = Emulator.getTexts().getValue("commands.generic.cmd_stalk.same_room").replace("%user%", json.user_id + ""); this.status = STATUS_ERROR; return; } if (this.status == 0) { - habbo.getClient().sendResponse(new RoomForwardMessageComposer(target.getHabboInfo().getCurrentRoom().getId())); + habbo.getClient().sendResponse(new RoomForwardMessageComposer(target.getRoomUnit().getRoom().getRoomInfo().getId())); } } } diff --git a/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java index cfb39f08..c73cd92c 100644 --- a/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java +++ b/src/main/java/com/eu/habbo/messages/rcon/UpdateUser.java @@ -53,8 +53,8 @@ public class UpdateUser extends RCONMessage { habbo.getClient().sendResponse(new FigureUpdateComposer(habbo).compose()); } - if (habbo.getHabboInfo().getCurrentRoom() != null) { - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); + if (habbo.getRoomUnit().getRoom() != null) { + habbo.getRoomUnit().getRoom().sendComposer(new UserChangeMessageComposer(habbo).compose()); } } diff --git a/src/main/java/com/eu/habbo/plugin/PluginManager.java b/src/main/java/com/eu/habbo/plugin/PluginManager.java index 62ab70cc..28b7d0d1 100644 --- a/src/main/java/com/eu/habbo/plugin/PluginManager.java +++ b/src/main/java/com/eu/habbo/plugin/PluginManager.java @@ -41,7 +41,6 @@ import com.eu.habbo.plugin.events.emulator.EmulatorConfigUpdatedEvent; import com.eu.habbo.plugin.events.emulator.EmulatorLoadedEvent; import com.eu.habbo.plugin.events.roomunit.RoomUnitLookAtPointEvent; import com.eu.habbo.plugin.events.users.*; -import com.eu.habbo.threading.runnables.RoomTrashing; import com.eu.habbo.threading.runnables.ShutdownEmulator; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -115,8 +114,8 @@ public class PluginManager { NavigatorManager.MAXIMUM_RESULTS_PER_PAGE = Emulator.getConfig().getInt("hotel.navigator.search.maxresults"); NavigatorManager.CATEGORY_SORT_USING_ORDER_NUM = Emulator.getConfig().getBoolean("hotel.navigator.sort.ordernum"); RoomChatMessage.MAXIMUM_LENGTH = Emulator.getConfig().getInt("hotel.chat.max.length"); - TraxManager.LARGE_JUKEBOX_LIMIT = Emulator.getConfig().getInt("hotel.jukebox.limit.large"); - TraxManager.NORMAL_JUKEBOX_LIMIT = Emulator.getConfig().getInt("hotel.jukebox.limit.normal"); + RoomTraxManager.LARGE_JUKEBOX_LIMIT = Emulator.getConfig().getInt("hotel.jukebox.limit.large"); + RoomTraxManager.NORMAL_JUKEBOX_LIMIT = Emulator.getConfig().getInt("hotel.jukebox.limit.normal"); String[] bannedBubbles = Emulator.getConfig().getValue("commands.cmd_chatcolor.banned_numbers").split(";"); RoomChatMessage.BANNED_BUBBLES = new int[bannedBubbles.length]; @@ -409,7 +408,6 @@ public class PluginManager { private void registerDefaultEvents() { try { - this.methods.add(RoomTrashing.class.getMethod("onUserWalkEvent", UserTakeStepEvent.class)); this.methods.add(Easter.class.getMethod("onUserChangeMotto", UserSavedMottoEvent.class)); this.methods.add(TagGame.class.getMethod("onUserLookAtPoint", RoomUnitLookAtPointEvent.class)); this.methods.add(TagGame.class.getMethod("onUserWalkEvent", UserTakeStepEvent.class)); diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureBuildheightEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureBuildheightEvent.java index ada589e7..eac552ac 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureBuildheightEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureBuildheightEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurnitureBuildheightEvent extends FurnitureUserEvent { @@ -12,7 +12,7 @@ public class FurnitureBuildheightEvent extends FurnitureUserEvent { private boolean changedHeight = false; - public FurnitureBuildheightEvent(HabboItem furniture, Habbo habbo, double oldHeight, double newHeight) { + public FurnitureBuildheightEvent(RoomItem furniture, Habbo habbo, double oldHeight, double newHeight) { super(furniture, habbo); this.oldHeight = oldHeight; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureDiceRolledEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureDiceRolledEvent.java index 228a6568..b6c191d6 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureDiceRolledEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureDiceRolledEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; @Getter @@ -10,7 +10,7 @@ public class FurnitureDiceRolledEvent extends FurnitureUserEvent { private final int result; - public FurnitureDiceRolledEvent(HabboItem furniture, Habbo habbo, int result) { + public FurnitureDiceRolledEvent(RoomItem furniture, Habbo habbo, int result) { super(furniture, habbo); this.result = result; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureEvent.java index 00e5db80..c21048fe 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureEvent.java @@ -1,14 +1,14 @@ package com.eu.habbo.plugin.events.furniture; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.plugin.Event; public abstract class FurnitureEvent extends Event { - public final HabboItem furniture; + public final RoomItem furniture; - public FurnitureEvent(HabboItem furniture) { + public FurnitureEvent(RoomItem furniture) { this.furniture = furniture; } } diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java index cbf4e1e5..f0eddd0a 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureMovedEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurnitureMovedEvent extends FurnitureUserEvent { @@ -11,7 +11,7 @@ public class FurnitureMovedEvent extends FurnitureUserEvent { private boolean pluginHelper; - public FurnitureMovedEvent(HabboItem furniture, Habbo habbo, RoomTile oldPosition, RoomTile newPosition) { + public FurnitureMovedEvent(RoomItem furniture, Habbo habbo, RoomTile oldPosition, RoomTile newPosition) { super(furniture, habbo); this.oldPosition = oldPosition; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePickedUpEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePickedUpEvent.java index 37114d2f..d42eebaa 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePickedUpEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePickedUpEvent.java @@ -1,11 +1,11 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurniturePickedUpEvent extends FurnitureUserEvent { - public FurniturePickedUpEvent(HabboItem furniture, Habbo habbo) { + public FurniturePickedUpEvent(RoomItem furniture, Habbo habbo) { super(furniture, habbo); } } diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java index 6af5747e..ef6b028b 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurniturePlacedEvent.java @@ -2,14 +2,14 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurniturePlacedEvent extends FurnitureUserEvent { public final RoomTile location; private boolean pluginHelper; - public FurniturePlacedEvent(HabboItem furniture, Habbo habbo, RoomTile location) { + public FurniturePlacedEvent(RoomItem furniture, Habbo habbo, RoomTile location) { super(furniture, habbo); this.location = location; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRedeemedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRedeemedEvent.java index ce2dd0dc..11c4c519 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRedeemedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRedeemedEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurnitureRedeemedEvent extends FurnitureUserEvent { public static final int CREDITS = -1; @@ -11,7 +11,7 @@ public class FurnitureRedeemedEvent extends FurnitureUserEvent { public final int amount; public final int currencyID; - public FurnitureRedeemedEvent(HabboItem furniture, Habbo habbo, int amount, int currencyID) { + public FurnitureRedeemedEvent(RoomItem furniture, Habbo habbo, int amount, int currencyID) { super(furniture, habbo); this.amount = amount; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRolledEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRolledEvent.java index 92da1e6b..ff446c80 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRolledEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRolledEvent.java @@ -1,17 +1,17 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurnitureRolledEvent extends FurnitureEvent { - public final HabboItem roller; + public final RoomItem roller; public final RoomTile newLocation; - public FurnitureRolledEvent(HabboItem furniture, HabboItem roller, RoomTile newLocation) { + public FurnitureRolledEvent(RoomItem furniture, RoomItem roller, RoomTile newLocation) { super(furniture); this.roller = roller; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRoomTonerEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRoomTonerEvent.java index 402b16f8..ef6942c9 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRoomTonerEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRoomTonerEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; @Getter @@ -12,7 +12,7 @@ public class FurnitureRoomTonerEvent extends FurnitureUserEvent { private final int brightness; - public FurnitureRoomTonerEvent(HabboItem furniture, Habbo habbo, int hue, int saturation, int brightness) { + public FurnitureRoomTonerEvent(RoomItem furniture, Habbo habbo, int hue, int saturation, int brightness) { super(furniture, habbo); this.hue = hue; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRotatedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRotatedEvent.java index da314b59..29d931de 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRotatedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureRotatedEvent.java @@ -1,14 +1,14 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class FurnitureRotatedEvent extends FurnitureUserEvent { public final int oldRotation; - public FurnitureRotatedEvent(HabboItem furniture, Habbo habbo, int oldRotation) { + public FurnitureRotatedEvent(RoomItem furniture, Habbo habbo, int oldRotation) { super(furniture, habbo); this.oldRotation = oldRotation; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureToggleEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureToggleEvent.java index 89386461..e9c00479 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureToggleEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureToggleEvent.java @@ -1,14 +1,14 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; @Getter public class FurnitureToggleEvent extends FurnitureUserEvent { private final int state; - public FurnitureToggleEvent(HabboItem furniture, Habbo habbo, int state) { + public FurnitureToggleEvent(RoomItem furniture, Habbo habbo, int state) { super(furniture, habbo); this.state = state; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureUserEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureUserEvent.java index 54017a4b..2d2f79cc 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureUserEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/FurnitureUserEvent.java @@ -1,14 +1,14 @@ package com.eu.habbo.plugin.events.furniture; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public abstract class FurnitureUserEvent extends FurnitureEvent { public final Habbo habbo; - public FurnitureUserEvent(HabboItem furniture, Habbo habbo) { + public FurnitureUserEvent(RoomItem furniture, Habbo habbo) { super(furniture); this.habbo = habbo; } diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredConditionFailedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredConditionFailedEvent.java index c8e420f1..2d259087 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredConditionFailedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredConditionFailedEvent.java @@ -3,7 +3,7 @@ package com.eu.habbo.plugin.events.furniture.wired; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.plugin.events.roomunit.RoomUnitEvent; public class WiredConditionFailedEvent extends RoomUnitEvent { diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackExecutedEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackExecutedEvent.java index 9ed4385a..011af408 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackExecutedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackExecutedEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.plugin.events.roomunit.RoomUnitEvent; import gnu.trove.set.hash.THashSet; diff --git a/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackTriggeredEvent.java b/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackTriggeredEvent.java index 59e3f8ac..3ca3e482 100644 --- a/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackTriggeredEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/furniture/wired/WiredStackTriggeredEvent.java @@ -4,7 +4,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.plugin.events.roomunit.RoomUnitEvent; import gnu.trove.set.hash.THashSet; diff --git a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemAddedEvent.java b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemAddedEvent.java index af3ed727..3802e5ce 100644 --- a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemAddedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemAddedEvent.java @@ -1,10 +1,10 @@ package com.eu.habbo.plugin.events.inventory; import com.eu.habbo.habbohotel.users.HabboInventory; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class InventoryItemAddedEvent extends InventoryItemEvent { - public InventoryItemAddedEvent(HabboInventory inventory, HabboItem item) { + public InventoryItemAddedEvent(HabboInventory inventory, RoomItem item) { super(inventory, item); } } diff --git a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemEvent.java b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemEvent.java index 11581a4f..c8e70499 100644 --- a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemEvent.java @@ -1,14 +1,14 @@ package com.eu.habbo.plugin.events.inventory; import com.eu.habbo.habbohotel.users.HabboInventory; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; @Getter public class InventoryItemEvent extends InventoryEvent { - private final HabboItem item; + private final RoomItem item; - public InventoryItemEvent(HabboInventory inventory, HabboItem item) { + public InventoryItemEvent(HabboInventory inventory, RoomItem item) { super(inventory); this.item = item; diff --git a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemRemovedEvent.java b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemRemovedEvent.java index 26330b8a..e8259475 100644 --- a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemRemovedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemRemovedEvent.java @@ -1,10 +1,10 @@ package com.eu.habbo.plugin.events.inventory; import com.eu.habbo.habbohotel.users.HabboInventory; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class InventoryItemRemovedEvent extends InventoryItemEvent { - public InventoryItemRemovedEvent(HabboInventory inventory, HabboItem item) { + public InventoryItemRemovedEvent(HabboInventory inventory, RoomItem item) { super(inventory, item); } } diff --git a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemsAddedEvent.java b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemsAddedEvent.java index a0ead84f..22e5b667 100644 --- a/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemsAddedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/inventory/InventoryItemsAddedEvent.java @@ -1,13 +1,14 @@ package com.eu.habbo.plugin.events.inventory; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.HabboInventory; -import com.eu.habbo.habbohotel.users.HabboItem; -import gnu.trove.set.hash.THashSet; + +import java.util.HashSet; public class InventoryItemsAddedEvent extends InventoryEvent { - public final THashSet items; + public final HashSet items; - public InventoryItemsAddedEvent(HabboInventory inventory, THashSet items) { + public InventoryItemsAddedEvent(HabboInventory inventory, HashSet items) { super(inventory); this.items = items; } diff --git a/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemOfferedEvent.java b/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemOfferedEvent.java index 100228e4..4a3d39e8 100644 --- a/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemOfferedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemOfferedEvent.java @@ -1,16 +1,16 @@ package com.eu.habbo.plugin.events.marketplace; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.Getter; @Getter public class MarketPlaceItemOfferedEvent extends MarketPlaceEvent { private final Habbo habbo; - private final HabboItem item; + private final RoomItem item; private final int price; - public MarketPlaceItemOfferedEvent(Habbo habbo, HabboItem item, int price) { + public MarketPlaceItemOfferedEvent(Habbo habbo, RoomItem item, int price) { this.habbo = habbo; this.item = item; this.price = price; diff --git a/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemSoldEvent.java b/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemSoldEvent.java index 2f6957b8..5dfc03ca 100644 --- a/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemSoldEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/marketplace/MarketPlaceItemSoldEvent.java @@ -1,15 +1,15 @@ package com.eu.habbo.plugin.events.marketplace; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class MarketPlaceItemSoldEvent extends MarketPlaceEvent { public final Habbo seller; public final Habbo purchaser; - public final HabboItem item; + public final RoomItem item; public int price; - public MarketPlaceItemSoldEvent(Habbo seller, Habbo purchaser, HabboItem item, int price) { + public MarketPlaceItemSoldEvent(Habbo seller, Habbo purchaser, RoomItem item, int price) { this.seller = seller; this.purchaser = purchaser; this.item = item; diff --git a/src/main/java/com/eu/habbo/plugin/events/rooms/RoomFloorItemsLoadEvent.java b/src/main/java/com/eu/habbo/plugin/events/rooms/RoomFloorItemsLoadEvent.java index 01bea305..659ab411 100644 --- a/src/main/java/com/eu/habbo/plugin/events/rooms/RoomFloorItemsLoadEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/rooms/RoomFloorItemsLoadEvent.java @@ -1,21 +1,21 @@ package com.eu.habbo.plugin.events.rooms; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.plugin.events.users.UserEvent; import gnu.trove.set.hash.THashSet; public class RoomFloorItemsLoadEvent extends UserEvent { - private THashSet floorItems; + private THashSet floorItems; private boolean changedFloorItems; - public RoomFloorItemsLoadEvent(Habbo habbo, THashSet floorItems) { + public RoomFloorItemsLoadEvent(Habbo habbo, THashSet floorItems) { super(habbo); this.floorItems = floorItems; this.changedFloorItems = false; } - public void setFloorItems(THashSet floorItems) { + public void setFloorItems(THashSet floorItems) { this.changedFloorItems = true; this.floorItems = floorItems; } @@ -24,7 +24,7 @@ public class RoomFloorItemsLoadEvent extends UserEvent { return this.changedFloorItems; } - public THashSet getFloorItems() { + public THashSet getFloorItems() { return this.floorItems; } } diff --git a/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitEvent.java b/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitEvent.java index 6979df52..dbb1cb13 100644 --- a/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitEvent.java @@ -1,7 +1,7 @@ package com.eu.habbo.plugin.events.roomunit; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.plugin.Event; public abstract class RoomUnitEvent extends Event { diff --git a/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitLookAtPointEvent.java b/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitLookAtPointEvent.java index b1e5c280..a18290a8 100644 --- a/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitLookAtPointEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitLookAtPointEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.plugin.events.roomunit; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; public class RoomUnitLookAtPointEvent extends RoomUnitEvent { diff --git a/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitSetGoalEvent.java b/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitSetGoalEvent.java index c7583272..c361c32b 100644 --- a/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitSetGoalEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/roomunit/RoomUnitSetGoalEvent.java @@ -2,7 +2,7 @@ package com.eu.habbo.plugin.events.roomunit; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; public class RoomUnitSetGoalEvent extends RoomUnitEvent { @@ -16,6 +16,6 @@ public class RoomUnitSetGoalEvent extends RoomUnitEvent { public void setGoal(RoomTile t) { - super.roomUnit.setGoalLocation(t); + super.roomUnit.walkTo(t); } } diff --git a/src/main/java/com/eu/habbo/plugin/events/users/UserRolledEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/UserRolledEvent.java index c38f36a3..0f1037ed 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/UserRolledEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/UserRolledEvent.java @@ -2,17 +2,17 @@ package com.eu.habbo.plugin.events.users; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class UserRolledEvent extends UserEvent { - public final HabboItem roller; + public final RoomItem roller; public final RoomTile location; - public UserRolledEvent(Habbo habbo, HabboItem roller, RoomTile location) { + public UserRolledEvent(Habbo habbo, RoomItem roller, RoomTile location) { super(habbo); this.roller = roller; diff --git a/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogFurnitureBoughtEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogFurnitureBoughtEvent.java index 2e38aa88..eff807d8 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogFurnitureBoughtEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogFurnitureBoughtEvent.java @@ -1,16 +1,17 @@ package com.eu.habbo.plugin.events.users.catalog; import com.eu.habbo.habbohotel.catalog.CatalogItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import gnu.trove.set.hash.THashSet; + +import java.util.HashSet; public class UserCatalogFurnitureBoughtEvent extends UserCatalogEvent { - public final THashSet furniture; + public final HashSet furniture; - public UserCatalogFurnitureBoughtEvent(Habbo habbo, CatalogItem catalogItem, THashSet furniture) { + public UserCatalogFurnitureBoughtEvent(Habbo habbo, CatalogItem catalogItem, HashSet furniture) { super(habbo, catalogItem); this.furniture = furniture; diff --git a/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogItemPurchasedEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogItemPurchasedEvent.java index 6875591b..c7aefcc2 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogItemPurchasedEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/catalog/UserCatalogItemPurchasedEvent.java @@ -1,23 +1,23 @@ package com.eu.habbo.plugin.events.users.catalog; import com.eu.habbo.habbohotel.catalog.CatalogItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import gnu.trove.set.hash.THashSet; import lombok.Getter; +import java.util.HashSet; import java.util.List; @Getter public class UserCatalogItemPurchasedEvent extends UserCatalogEvent { - public final THashSet itemsList; + public final HashSet itemsList; private final int totalCredits; private final int totalPoints; private final List badges; - public UserCatalogItemPurchasedEvent(Habbo habbo, CatalogItem catalogItem, THashSet itemsList, int totalCredits, int totalPoints, List badges) { + public UserCatalogItemPurchasedEvent(Habbo habbo, CatalogItem catalogItem, HashSet itemsList, int totalCredits, int totalPoints, List badges) { super(habbo, catalogItem); this.itemsList = itemsList; diff --git a/src/main/java/com/eu/habbo/threading/runnables/BackgroundAnimation.java b/src/main/java/com/eu/habbo/threading/runnables/BackgroundAnimation.java index 2e275877..200044e7 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/BackgroundAnimation.java +++ b/src/main/java/com/eu/habbo/threading/runnables/BackgroundAnimation.java @@ -2,12 +2,12 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class BackgroundAnimation implements Runnable { - private final HabboItem toner; + private final RoomItem toner; private final Room room; private int length = 1000; private int state = 0; @@ -16,7 +16,7 @@ public class BackgroundAnimation implements Runnable { @Override public void run() { if (this.room.isLoaded() && !this.room.isPreLoaded()) { - this.toner.setExtradata("1:" + this.state + ":126:126"); + this.toner.setExtraData("1:" + this.state + ":126:126"); this.state = (this.state + 1) % 256; this.room.updateItem(this.toner); diff --git a/src/main/java/com/eu/habbo/threading/runnables/BanzaiRandomTeleport.java b/src/main/java/com/eu/habbo/threading/runnables/BanzaiRandomTeleport.java index 7c034d46..8527cdb1 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/BanzaiRandomTeleport.java +++ b/src/main/java/com/eu/habbo/threading/runnables/BanzaiRandomTeleport.java @@ -3,25 +3,25 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.habbohotel.users.HabboItem; +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 lombok.AllArgsConstructor; import org.slf4j.LoggerFactory; @AllArgsConstructor public class BanzaiRandomTeleport implements Runnable { - private final HabboItem item; - private final HabboItem toItem; + private final RoomItem item; + private final RoomItem toItem; private final RoomUnit habbo; private final Room room; @Override public void run() { - HabboItem topItemNow = this.room.getTopItemAt(this.habbo.getX(), this.habbo.getY()); - RoomTile lastLocation = this.habbo.getCurrentLocation(); - RoomTile newLocation = this.room.getLayout().getTile(toItem.getX(), toItem.getY()); + RoomItem topItemNow = this.room.getRoomItemManager().getTopItemAt(this.habbo.getCurrentPosition().getX(), this.habbo.getCurrentPosition().getY()); + RoomTile lastLocation = this.habbo.getCurrentPosition(); + RoomTile newLocation = this.room.getLayout().getTile(toItem.getCurrentPosition().getX(), toItem.getCurrentPosition().getY()); if(topItemNow != null) { try { @@ -32,20 +32,20 @@ public class BanzaiRandomTeleport implements Runnable { } Emulator.getThreading().run(() -> { - if (this.item.getExtradata().equals("1")) { - this.item.setExtradata("0"); + if (this.item.getExtraData().equals("1")) { + this.item.setExtraData("0"); this.room.updateItemState(this.item); } }, 500); - if(!this.toItem.getExtradata().equals("1")) { - this.toItem.setExtradata("1"); + if(!this.toItem.getExtraData().equals("1")) { + this.toItem.setExtraData("1"); this.room.updateItemState(this.toItem); } Emulator.getThreading().run(() -> { this.habbo.setCanWalk(true); - HabboItem topItemNext = this.room.getTopItemAt(this.habbo.getX(), this.habbo.getY()); + RoomItem topItemNext = this.room.getRoomItemManager().getTopItemAt(this.habbo.getCurrentPosition().getX(), this.habbo.getCurrentPosition().getY()); if(topItemNext != null) { try { @@ -55,14 +55,14 @@ public class BanzaiRandomTeleport implements Runnable { } } - if (this.toItem.getExtradata().equals("1")) { - this.toItem.setExtradata("0"); + if (this.toItem.getExtraData().equals("1")) { + this.toItem.setExtraData("0"); this.room.updateItemState(this.toItem); } }, 750); Emulator.getThreading().run(() -> { - this.habbo.setRotation(RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8))); + this.habbo.setRotation(RoomRotation.fromValue(Emulator.getRandom().nextInt(8))); this.room.teleportRoomUnitToLocation(this.habbo, newLocation.getX(), newLocation.getY(), newLocation.getStackHeight()); }, 250); diff --git a/src/main/java/com/eu/habbo/threading/runnables/BattleBanzaiTilesFlicker.java b/src/main/java/com/eu/habbo/threading/runnables/BattleBanzaiTilesFlicker.java index 8828e86d..a1ebe1a2 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/BattleBanzaiTilesFlicker.java +++ b/src/main/java/com/eu/habbo/threading/runnables/BattleBanzaiTilesFlicker.java @@ -4,14 +4,14 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.games.GameTeamColors; import com.eu.habbo.habbohotel.items.interactions.games.battlebanzai.InteractionBattleBanzaiSphere; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.items.ItemsDataUpdateComposer; import gnu.trove.set.hash.THashSet; import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class BattleBanzaiTilesFlicker implements Runnable { - private final THashSet items; + private final THashSet items; private final GameTeamColors color; private final Room room; @@ -32,15 +32,15 @@ public class BattleBanzaiTilesFlicker implements Runnable { this.on = true; } - for (HabboItem item : this.items) { - item.setExtradata(state + ""); + for (RoomItem item : this.items) { + item.setExtraData(state + ""); } this.room.sendComposer(new ItemsDataUpdateComposer(this.items).compose()); if (this.count == 9) { - for (HabboItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { - item.setExtradata("0"); + for (RoomItem item : this.room.getRoomSpecialTypes().getItemsOfType(InteractionBattleBanzaiSphere.class)) { + item.setExtraData("0"); this.room.updateItemState(item); } return; diff --git a/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java b/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java index 493497a6..5b122bf5 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/BotFollowHabbo.java @@ -20,16 +20,16 @@ public class BotFollowHabbo implements Runnable { public void run() { if (this.bot != null) { if (this.habbo != null && this.bot.getFollowingHabboId() == this.habbo.getHabboInfo().getId()) { - if (this.habbo.getHabboInfo().getCurrentRoom() != null && this.habbo.getHabboInfo().getCurrentRoom() == this.room) { + if (this.habbo.getRoomUnit().getRoom() != null && this.habbo.getRoomUnit().getRoom() == this.room) { if (this.habbo.getRoomUnit() != null) { if (this.bot.getRoomUnit() != null) { - RoomTile target = this.room.getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentLocation(), Math.abs((this.habbo.getRoomUnit().getBodyRotation().getValue() + 4)) % 8); + RoomTile target = this.room.getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentPosition(), Math.abs((this.habbo.getRoomUnit().getBodyRotation().getValue() + 4)) % 8); if (target != null) { if (target.getX() < 0 || target.getY() < 0) - target = this.room.getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentLocation(), this.habbo.getRoomUnit().getBodyRotation().getValue()); + target = this.room.getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentPosition(), this.habbo.getRoomUnit().getBodyRotation().getValue()); - if(this.habbo.getRoomUnit().getCurrentLocation().distance(this.bot.getRoomUnit().getCurrentLocation()) < 2) { + if(this.habbo.getRoomUnit().getCurrentPosition().distance(this.bot.getRoomUnit().getCurrentPosition()) < 2) { if(!hasReached) { WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, bot.getRoomUnit(), room, new Object[]{}); hasReached = true; @@ -40,7 +40,7 @@ public class BotFollowHabbo implements Runnable { } if (target.getX() >= 0 && target.getY() >= 0) { - this.bot.getRoomUnit().setGoalLocation(target); + this.bot.getRoomUnit().walkTo(target); this.bot.getRoomUnit().setCanWalk(true); Emulator.getThreading().run(this, 500); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/CannonKickAction.java b/src/main/java/com/eu/habbo/threading/runnables/CannonKickAction.java index 68fa5b31..878246d7 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/CannonKickAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/CannonKickAction.java @@ -32,15 +32,17 @@ public class CannonKickAction implements Runnable { dater.put("message", "${notification.room.kick.cannonball.message}"); int rotation = this.cannon.getRotation(); - List tiles = this.room.getLayout().getTilesInFront(this.room.getLayout().getTile(this.cannon.getX(), this.cannon.getY()), rotation + 6, 3); + List tiles = this.room.getLayout().getTilesInFront(this.room.getLayout().getTile(this.cannon.getCurrentPosition().getX(), this.cannon.getCurrentPosition().getY()), rotation + 6, 3); ServerMessage message = new NotificationDialogMessageComposer("cannon.png", dater).compose(); for (RoomTile t : tiles) { - for (Habbo habbo : this.room.getHabbosAt(t.getX(), t.getY())) { - if (!habbo.hasRight(Permission.ACC_UNKICKABLE) && !this.room.isOwner(habbo)) { - Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room); - habbo.getClient().sendResponse(message); //kicked composer + for (Habbo habbo : this.room.getRoomUnitManager().getHabbosAt(t)) { + if (!habbo.hasPermissionRight(Permission.ACC_UNKICKABLE)) { + if (!this.room.getRoomInfo().isRoomOwner(habbo)) { + Emulator.getGameEnvironment().getRoomManager().leaveRoom(habbo, this.room); + habbo.getClient().sendResponse(message); //kicked composer + } } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/ClearRentedSpace.java b/src/main/java/com/eu/habbo/threading/runnables/ClearRentedSpace.java index 4d4ff335..c82e129a 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/ClearRentedSpace.java +++ b/src/main/java/com/eu/habbo/threading/runnables/ClearRentedSpace.java @@ -4,12 +4,13 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionRentableSpace; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; -import gnu.trove.set.hash.THashSet; import lombok.AllArgsConstructor; +import java.util.HashSet; + @AllArgsConstructor public class ClearRentedSpace implements Runnable { private final InteractionRentableSpace item; @@ -17,14 +18,16 @@ public class ClearRentedSpace implements Runnable { @Override public void run() { - THashSet items = new THashSet<>(); + HashSet items = new HashSet<>(); - for (RoomTile t : this.room.getLayout().getTilesAt(this.room.getLayout().getTile(this.item.getX(), this.item.getY()), this.item.getBaseItem().getWidth(), this.item.getBaseItem().getLength(), this.item.getRotation())) { - for (HabboItem i : this.room.getItemsAt(t)) { - if (i.getUserId() == this.item.getRenterId()) { + for (RoomTile t : this.room.getLayout().getTilesAt(this.room.getLayout().getTile(this.item.getCurrentPosition().getX(), this.item.getCurrentPosition().getY()), this.item.getBaseItem().getWidth(), this.item.getBaseItem().getLength(), this.item.getRotation())) { + for (RoomItem i : this.room.getRoomItemManager().getItemsAt(t)) { + if (i.getOwnerInfo().getId() == this.item.getRenterId()) { items.add(i); + //Deprecated i.setRoomId(0); - i.needsUpdate(true); + i.setRoom(null); + i.setSqlUpdateNeeded(true); } } } @@ -36,7 +39,7 @@ public class ClearRentedSpace implements Runnable { owner.getHabboStats().setRentedItemId(0); owner.getHabboStats().setRentedTimeEnd(0); } else { - for (HabboItem i : items) { + for (RoomItem i : items) { i.run(); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/CloseGate.java b/src/main/java/com/eu/habbo/threading/runnables/CloseGate.java index 2a092f01..5466cb30 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/CloseGate.java +++ b/src/main/java/com/eu/habbo/threading/runnables/CloseGate.java @@ -1,22 +1,29 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; @AllArgsConstructor public class CloseGate implements Runnable { - private final HabboItem gate; + private final RoomItem gate; private final Room room; @Override public void run() { - if (this.gate.getRoomId() == this.room.getId()) { + if (this.gate.getRoomId() == this.room.getRoomInfo().getId()) { if (this.room.isLoaded()) { - if (this.room.getHabbosAt(this.gate.getX(), this.gate.getY()).isEmpty()) { - this.gate.setExtradata("0"); + RoomTile tile = this.room.getLayout().getTile(this.gate.getCurrentPosition().getX(), this.gate.getCurrentPosition().getY()); + + if(tile == null) { + return; + } + + if (!this.room.getRoomUnitManager().hasHabbosAt(tile)) { + this.gate.setExtraData("0"); this.room.updateItem(this.gate); - this.gate.needsUpdate(true); + this.gate.setSqlUpdateNeeded(true); } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java b/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java index 22d9aafa..42e74d8d 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java +++ b/src/main/java/com/eu/habbo/threading/runnables/CrackableExplode.java @@ -5,8 +5,9 @@ import com.eu.habbo.habbohotel.items.FurnitureType; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionCrackable; import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; import com.eu.habbo.messages.outgoing.rooms.items.ObjectAddMessageComposer; @@ -19,8 +20,7 @@ public class CrackableExplode implements Runnable { private final InteractionCrackable habboItem; private final Habbo habbo; private final boolean toInventory; - private final short x; - private final short y; + private final RoomTile tile; @Override public void run() { @@ -29,9 +29,11 @@ public class CrackableExplode implements Runnable { } if (!this.habboItem.resetable()) { - this.room.removeHabboItem(this.habboItem); + this.room.getRoomItemManager().removeRoomItem(this.habboItem); this.room.sendComposer(new RemoveFloorItemComposer(this.habboItem, true).compose()); + //Deprecated this.habboItem.setRoomId(0); + this.habboItem.setRoom(null); Emulator.getGameEnvironment().getItemManager().deleteItem(this.habboItem); } else { this.habboItem.reset(this.room); @@ -40,7 +42,7 @@ public class CrackableExplode implements Runnable { Item rewardItem = Emulator.getGameEnvironment().getItemManager().getCrackableReward(this.habboItem.getBaseItem().getId()); if (rewardItem != null) { - HabboItem newItem = Emulator.getGameEnvironment().getItemManager().createItem(this.habboItem.allowAnyone() ? this.habbo.getHabboInfo().getId() : this.habboItem.getUserId(), rewardItem, 0, 0, ""); + RoomItem newItem = Emulator.getGameEnvironment().getItemManager().createItem(this.habboItem.allowAnyone() ? this.habbo.getHabboInfo().getId() : this.habboItem.getOwnerInfo().getId(), rewardItem, 0, 0, ""); if (newItem != null) { //Add to inventory in case if isn't possible place the item or in case is wall item @@ -49,18 +51,19 @@ public class CrackableExplode implements Runnable { this.habbo.getClient().sendResponse(new UnseenItemsComposer(newItem)); this.habbo.getClient().sendResponse(new FurniListInvalidateComposer()); } else { - newItem.setX(this.x); - newItem.setY(this.y); - newItem.setZ(this.room.getStackHeight(this.x, this.y, false)); - newItem.setRoomId(this.room.getId()); - newItem.needsUpdate(true); - this.room.addHabboItem(newItem); + newItem.setCurrentPosition(this.tile); + newItem.setCurrentZ(this.room.getStackHeight(this.tile.getX(), this.tile.getY(), false)); + //Deprecated + newItem.setRoomId(this.room.getRoomInfo().getId()); + newItem.setRoom(this.room); + newItem.setSqlUpdateNeeded(true); + this.room.getRoomItemManager().addRoomItem(newItem); this.room.updateItem(newItem); - this.room.sendComposer(new ObjectAddMessageComposer(newItem, this.room.getFurniOwnerNames().get(newItem.getUserId())).compose()); + this.room.sendComposer(new ObjectAddMessageComposer(newItem, this.room.getFurniOwnerNames().get(newItem.getOwnerInfo().getId())).compose()); } } } - this.room.updateTile(this.room.getLayout().getTile(this.x, this.y)); + this.room.updateTile(this.tile); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/HabboGiveHandItemToHabbo.java b/src/main/java/com/eu/habbo/threading/runnables/HabboGiveHandItemToHabbo.java index bdc2b307..b4cdd327 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/HabboGiveHandItemToHabbo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/HabboGiveHandItemToHabbo.java @@ -12,22 +12,21 @@ public class HabboGiveHandItemToHabbo implements Runnable { @Override public void run() { - if (this.from.getHabboInfo().getCurrentRoom() == null || this.target.getHabboInfo().getCurrentRoom() == null) + if (this.from.getRoomUnit().getRoom() == null || this.target.getRoomUnit().getRoom() == null) return; - if (this.from.getHabboInfo().getCurrentRoom() != this.target.getHabboInfo().getCurrentRoom()) + if (this.from.getRoomUnit().getRoom() != this.target.getRoomUnit().getRoom()) return; int itemId = this.from.getRoomUnit().getHandItem(); if (itemId > 0) { this.from.getRoomUnit().setHandItem(0); - this.from.getHabboInfo().getCurrentRoom().sendComposer(new CarryObjectMessageComposer(this.from.getRoomUnit()).compose()); - this.target.getRoomUnit().lookAtPoint(this.from.getRoomUnit().getCurrentLocation()); - this.target.getRoomUnit().statusUpdate(true); + this.from.getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(this.from.getRoomUnit()).compose()); + this.target.getRoomUnit().lookAtPoint(this.from.getRoomUnit().getCurrentPosition()); this.target.getClient().sendResponse(new HandItemReceivedMessageComposer(this.from.getRoomUnit(), itemId)); this.target.getRoomUnit().setHandItem(itemId); - this.target.getHabboInfo().getCurrentRoom().sendComposer(new CarryObjectMessageComposer(this.target.getRoomUnit()).compose()); + this.target.getRoomUnit().getRoom().sendComposer(new CarryObjectMessageComposer(this.target.getRoomUnit()).compose()); } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/HabboItemNewState.java b/src/main/java/com/eu/habbo/threading/runnables/HabboItemNewState.java index 8a6492c5..639d9248 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/HabboItemNewState.java +++ b/src/main/java/com/eu/habbo/threading/runnables/HabboItemNewState.java @@ -1,20 +1,20 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; @AllArgsConstructor public class HabboItemNewState implements Runnable { - private final HabboItem item; + private final RoomItem item; private final Room room; private final String state; @Override public void run() { - this.item.setExtradata(this.state); + this.item.setExtraData(this.state); - if (this.item.getRoomId() == this.room.getId()) { + if (this.item.getRoomId() == this.room.getRoomInfo().getId()) { this.room.updateItemState(this.item); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/KickBallAction.java b/src/main/java/com/eu/habbo/threading/runnables/KickBallAction.java index d1305f7e..eb8c6e11 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/KickBallAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/KickBallAction.java @@ -4,8 +4,8 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionPushable; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; @@ -16,11 +16,11 @@ public class KickBallAction implements Runnable { private final RoomUnit kicker; //The Habbo which initiated the move of the item private final int totalSteps; //The total number of steps in the move sequence public boolean dead = false; //When true the run() function will not execute. Used when another user kicks the ball whilst it is arleady moving. - private RoomUserRotation currentDirection; //The current direction the item is moving in + private RoomRotation currentDirection; //The current direction the item is moving in private int currentStep; //The current step of the move sequence public final boolean isDrag; - public KickBallAction(InteractionPushable ball, Room room, RoomUnit kicker, RoomUserRotation direction, int steps, boolean isDrag) { + public KickBallAction(InteractionPushable ball, Room room, RoomUnit kicker, RoomRotation direction, int steps, boolean isDrag) { this.ball = ball; this.room = room; this.kicker = kicker; @@ -36,11 +36,11 @@ public class KickBallAction implements Runnable { return; if (this.currentStep < this.totalSteps) { - RoomTile currentTile = this.room.getLayout().getTile(this.ball.getX(), this.ball.getY()); + RoomTile currentTile = this.room.getLayout().getTile(this.ball.getCurrentPosition().getX(), this.ball.getCurrentPosition().getY()); RoomTile next = this.room.getLayout().getTileInFront(currentTile, this.currentDirection.getValue()); - if (next == null || !this.ball.validMove(this.room, this.room.getLayout().getTile(this.ball.getX(), this.ball.getY()), next)) { - RoomUserRotation oldDirection = this.currentDirection; + if (next == null || !this.ball.validMove(this.room, this.room.getLayout().getTile(this.ball.getCurrentPosition().getX(), this.ball.getCurrentPosition().getY()), next)) { + RoomRotation oldDirection = this.currentDirection; if(!this.isDrag) { this.currentDirection = this.ball.getBounceDirection(this.room, this.currentDirection); @@ -58,10 +58,10 @@ public class KickBallAction implements Runnable { int delay = this.ball.getNextRollDelay(this.currentStep, this.totalSteps); //Algorithm to work out the delay till next run - if (this.ball.canStillMove(this.room, this.room.getLayout().getTile(this.ball.getX(), this.ball.getY()), next, this.currentDirection, this.kicker, delay, this.currentStep, this.totalSteps)) { - this.ball.onMove(this.room, this.room.getLayout().getTile(this.ball.getX(), this.ball.getY()), next, this.currentDirection, this.kicker, delay, this.currentStep, this.totalSteps); + if (this.ball.canStillMove(this.room, this.room.getLayout().getTile(this.ball.getCurrentPosition().getX(), this.ball.getCurrentPosition().getY()), next, this.currentDirection, this.kicker, delay, this.currentStep, this.totalSteps)) { + this.ball.onMove(this.room, this.room.getLayout().getTile(this.ball.getCurrentPosition().getX(), this.ball.getCurrentPosition().getY()), next, this.currentDirection, this.kicker, delay, this.currentStep, this.totalSteps); - this.room.sendComposer(new FloorItemOnRollerComposer(this.ball, null, next, next.getStackHeight() - this.ball.getZ(), this.room).compose()); + this.room.sendComposer(new FloorItemOnRollerComposer(this.ball, null, next, next.getStackHeight() - this.ball.getCurrentZ(), this.room).compose()); Emulator.getThreading().run(this, delay); } else { diff --git a/src/main/java/com/eu/habbo/threading/runnables/OneWayGateActionOne.java b/src/main/java/com/eu/habbo/threading/runnables/OneWayGateActionOne.java index 428d53e3..ad3b71db 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/OneWayGateActionOne.java +++ b/src/main/java/com/eu/habbo/threading/runnables/OneWayGateActionOne.java @@ -4,7 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import lombok.AllArgsConstructor; @@ -12,24 +12,20 @@ import lombok.AllArgsConstructor; public class OneWayGateActionOne implements Runnable { private final GameClient client; private final Room room; - private final HabboItem oneWayGate; + private final RoomItem oneWayGate; @Override public void run() { this.room.sendComposer(new UserUpdateComposer(this.client.getHabbo().getRoomUnit()).compose()); - RoomTile t = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.oneWayGate.getX(), this.oneWayGate.getY()), (this.oneWayGate.getRotation() + 4) % 8); - - if (this.client.getHabbo().getRoomUnit().isAnimateWalk()) { - this.client.getHabbo().getRoomUnit().setAnimateWalk(false); - } + RoomTile t = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.oneWayGate.getCurrentPosition().getX(), this.oneWayGate.getCurrentPosition().getY()), (this.oneWayGate.getRotation() + 4) % 8); if (t.isWalkable()) { - if (this.room.tileWalkable(t) && this.client.getHabbo().getRoomUnit().getX() == this.oneWayGate.getX() && this.client.getHabbo().getRoomUnit().getY() == this.oneWayGate.getY()) { - this.client.getHabbo().getRoomUnit().setGoalLocation(t); + if (this.room.getLayout().tileWalkable(t) && this.client.getHabbo().getRoomUnit().getCurrentPosition().getX() == this.oneWayGate.getCurrentPosition().getX() && this.client.getHabbo().getRoomUnit().getCurrentPosition().getY() == this.oneWayGate.getCurrentPosition().getY()) { + this.client.getHabbo().getRoomUnit().walkTo(t); - if (!this.oneWayGate.getExtradata().equals("0")) { + if (!this.oneWayGate.getExtraData().equals("0")) { Emulator.getThreading().run(new HabboItemNewState(this.oneWayGate, this.room, "0"), 1000); } } @@ -38,7 +34,7 @@ public class OneWayGateActionOne implements Runnable { //} else { - if (!this.oneWayGate.getExtradata().equals("0")) { + if (!this.oneWayGate.getExtraData().equals("0")) { Emulator.getThreading().run(new HabboItemNewState(this.oneWayGate, this.room, "0"), 1000); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java index e711e000..b6323c92 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java +++ b/src/main/java/com/eu/habbo/threading/runnables/OpenGift.java @@ -4,41 +4,37 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionGift; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.outgoing.inventory.FurniListAddOrUpdateComposer; import com.eu.habbo.messages.outgoing.inventory.FurniListInvalidateComposer; import com.eu.habbo.messages.outgoing.inventory.UnseenItemsComposer; import com.eu.habbo.messages.outgoing.rooms.items.PresentOpenedMessageComposer; -import gnu.trove.set.hash.THashSet; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Slf4j @AllArgsConstructor public class OpenGift implements Runnable { - private final HabboItem item; + private final RoomItem item; private final Habbo habbo; private final Room room; @Override public void run() { try { - HabboItem inside = null; + RoomItem inside = null; - THashSet items = ((InteractionGift) this.item).loadItems(); - for (HabboItem i : items) { + HashSet items = ((InteractionGift) this.item).loadItems(); + for (RoomItem i : items) { if (inside == null) inside = i; - i.setUserId(this.habbo.getHabboInfo().getId()); - i.needsUpdate(true); + i.setOwnerInfo(this.habbo.getHabboInfo()); + i.setSqlUpdateNeeded(true); i.run(); } @@ -46,7 +42,7 @@ public class OpenGift implements Runnable { this.habbo.getInventory().getItemsComponent().addItems(items); - RoomTile tile = this.room.getLayout().getTile(this.item.getX(), this.item.getY()); + RoomTile tile = this.room.getLayout().getTile(this.item.getCurrentPosition().getX(), this.item.getCurrentPosition().getY()); if (tile != null) { this.room.updateTile(tile); } @@ -58,7 +54,7 @@ public class OpenGift implements Runnable { Map> unseenItems = new HashMap<>(); - for (HabboItem item : items) { + for (RoomItem item : items) { switch (item.getBaseItem().getType()) { case WALL, FLOOR -> { if (!unseenItems.containsKey(UnseenItemsComposer.AddHabboItemCategory.OWNED_FURNI)) diff --git a/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java b/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java index dba130aa..d068b126 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/PetEatAction.java @@ -20,12 +20,12 @@ public class PetEatAction implements Runnable { @Override public void run() { if (this.pet.getRoomUnit() != null && this.pet.getRoom() != null) { - if (this.pet.levelHunger >= 20 && this.food != null && Integer.parseInt(this.food.getExtradata()) < this.food.getBaseItem().getStateCount()) { + if (this.pet.levelHunger >= 20 && this.food != null && Integer.parseInt(this.food.getExtraData()) < this.food.getBaseItem().getStateCount()) { this.pet.addHunger(-20); this.pet.setTask(PetTasks.EAT); this.pet.getRoomUnit().setCanWalk(false); - this.food.setExtradata(Integer.parseInt(this.food.getExtradata()) + 1 + ""); + this.food.setExtraData(Integer.parseInt(this.food.getExtraData()) + 1 + ""); this.pet.getRoom().updateItem(this.food); if (this.pet instanceof GnomePet) { @@ -40,10 +40,10 @@ public class PetEatAction implements Runnable { Emulator.getThreading().run(this, 1000); } else { - if (this.food != null && Integer.parseInt(this.food.getExtradata()) == this.food.getBaseItem().getStateCount()) { + if (this.food != null && Integer.parseInt(this.food.getExtraData()) == this.food.getBaseItem().getStateCount()) { Emulator.getThreading().run(new QueryDeleteHabboItem(this.food.getId()), 500); if (this.pet.getRoom() != null) { - this.pet.getRoom().removeHabboItem(this.food); + this.pet.getRoom().getRoomItemManager().removeRoomItem(this.food); this.pet.getRoom().sendComposer(new RemoveFloorItemComposer(this.food, true).compose()); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/PetFollowHabbo.java b/src/main/java/com/eu/habbo/threading/runnables/PetFollowHabbo.java index 3cf9613e..b7230e04 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/PetFollowHabbo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/PetFollowHabbo.java @@ -22,20 +22,20 @@ public class PetFollowHabbo implements Runnable { if (this.habbo != null) { if (this.habbo.getRoomUnit() != null) { if (this.pet.getRoomUnit() != null) { - RoomTile target = this.habbo.getHabboInfo().getCurrentRoom().getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentLocation(), Math.abs((this.habbo.getRoomUnit().getBodyRotation().getValue() + this.directionOffset + 4) % 8)); + RoomTile target = this.habbo.getRoomUnit().getRoom().getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentPosition(), Math.abs((this.habbo.getRoomUnit().getBodyRotation().getValue() + this.directionOffset + 4) % 8)); if (target != null) { if (target.getX() < 0 || target.getY() < 0) - target = this.habbo.getHabboInfo().getCurrentRoom().getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentLocation(), this.habbo.getRoomUnit().getBodyRotation().getValue()); + target = this.habbo.getRoomUnit().getRoom().getLayout().getTileInFront(this.habbo.getRoomUnit().getCurrentPosition(), this.habbo.getRoomUnit().getBodyRotation().getValue()); if (target.getX() >= 0 && target.getY() >= 0) { - if (this.pet.getRoom().getLayout().tileWalkable(target.getX(), target.getY())) { - this.pet.getRoomUnit().setGoalLocation(target); + if (this.pet.getRoom().getLayout().tileWalkable(target)) { + this.pet.getRoomUnit().walkTo(target); this.pet.getRoomUnit().setCanWalk(true); this.pet.setTask(PetTasks.FOLLOW); } } - if(target.distance(this.pet.getRoomUnit().getCurrentLocation()) > 1) { + if(target.distance(this.pet.getRoomUnit().getCurrentPosition()) > 1) { Emulator.getThreading().run(this, 500); } else { this.pet.setTask(PetTasks.FREE); diff --git a/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java b/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java index f0493e9f..796df747 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java +++ b/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItem.java @@ -1,7 +1,7 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -16,7 +16,7 @@ public class QueryDeleteHabboItem implements Runnable { private final int itemId; - public QueryDeleteHabboItem(HabboItem item) { + public QueryDeleteHabboItem(RoomItem item) { this.itemId = item.getId(); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItems.java b/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItems.java index 6ee3bc53..fa125375 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItems.java +++ b/src/main/java/com/eu/habbo/threading/runnables/QueryDeleteHabboItems.java @@ -1,7 +1,7 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import gnu.trove.map.TIntObjectMap; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,13 +14,13 @@ import java.sql.SQLException; @AllArgsConstructor public class QueryDeleteHabboItems implements Runnable { - private TIntObjectMap items; + private TIntObjectMap items; @Override public void run() { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM items WHERE id = ?")) { - for (HabboItem item : this.items.valueCollection()) { + for (RoomItem item : this.items.valueCollection()) { if (item.getRoomId() > 0) continue; diff --git a/src/main/java/com/eu/habbo/threading/runnables/RandomDiceNumber.java b/src/main/java/com/eu/habbo/threading/runnables/RandomDiceNumber.java index e6c83600..f07f3bd8 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RandomDiceNumber.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RandomDiceNumber.java @@ -3,22 +3,22 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.items.interactions.InteractionColorWheel; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class RandomDiceNumber implements Runnable { - private final HabboItem item; + private final RoomItem item; private final Room room; private final int maxNumber; private int result; - public RandomDiceNumber(HabboItem item, Room room, int maxNumber) { + public RandomDiceNumber(RoomItem item, Room room, int maxNumber) { this.item = item; this.room = room; this.maxNumber = maxNumber; this.result = -1; } - public RandomDiceNumber(Room room, HabboItem item, int result) { + public RandomDiceNumber(Room room, RoomItem item, int result) { this.item = item; this.room = room; this.maxNumber = -1; @@ -30,8 +30,8 @@ public class RandomDiceNumber implements Runnable { if (this.result <= 0) this.result = (Emulator.getRandom().nextInt(this.maxNumber) + 1); - this.item.setExtradata(this.result + ""); - this.item.needsUpdate(true); + this.item.setExtraData(this.result + ""); + this.item.setSqlUpdateNeeded(true); Emulator.getThreading().run(this.item); this.room.updateItem(this.item); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java b/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java index 53f17b63..33c11516 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RandomSpinningBottleNumber.java @@ -2,22 +2,22 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; public class RandomSpinningBottleNumber implements Runnable { - private final HabboItem item; + private final RoomItem item; private final Room room; private final int maxNumber; private int result; - public RandomSpinningBottleNumber(HabboItem item, Room room, int maxNumber) { + public RandomSpinningBottleNumber(RoomItem item, Room room, int maxNumber) { this.item = item; this.room = room; this.maxNumber = maxNumber; this.result = -1; } - public RandomSpinningBottleNumber(Room room, HabboItem item, int result) { + public RandomSpinningBottleNumber(Room room, RoomItem item, int result) { this.item = item; this.room = room; this.maxNumber = -1; @@ -29,8 +29,8 @@ public class RandomSpinningBottleNumber implements Runnable { if (this.result <= 0) this.result = Emulator.getRandom().nextInt(this.maxNumber); - this.item.setExtradata(this.result + ""); - this.item.needsUpdate(true); + this.item.setExtraData(this.result + ""); + this.item.setSqlUpdateNeeded(true); Emulator.getThreading().run(this.item); this.room.updateItem(this.item); diff --git a/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java b/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java index 27d26b3b..26f68060 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RemoveFloorItemTask.java @@ -2,7 +2,7 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.HeightMapUpdateMessageComposer; import com.eu.habbo.messages.outgoing.rooms.items.RemoveFloorItemComposer; import lombok.AllArgsConstructor; @@ -10,7 +10,7 @@ import lombok.AllArgsConstructor; @AllArgsConstructor class RemoveFloorItemTask implements Runnable { private final Room room; - private final HabboItem item; + private final RoomItem item; @Override @@ -18,10 +18,10 @@ class RemoveFloorItemTask implements Runnable { if (this.item == null || this.room == null) return; - RoomTile tile = this.room.getLayout().getTile(this.item.getX(), this.item.getY()); - this.room.removeHabboItem(this.item); + RoomTile tile = this.room.getLayout().getTile(this.item.getCurrentPosition().getX(), this.item.getCurrentPosition().getY()); + this.room.getRoomItemManager().removeRoomItem(this.item); this.room.updateTile(tile); this.room.sendComposer(new RemoveFloorItemComposer(this.item, true).compose()); - this.room.sendComposer(new HeightMapUpdateMessageComposer(this.item.getX(), this.item.getY(), tile.getZ(), tile.relativeHeight()).compose()); + this.room.sendComposer(new HeightMapUpdateMessageComposer(this.item.getCurrentPosition().getX(), this.item.getCurrentPosition().getY(), tile.getZ(), tile.relativeHeight()).compose()); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomTrashing.java b/src/main/java/com/eu/habbo/threading/runnables/RoomTrashing.java deleted file mode 100644 index ba50a1d9..00000000 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomTrashing.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.eu.habbo.threading.runnables; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; -import com.eu.habbo.plugin.EventHandler; -import com.eu.habbo.plugin.events.users.UserTakeStepEvent; -import gnu.trove.set.hash.THashSet; - -public class RoomTrashing implements Runnable { - public static RoomTrashing INSTANCE; - - private Habbo habbo; - private Room room; - - public RoomTrashing(Habbo habbo, Room room) { - this.habbo = habbo; - this.room = room; - - RoomTrashing.INSTANCE = this; - } - - @EventHandler - public static void onUserWalkEvent(UserTakeStepEvent event) { - if (INSTANCE == null) - return; - - if (INSTANCE.habbo == null) - return; - - if (!INSTANCE.habbo.isOnline()) - INSTANCE.habbo = null; - - if (INSTANCE.habbo == event.habbo) { - if (event.habbo.getHabboInfo().getCurrentRoom() != null) { - if (event.habbo.getHabboInfo().getCurrentRoom().equals(INSTANCE.room)) { - THashSet messages = new THashSet<>(); - - THashSet items = INSTANCE.room.getItemsAt(event.toLocation); - - int offset = Emulator.getRandom().nextInt(4) + 2; - - RoomTile t = null; - while (offset > 0) { - t = INSTANCE.room.getLayout().getTileInFront(INSTANCE.room.getLayout().getTile(event.toLocation.getX(), event.toLocation.getY()), event.habbo.getRoomUnit().getBodyRotation().getValue(), (short) offset); - - if (!INSTANCE.room.getLayout().tileWalkable(t.getX(), t.getY())) { - offset--; - } else { - break; - } - } - - for (HabboItem item : items) { - double offsetZ = (INSTANCE.room.getTopHeightAt(t.getX(), t.getY())) - item.getZ(); - - messages.add(new FloorItemOnRollerComposer(item, null, t, offsetZ, INSTANCE.room).compose()); - } - - - offset = Emulator.getRandom().nextInt(4) + 2; - - t = null; - while (offset > 0) { - t = INSTANCE.room.getLayout().getTileInFront(INSTANCE.room.getLayout().getTile(event.toLocation.getX(), event.toLocation.getY()), event.habbo.getRoomUnit().getBodyRotation().getValue() + 7, (short) offset); - - if (!INSTANCE.room.getLayout().tileWalkable(t.getX(), t.getY())) { - offset--; - } else { - break; - } - } - - RoomTile s = INSTANCE.room.getLayout().getTileInFront(INSTANCE.habbo.getRoomUnit().getCurrentLocation(), INSTANCE.habbo.getRoomUnit().getBodyRotation().getValue() + 7); - - if (s != null) { - items = INSTANCE.room.getItemsAt(s); - } - - for (HabboItem item : items) { - double offsetZ = (INSTANCE.room.getTopHeightAt(t.getX(), t.getY())) - item.getZ(); - - messages.add(new FloorItemOnRollerComposer(item, null, t, offsetZ, INSTANCE.room).compose()); - } - - offset = Emulator.getRandom().nextInt(4) + 2; - - t = null; - while (offset > 0) { - t = INSTANCE.getRoom().getLayout().getTileInFront(event.toLocation, event.habbo.getRoomUnit().getBodyRotation().getValue() + 1, (short) offset); - - if (!INSTANCE.room.getLayout().tileWalkable(t.getX(), t.getY())) { - offset--; - } else { - break; - } - } - - s = INSTANCE.getRoom().getLayout().getTileInFront(INSTANCE.habbo.getRoomUnit().getCurrentLocation(), INSTANCE.habbo.getRoomUnit().getBodyRotation().getValue() + 1); - items = INSTANCE.room.getItemsAt(s); - - for (HabboItem item : items) { - double offsetZ = (INSTANCE.room.getTopHeightAt(t.getX(), t.getY())) - item.getZ(); - - messages.add(new FloorItemOnRollerComposer(item, null, t, offsetZ, INSTANCE.room).compose()); - } - - for (ServerMessage message : messages) { - INSTANCE.room.sendComposer(message); - } - } else { - INSTANCE.habbo = null; - INSTANCE.room = null; - } - } - } - } - - @Override - public void run() { - - } - - public Habbo getHabbo() { - return this.habbo; - } - - public void setHabbo(Habbo habbo) { - this.habbo = habbo; - } - - public Room getRoom() { - return this.room; - } - - public void setRoom(Room room) { - this.room = room; - } -} diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitGiveHanditem.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitGiveHanditem.java index 8fe54bec..bb05a419 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitGiveHanditem.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitGiveHanditem.java @@ -1,21 +1,21 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.messages.outgoing.rooms.users.CarryObjectMessageComposer; import lombok.AllArgsConstructor; @AllArgsConstructor public class RoomUnitGiveHanditem implements Runnable { - private final RoomUnit roomUnit; + private final RoomAvatar roomAvatar; private final Room room; private final int itemId; @Override public void run() { - if (this.room != null && this.roomUnit.isInRoom()) { - this.roomUnit.setHandItem(this.itemId); - this.room.sendComposer(new CarryObjectMessageComposer(this.roomUnit).compose()); + if (this.room != null && this.roomAvatar.isInRoom()) { + this.roomAvatar.setHandItem(this.itemId); + this.room.sendComposer(new CarryObjectMessageComposer(this.roomAvatar).compose()); } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitKick.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitKick.java index e290ab01..fd3fbe5a 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitKick.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitKick.java @@ -14,7 +14,8 @@ public class RoomUnitKick implements Runnable { @Override public void run() { if (this.removeEffect) { - this.habbo.getRoomUnit().setEffectId(0, 0); + this.habbo.getRoomUnit().setEffectId(0); + this.habbo.getRoomUnit().setEffectEndTimestamp(0); } Emulator.getGameEnvironment().getRoomManager().leaveRoom(this.habbo, this.room); 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 75f3ad42..36d67f99 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitRidePet.java @@ -7,38 +7,51 @@ import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; -import lombok.AllArgsConstructor; -@AllArgsConstructor public class RoomUnitRidePet implements Runnable { + private final int MAX_RETRIES = 3; private final RideablePet pet; private final Habbo habbo; private final RoomTile goalTile; + private int retries; + public RoomUnitRidePet(RideablePet pet, Habbo rider, RoomTile petTile) { + this.pet = pet; + this.habbo = rider; + this.goalTile = petTile; + this.retries = 0; + } @Override public void run() { - if (this.habbo.getRoomUnit() == null || this.pet.getRoomUnit() == null || this.pet.getRoom() != this.habbo.getHabboInfo().getCurrentRoom() || this.goalTile == null || this.habbo.getRoomUnit().getGoalLocation() != this.goalTile) + if (this.pet.getRoom() != this.habbo.getRoomUnit().getRoom()) { + this.habbo.getRoomUnit().setRideLocked(false); return; + } - if (habbo.getRoomUnit().getCurrentLocation().distance(pet.getRoomUnit().getCurrentLocation()) <= 1) { + if(this.retries >= MAX_RETRIES) { + this.habbo.getRoomUnit().setRideLocked(false); + return; + } + + this.retries++; + + if (habbo.getRoomUnit().getCurrentPosition().distance(pet.getRoomUnit().getCurrentPosition()) <= 1) { habbo.getRoomUnit().stopWalking(); - habbo.getHabboInfo().getCurrentRoom().giveEffect(habbo, 77, -1); - habbo.getHabboInfo().setRiding(pet); - habbo.getRoomUnit().setCurrentLocation(this.pet.getRoomUnit().getCurrentLocation()); - habbo.getRoomUnit().setPreviousLocation(this.pet.getRoomUnit().getCurrentLocation()); - habbo.getRoomUnit().setZ(this.pet.getRoomUnit().getZ() + 1); - habbo.getRoomUnit().setPreviousLocationZ(this.pet.getRoomUnit().getZ() + 1); + habbo.getRoomUnit().giveEffect(77, -1); + habbo.getRoomUnit().setRidingPet(pet); + habbo.getRoomUnit().setCurrentPosition(this.pet.getRoomUnit().getCurrentPosition()); + habbo.getRoomUnit().setCurrentZ(this.pet.getRoomUnit().getCurrentZ() + 1); habbo.getRoomUnit().setRotation(this.pet.getRoomUnit().getBodyRotation()); - habbo.getRoomUnit().statusUpdate(true); + habbo.getRoomUnit().setRideLocked(false); pet.setRider(habbo); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose()); - habbo.getHabboInfo().getCurrentRoom().sendComposer(new AvatarEffectMessageComposer(habbo.getRoomUnit()).compose()); + habbo.getRoomUnit().getRoom().sendComposer(new UserUpdateComposer(habbo.getRoomUnit()).compose()); + habbo.getRoomUnit().getRoom().sendComposer(new AvatarEffectMessageComposer(habbo.getRoomUnit()).compose()); pet.setTask(PetTasks.RIDE); } else { pet.getRoomUnit().setWalkTimeOut(3 + Emulator.getIntUnixTimestamp()); pet.getRoomUnit().stopWalking(); - habbo.getRoomUnit().setGoalLocation(goalTile); + habbo.getRoomUnit().walkTo(goalTile); Emulator.getThreading().run(this, 500); } } 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 58fbcc87..4cf9b23c 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleport.java @@ -2,9 +2,9 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,10 +33,10 @@ public class RoomUnitTeleport implements Runnable { return; } - RoomTile lastLocation = this.roomUnit.getCurrentLocation(); + RoomTile lastLocation = this.roomUnit.getCurrentPosition(); RoomTile newLocation = this.room.getLayout().getTile((short) this.x, (short) this.y); - HabboItem topItem = this.room.getTopItemAt(this.roomUnit.getCurrentLocation().getX(), this.roomUnit.getCurrentLocation().getY()); + RoomItem topItem = this.room.getRoomItemManager().getTopItemAt(this.roomUnit.getCurrentPosition().getX(), this.roomUnit.getCurrentPosition().getY()); if (topItem != null) { try { topItem.onWalkOff(this.roomUnit, this.room, new Object[]{this}); @@ -45,22 +45,20 @@ public class RoomUnitTeleport implements Runnable { } } this.roomUnit.setPath(new LinkedList<>()); - this.roomUnit.setCurrentLocation(newLocation); - this.roomUnit.setPreviousLocation(newLocation); - this.roomUnit.setZ(this.z); - this.roomUnit.setPreviousLocationZ(this.z); + this.roomUnit.setCurrentPosition(newLocation); + this.roomUnit.setCurrentZ(this.z); this.roomUnit.removeStatus(RoomUnitStatus.MOVE); //ServerMessage teleportMessage = new RoomUnitOnRollerComposer(this.roomUnit, newLocation, this.room).compose(); this.roomUnit.setLocation(newLocation); //this.room.sendComposer(teleportMessage); - this.roomUnit.statusUpdate(true); + this.roomUnit.setStatusUpdateNeeded(true); roomUnit.setWiredTeleporting(false); - this.room.updateHabbosAt(newLocation.getX(), newLocation.getY()); - this.room.updateBotsAt(newLocation.getX(), newLocation.getY()); + this.room.getRoomUnitManager().updateHabbosAt(newLocation); + this.room.getRoomUnitManager().updateBotsAt(newLocation); - topItem = room.getTopItemAt(x, y); - if (topItem != null && roomUnit.getCurrentLocation().equals(room.getLayout().getTile((short) x, (short) y))) { + topItem = room.getRoomItemManager().getTopItemAt(x, y); + if (topItem != null && roomUnit.getCurrentPosition().equals(room.getLayout().getTile((short) x, (short) y))) { try { topItem.onWalkOn(roomUnit, room, new Object[]{ lastLocation, newLocation, this }); } catch (Exception ignored) { diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java index 8285f9cd..bd73bbf7 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitTeleportWalkToAction.java @@ -3,8 +3,8 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -13,29 +13,29 @@ import lombok.extern.slf4j.Slf4j; public class RoomUnitTeleportWalkToAction implements Runnable { private final Habbo habbo; - private final HabboItem habboItem; + private final RoomItem roomItem; private final Room room; @Override public void run() { - if (this.habbo.getHabboInfo().getCurrentRoom() != this.room || this.habboItem.getRoomId() != this.room.getId()) { + if (this.habbo.getRoomUnit().getRoom() != this.room || this.roomItem.getRoomId() != this.room.getRoomInfo().getId()) { return; } - RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem); + RoomTile tile = RoomItem.getSquareInFront(this.room.getLayout(), this.roomItem); - if (!this.habbo.getRoomUnit().getGoalLocation().equals(tile)) { + if (!this.habbo.getRoomUnit().getTargetPosition().equals(tile)) { return; } - if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) { + if (this.habbo.getRoomUnit().getCurrentPosition().equals(tile)) { try { - this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); + this.roomItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); } catch (Exception e) { log.error("Caught exception", e); } } else if (tile.isWalkable()) { - this.habbo.getRoomUnit().setGoalLocation(tile); + this.habbo.getRoomUnit().walkTo(tile); Emulator.getThreading().run(this, (long) this.habbo.getRoomUnit().getPath().size() + 2 * 510); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java index 786843d8..df9e9c86 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitVendingMachineAction.java @@ -3,8 +3,8 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -13,30 +13,30 @@ import lombok.extern.slf4j.Slf4j; public class RoomUnitVendingMachineAction implements Runnable { private final Habbo habbo; - private final HabboItem habboItem; + private final RoomItem roomItem; private final Room room; @Override public void run() { - if (this.habbo.getHabboInfo().getCurrentRoom() != this.room || this.habboItem.getRoomId() != this.room.getId()) { + if (this.habbo.getRoomUnit().getRoom() != this.room || this.roomItem.getRoomId() != this.room.getRoomInfo().getId()) { return; } - RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.habboItem); + RoomTile tile = RoomItem.getSquareInFront(this.room.getLayout(), this.roomItem); if (tile == null) { return; } - if (this.habbo.getRoomUnit().getGoalLocation().equals(tile)) { - if (this.habbo.getRoomUnit().getCurrentLocation().equals(tile)) { + if (this.habbo.getRoomUnit().getTargetPosition().equals(tile)) { + if (this.habbo.getRoomUnit().getCurrentPosition().equals(tile)) { try { - this.habboItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); + this.roomItem.onClick(this.habbo.getClient(), this.room, new Object[]{0}); } catch (Exception e) { log.error("Caught exception", e); } } else { if (this.room.getLayout().getTile(tile.getX(), tile.getY()).isWalkable()) { - this.habbo.getRoomUnit().setGoalLocation(tile); + this.habbo.getRoomUnit().walkTo(tile); Emulator.getThreading().run(this, (long) this.habbo.getRoomUnit().getPath().size() + 2 * 510); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java index 4ebf20fc..61256ee0 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToLocation.java @@ -3,8 +3,8 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import lombok.AllArgsConstructor; import java.util.ArrayList; @@ -33,17 +33,17 @@ public class RoomUnitWalkToLocation implements Runnable { @Override public void run() { - if (this.goalTile == null || this.walker == null || this.room == null || this.walker.getRoom() == null || this.walker.getRoom().getId() != this.room.getId()) { + if (this.goalTile == null || this.walker == null || this.room == null || this.walker.getRoom() == null || this.walker.getRoom().getRoomInfo().getId() != this.room.getRoomInfo().getId()) { onFail(); return; } - if (this.walker.getCurrentLocation().equals(this.goalTile)) { + if (this.walker.getCurrentPosition().equals(this.goalTile)) { onSuccess(); return; } - if (!this.walker.getGoalLocation().equals(this.goalTile) || (this.walker.getPath().isEmpty() && !this.walker.hasStatus(RoomUnitStatus.MOVE))) { + if (!this.walker.getTargetPosition().equals(this.goalTile) || (this.walker.getPath().isEmpty() && !this.walker.hasStatus(RoomUnitStatus.MOVE))) { onFail(); return; } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java index 7e84e3c9..88fa53f8 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -3,7 +3,7 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import lombok.RequiredArgsConstructor; @@ -38,8 +38,8 @@ public class RoomUnitWalkToRoomUnit implements Runnable { return; } - if (this.walker.getGoalLocation().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal - if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { + if (this.walker.getTargetPosition().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal + if (this.walker.getCurrentPosition().distance(this.goalTile) <= this.minDistance) { for (Runnable r : this.targetReached) { Emulator.getThreading().run(r); @@ -52,7 +52,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable { } private void findNewLocation() { - this.goalTile = this.walker.getClosestAdjacentTile(this.target.getCurrentLocation().getX(), this.target.getCurrentLocation().getY(), true); + this.goalTile = this.walker.getClosestAdjacentTile(this.target.getCurrentPosition().getX(), this.target.getCurrentPosition().getY(), true); if (this.goalTile == null) { if (this.failedReached != null) { @@ -64,7 +64,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable { return; } - this.walker.setGoalLocation(this.goalTile); + this.walker.walkTo(this.goalTile); if (this.walker.getPath().isEmpty() && this.failedReached != null) { for (Runnable r : this.failedReached) { diff --git a/src/main/java/com/eu/habbo/threading/runnables/SaveScoreForTeam.java b/src/main/java/com/eu/habbo/threading/runnables/SaveScoreForTeam.java index 8871b071..7f3cbab6 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/SaveScoreForTeam.java +++ b/src/main/java/com/eu/habbo/threading/runnables/SaveScoreForTeam.java @@ -4,6 +4,7 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.games.Game; import com.eu.habbo.habbohotel.games.GamePlayer; import com.eu.habbo.habbohotel.games.GameTeam; +import com.eu.habbo.habbohotel.rooms.Room; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,7 +24,8 @@ public class SaveScoreForTeam implements Runnable { public void run() { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_game_scores (room_id, game_start_timestamp, game_name, user_id, team_id, score, team_score) VALUES (?, ?, ?, ?, ?, ?, ?)")) { for (GamePlayer player : this.team.getMembers()) { - statement.setInt(1, this.game.getRoom().getId()); + Room room = this.game.getRoom(); + statement.setInt(1, room.getRoomInfo().getId()); statement.setInt(2, this.game.getStartTime()); statement.setString(3, this.game.getClass().getName()); statement.setInt(4, player.getHabbo().getHabboInfo().getId()); diff --git a/src/main/java/com/eu/habbo/threading/runnables/SendRoomUnitEffectComposer.java b/src/main/java/com/eu/habbo/threading/runnables/SendRoomUnitEffectComposer.java index ec90782f..69312a1c 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/SendRoomUnitEffectComposer.java +++ b/src/main/java/com/eu/habbo/threading/runnables/SendRoomUnitEffectComposer.java @@ -1,20 +1,20 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar; import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer; import lombok.AllArgsConstructor; @AllArgsConstructor public class SendRoomUnitEffectComposer implements Runnable { private final Room room; - private final RoomUnit roomUnit; + private final RoomAvatar roomAvatar; @Override public void run() { - if (this.room != null && this.roomUnit != null) { - this.room.sendComposer(new AvatarEffectMessageComposer(roomUnit).compose()); + if (this.room != null && this.roomAvatar != null) { + this.room.sendComposer(new AvatarEffectMessageComposer(roomAvatar).compose()); } } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/threading/runnables/TeleportInteraction.java b/src/main/java/com/eu/habbo/threading/runnables/TeleportInteraction.java index 01366809..22092b4f 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/TeleportInteraction.java +++ b/src/main/java/com/eu/habbo/threading/runnables/TeleportInteraction.java @@ -5,8 +5,8 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.users.AvatarEffectMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer; @@ -18,13 +18,13 @@ class TeleportInteraction extends Thread { private final Room room; private final GameClient client; - private final HabboItem teleportOne; + private final RoomItem teleportOne; private int state; private Room targetRoom; - private HabboItem teleportTwo; + private RoomItem teleportTwo; @Deprecated - public TeleportInteraction(Room room, GameClient client, HabboItem teleportOne) { + public TeleportInteraction(Room room, GameClient client, RoomItem teleportOne) { this.room = room; this.client = client; this.teleportOne = teleportOne; @@ -37,46 +37,46 @@ class TeleportInteraction extends Thread { public void run() { try { if (this.state == 5) { - this.teleportTwo.setExtradata("1"); + this.teleportTwo.setExtraData("1"); this.targetRoom.updateItem(this.teleportTwo); this.room.updateItem(this.teleportOne); - RoomTile tile = HabboItem.getSquareInFront(this.room.getLayout(), this.teleportTwo); + RoomTile tile = RoomItem.getSquareInFront(this.room.getLayout(), this.teleportTwo); if (tile != null) { - this.client.getHabbo().getRoomUnit().setGoalLocation(tile); + this.client.getHabbo().getRoomUnit().walkTo(tile); } Emulator.getThreading().run(this.teleportTwo, 500); Emulator.getThreading().run(this.teleportOne, 500); } else if (this.state == 4) { int[] data = Emulator.getGameEnvironment().getItemManager().getTargetTeleportRoomId(this.teleportOne); if (data.length == 2 && data[0] != 0) { - if (this.room.getId() == data[0]) { + if (this.room.getRoomInfo().getId() == data[0]) { this.targetRoom = this.room; - this.teleportTwo = this.room.getHabboItem(data[1]); + this.teleportTwo = this.room.getRoomItemManager().getRoomItemById(data[1]); if (this.teleportTwo == null) { this.teleportTwo = this.teleportOne; } } else { - this.targetRoom = Emulator.getGameEnvironment().getRoomManager().loadRoom(data[0]); - this.teleportTwo = this.targetRoom.getHabboItem(data[1]); + this.targetRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(data[0]); + this.teleportTwo = this.targetRoom.getRoomItemManager().getRoomItemById(data[1]); } } else { this.targetRoom = this.room; this.teleportTwo = this.teleportOne; } - this.teleportOne.setExtradata("2"); - this.teleportTwo.setExtradata("2"); + this.teleportOne.setExtraData("2"); + this.teleportTwo.setExtraData("2"); if (this.room != this.targetRoom) { Emulator.getGameEnvironment().getRoomManager().logExit(this.client.getHabbo()); - this.room.removeHabbo(this.client.getHabbo(), true); + this.room.getRoomUnitManager().removeHabbo(this.client.getHabbo(), true); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), this.targetRoom); } - this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[this.teleportTwo.getRotation()]); - this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.teleportTwo.getX(), this.teleportTwo.getY())); - this.client.getHabbo().getRoomUnit().setZ(this.teleportTwo.getZ()); + this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[this.teleportTwo.getRotation()]); + this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.teleportTwo.getCurrentPosition().getX(), this.teleportTwo.getCurrentPosition().getY())); + this.client.getHabbo().getRoomUnit().setCurrentZ(this.teleportTwo.getCurrentZ()); this.room.sendComposer(new UserRemoveMessageComposer(this.client.getHabbo().getRoomUnit()).compose()); this.targetRoom.sendComposer(new UserRemoveMessageComposer(this.client.getHabbo().getRoomUnit()).compose()); @@ -90,28 +90,30 @@ class TeleportInteraction extends Thread { Emulator.getThreading().run(this, 500); } else if (this.state == 3) { - this.teleportOne.setExtradata("0"); + this.teleportOne.setExtraData("0"); this.room.updateItem(this.teleportOne); this.state = 4; Emulator.getThreading().run(this, 500); } else if (this.state == 2) { - this.client.getHabbo().getRoomUnit().setGoalLocation(this.room.getLayout().getTile(this.teleportOne.getX(), this.teleportOne.getY())); - this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[this.newRotation(this.teleportOne.getRotation())]); - this.client.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.MOVE, this.teleportOne.getX() + "," + this.teleportOne.getY() + "," + this.teleportOne.getZ()); + this.client.getHabbo().getRoomUnit().walkTo(this.room.getLayout().getTile(this.teleportOne.getCurrentPosition().getX(), this.teleportOne.getCurrentPosition().getY())); + this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[this.newRotation(this.teleportOne.getRotation())]); + this.client.getHabbo().getRoomUnit().addStatus(RoomUnitStatus.MOVE, this.teleportOne.getCurrentPosition().getX() + "," + this.teleportOne.getCurrentPosition().getY() + "," + this.teleportOne.getCurrentZ()); //room.sendComposer(new RoomUserStatusComposer(this.client.getHabbo().getRoomUnit())); this.state = 3; Emulator.getThreading().run(this, 500); } else if (this.state == 1) { - RoomTile loc = HabboItem.getSquareInFront(this.room.getLayout(), this.teleportOne); + RoomTile loc = RoomItem.getSquareInFront(this.room.getLayout(), this.teleportOne); - if (this.client.getHabbo().getRoomUnit().getX() == loc.getX() && this.client.getHabbo().getRoomUnit().getY() == loc.getY()) { - this.teleportOne.setExtradata("1"); - this.room.updateItem(this.teleportOne); - this.state = 2; + if (this.client.getHabbo().getRoomUnit().getCurrentPosition().getX() == loc.getX()) { + if (this.client.getHabbo().getRoomUnit().getCurrentPosition().getY() == loc.getY()) { + this.teleportOne.setExtraData("1"); + this.room.updateItem(this.teleportOne); + this.state = 2; - Emulator.getThreading().run(this, 250); + Emulator.getThreading().run(this, 250); + } } } } catch (Exception e) { diff --git a/src/main/java/com/eu/habbo/threading/runnables/WiredCollissionRunnable.java b/src/main/java/com/eu/habbo/threading/runnables/WiredCollissionRunnable.java index 126371c6..4648472c 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/WiredCollissionRunnable.java +++ b/src/main/java/com/eu/habbo/threading/runnables/WiredCollissionRunnable.java @@ -1,7 +1,7 @@ package com.eu.habbo.threading.runnables; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/eu/habbo/threading/runnables/WiredExecuteTask.java b/src/main/java/com/eu/habbo/threading/runnables/WiredExecuteTask.java index a7479cfa..68be8a64 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/WiredExecuteTask.java +++ b/src/main/java/com/eu/habbo/threading/runnables/WiredExecuteTask.java @@ -26,16 +26,18 @@ public class WiredExecuteTask implements Runnable { @Override public void run() { if (!Emulator.isShuttingDown && Emulator.isReady) { - if (this.room != null && this.room.getId() == this.task.getRoomId()) { - if (this.task instanceof WiredTriggerAtSetTime) { - if (((WiredTriggerAtSetTime) this.task).taskId != this.taskId) - return; + if (this.room != null) { + if (this.room.getRoomInfo().getId() == this.task.getRoomId()) { + if (this.task instanceof WiredTriggerAtSetTime) { + if (((WiredTriggerAtSetTime) this.task).taskId != this.taskId) + return; + } + if (this.task instanceof WiredTriggerAtTimeLong) { + if (((WiredTriggerAtTimeLong) this.task).taskId != this.taskId) + return; + } + WiredHandler.handle(this.task, null, this.room, null); } - if (this.task instanceof WiredTriggerAtTimeLong) { - if (((WiredTriggerAtTimeLong) this.task).taskId != this.taskId) - return; - } - WiredHandler.handle(this.task, null, this.room, null); } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/WiredRepeatEffectTask.java b/src/main/java/com/eu/habbo/threading/runnables/WiredRepeatEffectTask.java index 36ee8c67..8bcb97da 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/WiredRepeatEffectTask.java +++ b/src/main/java/com/eu/habbo/threading/runnables/WiredRepeatEffectTask.java @@ -15,10 +15,12 @@ class WiredRepeatEffectTask implements Runnable { @Override public void run() { if (!Emulator.isShuttingDown && Emulator.isReady) { - if (this.room != null && this.room.getId() == this.effect.getRoomId()) { - this.effect.execute(null, this.room, null); + if (this.room != null) { + if (this.room.getRoomInfo().getId() == this.effect.getRoomId()) { + this.effect.execute(null, this.room, null); - Emulator.getThreading().run(this, this.delay); + Emulator.getThreading().run(this, this.delay); + } } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/YouAreAPirate.java b/src/main/java/com/eu/habbo/threading/runnables/YouAreAPirate.java index c1787a10..3db77017 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/YouAreAPirate.java +++ b/src/main/java/com/eu/habbo/threading/runnables/YouAreAPirate.java @@ -81,19 +81,19 @@ public class YouAreAPirate implements Runnable { this.habbo = habbo; this.room = room; this.oldEffect = this.habbo.getRoomUnit().getEffectId(); - this.room.giveEffect(this.habbo, 161, -1); + this.habbo.getRoomUnit().giveEffect(161, -1); } @Override public void run() { - if (this.room == this.habbo.getHabboInfo().getCurrentRoom()) { + if (this.room == this.habbo.getRoomUnit().getRoom()) { if (!iamapirate[this.index].isEmpty()) { this.room.talk(this.habbo, new RoomChatMessage(iamapirate[this.index], this.habbo, RoomChatMessageBubbles.PIRATE), RoomChatType.SHOUT); } this.index++; if (this.index == iamapirate.length) { - this.room.giveEffect(this.habbo, this.oldEffect, -1); + this.habbo.getRoomUnit().giveEffect(this.oldEffect, -1); return; } diff --git a/src/main/java/com/eu/habbo/threading/runnables/YoutubeAdvanceVideo.java b/src/main/java/com/eu/habbo/threading/runnables/YoutubeAdvanceVideo.java index 9f60fa0c..05e42c1f 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/YoutubeAdvanceVideo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/YoutubeAdvanceVideo.java @@ -14,7 +14,7 @@ public class YoutubeAdvanceVideo implements Runnable { public void run() { if (this.tv.autoAdvance == null) return; - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.tv.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(this.tv.getRoomId()); if (room == null) return; diff --git a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeClearEffects.java b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeClearEffects.java index b02f2d17..7fed4683 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeClearEffects.java +++ b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeClearEffects.java @@ -11,10 +11,11 @@ public class FreezeClearEffects implements Runnable { @Override public void run() { - this.habbo.getRoomUnit().setEffectId(0, 0); + this.habbo.getRoomUnit().setEffectId(0); + this.habbo.getRoomUnit().setEffectEndTimestamp(0); this.habbo.getRoomUnit().setCanWalk(true); - if (this.habbo.getHabboInfo().getCurrentRoom() != null) { - this.habbo.getHabboInfo().getCurrentRoom().sendComposer(new AvatarEffectMessageComposer(this.habbo.getRoomUnit()).compose()); + if (this.habbo.getRoomUnit().getRoom() != null) { + this.habbo.getRoomUnit().getRoom().sendComposer(new AvatarEffectMessageComposer(this.habbo.getRoomUnit()).compose()); } } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeHandleSnowballExplosion.java b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeHandleSnowballExplosion.java index dde9430e..1c607a74 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeHandleSnowballExplosion.java +++ b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeHandleSnowballExplosion.java @@ -7,8 +7,8 @@ import com.eu.habbo.habbohotel.games.freeze.FreezeGamePlayer; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeBlock; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile; import com.eu.habbo.habbohotel.rooms.RoomTile; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; import gnu.trove.set.hash.THashSet; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -41,36 +41,37 @@ class FreezeHandleSnowballExplosion implements Runnable { return; if (player.nextHorizontal) { - tiles.addAll(game.affectedTilesByExplosion(this.thrownData.targetTile.getX(), this.thrownData.targetTile.getY(), this.thrownData.radius + 1)); + tiles.addAll(game.affectedTilesByExplosion(this.thrownData.targetTile.getCurrentPosition().getX(), this.thrownData.targetTile.getCurrentPosition().getY(), this.thrownData.radius + 1)); } if (player.nextDiagonal) { - tiles.addAll(game.affectedTilesByExplosionDiagonal(this.thrownData.targetTile.getX(), this.thrownData.targetTile.getY(), this.thrownData.radius + 1)); + tiles.addAll(game.affectedTilesByExplosionDiagonal(this.thrownData.targetTile.getCurrentPosition().getX(), this.thrownData.targetTile.getCurrentPosition().getY(), this.thrownData.radius + 1)); player.nextDiagonal = false; } THashSet freezeTiles = new THashSet<>(); for (RoomTile roomTile : tiles) { - THashSet items = this.thrownData.room.getItemsAt(roomTile); + THashSet items = this.thrownData.room.getRoomItemManager().getItemsAt(roomTile); - for (HabboItem freezeTile : items) { + for (RoomItem freezeTile : items) { if (freezeTile instanceof InteractionFreezeTile || freezeTile instanceof InteractionFreezeBlock) { int distance = 0; - if (freezeTile.getX() != this.thrownData.targetTile.getX() && freezeTile.getY() != this.thrownData.targetTile.getY()) { - distance = Math.abs(freezeTile.getX() - this.thrownData.targetTile.getX()); + if (freezeTile.getCurrentPosition().getX() != this.thrownData.targetTile.getCurrentPosition().getX() && freezeTile.getCurrentPosition().getY() != this.thrownData.targetTile.getCurrentPosition().getY()) { + distance = Math.abs(freezeTile.getCurrentPosition().getX() - this.thrownData.targetTile.getCurrentPosition().getX()); } else { - distance = (int) Math.ceil(this.thrownData.room.getLayout().getTile(this.thrownData.targetTile.getX(), this.thrownData.targetTile.getY()).distance(roomTile)); + distance = (int) Math.ceil(this.thrownData.room.getLayout().getTile(this.thrownData.targetTile.getCurrentPosition().getX(), this.thrownData.targetTile.getCurrentPosition().getY()).distance(roomTile)); } if (freezeTile instanceof InteractionFreezeTile) { - freezeTile.setExtradata("11" + String.format("%03d", distance * 100)); //TODO Investigate this further. Probably height dependent or something. + freezeTile.setExtraData("11" + String.format("%03d", distance * 100)); //TODO Investigate this further. Probably height dependent or something. freezeTiles.add((InteractionFreezeTile) freezeTile); this.thrownData.room.updateItem(freezeTile); THashSet habbos = new THashSet<>(); - habbos.addAll(this.thrownData.room.getHabbosAt(freezeTile.getX(), freezeTile.getY())); + RoomTile tile = this.thrownData.room.getLayout().getTile(freezeTile.getCurrentPosition().getX(), freezeTile.getCurrentPosition().getY()); + habbos.addAll(this.thrownData.room.getRoomUnitManager().getHabbosAt(tile)); for (Habbo habbo : habbos) { if (habbo.getHabboInfo().getGamePlayer() != null && habbo.getHabboInfo().getGamePlayer() instanceof FreezeGamePlayer hPlayer) { @@ -90,7 +91,7 @@ class FreezeHandleSnowballExplosion implements Runnable { } } } else { - if (freezeTile.getExtradata().equalsIgnoreCase("0")) { + if (freezeTile.getExtraData().equalsIgnoreCase("0")) { game.explodeBox((InteractionFreezeBlock) freezeTile, distance * 100); player.addScore(FreezeGame.DESTROY_BLOCK_POINTS); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeResetExplosionTiles.java b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeResetExplosionTiles.java index b81932ac..da8426d9 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeResetExplosionTiles.java +++ b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeResetExplosionTiles.java @@ -2,7 +2,7 @@ package com.eu.habbo.threading.runnables.freeze; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import gnu.trove.set.hash.THashSet; import lombok.AllArgsConstructor; @@ -14,8 +14,8 @@ class FreezeResetExplosionTiles implements Runnable { @Override public void run() { - for (HabboItem item : this.tiles) { - item.setExtradata("0"); + for (RoomItem item : this.tiles) { + item.setExtraData("0"); this.room.updateItem(item); } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeThrowSnowball.java b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeThrowSnowball.java index a6101523..0ed63f60 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeThrowSnowball.java +++ b/src/main/java/com/eu/habbo/threading/runnables/freeze/FreezeThrowSnowball.java @@ -5,7 +5,7 @@ import com.eu.habbo.habbohotel.games.freeze.FreezeGamePlayer; import com.eu.habbo.habbohotel.items.interactions.games.freeze.InteractionFreezeTile; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.threading.runnables.HabboItemNewState; public class FreezeThrowSnowball implements Runnable { @@ -14,7 +14,7 @@ public class FreezeThrowSnowball implements Runnable { public final Room room; public final int radius; - public FreezeThrowSnowball(Habbo habbo, HabboItem targetTile, Room room) { + public FreezeThrowSnowball(Habbo habbo, RoomItem targetTile, Room room) { this.habbo = habbo; this.targetTile = (InteractionFreezeTile) targetTile; this.room = room; @@ -24,7 +24,7 @@ public class FreezeThrowSnowball implements Runnable { @Override public void run() { ((FreezeGamePlayer) this.habbo.getHabboInfo().getGamePlayer()).takeSnowball(); - this.targetTile.setExtradata((this.radius + 1) * 1000 + ""); + this.targetTile.setExtraData((this.radius + 1) * 1000 + ""); this.room.updateItem(this.targetTile); Emulator.getThreading().run(new FreezeHandleSnowballExplosion(this), 2000); Emulator.getThreading().run(new HabboItemNewState(this.targetTile, this.room, "11000"), 2000); diff --git a/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java b/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java index fe8124ab..05498a3d 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java +++ b/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java @@ -20,7 +20,7 @@ public class GameTimer implements Runnable { return; } - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(timer.getRoomId()); + Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(timer.getRoomId()); if (room == null || !timer.isRunning() || timer.isPaused()) { timer.setThreadActive(false); diff --git a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFive.java index 1097c8e3..0e41dea4 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFive.java +++ b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFive.java @@ -4,22 +4,22 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.threading.runnables.HabboItemNewState; import lombok.AllArgsConstructor; @AllArgsConstructor class HopperActionFive implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @Override public void run() { this.client.getHabbo().getRoomUnit().setTeleporting(false); - RoomTile tile = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()), this.currentTeleport.getRotation()); + RoomTile tile = this.room.getLayout().getTileInFront(this.room.getLayout().getTile(this.currentTeleport.getCurrentPosition().getX(), this.currentTeleport.getCurrentPosition().getY()), this.currentTeleport.getRotation()); if (tile != null) { - this.client.getHabbo().getRoomUnit().setGoalLocation(tile); + this.client.getHabbo().getRoomUnit().walkTo(tile); } Emulator.getThreading().run(new HabboItemNewState(this.currentTeleport, this.room, "0"), 1000); diff --git a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFour.java b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFour.java index d0584b75..a7b0f75b 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFour.java +++ b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionFour.java @@ -3,18 +3,18 @@ package com.eu.habbo.threading.runnables.hopper; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; @AllArgsConstructor class HopperActionFour implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @Override public void run() { - this.currentTeleport.setExtradata("1"); + this.currentTeleport.setExtraData("1"); this.room.updateItem(this.currentTeleport); Emulator.getThreading().run(new HopperActionFive(this.currentTeleport, this.room, this.client), 500); diff --git a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionOne.java b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionOne.java index 88df9fa3..3f7c1188 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionOne.java +++ b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionOne.java @@ -4,26 +4,25 @@ import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import lombok.AllArgsConstructor; @AllArgsConstructor public class HopperActionOne implements Runnable { - private final HabboItem teleportOne; + private final RoomItem teleportOne; private final Room room; private final GameClient client; @Override public void run() { //this.client.getHabbo().getRoomUnit().setGoalLocation(this.teleportOne.getX(), this.teleportOne.getY()); - this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[(this.teleportOne.getRotation() + 4) % 8]); - this.client.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.MOVE, this.teleportOne.getX() + "," + this.teleportOne.getY() + "," + this.teleportOne.getZ()); + this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[(this.teleportOne.getRotation() + 4) % 8]); + this.client.getHabbo().getRoomUnit().addStatus(RoomUnitStatus.MOVE, this.teleportOne.getCurrentPosition().getX() + "," + this.teleportOne.getCurrentPosition().getY() + "," + this.teleportOne.getCurrentZ()); this.room.scheduledComposers.add(new UserUpdateComposer(this.client.getHabbo().getRoomUnit()).compose()); - this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.teleportOne.getX(), this.teleportOne.getY())); - this.client.getHabbo().getRoomUnit().setZ(this.teleportOne.getZ()); - this.client.getHabbo().getRoomUnit().setPreviousLocationZ(this.teleportOne.getZ()); + this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.teleportOne.getCurrentPosition().getX(), this.teleportOne.getCurrentPosition().getY())); + this.client.getHabbo().getRoomUnit().setCurrentZ(this.teleportOne.getCurrentZ()); Emulator.getThreading().run(() -> { HopperActionOne.this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); diff --git a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionThree.java b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionThree.java index 2af1f7f6..aca84321 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionThree.java +++ b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionThree.java @@ -6,15 +6,15 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.interactions.InteractionCostumeHopper; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import com.eu.habbo.threading.runnables.HabboItemNewState; import lombok.AllArgsConstructor; @AllArgsConstructor class HopperActionThree implements Runnable { - private final HabboItem teleportOne; + private final RoomItem teleportOne; private final Room room; private final GameClient client; private final int targetRoomId; @@ -23,16 +23,16 @@ class HopperActionThree implements Runnable { @Override public void run() { - HabboItem targetTeleport; + RoomItem targetTeleport; Room targetRoom = this.room; if (this.teleportOne.getRoomId() != this.targetRoomId) { Emulator.getGameEnvironment().getRoomManager().leaveRoom(this.client.getHabbo(), this.room, false); - targetRoom = Emulator.getGameEnvironment().getRoomManager().loadRoom(this.targetRoomId); - Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", false); + targetRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(this.targetRoomId); + Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getRoomInfo().getId(), "", false); } - targetTeleport = targetRoom.getHabboItem(this.targetItemId); + targetTeleport = targetRoom.getRoomItemManager().getRoomItemById(this.targetItemId); if (targetTeleport == null) { this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); @@ -40,12 +40,11 @@ class HopperActionThree implements Runnable { return; } - targetTeleport.setExtradata("2"); + targetTeleport.setExtraData("2"); targetRoom.updateItem(targetTeleport); - this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(targetTeleport.getX(), targetTeleport.getY())); - this.client.getHabbo().getRoomUnit().setPreviousLocationZ(targetTeleport.getZ()); - this.client.getHabbo().getRoomUnit().setZ(targetTeleport.getZ()); - this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[targetTeleport.getRotation() % 8]); + this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(targetTeleport.getCurrentPosition().getX(), targetTeleport.getCurrentPosition().getY())); + this.client.getHabbo().getRoomUnit().setCurrentZ(targetTeleport.getCurrentZ()); + this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[targetTeleport.getRotation() % 8]); this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); targetRoom.sendComposer(new UserUpdateComposer(this.client.getHabbo().getRoomUnit()).compose()); diff --git a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionTwo.java b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionTwo.java index 0eb672c7..545ffd68 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionTwo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/hopper/HopperActionTwo.java @@ -3,7 +3,7 @@ package com.eu.habbo.threading.runnables.hopper; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -16,13 +16,13 @@ import java.sql.SQLException; @AllArgsConstructor class HopperActionTwo implements Runnable { - private final HabboItem teleportOne; + private final RoomItem teleportOne; private final Room room; private final GameClient client; @Override public void run() { - this.teleportOne.setExtradata("2"); + this.teleportOne.setExtraData("2"); int targetRoomId = 0; int targetItemId = 0; @@ -44,7 +44,7 @@ class HopperActionTwo implements Runnable { if (targetRoomId != 0 && targetItemId != 0) { Emulator.getThreading().run(new HopperActionThree(this.teleportOne, this.room, this.client, targetRoomId, targetItemId), 500); } else { - this.teleportOne.setExtradata("0"); + this.teleportOne.setExtraData("0"); this.client.getHabbo().getRoomUnit().setCanWalk(true); this.client.getHabbo().getRoomUnit().setTeleporting(false); Emulator.getThreading().run(new HopperActionFour(this.teleportOne, this.room, this.client), 500); diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java index 6d4d0732..034c1d1c 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFive.java @@ -5,8 +5,8 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleportTile; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; -import com.eu.habbo.habbohotel.rooms.RoomUnit; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; +import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit; import com.eu.habbo.threading.runnables.HabboItemNewState; import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; import lombok.AllArgsConstructor; @@ -16,7 +16,7 @@ import java.util.List; @AllArgsConstructor class TeleportActionFive implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @@ -30,14 +30,14 @@ class TeleportActionFive implements Runnable { unit.setTeleporting(false); unit.setCanWalk(true); - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) + if (this.client.getHabbo().getRoomUnit().getRoom() != this.room) return; //if (!(this.currentTeleport instanceof InteractionTeleportTile)) if (this.room.getLayout() == null || this.currentTeleport == null) return; - RoomTile currentLocation = this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY()); + RoomTile currentLocation = this.room.getLayout().getTile(this.currentTeleport.getCurrentPosition().getX(), this.currentTeleport.getCurrentPosition().getY()); RoomTile tile = this.room.getLayout().getTileInFront(currentLocation, this.currentTeleport.getRotation()); if (tile != null) { @@ -49,18 +49,18 @@ class TeleportActionFive implements Runnable { }); unit.setCanLeaveRoomByDoor(false); - unit.setGoalLocation(tile); - unit.statusUpdate(true); + unit.walkTo(tile); + unit.setStatusUpdateNeeded(true); unit.setLeavingTeleporter(true); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, tile, room, onSuccess, onSuccess)); } - this.currentTeleport.setExtradata("1"); + this.currentTeleport.setExtraData("1"); this.room.updateItem(this.currentTeleport); Emulator.getThreading().run(new HabboItemNewState(this.currentTeleport, this.room, "0"), 1000); - HabboItem teleportTile = this.room.getTopItemAt(unit.getX(), unit.getY()); + RoomItem teleportTile = this.room.getRoomItemManager().getTopItemAt(unit.getCurrentPosition().getX(), unit.getCurrentPosition().getY()); if (teleportTile instanceof InteractionTeleportTile && teleportTile != this.currentTeleport) { try { diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java index 817ec8aa..8b360570 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionFour.java @@ -3,21 +3,21 @@ package com.eu.habbo.threading.runnables.teleport; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; @AllArgsConstructor class TeleportActionFour implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @Override public void run() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) { + if (this.client.getHabbo().getRoomUnit().getRoom() != this.room) { this.client.getHabbo().getRoomUnit().setCanWalk(true); - this.currentTeleport.setExtradata("0"); + this.currentTeleport.setExtraData("0"); this.room.updateItem(this.currentTeleport); return; } diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionOne.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionOne.java index 03128e18..2ab481b9 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionOne.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionOne.java @@ -5,20 +5,20 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleportTile; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import lombok.AllArgsConstructor; @AllArgsConstructor public class TeleportActionOne implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @Override public void run() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) + if (this.client.getHabbo().getRoomUnit().getRoom() != this.room) return; int delay = 500; @@ -27,12 +27,12 @@ public class TeleportActionOne implements Runnable { delay = 0; } - if (this.client.getHabbo().getRoomUnit().getCurrentLocation() != this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY())) { - this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY())); - this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[(this.currentTeleport.getRotation() + 4) % 8]); - this.client.getHabbo().getRoomUnit().setStatus(RoomUnitStatus.MOVE, this.currentTeleport.getX() + "," + this.currentTeleport.getY() + "," + this.currentTeleport.getZ()); + if (this.client.getHabbo().getRoomUnit().getCurrentPosition() != this.room.getLayout().getTile(this.currentTeleport.getCurrentPosition().getX(), this.currentTeleport.getCurrentPosition().getY())) { + this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.currentTeleport.getCurrentPosition().getX(), this.currentTeleport.getCurrentPosition().getY())); + this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[(this.currentTeleport.getRotation() + 4) % 8]); + this.client.getHabbo().getRoomUnit().addStatus(RoomUnitStatus.MOVE, this.currentTeleport.getCurrentPosition().getX() + "," + this.currentTeleport.getCurrentPosition().getY() + "," + this.currentTeleport.getCurrentZ()); this.room.scheduledComposers.add(new UserUpdateComposer(this.client.getHabbo().getRoomUnit()).compose()); - this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.currentTeleport.getX(), this.currentTeleport.getY())); + this.client.getHabbo().getRoomUnit().setLocation(this.room.getLayout().getTile(this.currentTeleport.getCurrentPosition().getX(), this.currentTeleport.getCurrentPosition().getY())); } Emulator.getThreading().run(new TeleportActionTwo(this.currentTeleport, this.room, this.client), delay); 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 1083f9af..a80e13c2 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 @@ -7,26 +7,26 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionTeleportTile; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.rooms.RoomUserRotation; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import lombok.AllArgsConstructor; @AllArgsConstructor class TeleportActionThree implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @Override public void run() { - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) + if (this.client.getHabbo().getRoomUnit().getRoom() != this.room) return; - HabboItem targetTeleport; + RoomItem targetTeleport; Room targetRoom = this.room; if (this.currentTeleport.getRoomId() != ((InteractionTeleport) this.currentTeleport).getTargetRoomId()) { - targetRoom = Emulator.getGameEnvironment().getRoomManager().loadRoom(((InteractionTeleport) this.currentTeleport).getTargetRoomId()); + targetRoom = Emulator.getGameEnvironment().getRoomManager().getRoom(((InteractionTeleport) this.currentTeleport).getTargetRoomId()); } if (targetRoom == null) { @@ -38,14 +38,15 @@ class TeleportActionThree implements Runnable { targetRoom.loadData(); } - targetTeleport = targetRoom.getHabboItem(((InteractionTeleport) this.currentTeleport).getTargetId()); + int id = ((InteractionTeleport) this.currentTeleport).getTargetId(); + targetTeleport = targetRoom.getRoomItemManager().getRoomItemById(id); if (targetTeleport == null) { Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 0); return; } - RoomTile teleportLocation = targetRoom.getLayout().getTile(targetTeleport.getX(), targetTeleport.getY()); + RoomTile teleportLocation = targetRoom.getLayout().getTile(targetTeleport.getCurrentPosition().getX(), targetTeleport.getCurrentPosition().getY()); if (teleportLocation == null) { Emulator.getThreading().run(new TeleportActionFive(this.currentTeleport, this.room, this.client), 0); @@ -54,23 +55,18 @@ class TeleportActionThree implements Runnable { this.client.getHabbo().getRoomUnit().setLocation(teleportLocation); this.client.getHabbo().getRoomUnit().getPath().clear(); this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); - this.client.getHabbo().getRoomUnit().setZ(teleportLocation.getStackHeight()); - this.client.getHabbo().getRoomUnit().setPreviousLocationZ(teleportLocation.getStackHeight()); + this.client.getHabbo().getRoomUnit().setCurrentZ(teleportLocation.getStackHeight()); if (targetRoom != this.room) { - this.room.removeHabbo(this.client.getHabbo(), false); - Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); + this.room.getRoomUnitManager().removeHabbo(this.client.getHabbo(), false); + Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getRoomInfo().getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); } - this.client.getHabbo().getRoomUnit().setRotation(RoomUserRotation.values()[targetTeleport.getRotation() % 8]); - this.client.getHabbo().getRoomUnit().statusUpdate(true); + this.client.getHabbo().getRoomUnit().setRotation(RoomRotation.values()[targetTeleport.getRotation() % 8]); - targetTeleport.setExtradata("2"); + targetTeleport.setExtraData("2"); targetRoom.updateItem(targetTeleport); - //targetRoom.updateHabbo(this.client.getHabbo()); - //LOGGER.info((targetTeleport.getX() + " | " + targetTeleport.getY()); - this.client.getHabbo().getHabboInfo().setCurrentRoom(targetRoom); - //Emulator.getThreading().run(new HabboItemNewState(this.currentTeleport, this.room, "0"), 500); + this.client.getHabbo().getRoomUnit().setRoom(targetRoom); Emulator.getThreading().run(new TeleportActionFour(targetTeleport, targetRoom, this.client), this.currentTeleport instanceof InteractionTeleportTile ? 0 : 500); } diff --git a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionTwo.java b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionTwo.java index 377a4812..f089d215 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionTwo.java +++ b/src/main/java/com/eu/habbo/threading/runnables/teleport/TeleportActionTwo.java @@ -6,7 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionTeleport; import com.eu.habbo.habbohotel.items.interactions.InteractionTeleportTile; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnitStatus; -import com.eu.habbo.habbohotel.users.HabboItem; +import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem; import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer; import com.eu.habbo.threading.runnables.HabboItemNewState; import lombok.AllArgsConstructor; @@ -21,7 +21,7 @@ import java.sql.SQLException; @AllArgsConstructor class TeleportActionTwo implements Runnable { - private final HabboItem currentTeleport; + private final RoomItem currentTeleport; private final Room room; private final GameClient client; @@ -34,14 +34,15 @@ class TeleportActionTwo implements Runnable { delayOffset = 0; } - if (this.client.getHabbo().getHabboInfo().getCurrentRoom() != this.room) + if (this.client.getHabbo().getRoomUnit().getRoom() != this.room) return; this.client.getHabbo().getRoomUnit().removeStatus(RoomUnitStatus.MOVE); this.room.sendComposer(new UserUpdateComposer(this.client.getHabbo().getRoomUnit()).compose()); if (((InteractionTeleport) this.currentTeleport).getTargetRoomId() > 0 && ((InteractionTeleport) this.currentTeleport).getTargetId() > 0) { - HabboItem item = this.room.getHabboItem(((InteractionTeleport) this.currentTeleport).getTargetId()); + int id = ((InteractionTeleport) this.currentTeleport).getTargetId(); + RoomItem item = this.room.getRoomItemManager().getRoomItemById(id); if (item == null) { ((InteractionTeleport) this.currentTeleport).setTargetRoomId(0); ((InteractionTeleport) this.currentTeleport).setTargetId(0); @@ -76,7 +77,7 @@ class TeleportActionTwo implements Runnable { } } - this.currentTeleport.setExtradata("0"); + this.currentTeleport.setExtraData("0"); this.room.updateItem(this.currentTeleport); if (((InteractionTeleport) this.currentTeleport).getTargetRoomId() == 0) {