From 09294f99280cedf570fe6d5916d378f76d070739 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 28 Dec 2020 21:45:48 +0100 Subject: [PATCH 01/89] Bot variables are now available for use in wireds --- src/main/java/com/eu/habbo/habbohotel/bots/Bot.java | 10 +++++----- .../wired/effects/WiredEffectBotTalk.java | 13 +++++++++---- .../wired/effects/WiredEffectBotTalkToHabbo.java | 7 ++++++- 3 files changed, 20 insertions(+), 10 deletions(-) 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 8f0b0360..b1149aa9 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/Bot.java @@ -194,11 +194,11 @@ public class Bot implements Runnable { } String message = this.chatLines.get(this.lastChatIndex) - .replace("%owner%", this.room.getOwnerName()) - .replace("%item_count%", this.room.itemCount() + "") - .replace("%name%", this.name) - .replace("%roomname%", this.room.getName()) - .replace("%user_count%", this.room.getUserCount() + ""); + .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); 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 0b7b0d3a..735b0f39 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 @@ -97,10 +97,15 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { Habbo habbo = room.getHabbo(roomUnit); if (habbo != null) { - message = message.replace(Emulator.getTexts().getValue("wired.variable.username"), habbo.getHabboInfo().getUsername()) - .replace(Emulator.getTexts().getValue("wired.variable.credits"), habbo.getHabboInfo().getCredits() + "") - .replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "") - .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + ""); + 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() + ""); } List bots = room.getBots(this.botName); 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 index 85d93546..b5015ec7 100644 --- 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 @@ -119,7 +119,12 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { m = m.replace(Emulator.getTexts().getValue("wired.variable.username"), habbo.getHabboInfo().getUsername()) .replace(Emulator.getTexts().getValue("wired.variable.credits"), habbo.getHabboInfo().getCredits() + "") .replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "") - .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + ""); + .replace(Emulator.getTexts().getValue("wired.variable.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); From 8c161284f850ec9440e31617c9a818240f1a291e Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 28 Dec 2020 21:49:39 +0100 Subject: [PATCH 02/89] Added default values for wired variables --- .../wired/effects/WiredEffectBotTalkToHabbo.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index b5015ec7..8fede69c 100644 --- 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 @@ -116,10 +116,10 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { if (habbo != null) { String m = this.message; - m = m.replace(Emulator.getTexts().getValue("wired.variable.username"), habbo.getHabboInfo().getUsername()) - .replace(Emulator.getTexts().getValue("wired.variable.credits"), habbo.getHabboInfo().getCredits() + "") - .replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "") - .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "") + 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) From 01b613e1cf94b23b0a7a2bd96eece22f0b99e888 Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 29 Dec 2020 19:41:09 +0100 Subject: [PATCH 03/89] Added SQL for wired variables for bots --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index cbd02a7b..79299b38 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -112,3 +112,10 @@ ADD COLUMN `bubble_id` int(3) NULL DEFAULT 31 AFTER `effect`; -- Permissions to see tent chat ALTER TABLE `permissions` ADD `acc_see_tentchat` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `acc_see_whispers`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', 'Tent'); + +-- Wired variables for bots +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.name', '%name%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.roomname', '%roomname%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.user_count', '%user_count%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.owner', '%owner%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.item_count', '%item_count%'); \ No newline at end of file From 02cb78f710025e5e4cdab2652f534777c64afe47 Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 29 Dec 2020 21:54:03 +0100 Subject: [PATCH 04/89] Effect_tile interaction now keeps the effect after walkoff --- .../items/interactions/InteractionEffectTile.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 cb8eb2ab..ac10dcc7 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 @@ -1,5 +1,6 @@ package com.eu.habbo.habbohotel.items.interactions; +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; @@ -7,6 +8,8 @@ import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.rooms.RoomUnitType; import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.HabboGender; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; import java.sql.ResultSet; import java.sql.SQLException; @@ -32,7 +35,11 @@ public class InteractionEffectTile extends InteractionPressurePlate { @Override public void onWalkOff(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - super.onWalkOff(roomUnit, room, objects); + Emulator.getThreading().run(() -> updateState(room), 100); + + if(objects != null && objects.length > 0) { + WiredHandler.handle(WiredTriggerType.WALKS_OFF_FURNI, roomUnit, room, new Object[]{this}); + } } @Override From 909047010062389a0fae67f46ea238bc64d46590 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 3 Jan 2021 17:33:27 +0100 Subject: [PATCH 05/89] Fireworks working like Habbo --- .../interactions/InteractionFireworks.java | 132 ++++++++++++++---- .../com/eu/habbo/habbohotel/rooms/Room.java | 8 ++ 2 files changed, 115 insertions(+), 25 deletions(-) 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 645c0d4e..bc8385c5 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 @@ -5,14 +5,28 @@ 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.rooms.RoomLayout; +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.messages.ServerMessage; +import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredEffectType; +import com.eu.habbo.threading.runnables.RoomUnitWalkToLocation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class InteractionFireworks extends InteractionDefault { + + private static final Logger LOGGER = LoggerFactory.getLogger(InteractionFireworks.class); + + private static final String STATE_EMPTY = "0"; // Not used since the removal of pixels + private static final String STATE_CHARGED = "1"; + private static final String STATE_EXPLOSION = "2"; -public class InteractionFireworks extends HabboItem { public InteractionFireworks(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } @@ -26,35 +40,103 @@ public class InteractionFireworks extends HabboItem { return false; } - @Override - public boolean isWalkable() { - return this.getBaseItem().allowWalk(); - } - - @Override - public void onWalk(RoomUnit roomUnit, Room room, Object[] objects) throws Exception { - - } - - @Override - public void serializeExtradata(ServerMessage serverMessage) { - serverMessage.appendInt((this.isLimited() ? 256 : 0)); - serverMessage.appendString(this.getExtradata()); - super.serializeExtradata(serverMessage); //Design flaw ;( - } - + /** + * Checked in Habbo on 2021-01-03 + * - Fireworks should be charged to be able to detonate them + * - Habbos with Rights can detonate fireworks from anywhere in a room + * - Habbos without rights have to walk to an adjecent tile to be able to detonate (see Iteraction Switch) + * - Wired can always detonate fireworks + */ @Override public void onClick(GameClient client, Room room, Object[] objects) throws Exception { - super.onClick(client, room, objects); + if (room == null) + return; - if (client != null && this.getExtradata().equalsIgnoreCase("2")) //2 explodes I think (0 = empty, 1 = charged, 2 = effect) - { - AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger")); + // 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)) { + super.onClick(client, room, objects); + + if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION)) { + this.reCharge(room); + } + } + + return; + } + + if (client == null) + return; + + // 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()))) { + closestTile = tile; + } + } + + if (closestTile != null && !closestTile.equals(client.getHabbo().getRoomUnit().getCurrentLocation())) { + List onSuccess = new ArrayList<>(); + onSuccess.add(() -> { + try { + this.onClick(client, room, objects); + } catch (Exception e) { + e.printStackTrace(); + } + }); + + client.getHabbo().getRoomUnit().setGoalLocation(closestTile); + Emulator.getThreading().run(new RoomUnitWalkToLocation(client.getHabbo().getRoomUnit(), closestTile, room, onSuccess, new ArrayList<>())); + } + } + + if (this.getExtradata().equalsIgnoreCase(STATE_CHARGED)) { + super.onClick(client, room, objects); + + if (this.getExtradata().equalsIgnoreCase(STATE_EXPLOSION)) + { + this.reCharge(room); + AchievementManager.progressAchievement(client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("FireworksCharger")); + } } } @Override public boolean allowWiredResetState() { - return true; + return false; + } + + @Override + public void onPlace(Room room) { + super.onPlace(room); + 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() + ); + } + + private void reCharge(Room room) { + // Default = 5000, Nuclear Firework should have 10000 in its custom params according to Habbo + int explodeDuration = 5000; + if (!this.getBaseItem().getCustomParams().isEmpty()) { + try { + explodeDuration = Integer.parseInt(this.getBaseItem().getCustomParams()); + } catch (NumberFormatException e) { + LOGGER.error("Incorrect customparams (" + this.getBaseItem().getCustomParams() + ") for base item ID (" + this.getBaseItem().getId() + ") of type (" + this.getBaseItem().getName() + ")"); + } + } + + Emulator.getThreading().run(() -> { + this.setExtradata(STATE_CHARGED); + this.needsUpdate(true); + room.updateItemState(this); + }, explodeDuration); } } 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 d0704c82..7a955925 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -383,6 +383,11 @@ public class Room implements Comparable, ISerialize, Runnable { this.updateItem(item); } } + + for (HabboItem item : this.roomSpecialTypes.getItemsOfType(InteractionFireworks.class)) { + item.setExtradata("1"); + this.updateItem(item); + } } Emulator.getPluginManager().fireEvent(new RoomLoadedEvent(this)); @@ -2419,7 +2424,10 @@ public class Room implements Comparable, ISerialize, Runnable { this.roomSpecialTypes.addUndefined(item); } else if (item instanceof InteractionSnowboardSlope) { this.roomSpecialTypes.addUndefined(item); + } else if (item instanceof InteractionFireworks) { + this.roomSpecialTypes.addUndefined(item); } + } } From c7bfcf76e5c78f70fbf3c68f636d0c0ae1a0dadb Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 3 Jan 2021 17:38:49 +0100 Subject: [PATCH 06/89] Fix typo --- .../habbohotel/items/interactions/InteractionFireworks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bc8385c5..b2255e2f 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 @@ -44,7 +44,7 @@ public class InteractionFireworks extends InteractionDefault { * Checked in Habbo on 2021-01-03 * - Fireworks should be charged to be able to detonate them * - Habbos with Rights can detonate fireworks from anywhere in a room - * - Habbos without rights have to walk to an adjecent tile to be able to detonate (see Iteraction Switch) + * - Habbos without rights have to walk to an adjecent tile to be able to detonate (see Interaction Switch) * - Wired can always detonate fireworks */ @Override From 74e631f00a66fa61486f3701baa30c01ec913d3d Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 3 Jan 2021 23:32:10 +0100 Subject: [PATCH 07/89] WiredEffectGiveHotelviewBonusRarePoints now saves as json --- ...redEffectGiveHotelviewBonusRarePoints.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) 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 1a84a14d..c50f7e5b 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 @@ -9,6 +9,7 @@ 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.hotelview.BonusRareComposer; @@ -70,7 +71,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff packet.readInt(); try { - this.amount = Integer.valueOf(packet.readString()); + this.amount = Integer.parseInt(packet.readString()); } catch (Exception e) { return false; } @@ -103,20 +104,26 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff @Override public String getWiredData() { - return this.getDelay() + "\t" + this.amount; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay(), this.amount)); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wireData = set.getString("wired_data"); + String wiredData = set.getString("wired_data"); this.amount = 0; - if (wireData.split("\t").length >= 2) { - super.setDelay(Integer.valueOf(wireData.split("\t")[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.valueOf(this.getWiredData().split("\t")[1]); - } catch (Exception e) { + try { + this.amount = Integer.parseInt(this.getWiredData().split("\t")[1]); + } catch (Exception e) { + } } } } @@ -131,4 +138,14 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + int delay; + int amount; + + public JsonData(int delay, int amount) { + this.delay = delay; + this.amount = amount; + } + } } From 4afdf1b4b015d3a6dd022db6321d0bb397c10702 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 3 Jan 2021 23:32:52 +0100 Subject: [PATCH 08/89] WiredEffectMoveFurniAway now saves as json --- .../effects/WiredEffectMoveFurniAway.java | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) 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 9efd0a32..3d985d74 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 @@ -21,6 +21,7 @@ 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; @@ -98,32 +99,40 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); - - if (this.items != null && !this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + 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").split("\t"); + String wiredData = set.getString("wired_data"); - if (wiredData.length >= 1) { - this.setDelay(Integer.valueOf(wiredData[0])); - } - if (wiredData.length == 2) { - if (wiredData[1].contains(";")) { - for (String s : wiredData[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + 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 (item != null) - this.items.add(item); + 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); + } } } } @@ -206,4 +215,14 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { protected long requiredCooldown() { return 495; } + + static class JsonData { + int delay; + List itemIds; + + public JsonData(int delay, List itemIds) { + this.delay = delay; + this.itemIds = itemIds; + } + } } From a17dd00fcb8c2277f48af29a779db6d72d3a8d8b Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 3 Jan 2021 23:47:59 +0100 Subject: [PATCH 09/89] WiredEffectMoveFurniTo now saves as json --- .../effects/WiredEffectMoveFurniAway.java | 4 +- .../wired/effects/WiredEffectMoveFurniTo.java | 75 +++++++++++++------ 2 files changed, 54 insertions(+), 25 deletions(-) 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 3d985d74..76fe1ed9 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 @@ -101,8 +101,8 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect { public String getWiredData() { return WiredHandler.getGsonBuilder().create().toJson(new JsonData( this.getDelay(), - this.items.stream().map(HabboItem::getId).collect(Collectors.toList())) - ); + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + )); } @Override 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 bb7853c8..3b9367e2 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 @@ -21,6 +21,7 @@ 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; @@ -123,24 +124,23 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { @Override public String getWiredData() { - THashSet items = new THashSet<>(); + THashSet itemsToRemove = 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); + itemsToRemove.add(item); } - for (HabboItem item : items) { + for (HabboItem item : itemsToRemove) { this.items.remove(item); } - StringBuilder data = new StringBuilder(this.direction + "\t" + this.spacing + "\t" + this.getDelay() + "\t"); - - for (HabboItem item : this.items) { - data.append(item.getId()).append("\r"); - } - - return data.toString(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.direction, + this.spacing, + this.getDelay(), + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + )); } @Override @@ -176,22 +176,37 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { this.items.clear(); + String wiredData = set.getString("wired_data"); - String[] data = set.getString("wired_data").split("\t"); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.direction = data.direction; + this.spacing = data.spacing; + this.setDelay(data.delay); - if (data.length == 4) { - try { - this.direction = Integer.valueOf(data[0]); - this.spacing = Integer.valueOf(data[1]); - this.setDelay(Integer.valueOf(data[2])); - } catch (Exception e) { - } - - for (String s : data[3].split("\r")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); - - if (item != null) + 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 e) { + } + + for (String s : data[3].split("\r")) { + HabboItem item = room.getHabboItem(Integer.parseInt(s)); + + if (item != null) + this.items.add(item); + } } } } @@ -209,4 +224,18 @@ public class WiredEffectMoveFurniTo extends InteractionWiredEffect { protected long requiredCooldown() { 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; + } + } } \ No newline at end of file From 8a3361ec5e84ac4d215a861645be5f15d9f8aed6 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 05:30:29 -0500 Subject: [PATCH 10/89] WiredEffectMoveFurniTowards now saves as json --- .../effects/WiredEffectMoveFurniTowards.java | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) 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 454b3216..2a8c62b2 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 @@ -233,32 +233,41 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); - - if (this.items != null && !this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + 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").split("\t"); + String wiredData = set.getString("wired_data"); - if (wiredData.length >= 1) { - this.setDelay(Integer.parseInt(wiredData[0])); - } - if (wiredData.length == 2) { - if (wiredData[1].contains(";")) { - for (String s : wiredData[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); - if (item != null) - this.items.add(item); + 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); + } } } } @@ -342,4 +351,14 @@ public class WiredEffectMoveFurniTowards extends InteractionWiredEffect { protected long requiredCooldown() { return 495; } + + static class JsonData { + int delay; + List itemIds; + + public JsonData(int delay, List itemIds) { + this.delay = delay; + this.itemIds = itemIds; + } + } } From 9341d164a96697e43d23e9b4727bd4ffbcfc8a47 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 06:03:19 -0500 Subject: [PATCH 11/89] WiredEffectMoveRotateFurni now saves as json --- .../effects/WiredEffectMoveRotateFurni.java | 81 ++++++++++++------- 1 file changed, 53 insertions(+), 28 deletions(-) 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 d933aaae..6b701093 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 @@ -80,50 +80,61 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement @Override public String getWiredData() { - THashSet items = new THashSet<>(this.items.size() / 2); + 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)) - items.add(item); + itemsToRemove.add(item); } - for (HabboItem item : items) { + for (HabboItem item : itemsToRemove) { this.items.remove(item); } - StringBuilder data = new StringBuilder(this.direction + "\t" + - this.rotation + "\t" + - this.getDelay() + "\t"); - - for (HabboItem item : this.items) { - data.append(item.getId()).append("\r"); - } - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").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) + 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); + } } } } @@ -303,4 +314,18 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement public void cycle(Room room) { this.itemCooldowns.clear(); } -} \ No newline at end of file + + 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; + } + } +} From b1e9276940195de831692c4aac13d211598b2293 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 06:12:20 -0500 Subject: [PATCH 12/89] WiredEffectMuteHabbo now saves as json --- .../wired/effects/WiredEffectMuteHabbo.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) 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 index 27a1d2b3..e6f7b020 100644 --- 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 @@ -79,19 +79,32 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "\t" + this.length + "\t" + this.message; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.getDelay(), + this.length, + this.message + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split("\t"); + String wiredData = set.getString("wired_data"); - if (data.length >= 3) { - try { - this.setDelay(Integer.valueOf(data[0])); - this.length = Integer.valueOf(data[1]); - this.message = data[2]; - } catch (Exception e) { + 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.valueOf(data[0])); + this.length = Integer.valueOf(data[1]); + this.message = data[2]; + } catch (Exception e) { + } } } } @@ -112,4 +125,16 @@ public class WiredEffectMuteHabbo extends InteractionWiredEffect { 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; + } + } } From 9b6ae05ac3b31ddb379da90199cb844afe7cccb4 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 06:20:28 -0500 Subject: [PATCH 13/89] WiredEffectResetTimers now saves as json --- .../wired/effects/WiredEffectResetTimers.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) 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 5d6f6cfe..32e167c7 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 @@ -85,17 +85,25 @@ public class WiredEffectResetTimers extends InteractionWiredEffect { @Override public String getWiredData() { - return this.delay + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.delay + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { String data = set.getString("wired_data"); - try { - if (!data.equals("")) - this.delay = Integer.valueOf(data); - } catch (Exception e) { + if (data.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.delay = data.delay; + } else { + try { + if (!data.equals("")) { + this.delay = Integer.valueOf(data); + } + } catch (Exception e) { + } } this.setDelay(this.delay); @@ -111,4 +119,12 @@ public class WiredEffectResetTimers extends InteractionWiredEffect { public WiredEffectType getType() { return type; } + + static class JsonData { + int delay; + + public JsonData(int delay) { + this.delay = delay; + } + } } From e73625806f47b75697815889c9a46f55eef0a37d Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 06:35:58 -0500 Subject: [PATCH 14/89] WiredEffectTeleport now saves as json --- .../wired/effects/WiredEffectTeleport.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) 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 bfe0ef15..09e5cbed 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 @@ -181,32 +181,40 @@ public class WiredEffectTeleport extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); - - if (this.items != null && !this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.delay, + 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").split("\t"); + String wiredData = set.getString("wired_data"); - if (wiredData.length >= 1) { - this.setDelay(Integer.valueOf(wiredData[0])); - } - if (wiredData.length == 2) { - if (wiredData[1].contains(";")) { - for (String s : wiredData[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + 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 (item != null) - this.items.add(item); + if (wiredDataOld.length >= 1) { + this.setDelay(Integer.valueOf(wiredDataOld[0])); + } + if (wiredDataOld.length == 2) { + if (wiredDataOld[1].contains(";")) { + for (String s : wiredDataOld[1].split(";")) { + HabboItem item = room.getHabboItem(Integer.valueOf(s)); + + if (item != null) + this.items.add(item); + } } } } @@ -232,4 +240,14 @@ public class WiredEffectTeleport extends InteractionWiredEffect { protected long requiredCooldown() { return 50L; } + + static class JsonData { + int delay; + List itemIds; + + public JsonData(int delay, List itemIds) { + this.delay = delay; + this.itemIds = itemIds; + } + } } From 39d20520cb9d634a79efca3c89c765fcd65242a0 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 06:44:08 -0500 Subject: [PATCH 15/89] WiredEffectToggleFurni now saves as json --- .../wired/effects/WiredEffectToggleFurni.java | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) 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 21f2926b..e6191579 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 @@ -212,35 +212,48 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); - - if (this.items != null && !this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + 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").split("\t"); + String wiredData = set.getString("wired_data"); - if (wiredData.length >= 1) { - this.setDelay(Integer.valueOf(wiredData[0])); - } - if (wiredData.length == 2) { - if (wiredData[1].contains(";")) { - for (String s : wiredData[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + 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 instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) { + continue; + } - if (item != null) - this.items.add(item); + if (item != null) { + this.items.add(item); + } + } + } else { + String[] wiredDataOld = wiredData.split("\t"); + + if (wiredDataOld.length >= 1) { + this.setDelay(Integer.valueOf(wiredDataOld[0])); + } + if (wiredDataOld.length == 2) { + if (wiredDataOld[1].contains(";")) { + for (String s : wiredDataOld[1].split(";")) { + HabboItem item = room.getHabboItem(Integer.valueOf(s)); + + if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) + continue; + + if (item != null) + this.items.add(item); + } } } } @@ -256,4 +269,14 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { public WiredEffectType getType() { return type; } + + static class JsonData { + int delay; + List itemIds; + + public JsonData(int delay, List itemIds) { + this.delay = delay; + this.itemIds = itemIds; + } + } } From eb00da28ef5989e77058380b9ff2184f1d9ea9aa Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 06:55:33 -0500 Subject: [PATCH 16/89] WiredEffectToggleRandom now saves as json --- .../effects/WiredEffectToggleRandom.java | 63 ++++++++++++------- 1 file changed, 42 insertions(+), 21 deletions(-) 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 3a703929..ba73506d 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 @@ -192,35 +192,46 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); - - if (!this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + 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").split("\t"); + String wiredData = set.getString("wired_data"); - if (wiredData.length >= 1) { - this.setDelay(Integer.valueOf(wiredData[0])); - } - if (wiredData.length == 2) { - if (wiredData[1].contains(";")) { - for (String s : wiredData[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + 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 instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable) - continue; + if (item != null) + this.items.add(item); + } + } else { + String[] wiredDataOld = wiredData.split("\t"); - if (item != null) - this.items.add(item); + if (wiredDataOld.length >= 1) { + this.setDelay(Integer.valueOf(wiredDataOld[0])); + } + if (wiredDataOld.length == 2) { + if (wiredDataOld[1].contains(";")) { + for (String s : wiredDataOld[1].split(";")) { + HabboItem item = room.getHabboItem(Integer.valueOf(s)); + + if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable) + continue; + + if (item != null) + this.items.add(item); + } } } } @@ -236,4 +247,14 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { public WiredEffectType getType() { return type; } + + static class JsonData { + int delay; + List itemIds; + + public JsonData(int delay, List itemIds) { + this.delay = delay; + this.itemIds = itemIds; + } + } } From a849328412a554814b7fe3b10e9fd85d41f22eb9 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 07:09:37 -0500 Subject: [PATCH 17/89] WiredEffectTriggerStacks now saves as json --- .../effects/WiredEffectTriggerStacks.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) 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 da811cd6..79ea7f9c 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 @@ -156,32 +156,40 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); - - if (this.items != null && !this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + 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").split("\t"); + String wiredData = set.getString("wired_data"); - if (wiredData.length >= 1) { - this.setDelay(Integer.valueOf(wiredData[0])); - } - if (wiredData.length == 2) { - if (wiredData[1].contains(";")) { - for (String s : wiredData[1].split(";")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + 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 (item != null) - this.items.add(item); + if (wiredDataOld.length >= 1) { + this.setDelay(Integer.valueOf(wiredDataOld[0])); + } + if (wiredDataOld.length == 2) { + if (wiredDataOld[1].contains(";")) { + for (String s : wiredDataOld[1].split(";")) { + HabboItem item = room.getHabboItem(Integer.valueOf(s)); + + if (item != null) + this.items.add(item); + } } } } @@ -202,4 +210,14 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { protected long requiredCooldown() { return 250; } + + static class JsonData { + int delay; + List itemIds; + + public JsonData(int delay, List itemIds) { + this.delay = delay; + this.itemIds = itemIds; + } + } } From 7c8789a1246599715d0bf0ce87a05a11b485d0fb Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 07:53:32 -0500 Subject: [PATCH 18/89] WiredTriggerAtSetTime now saves as json --- .../wired/triggers/WiredTriggerAtSetTime.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 414412eb..08ecd7a2 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 @@ -39,13 +39,22 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi @Override public String getWiredData() { - return this.executeTime + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.executeTime + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - if (set.getString("wired_data").length() >= 1) { - this.executeTime = (Integer.valueOf(set.getString("wired_data"))); + 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.valueOf(wiredData)); + } } if (this.executeTime < 500) { @@ -115,4 +124,12 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime); } + + static class JsonData { + int executeTime; + + public JsonData(int executeTime) { + this.executeTime = executeTime; + } + } } From abe70991a0765e0e88de2182eef69bcb93f06f86 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 07:57:18 -0500 Subject: [PATCH 19/89] WiredTriggerAtTimeLong now saves as json --- .../triggers/WiredTriggerAtTimeLong.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 4bcec897..f7779c7a 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 @@ -38,13 +38,22 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W @Override public String getWiredData() { - return this.executeTime + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.executeTime + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - if (set.getString("wired_data").length() >= 1) { - this.executeTime = (Integer.valueOf(set.getString("wired_data"))); + 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.valueOf(wiredData)); + } } if (this.executeTime < 500) { @@ -113,4 +122,12 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W Emulator.getThreading().run(new WiredExecuteTask(this, Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId())), this.executeTime); } + + static class JsonData { + int executeTime; + + public JsonData(int executeTime) { + this.executeTime = executeTime; + } + } } From fd90c23a3a56e913c484bb1de616da615ac2eb07 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 08:14:51 -0500 Subject: [PATCH 20/89] WiredTriggerBotReachedFurni now saves as json --- .../triggers/WiredTriggerBotReachedFurni.java | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) 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 36c266b9..a991c23f 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 @@ -124,38 +124,45 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.botName + ":"); - - if (!this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } - - return wiredData.toString(); + 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"); - String[] data = set.getString("wired_data").split(":"); + 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]; + if (data.length == 1) { + this.botName = data[0]; + } else if (data.length == 2) { + this.botName = data[0]; - String[] items = data[1].split(";"); + String[] items = data[1].split(";"); - for (int i = 0; i < items.length; i++) { - try { - HabboItem item = room.getHabboItem(Integer.valueOf(items[i])); + for (int i = 0; i < items.length; i++) { + try { + HabboItem item = room.getHabboItem(Integer.valueOf(items[i])); - if (item != null) - this.items.add(item); - } catch (Exception e) { - LOGGER.error("Caught exception", e); + if (item != null) + this.items.add(item); + } catch (Exception e) { + LOGGER.error("Caught exception", e); + } } } } @@ -166,4 +173,13 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { this.items.clear(); this.botName = ""; } + + static class JsonData { + String botName; + List itemIds; + + public JsonData(String botName, List itemIds) { + this.executeTime = executeTime; + } + } } From b781f1d731f9d712e903fd26d4a796954a8e1dfb Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 08:19:56 -0500 Subject: [PATCH 21/89] WiredTriggerBotReachedHabbo now saves as json --- .../triggers/WiredTriggerBotReachedHabbo.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 index 161f2acf..2174d868 100644 --- 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 @@ -62,12 +62,21 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger { @Override public String getWiredData() { - return this.botName; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.botName + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.botName = set.getString("wired_data"); + 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 @@ -79,4 +88,12 @@ public class WiredTriggerBotReachedHabbo extends InteractionWiredTrigger { public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + String botName; + + public JsonData(String botName) { + this.botName = botName; + } + } } From 0cdadfab8baa38c0af8aba764be84c5dc1d9c502 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 08:20:37 -0500 Subject: [PATCH 22/89] WiredTriggerBotReachedFurni now saves as json --- .../wired/triggers/WiredTriggerBotReachedFurni.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 a991c23f..3ea953f7 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 @@ -179,7 +179,8 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { List itemIds; public JsonData(String botName, List itemIds) { - this.executeTime = executeTime; + this.botName = botName; + this.itemIds = itemIds; } } } From 412359330895952f52a3fd919ecb6caa7d31432f Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 09:31:11 -0500 Subject: [PATCH 23/89] WiredTriggerHabboEntersRoom now saves as json --- .../triggers/WiredTriggerHabboEntersRoom.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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 index 69175e52..ddb8f3ec 100644 --- 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 @@ -41,12 +41,21 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger { @Override public String getWiredData() { - return this.username; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.username + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.username = set.getString("wired_data"); + 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 @@ -86,4 +95,12 @@ public class WiredTriggerHabboEntersRoom extends InteractionWiredTrigger { public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + String username; + + public JsonData(String username) { + this.username = username; + } + } } From 4fcf7507634a9b0b6f5f1ffb52d7e549a3dfb26c Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 09:40:53 -0500 Subject: [PATCH 24/89] WiredTriggerHabboSaysKeyword now saves as json --- .../WiredTriggerHabboSaysKeyword.java | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) 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 index 341f912a..ef219299 100644 --- 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 @@ -41,16 +41,27 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger { @Override public String getWiredData() { - return (this.ownerOnly ? "1" : "0") + "\t" + this.key; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.ownerOnly, + this.key + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split("\t"); + String wiredData = set.getString("wired_data"); - if (data.length == 2) { - this.ownerOnly = data[0].equalsIgnoreCase("1"); - this.key = data[1]; + 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]; + } } } @@ -93,4 +104,14 @@ public class WiredTriggerHabboSaysKeyword extends InteractionWiredTrigger { public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + boolean ownerOnly; + String key; + + public JsonData(boolean ownerOnly, String key) { + this.ownerOnly = ownerOnly; + this.key = key; + } + } } From 9b62b4390739cee20656964ecf100c3ab6d6c7ae Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 10:25:46 -0500 Subject: [PATCH 25/89] WiredTriggerRepeater now saves as json --- .../wired/triggers/WiredTriggerRepeater.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 a0f693c9..36d48b3e 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 @@ -41,13 +41,22 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy @Override public String getWiredData() { - return this.repeatTime + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.repeatTime + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - if (set.getString("wired_data").length() >= 1) { - this.repeatTime = (Integer.valueOf(set.getString("wired_data"))); + 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.valueOf(wiredData)); + } } if (this.repeatTime < 500) { @@ -136,4 +145,12 @@ public class WiredTriggerRepeater extends InteractionWiredTrigger implements ICy } } } + + static class JsonData { + int repeatTime; + + public JsonData(int repeatTime) { + this.repeatTime = repeatTime; + } + } } From eaeafd21ad236b832701ee8b21aa3b6ee80e1dbd Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 10:27:26 -0500 Subject: [PATCH 26/89] WiredTriggerRepeaterLong now saves as json --- .../triggers/WiredTriggerRepeaterLong.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 ff3f9688..ad93a09d 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 @@ -40,13 +40,22 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements @Override public String getWiredData() { - return this.repeatTime + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.repeatTime + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - if (set.getString("wired_data").length() >= 1) { - this.repeatTime = (Integer.valueOf(set.getString("wired_data"))); + 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.valueOf(wiredData)); + } } if (this.repeatTime < 5000) { @@ -130,4 +139,12 @@ public class WiredTriggerRepeaterLong extends InteractionWiredTrigger implements } } } + + static class JsonData { + int repeatTime; + + public JsonData(int repeatTime) { + this.repeatTime = repeatTime; + } + } } From 09e29163104ddccccf59075677f355dc2a575d12 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 10:30:19 -0500 Subject: [PATCH 27/89] WiredTriggerScoreAchieved now saves as json --- .../triggers/WiredTriggerScoreAchieved.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) 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 b8fc74dd..e9be6e99 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 @@ -37,14 +37,23 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger { @Override public String getWiredData() { - return this.score + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.score + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - try { - this.score = Integer.valueOf(set.getString("wired_data")); - } catch (Exception e) { + 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.valueOf(wiredData); + } catch (Exception e) { + } } } @@ -85,4 +94,12 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger { public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + int score; + + public JsonData(int score) { + this.score = score; + } + } } From 5720adf61c7ed426321cbba87755735c484d4049 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 18:54:59 +0100 Subject: [PATCH 28/89] WiredEffectMoveFurniTowards now saves as json import fix --- .../interactions/wired/effects/WiredEffectMoveFurniTowards.java | 1 + 1 file changed, 1 insertion(+) 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 2a8c62b2..c069dc93 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 @@ -22,6 +22,7 @@ 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 From 75b61b180910e0e83cfd3bdfe9098d16e12e6331 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 19:03:42 +0100 Subject: [PATCH 29/89] WiredData now saves as JSON import fixes --- .../wired/effects/WiredEffectMoveRotateFurni.java | 2 ++ .../wired/effects/WiredEffectMuteHabbo.java | 1 + .../wired/effects/WiredEffectResetTimers.java | 11 ++++++----- .../wired/effects/WiredEffectTeleport.java | 9 +++++---- .../wired/effects/WiredEffectToggleFurni.java | 7 ++++--- .../wired/effects/WiredEffectToggleRandom.java | 5 +++-- .../wired/effects/WiredEffectTriggerStacks.java | 5 +++-- .../wired/triggers/WiredTriggerAtSetTime.java | 5 +++-- .../wired/triggers/WiredTriggerAtTimeLong.java | 5 +++-- .../wired/triggers/WiredTriggerBotReachedFurni.java | 5 +++-- .../wired/triggers/WiredTriggerBotReachedHabbo.java | 1 + .../wired/triggers/WiredTriggerHabboEntersRoom.java | 1 + .../wired/triggers/WiredTriggerHabboSaysKeyword.java | 1 + .../wired/triggers/WiredTriggerScoreAchieved.java | 3 ++- 14 files changed, 38 insertions(+), 23 deletions(-) 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 6b701093..5928e671 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 @@ -19,6 +19,8 @@ import org.slf4j.LoggerFactory; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implements ICycleable { 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 index e6f7b020..39788018 100644 --- 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 @@ -10,6 +10,7 @@ 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserWhisperComposer; 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 32e167c7..583e4f6a 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 @@ -8,6 +8,7 @@ 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.wired.WiredEffectType; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.threading.runnables.WiredResetTimers; @@ -86,21 +87,21 @@ public class WiredEffectResetTimers extends InteractionWiredEffect { @Override public String getWiredData() { return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.delay + this.delay )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String data = set.getString("wired_data"); + String wiredData = set.getString("wired_data"); - if (data.startsWith("{")) { + if (wiredData.startsWith("{")) { JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); this.delay = data.delay; } else { try { - if (!data.equals("")) { - this.delay = Integer.valueOf(data); + if (!wiredData.equals("")) { + this.delay = Integer.parseInt(wiredData); } } catch (Exception e) { } 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 09e5cbed..304703f1 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 @@ -26,6 +26,7 @@ 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; @@ -182,8 +183,8 @@ public class WiredEffectTeleport extends InteractionWiredEffect { @Override public String getWiredData() { return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.delay, - this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) + this.getDelay(), + this.items.stream().map(HabboItem::getId).collect(Collectors.toList()) )); } @@ -205,12 +206,12 @@ public class WiredEffectTeleport extends InteractionWiredEffect { String[] wiredDataOld = wiredData.split("\t"); if (wiredDataOld.length >= 1) { - this.setDelay(Integer.valueOf(wiredDataOld[0])); + 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.valueOf(s)); + HabboItem item = room.getHabboItem(Integer.parseInt(s)); if (item != null) this.items.add(item); 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 e6191579..05eef1f3 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 @@ -35,6 +35,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class WiredEffectToggleFurni extends InteractionWiredEffect { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectToggleFurni.class); @@ -193,7 +194,7 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { int state = 0; if (!item.getExtradata().isEmpty()) { try { - state = Integer.valueOf(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc. + state = Integer.parseInt(item.getExtradata()); // assumes that extradata is state, could be something else for trophies etc. } catch (NumberFormatException ignored) { } @@ -241,12 +242,12 @@ public class WiredEffectToggleFurni extends InteractionWiredEffect { String[] wiredDataOld = wiredData.split("\t"); if (wiredDataOld.length >= 1) { - this.setDelay(Integer.valueOf(wiredDataOld[0])); + 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.valueOf(s)); + HabboItem item = room.getHabboItem(Integer.parseInt(s)); if (item instanceof InteractionFreezeBlock || item instanceof InteractionFreezeTile || item instanceof InteractionCrackable) continue; 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 ba73506d..4fbd9203 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 @@ -32,6 +32,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class WiredEffectToggleRandom extends InteractionWiredEffect { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectToggleRandom.class); @@ -219,12 +220,12 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect { String[] wiredDataOld = wiredData.split("\t"); if (wiredDataOld.length >= 1) { - this.setDelay(Integer.valueOf(wiredDataOld[0])); + 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.valueOf(s)); + HabboItem item = room.getHabboItem(Integer.parseInt(s)); if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable) continue; 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 79ea7f9c..db37872b 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 @@ -21,6 +21,7 @@ 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; @@ -180,12 +181,12 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect { String[] wiredDataOld = wiredData.split("\t"); if (wiredDataOld.length >= 1) { - this.setDelay(Integer.valueOf(wiredDataOld[0])); + 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.valueOf(s)); + HabboItem item = room.getHabboItem(Integer.parseInt(s)); if (item != null) this.items.add(item); 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 08ecd7a2..f6364641 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 @@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.items.interactions.wired.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.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -40,7 +41,7 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi @Override public String getWiredData() { return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.executeTime + this.executeTime )); } @@ -53,7 +54,7 @@ public class WiredTriggerAtSetTime extends InteractionWiredTrigger implements Wi this.executeTime = data.executeTime; } else { if (wiredData.length() >= 1) { - this.executeTime = (Integer.valueOf(wiredData)); + this.executeTime = (Integer.parseInt(wiredData)); } } 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 f7779c7a..751d21c7 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 @@ -7,6 +7,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.items.interactions.wired.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.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -39,7 +40,7 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W @Override public String getWiredData() { return WiredHandler.getGsonBuilder().create().toJson(new JsonData( - this.executeTime + this.executeTime )); } @@ -52,7 +53,7 @@ public class WiredTriggerAtTimeLong extends InteractionWiredTrigger implements W this.executeTime = data.executeTime; } else { if (wiredData.length() >= 1) { - this.executeTime = (Integer.valueOf(wiredData)); + this.executeTime = (Integer.parseInt(wiredData)); } } 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 3ea953f7..596fbc8f 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 @@ -21,6 +21,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { private static final Logger LOGGER = LoggerFactory.getLogger(WiredTriggerBotReachedFurni.class); @@ -154,9 +155,9 @@ public class WiredTriggerBotReachedFurni extends InteractionWiredTrigger { String[] items = data[1].split(";"); - for (int i = 0; i < items.length; i++) { + for (String id : items) { try { - HabboItem item = room.getHabboItem(Integer.valueOf(items[i])); + HabboItem item = room.getHabboItem(Integer.parseInt(id)); if (item != null) this.items.add(item); 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 index 2174d868..0e7b22fd 100644 --- 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 @@ -5,6 +5,7 @@ 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.RoomUnit; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; 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 index ddb8f3ec..9a1400b2 100644 --- 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 @@ -5,6 +5,7 @@ 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.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; 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 index ef219299..f3b90ae3 100644 --- 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 @@ -5,6 +5,7 @@ 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.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; 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 e9be6e99..1f558d88 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 @@ -4,6 +4,7 @@ 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.RoomUnit; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -51,7 +52,7 @@ public class WiredTriggerScoreAchieved extends InteractionWiredTrigger { this.score = data.score; } else { try { - this.score = Integer.valueOf(wiredData); + this.score = Integer.parseInt(wiredData); } catch (Exception e) { } } From b8ea8fcd1be2fc95a86103c51f6d8da23f84d535 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 20:59:52 +0100 Subject: [PATCH 30/89] WiredTriggerFurniStateToggled now saves as JSON --- .../WiredTriggerFurniStateToggled.java | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) 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 c31b571a..dd1c0204 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 @@ -16,12 +16,13 @@ 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; - private String message = ""; public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -55,34 +56,36 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:"); - - if (this.items != null) { - if (!this.items.isEmpty()) { - for (HabboItem item : this.items) { - wiredData.append(item.getId()).append(";"); - } - } else - wiredData.append("\t"); - } - - return wiredData.toString(); + 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.split(":").length >= 3) { - super.setDelay(Integer.valueOf(wiredData.split(":")[0])); - this.message = wiredData.split(":")[1]; - if (!wiredData.split(":")[2].equals("\t")) { - for (String s : wiredData.split(":")[2].split(";")) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + super.setDelay(1000); + 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 (item != null) - this.items.add(item); + 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); + } } } } @@ -91,7 +94,6 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger { @Override public void onPickUp() { this.items.clear(); - this.message = ""; } @Override @@ -126,7 +128,7 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger { } message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); - message.appendString(this.message); + message.appendString(""); message.appendInt(0); message.appendInt(0); message.appendInt(this.getType().code); @@ -153,4 +155,12 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger { public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From 19b1b187a5e8e2f6d938f22ad3542664cb98bfec Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:07:17 +0100 Subject: [PATCH 31/89] Removed delay since its not used --- .../wired/triggers/WiredTriggerFurniStateToggled.java | 1 - 1 file changed, 1 deletion(-) 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 dd1c0204..f97f332f 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 @@ -68,7 +68,6 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger { if (wiredData.startsWith("{")) { JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - super.setDelay(1000); for (Integer id: data.itemIds) { HabboItem item = room.getHabboItem(id); if (item != null) { From c6af5baa7001e244cba58ffce9f839333fd19c13 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:18:02 +0100 Subject: [PATCH 32/89] WiredTriggerHabboWalkOffFurni now saves as JSON --- .../WiredTriggerHabboWalkOffFurni.java | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) 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 index 0e05ba01..64e9dae9 100644 --- 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 @@ -14,14 +14,13 @@ 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 WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger { public static final WiredTriggerType type = WiredTriggerType.WALKS_OFF_FURNI; private THashSet items; - private String message = ""; public WiredTriggerHabboWalkOffFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -45,55 +44,49 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:"); - - if (!this.items.isEmpty()) { - List toRemove = new ArrayList<>(0); - for (HabboItem item : this.items) { - if (item.getRoomId() == this.getRoomId()) { - wiredData.append(item.getId()).append(";"); - } else { - toRemove.add(item); - } - } - - this.items.removeAll(toRemove); - } else - wiredData.append("\t"); - - return wiredData.toString(); + 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.split(":").length >= 3) { - super.setDelay(Integer.valueOf(wiredData.split(":")[0])); - this.message = wiredData.split(":")[1]; - if (!wiredData.split(":")[2].equals("\t")) { - for (String s : wiredData.split(":")[2].split(";")) { - if (s.isEmpty()) - continue; + 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])); - try { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + if (!wiredData.split(":")[2].equals("\t")) { + for (String s : wiredData.split(":")[2].split(";")) { + if (s.isEmpty()) + continue; - if (item != null) - this.items.add(item); - } catch (Exception e) { + try { + HabboItem item = room.getHabboItem(Integer.parseInt(s)); + + if (item != null) + this.items.add(item); + } catch (Exception e) { + } } } } } - } @Override public void onPickUp() { this.items.clear(); - this.message = ""; } @Override @@ -126,7 +119,7 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger { } message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); - message.appendString(this.message); + message.appendString(""); message.appendInt(0); message.appendInt(0); message.appendInt(this.getType().code); @@ -154,4 +147,12 @@ public class WiredTriggerHabboWalkOffFurni extends InteractionWiredTrigger { public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From 069bffb9076a3aec29c6f64ebabc59a20b34805a Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:23:59 +0100 Subject: [PATCH 33/89] WiredTriggerHabboWalkOnFurni now saves as JSON --- .../WiredTriggerHabboWalkOnFurni.java | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) 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 index 1ebad4c9..257f23bb 100644 --- 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 @@ -16,12 +16,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; 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; - private String message = ""; public WiredTriggerHabboWalkOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -73,7 +73,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger { } message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); - message.appendString(this.message); + message.appendString(""); message.appendInt(0); message.appendInt(0); message.appendInt(this.getType().code); @@ -99,44 +99,40 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:"); - - if (!this.items.isEmpty()) { - List toRemove = new ArrayList<>(0); - for (HabboItem item : this.items) { - if (item.getRoomId() == this.getRoomId()) { - wiredData.append(item.getId()).append(";"); - } else { - toRemove.add(item); - } - } - - this.items.removeAll(toRemove); - } else - wiredData.append("\t"); - - return wiredData.toString(); + 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.split(":").length >= 3) { - super.setDelay(Integer.valueOf(wiredData.split(":")[0])); - this.message = wiredData.split(":")[1]; - if (!wiredData.split(":")[2].equals("\t")) { - for (String s : wiredData.split(":")[2].split(";")) { - if (s.isEmpty()) - continue; + 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])); - try { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + if (!wiredData.split(":")[2].equals("\t")) { + for (String s : wiredData.split(":")[2].split(";")) { + if (s.isEmpty()) + continue; - if (item != null) - this.items.add(item); - } catch (Exception e) { + try { + HabboItem item = room.getHabboItem(Integer.parseInt(s)); + + if (item != null) + this.items.add(item); + } catch (Exception e) { + } } } } @@ -146,11 +142,18 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger { @Override public void onPickUp() { this.items.clear(); - this.message = ""; } @Override public boolean isTriggeredByRoomUnit() { return true; } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From 0769e85a270037dbc77408753fc4155d69e91365 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:29:12 +0100 Subject: [PATCH 34/89] WiredConditionDateRangeActive now saves as JSON --- .../WiredConditionDateRangeActive.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) 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 30ba25bd..d4b92964 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 @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -64,18 +65,29 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition { @Override public String getWiredData() { - return this.startDate + "\t" + this.endDate; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.startDate, + this.endDate + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split("\t"); + String wiredData = set.getString("wired_data"); - if (data.length == 2) { - try { - this.startDate = Integer.valueOf(data[0]); - this.endDate = Integer.valueOf(data[1]); - } catch (Exception e) { + 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 e) { + } } } } @@ -85,4 +97,14 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition { this.startDate = 0; this.endDate = 0; } + + static class JsonData { + int startDate; + int endDate; + + public JsonData(int startDate, int endDate) { + this.startDate = startDate; + this.endDate = endDate; + } + } } From 3960ee53f5acddbd19b3a604aa7917e366c6d407 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:36:42 +0100 Subject: [PATCH 35/89] WiredConditionFurniHaveFurni now saves as JSON --- .../WiredConditionFurniHaveFurni.java | 57 +++++++++++++------ 1 file changed, 41 insertions(+), 16 deletions(-) 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 d83921c4..ddce19a5 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 @@ -15,6 +15,8 @@ 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 WiredConditionFurniHaveFurni extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.FURNI_HAS_FURNI; @@ -58,30 +60,43 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":"); - - for (HabboItem item : this.items) - data.append(item.getId()).append(";"); - - return data.toString(); + 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 { - String[] data = set.getString("wired_data").split(":"); + String wiredData = set.getString("wired_data"); - if (data.length >= 1) { - this.all = (data[0].equals("1")); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.all = data.all; - if (data.length == 2) { - String[] items = data[1].split(";"); + for(int id : data.itemIds) { + HabboItem item = room.getHabboItem(id); - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + if (item != null) { + this.items.add(item); + } + } - 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); + } } } } @@ -166,4 +181,14 @@ public class WiredConditionFurniHaveFurni extends InteractionWiredCondition { this.items.remove(item); } } + + static class JsonData { + boolean all; + List itemIds; + + public JsonData(boolean all, List itemIds) { + this.all = all; + this.itemIds = itemIds; + } + } } From 8fe9cadb76bb4fc49a6cfe6c26ca6b695a20dfab Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:43:14 +0100 Subject: [PATCH 36/89] Fixed wireddata incompatibility issue --- .../wired/effects/WiredEffectGiveHotelviewBonusRarePoints.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c50f7e5b..63920ffc 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 @@ -121,7 +121,7 @@ public class WiredEffectGiveHotelviewBonusRarePoints extends InteractionWiredEff super.setDelay(Integer.parseInt(wiredData.split("\t")[0])); try { - this.amount = Integer.parseInt(this.getWiredData().split("\t")[1]); + this.amount = Integer.parseInt(wiredData.split("\t")[1]); } catch (Exception e) { } } From f8520919ba43c8393f97d47bc1c0073542abc168 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:47:13 +0100 Subject: [PATCH 37/89] WiredConditionFurniHaveHabbo now saves as JSON --- .../WiredConditionFurniHaveHabbo.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) 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 index 3f9033f3..a0d07087 100644 --- 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 @@ -14,13 +14,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; -import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; -import java.util.Map; +import java.util.List; +import java.util.stream.Collectors; public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.FURNI_HAVE_HABBO; @@ -66,33 +66,43 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":"); - - for (HabboItem item : this.items) { - data.append(item.getId()).append(";"); - } - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(":"); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.all = data.all; - if (data.length >= 1) { - this.all = (data[0].equals("1")); + for(int id : data.itemIds) { + HabboItem item = room.getHabboItem(id); - if (data.length == 2) { - String[] items = data[1].split(";"); + if (item != null) { + this.items.add(item); + } + } + } else { + String[] data = wiredData.split(":"); - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + if (data.length >= 1) { + this.all = (data[0].equals("1")); - if (item != null) - this.items.add(item); + 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); + } } } } @@ -170,4 +180,14 @@ public class WiredConditionFurniHaveHabbo extends InteractionWiredCondition { this.items.remove(item); } } + + static class JsonData { + boolean all; + List itemIds; + + public JsonData(boolean all, List itemIds) { + this.all = all; + this.itemIds = itemIds; + } + } } From da751cca421143736471cc55bf24b38a6aad9815 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 21:52:45 +0100 Subject: [PATCH 38/89] WiredConditionFurniTypeMatch now saves as JSON --- .../WiredConditionFurniTypeMatch.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) 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 798054d0..47c42d64 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 @@ -14,6 +14,8 @@ 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; @@ -55,23 +57,37 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder(); - - for (HabboItem item : this.items) - data.append(item.getId()).append(";"); - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(";"); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - for (String s : data) - this.items.add(room.getHabboItem(Integer.valueOf(s))); + 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 @@ -138,4 +154,12 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition { this.items.remove(item); } } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From 4d10af2b41cd1492b9f810302bf42680c9dc436d Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:00:18 +0100 Subject: [PATCH 39/89] WiredConditionHabboCount now saves as JSON --- .../conditions/WiredConditionHabboCount.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) 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 index b131e517..d5e93e21 100644 --- 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 @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -34,15 +35,26 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { @Override public String getWiredData() { - return this.lowerLimit + ":" + this.upperLimit; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.lowerLimit, + this.upperLimit + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(":"); + String wiredData = set.getString("wired_data"); - this.lowerLimit = Integer.valueOf(data[0]); - this.upperLimit = Integer.valueOf(data[1]); + 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 @@ -82,4 +94,14 @@ public class WiredConditionHabboCount extends InteractionWiredCondition { return true; } + + static class JsonData { + int lowerLimit; + int upperLimit; + + public JsonData(int lowerLimit, int upperLimit) { + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + } } From 52650abfadbcf096490e53f47052b4be12784df8 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:03:05 +0100 Subject: [PATCH 40/89] WiredConditionHabboHasEffect now saves as JSON --- .../WiredConditionHabboHasEffect.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 index fdde8793..7e1580f0 100644 --- 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 @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -32,12 +33,21 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { @Override public String getWiredData() { - return this.effectId + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.effectId + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.effectId = Integer.valueOf(set.getString("wired_data")); + 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 @@ -73,4 +83,12 @@ public class WiredConditionHabboHasEffect extends InteractionWiredCondition { return true; } + + static class JsonData { + int effectId; + + public JsonData(int effectId) { + this.effectId = effectId; + } + } } From b9029cf1f380465af795cb32f763b800d5d2240b Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:06:19 +0100 Subject: [PATCH 41/89] WiredConditionHabboHasHandItem now saves as JSON --- .../WiredConditionHabboHasHandItem.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 index e47107c3..0d351e98 100644 --- 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 @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; import org.slf4j.Logger; @@ -66,13 +67,22 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { @Override public String getWiredData() { - return this.handItem + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.handItem + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { try { - this.handItem = Integer.valueOf(set.getString("wired_data")); + 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) { LOGGER.error("Caught exception", e); } @@ -82,4 +92,12 @@ public class WiredConditionHabboHasHandItem extends InteractionWiredCondition { public void onPickUp() { this.handItem = 0; } + + static class JsonData { + int handItemId; + + public JsonData(int handItemId) { + this.handItemId = handItemId; + } + } } From 7797e7f7cd1da3cb71f9802645044ad5d4e8b4fb Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:09:29 +0100 Subject: [PATCH 42/89] WiredConditionHabboWearsBadge now saves as JSON --- .../WiredConditionHabboWearsBadge.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 index d2ddf27c..b4f0df9f 100644 --- 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 @@ -7,6 +7,7 @@ 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -44,12 +45,21 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { @Override public String getWiredData() { - return this.badge; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.badge + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.badge = set.getString("wired_data"); + 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 @@ -85,4 +95,12 @@ public class WiredConditionHabboWearsBadge extends InteractionWiredCondition { return true; } + + static class JsonData { + String badge; + + public JsonData(String badge) { + this.badge = badge; + } + } } From fe52ad3458eef9a68da5440d54a0957791455a38 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:12:45 +0100 Subject: [PATCH 43/89] WiredConditionLessTimeElapsed now saves as JSON --- .../WiredConditionLessTimeElapsed.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 95e907ed..b40ee5e7 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 @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -32,16 +33,23 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition { @Override public String getWiredData() { - return this.cycles + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.cycles + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String data = set.getString("wired_data"); + String wiredData = set.getString("wired_data"); try { - if (!data.equals("")) - this.cycles = Integer.valueOf(data); + 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 e) { } } @@ -80,4 +88,12 @@ public class WiredConditionLessTimeElapsed extends InteractionWiredCondition { return true; } + + static class JsonData { + int cycles; + + public JsonData(int cycles) { + this.cycles = cycles; + } + } } From e6a5aaa27915320393f1457eb9de09c4cec3eea3 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:28:17 +0100 Subject: [PATCH 44/89] WiredConditionMatchStatePosition now saves as JSON --- .../WiredConditionMatchStatePosition.java | 66 ++++++++++++------- 1 file changed, 43 insertions(+), 23 deletions(-) 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 27c82d91..e489e781 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 @@ -15,6 +15,8 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class WiredConditionMatchStatePosition extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; @@ -138,38 +140,42 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition @Override public String getWiredData() { - StringBuilder data = new StringBuilder(this.settings.size() + ":"); - - if (this.settings.isEmpty()) { - data.append("\t;"); - } else { - for (WiredMatchFurniSetting item : this.settings) - data.append(item.toString()).append(";"); - } - - data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0); - - return data.toString(); + 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[] data = set.getString("wired_data").split(":"); + String wiredData = set.getString("wired_data"); - int itemCount = Integer.valueOf(data[0]); + 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(":"); - String[] items = data[1].split(";"); + int itemCount = Integer.parseInt(data[0]); - for (int i = 0; i < itemCount; i++) { - String[] stuff = items[i].split("-"); + String[] items = data[1].split(";"); - if (stuff.length >= 5) - this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4]))); + 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"); } - - this.state = data[2].equals("1"); - this.direction = data[3].equals("1"); - this.position = data[4].equals("1"); } @Override @@ -198,4 +204,18 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition } } } + + 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; + } + } } From 277464b365a84aaeedf11cea0afaabdcf21b3072 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:30:17 +0100 Subject: [PATCH 45/89] WiredConditionMoreTimeElapsed now saves as JSON --- .../WiredConditionMoreTimeElapsed.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 a1fa3c5c..0be6ba15 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 @@ -6,6 +6,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -32,16 +33,23 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition { @Override public String getWiredData() { - return this.cycles + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.cycles + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String data = set.getString("wired_data"); + String wiredData = set.getString("wired_data"); try { - if (!data.equals("")) - this.cycles = Integer.valueOf(data); + 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 e) { } } @@ -80,4 +88,12 @@ public class WiredConditionMoreTimeElapsed extends InteractionWiredCondition { return true; } + + static class JsonData { + int cycles; + + public JsonData(int cycles) { + this.cycles = cycles; + } + } } From 3488c8ad36da9bbc768e13b5b16fe3863fa875fe Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:33:33 +0100 Subject: [PATCH 46/89] WiredConditionNotFurniHaveFurni now saves as JSON --- .../WiredConditionNotFurniHaveFurni.java | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) 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 71fbc0b6..279f61bd 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 @@ -16,6 +16,8 @@ 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; @@ -59,32 +61,43 @@ public class WiredConditionNotFurniHaveFurni extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":"); - - for (HabboItem item : this.items) - data.append(item.getId()).append(";"); - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(":"); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.all = data.all; - if (data.length >= 1) { - this.all = (data[0].equals("1")); + for (int id : data.itemIds) { + HabboItem item = room.getHabboItem(id); - if (data.length == 2) { - String[] items = data[1].split(";"); + if (item != null) { + this.items.add(item); + } + } + } else { + String[] data = wiredData.split(":"); - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); + if (data.length >= 1) { + this.all = (data[0].equals("1")); - if (item != null) - this.items.add(item); + 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); + } } } } @@ -175,4 +188,14 @@ 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; + } + } } From 87ff24e40932ab6037aea4463df2c748e1c3fb15 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:38:20 +0100 Subject: [PATCH 47/89] WiredConditionNotFurniHaveHabbo now saves as JSON --- .../WiredConditionNotFurniHaveHabbo.java | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) 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 index b85217aa..87f3bc9a 100644 --- 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 @@ -14,13 +14,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; -import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; -import java.util.Map; +import java.util.List; +import java.util.stream.Collectors; public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO; @@ -66,33 +66,43 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder((this.all ? "1" : "0") + ":"); - - for (HabboItem item : this.items) { - data.append(item.getId()).append(";"); - } - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(":"); + if (wiredData.startsWith("{")) { + WiredConditionFurniHaveHabbo.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class); + this.all = data.all; - if (data.length >= 1) { - this.all = (data[0].equals("1")); + for(int id : data.itemIds) { + HabboItem item = room.getHabboItem(id); - if (data.length == 2) { - String[] items = data[1].split(";"); + if (item != null) { + this.items.add(item); + } + } + } else { + String[] data = wiredData.split(":"); - for (String s : items) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + if (data.length >= 1) { + this.all = (data[0].equals("1")); - if (item != null) - this.items.add(item); + 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); + } } } } @@ -169,4 +179,14 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { this.items.remove(item); } } + + static class JsonData { + boolean all; + List itemIds; + + public JsonData(boolean all, List itemIds) { + this.all = all; + this.itemIds = itemIds; + } + } } From b6b4ac936efd7116f36177b163154398beee7c21 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:42:13 +0100 Subject: [PATCH 48/89] WiredConditionNotFurniTypeMatch now saves as JSON --- .../WiredConditionNotFurniTypeMatch.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) 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 d9b6d466..30c9ea51 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 @@ -14,6 +14,8 @@ 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; @@ -50,23 +52,37 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder(); - - for (HabboItem item : this.items) - data.append(item.getId()).append(";"); - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(";"); + if (wiredData.startsWith("{")) { + WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class); - for (String s : data) - this.items.add(room.getHabboItem(Integer.valueOf(s))); + 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); + } + } + } } @Override @@ -138,4 +154,12 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { this.items.remove(item); } } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From ecfeaa9a5f2534ac390640d7bb07bef94c1eb041 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:45:49 +0100 Subject: [PATCH 49/89] WiredConditionNotHabboCount now saves as JSON --- .../WiredConditionNotHabboCount.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) 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 index 194d47c1..3075c4ff 100644 --- 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 @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -34,14 +35,25 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { @Override public String getWiredData() { - return this.lowerLimit + ":" + this.upperLimit; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.lowerLimit, + this.upperLimit + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(":"); - this.lowerLimit = Integer.valueOf(data[0]); - this.upperLimit = Integer.valueOf(data[1]); + 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 @@ -81,4 +93,14 @@ public class WiredConditionNotHabboCount extends InteractionWiredCondition { return true; } + + static class JsonData { + int lowerLimit; + int upperLimit; + + public JsonData(int lowerLimit, int upperLimit) { + this.lowerLimit = lowerLimit; + this.upperLimit = upperLimit; + } + } } From 218cb2f3fbcda17dbc963ec2ce47819af2c5f801 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:48:08 +0100 Subject: [PATCH 50/89] WiredConditionNotHabboHasEffect now saves as JSON --- .../WiredConditionNotHabboHasEffect.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 index 0994a2a3..ae1c20bb 100644 --- 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 @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredCondition; 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -32,12 +33,21 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { @Override public String getWiredData() { - return this.effectId + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.effectId + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.effectId = Integer.valueOf(set.getString("wired_data")); + 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 @@ -73,4 +83,12 @@ public class WiredConditionNotHabboHasEffect extends InteractionWiredCondition { return true; } + + static class JsonData { + int effectId; + + public JsonData(int effectId) { + this.effectId = effectId; + } + } } From a1bf9d7aa7a56a39b96672a0ace5187f0f0f4a5f Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 22:49:45 +0100 Subject: [PATCH 51/89] WiredConditionNotHabboWearsBadge now saves as JSON --- .../WiredConditionNotHabboWearsBadge.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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 index 3a30238f..6df96d6b 100644 --- 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 @@ -7,6 +7,7 @@ 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.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -45,12 +46,21 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition @Override public String getWiredData() { - return this.badge; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.badge + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.badge = set.getString("wired_data"); + 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 @@ -86,4 +96,12 @@ public class WiredConditionNotHabboWearsBadge extends InteractionWiredCondition return true; } + + static class JsonData { + String badge; + + public JsonData(String badge) { + this.badge = badge; + } + } } From bea21b715edc6129e57c94f0a0944e0055165514 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 23:05:45 +0100 Subject: [PATCH 52/89] WiredConditionNotInTeam now saves as JSON --- .../conditions/WiredConditionNotInTeam.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) 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 704921fc..b805c7b1 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 @@ -7,6 +7,7 @@ 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.WiredConditionType; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -39,16 +40,23 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { @Override public String getWiredData() { - return this.teamColor.type + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.teamColor + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String data = set.getString("wired_data"); - try { - if (!data.equals("")) - this.teamColor = GameTeamColors.values()[Integer.valueOf(data)]; + 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; } @@ -88,4 +96,12 @@ public class WiredConditionNotInTeam extends InteractionWiredCondition { return true; } + + static class JsonData { + GameTeamColors teamColor; + + public JsonData(GameTeamColors teamColor) { + this.teamColor = teamColor; + } + } } From 5617cd3da2194665b6fcb3d6a4ae1a937553ff10 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 23:07:36 +0100 Subject: [PATCH 53/89] WiredConditionTeamMember now saves as JSON --- .../conditions/WiredConditionTeamMember.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) 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 9349cbb2..027db810 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 @@ -7,6 +7,7 @@ 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.WiredConditionType; +import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ServerMessage; @@ -41,16 +42,23 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { @Override public String getWiredData() { - return this.teamColor.type + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData( + this.teamColor + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String data = set.getString("wired_data"); - try { - if (!data.equals("")) - this.teamColor = GameTeamColors.values()[Integer.valueOf(data)]; + 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; } @@ -90,4 +98,12 @@ public class WiredConditionTeamMember extends InteractionWiredCondition { return true; } + + static class JsonData { + GameTeamColors teamColor; + + public JsonData(GameTeamColors teamColor) { + this.teamColor = teamColor; + } + } } From 190a5cf86033b4df8c7643f670f825ce50e7291e Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 23:10:50 +0100 Subject: [PATCH 54/89] WiredConditionNotMatchStatePosition now saves as JSON --- .../WiredConditionNotMatchStatePosition.java | 66 ++++++++++++------- 1 file changed, 43 insertions(+), 23 deletions(-) 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 48983cef..11684c93 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 @@ -15,6 +15,8 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT; @@ -68,38 +70,42 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi @Override public String getWiredData() { - StringBuilder data = new StringBuilder(this.settings.size() + ":"); - - if (this.settings.isEmpty()) { - data.append("\t;"); - } else { - for (WiredMatchFurniSetting item : this.settings) - data.append(item.toString()).append(";"); - } - - data.append(":").append(this.state ? 1 : 0).append(":").append(this.rotation ? 1 : 0).append(":").append(this.position ? 1 : 0); - - return data.toString(); + return WiredHandler.getGsonBuilder().create().toJson(new WiredConditionMatchStatePosition.JsonData( + this.state, + this.position, + this.rotation, + new ArrayList<>(this.settings) + )); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(":"); + String wiredData = set.getString("wired_data"); - int itemCount = Integer.valueOf(data[0]); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.state = data.state; + this.position = data.position; + this.rotation = data.direction; + this.settings.addAll(data.settings); + } else { + String[] data = wiredData.split(":"); - String[] items = data[1].split(";"); + int itemCount = Integer.parseInt(data[0]); - for (int i = 0; i < itemCount; i++) { - String[] stuff = items[i].split("-"); + String[] items = data[1].split(";"); - if (stuff.length >= 5) - this.settings.add(new WiredMatchFurniSetting(Integer.valueOf(stuff[0]), stuff[1], Integer.valueOf(stuff[2]), Integer.valueOf(stuff[3]), Integer.valueOf(stuff[4]))); + 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.rotation = data[3].equals("1"); + this.position = data[4].equals("1"); } - - this.state = data[2].equals("1"); - this.rotation = data[3].equals("1"); - this.position = data[4].equals("1"); } @Override @@ -189,4 +195,18 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi } } } + + 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; + } + } } From ac1c6a3d9bace50df0c34ce259d01cb1da5f6af1 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 23:13:21 +0100 Subject: [PATCH 55/89] WiredConditionNotTriggerOnFurni now saves as JSON --- .../WiredConditionNotTriggerOnFurni.java | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) 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 cf31f254..f80f7df6 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 @@ -4,7 +4,6 @@ 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.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.wired.WiredConditionType; @@ -15,6 +14,8 @@ 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 WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI; @@ -44,26 +45,35 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder(); - - for (HabboItem item : this.items) - data.append(item.getId()).append(";"); - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(";"); + if (wiredData.startsWith("{")) { + WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class); - for (String s : data) { - HabboItem item = room.getHabboItem(Integer.valueOf(s)); + for(int id : data.itemIds) { + HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); + 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); + } } } } @@ -139,4 +149,12 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { this.items.removeAll(items); } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From ad84ef423e406f92ca68682ad0fb55714b0de04a Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 23:15:01 +0100 Subject: [PATCH 56/89] WiredConditionTriggerOnFurni now saves as JSON --- .../WiredConditionTriggerOnFurni.java | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) 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 5dcfb9cc..733c8581 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 @@ -16,6 +16,8 @@ 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; @@ -67,27 +69,35 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder(); - - for (HabboItem item : this.items) { - data.append(item.getId()).append(";"); - } - - return data.toString(); + 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"); - String[] data = set.getString("wired_data").split(";"); + if (wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); - for (String s : data) { - HabboItem item = room.getHabboItem(Integer.parseInt(s)); + for(int id : data.itemIds) { + HabboItem item = room.getHabboItem(id); - if (item != null) { - this.items.add(item); + 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); + } } } } @@ -168,4 +178,12 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { public WiredConditionOperator operator() { return WiredConditionOperator.AND; } + + static class JsonData { + List itemIds; + + public JsonData(List itemIds) { + this.itemIds = itemIds; + } + } } From d6ecdbeeecb992bf6cc9aacdb215b091f02e359b Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 5 Jan 2021 21:55:23 +0100 Subject: [PATCH 57/89] Added SQL to expand items.wired_data column --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index b8fc2d61..42a86b26 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -114,3 +114,6 @@ ADD COLUMN `bubble_id` int(3) NULL DEFAULT 31 AFTER `effect`; -- Permissions to see tent chat ALTER TABLE `permissions` ADD `acc_see_tentchat` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `acc_see_whispers`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', 'Tent'); + +-- Making items.wired_data column bigger since wired data is saved as JSON now +ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000) \ No newline at end of file From 4937ac298de4f5d029e40da106bd216cab9fe5df Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 6 Jan 2021 20:24:04 +0100 Subject: [PATCH 58/89] Added roombadge command --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 6 +++ .../habbohotel/commands/RoomBadgeCommand.java | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index b8fc2d61..23f3508b 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -114,3 +114,9 @@ ADD COLUMN `bubble_id` int(3) NULL DEFAULT 31 AFTER `effect`; -- Permissions to see tent chat ALTER TABLE `permissions` ADD `acc_see_tentchat` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `acc_see_whispers`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', 'Tent'); + +-- Roombadge command +ALTER TABLE `permissions` ADD `cmd_roombadge` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `cmd_massbadge`; +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_roombadge.no_badge', 'No badge specified!'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_massbadge', 'roombadge'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.description.cmd_massbadge', ':roombadge '); diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java new file mode 100644 index 00000000..a2693217 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/commands/RoomBadgeCommand.java @@ -0,0 +1,54 @@ +package com.eu.habbo.habbohotel.commands; + +import com.eu.habbo.Emulator; +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.HabboBadge; +import com.eu.habbo.habbohotel.users.inventory.BadgesComponent; +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; +import com.eu.habbo.messages.outgoing.users.AddUserBadgeComposer; +import gnu.trove.map.hash.THashMap; + +public class RoomBadgeCommand extends Command { + public RoomBadgeCommand() { + super("cmd_roombadge", Emulator.getTexts().getValue("commands.keys.cmd_roombadge").split(";")); + } + + @Override + public boolean handle(GameClient gameClient, String[] params) throws Exception { + if (gameClient == null) + return true; + + if (params.length == 2) { + String badge; + + badge = params[1]; + + if (!badge.isEmpty()) { + THashMap keys = new THashMap<>(); + keys.put("display", "BUBBLE"); + keys.put("image", "${image.library.url}album1584/" + badge + ".gif"); + keys.put("message", Emulator.getTexts().getValue("commands.generic.cmd_badge.received")); + ServerMessage message = new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys).compose(); + + for (Habbo habbo : gameClient.getHabbo().getRoomUnit().getRoom().getHabbos()) { + if (habbo.isOnline()) { + if (habbo.getInventory() != null && habbo.getInventory().getBadgesComponent() != null && !habbo.getInventory().getBadgesComponent().hasBadge(badge)) { + HabboBadge b = BadgesComponent.createBadge(badge, habbo); + + habbo.getClient().sendResponse(new AddUserBadgeComposer(b)); + habbo.getClient().sendResponse(message); + } + } + } + } + return true; + } + + gameClient.getHabbo().whisper(Emulator.getTexts().getValue("commands.error.cmd_roombadge.no_badge"), RoomChatMessageBubbles.ALERT); + return true; + } +} From 22efb1c925075c2827cbdb5ff9900e283c6f226e Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 6 Jan 2021 20:34:22 +0100 Subject: [PATCH 59/89] Oop.. --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index 23f3508b..1bc01add 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -118,5 +118,5 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', -- Roombadge command ALTER TABLE `permissions` ADD `cmd_roombadge` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `cmd_massbadge`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_roombadge.no_badge', 'No badge specified!'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_massbadge', 'roombadge'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.description.cmd_massbadge', ':roombadge '); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_roombadge', 'roombadge'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.description.cmd_roombadge', ':roombadge '); From 8a89f7ce4d572705f4ff1f67763c616d82a9b3be Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 6 Jan 2021 20:39:30 +0100 Subject: [PATCH 60/89] Actually added the RoomBadgeCommand --- .../java/com/eu/habbo/habbohotel/commands/CommandHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java b/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java index 1ec167c4..a37d9482 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/CommandHandler.java @@ -217,6 +217,7 @@ public class CommandHandler { addCommand(new LayCommand()); addCommand(new MachineBanCommand()); addCommand(new MassBadgeCommand()); + addCommand(new RoomBadgeCommand()); addCommand(new MassCreditsCommand()); addCommand(new MassGiftCommand()); addCommand(new MassPixelsCommand()); From 5981046523bd44ff09dee6e293e40db45a540985 Mon Sep 17 00:00:00 2001 From: Snaiker Date: Sun, 10 Jan 2021 02:49:15 +0000 Subject: [PATCH 61/89] Fix issue 936 --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 2 ++ src/main/java/com/eu/habbo/habbohotel/rooms/Room.java | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index b8fc2d61..21f3064c 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -101,6 +101,8 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_subscr INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('subscriptions.hc.payday.message', 'Woohoo HC Payday has arrived! You have received %amount% credits to your purse. Enjoy!'); +INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.roomuser.idle.not_dancing.ignore.wired_idle', '0'); + -- OPTIONAL HC MIGRATION -- INSERT INTO users_subscriptions SELECT NULL, user_id, 'HABBO_CLUB' as `subscription_type`, UNIX_TIMESTAMP() AS `timestamp_start`, (club_expire_timestamp - UNIX_TIMESTAMP()) AS `duration`, 1 AS `active` FROM users_settings WHERE club_expire_timestamp > UNIX_TIMESTAMP(); 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 d0704c82..512783f6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/Room.java @@ -1205,8 +1205,11 @@ public class Room implements Comparable, ISerialize, Runnable { habbo.getRoomUnit().increaseIdleTimer(); if (habbo.getRoomUnit().isIdle()) { - this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose()); - WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo}); + boolean danceIsNone = (habbo.getRoomUnit().getDanceType() == DanceType.NONE); + if (danceIsNone) + this.sendComposer(new RoomUnitIdleComposer(habbo.getRoomUnit()).compose()); + if (danceIsNone && !Emulator.getConfig().getBoolean("hotel.roomuser.idle.not_dancing.ignore.wired_idle")) + WiredHandler.handle(WiredTriggerType.IDLES, habbo.getRoomUnit(), this, new Object[]{habbo}); } } else { habbo.getRoomUnit().increaseIdleTimer(); From 35ac99b2c6c1f0622a2d09aa4a65fb1b39ebc62e Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 10 Jan 2021 20:45:44 +0100 Subject: [PATCH 62/89] Added Apply furni to set conditions feature --- .../WiredConditionMatchStatePosition.java | 23 ++++- .../WiredConditionNotMatchStatePosition.java | 23 ++++- .../wired/effects/WiredEffectMatchFurni.java | 23 ++++- .../InteractionWiredMatchFurniSettings.java | 11 +++ .../com/eu/habbo/messages/PacketManager.java | 4 +- .../eu/habbo/messages/incoming/Incoming.java | 2 + .../WiredEffectApplySetConditionsEvent.java | 98 +++++++++++++++++++ 7 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java 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 27c82d91..0fe350dd 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 @@ -3,6 +3,7 @@ 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -16,7 +17,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -public class WiredConditionMatchStatePosition extends InteractionWiredCondition { +public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; private THashSet settings; @@ -198,4 +199,24 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition } } } + + @Override + public THashSet getMatchFurniSettings() { + return this.settings; + } + + @Override + public boolean shouldMatchState() { + return this.state; + } + + @Override + public boolean shouldMatchRotation() { + return this.direction; + } + + @Override + public boolean shouldMatchPosition() { + return this.position; + } } 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 48983cef..b6d7cb5e 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 @@ -3,6 +3,7 @@ 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -16,7 +17,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition { +public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT; private THashSet settings; @@ -189,4 +190,24 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi } } } + + @Override + public THashSet getMatchFurniSettings() { + return this.settings; + } + + @Override + public boolean shouldMatchState() { + return this.state; + } + + @Override + public boolean shouldMatchRotation() { + return this.rotation; + } + + @Override + public boolean shouldMatchPosition() { + return this.position; + } } 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 fbd374d4..aa19b878 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 @@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; @@ -24,7 +25,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -public class WiredEffectMatchFurni extends InteractionWiredEffect { +public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMatchFurni.class); private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT; @@ -241,6 +242,26 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { } } + @Override + public THashSet getMatchFurniSettings() { + return this.settings; + } + + @Override + public boolean shouldMatchState() { + return this.state; + } + + @Override + public boolean shouldMatchRotation() { + return this.direction; + } + + @Override + public boolean shouldMatchPosition() { + return this.position; + } + static class JsonData { boolean state; boolean direction; 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 new file mode 100644 index 00000000..6db447f7 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java @@ -0,0 +1,11 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; +import gnu.trove.set.hash.THashSet; + +public interface InteractionWiredMatchFurniSettings { + public THashSet getMatchFurniSettings(); + public boolean shouldMatchState(); + public boolean shouldMatchRotation(); + public boolean shouldMatchPosition(); +} diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 00cdb987..f9b427a3 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -65,6 +65,7 @@ import com.eu.habbo.messages.incoming.unknown.RequestResolutionEvent; import com.eu.habbo.messages.incoming.unknown.UnknownEvent1; import com.eu.habbo.messages.incoming.users.*; import com.eu.habbo.messages.incoming.wired.WiredConditionSaveDataEvent; +import com.eu.habbo.messages.incoming.wired.WiredEffectApplySetConditionsEvent; import com.eu.habbo.messages.incoming.wired.WiredEffectSaveDataEvent; import com.eu.habbo.messages.incoming.wired.WiredTriggerSaveDataEvent; import com.eu.habbo.plugin.EventHandler; @@ -81,7 +82,7 @@ public class PacketManager { private static final Logger LOGGER = LoggerFactory.getLogger(PacketManager.class); private static final List logList = new ArrayList<>(); - public static boolean DEBUG_SHOW_PACKETS = false; + public static boolean DEBUG_SHOW_PACKETS = true; public static boolean MULTI_THREADED_PACKET_HANDLING = false; private final THashMap> incoming; private final THashMap> callables; @@ -579,6 +580,7 @@ public class PacketManager { this.registerHandler(Incoming.WiredTriggerSaveDataEvent, WiredTriggerSaveDataEvent.class); this.registerHandler(Incoming.WiredEffectSaveDataEvent, WiredEffectSaveDataEvent.class); this.registerHandler(Incoming.WiredConditionSaveDataEvent, WiredConditionSaveDataEvent.class); + this.registerHandler(Incoming.WiredEffectApplySetConditionsEvent, WiredEffectApplySetConditionsEvent.class); } void registerUnknown() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index 621a4775..c70b9b88 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -155,6 +155,8 @@ public class Incoming { public static final int RequestInventoryItemsEvent = 3150; public static final int ModToolRoomAlertEvent = 3842; public static final int WiredEffectSaveDataEvent = 2281; + public static final int WiredEffectApplySetConditionsEvent = 3373; +// public static final int WiredEffectApplySetConditionsEvent = 495; public static final int CheckPetNameEvent = 2109; public static final int SecureLoginEvent = 2419; public static final int BotSaveSettingsEvent = 2624; diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java new file mode 100644 index 00000000..4e8a40e2 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java @@ -0,0 +1,98 @@ +package com.eu.habbo.messages.incoming.wired; + +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings; +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.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; +import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class WiredEffectApplySetConditionsEvent extends MessageHandler { + + @Override + public void handle() throws Exception { + int itemId = this.packet.readInt(); + + // Executing Habbo has to be in a Room + if (!this.client.getHabbo().getRoomUnit().isInRoom()) { + this.client.sendResponse(new BubbleAlertComposer( + BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, + FurnitureMovementError.NO_RIGHTS.errorCode + )); + return; + } + + Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + + if (room != null) { + + // Executing Habbo should be able to edit wireds + if (room.hasRights(this.client.getHabbo()) || room.isOwner(this.client.getHabbo())) { + + 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() + .filter(wired -> wired.getId() == itemId) + .findFirst(); + + // If the item exists + if (item.isPresent()) { + HabboItem wiredItem = item.get(); + + // The item should have settings to match furni state, position and rotation + if (wiredItem instanceof InteractionWiredMatchFurniSettings) { + + InteractionWiredMatchFurniSettings wired = (InteractionWiredMatchFurniSettings) wiredItem; + + // Try to apply the set settings to each item + wired.getMatchFurniSettings().forEach(setting -> { + HabboItem matchItem = room.getHabboItem(setting.item_id); + + // Match state + if (wired.shouldMatchState() && matchItem.allowWiredResetState()) { + if (!setting.state.equals(" ") && !matchItem.getExtradata().equals(setting.state)) { + matchItem.setExtradata(setting.state); + room.updateItemState(matchItem); + } + } + + RoomTile oldLocation = room.getLayout().getTile(matchItem.getX(), matchItem.getY()); + double oldZ = matchItem.getZ(); + + // Match Position & Rotation + if(wired.shouldMatchRotation() && !wired.shouldMatchPosition()) { + if(matchItem.getRotation() != setting.rotation && room.furnitureFitsAt(oldLocation, matchItem, setting.rotation, false) == FurnitureMovementError.NONE) { + room.moveFurniTo(matchItem, oldLocation, setting.rotation, null, true); + } + } + else if(wired.shouldMatchPosition()) { + boolean slideAnimation = !wired.shouldMatchRotation() || matchItem.getRotation() == setting.rotation; + RoomTile newLocation = room.getLayout().getTile((short) setting.x, (short) setting.y); + int newRotation = wired.shouldMatchRotation() ? setting.rotation : matchItem.getRotation(); + + if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != matchItem.getRotation()) && room.furnitureFitsAt(newLocation, matchItem, newRotation, true) == FurnitureMovementError.NONE) { + if(room.moveFurniTo(matchItem, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) { + if(slideAnimation) { + room.sendComposer(new FloorItemOnRollerComposer(matchItem, null, oldLocation, oldZ, newLocation, matchItem.getZ(), 0, room).compose()); + } + } + } + } + }); + } + } + } + } + } +} From 32e7c29f84755f9076ff6ef1a58d9e1daebc0b32 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 10 Jan 2021 20:47:26 +0100 Subject: [PATCH 63/89] Removed commented code --- src/main/java/com/eu/habbo/messages/incoming/Incoming.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index c70b9b88..dd19f4a7 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -156,7 +156,6 @@ public class Incoming { public static final int ModToolRoomAlertEvent = 3842; public static final int WiredEffectSaveDataEvent = 2281; public static final int WiredEffectApplySetConditionsEvent = 3373; -// public static final int WiredEffectApplySetConditionsEvent = 495; public static final int CheckPetNameEvent = 2109; public static final int SecureLoginEvent = 2419; public static final int BotSaveSettingsEvent = 2624; From 2313276df067997120819fb106d2010f43c2f295 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 10 Jan 2021 20:50:03 +0100 Subject: [PATCH 64/89] Removed debugging code --- src/main/java/com/eu/habbo/messages/PacketManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index f9b427a3..16e85a04 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -82,7 +82,7 @@ public class PacketManager { private static final Logger LOGGER = LoggerFactory.getLogger(PacketManager.class); private static final List logList = new ArrayList<>(); - public static boolean DEBUG_SHOW_PACKETS = true; + public static boolean DEBUG_SHOW_PACKETS = false; public static boolean MULTI_THREADED_PACKET_HANDLING = false; private final THashMap> incoming; private final THashMap> callables; From 53fc7ece4a34a3b49f6782f23083a0a50fd8e90e Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 10 Jan 2021 20:55:09 +0100 Subject: [PATCH 65/89] Renamed event since it applies to both conditions and effects --- src/main/java/com/eu/habbo/messages/PacketManager.java | 4 ++-- ...ConditionsEvent.java => WiredApplySetConditionsEvent.java} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/com/eu/habbo/messages/incoming/wired/{WiredEffectApplySetConditionsEvent.java => WiredApplySetConditionsEvent.java} (98%) diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 16e85a04..f61928d2 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -65,7 +65,7 @@ import com.eu.habbo.messages.incoming.unknown.RequestResolutionEvent; import com.eu.habbo.messages.incoming.unknown.UnknownEvent1; import com.eu.habbo.messages.incoming.users.*; import com.eu.habbo.messages.incoming.wired.WiredConditionSaveDataEvent; -import com.eu.habbo.messages.incoming.wired.WiredEffectApplySetConditionsEvent; +import com.eu.habbo.messages.incoming.wired.WiredApplySetConditionsEvent; import com.eu.habbo.messages.incoming.wired.WiredEffectSaveDataEvent; import com.eu.habbo.messages.incoming.wired.WiredTriggerSaveDataEvent; import com.eu.habbo.plugin.EventHandler; @@ -580,7 +580,7 @@ public class PacketManager { this.registerHandler(Incoming.WiredTriggerSaveDataEvent, WiredTriggerSaveDataEvent.class); this.registerHandler(Incoming.WiredEffectSaveDataEvent, WiredEffectSaveDataEvent.class); this.registerHandler(Incoming.WiredConditionSaveDataEvent, WiredConditionSaveDataEvent.class); - this.registerHandler(Incoming.WiredEffectApplySetConditionsEvent, WiredEffectApplySetConditionsEvent.class); + this.registerHandler(Incoming.WiredEffectApplySetConditionsEvent, WiredApplySetConditionsEvent.class); } void registerUnknown() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java similarity index 98% rename from src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java rename to src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java index 4e8a40e2..12676201 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredEffectApplySetConditionsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java @@ -15,7 +15,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -public class WiredEffectApplySetConditionsEvent extends MessageHandler { +public class WiredApplySetConditionsEvent extends MessageHandler { @Override public void handle() throws Exception { From de7c51d78a1771465094fa513451a3c178fc5963 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 10 Jan 2021 22:15:20 +0100 Subject: [PATCH 66/89] Added ratelimit --- .../incoming/wired/WiredApplySetConditionsEvent.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java index 12676201..6fac8cab 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java @@ -17,6 +17,11 @@ import java.util.Optional; public class WiredApplySetConditionsEvent extends MessageHandler { + @Override + public int getRatelimit() { + return 500; + } + @Override public void handle() throws Exception { int itemId = this.packet.readInt(); From 40914b505080add986d31bd8e6642bb5e39474a7 Mon Sep 17 00:00:00 2001 From: Remco Date: Sun, 10 Jan 2021 23:10:15 +0100 Subject: [PATCH 67/89] Renamed incoming event --- src/main/java/com/eu/habbo/messages/PacketManager.java | 2 +- src/main/java/com/eu/habbo/messages/incoming/Incoming.java | 2 +- .../messages/incoming/wired/WiredApplySetConditionsEvent.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index f61928d2..edf209bb 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -580,7 +580,7 @@ public class PacketManager { this.registerHandler(Incoming.WiredTriggerSaveDataEvent, WiredTriggerSaveDataEvent.class); this.registerHandler(Incoming.WiredEffectSaveDataEvent, WiredEffectSaveDataEvent.class); this.registerHandler(Incoming.WiredConditionSaveDataEvent, WiredConditionSaveDataEvent.class); - this.registerHandler(Incoming.WiredEffectApplySetConditionsEvent, WiredApplySetConditionsEvent.class); + this.registerHandler(Incoming.WiredApplySetConditionsEvent, WiredApplySetConditionsEvent.class); } void registerUnknown() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index dd19f4a7..75223e4c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -155,7 +155,7 @@ public class Incoming { public static final int RequestInventoryItemsEvent = 3150; public static final int ModToolRoomAlertEvent = 3842; public static final int WiredEffectSaveDataEvent = 2281; - public static final int WiredEffectApplySetConditionsEvent = 3373; + public static final int WiredApplySetConditionsEvent = 3373; public static final int CheckPetNameEvent = 2109; public static final int SecureLoginEvent = 2419; public static final int BotSaveSettingsEvent = 2624; diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java index 6fac8cab..1d9266f3 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java @@ -21,7 +21,7 @@ public class WiredApplySetConditionsEvent extends MessageHandler { public int getRatelimit() { return 500; } - + @Override public void handle() throws Exception { int itemId = this.packet.readInt(); From f4869a6305370a5bbddc73fed5b85af4e466e0a4 Mon Sep 17 00:00:00 2001 From: Harmonic Date: Sun, 10 Jan 2021 18:04:47 -0500 Subject: [PATCH 68/89] Revert "Merge branch 'feature/packet-1094' into 'dev'" This reverts merge request !366 --- .../WiredConditionMatchStatePosition.java | 23 +--- .../WiredConditionNotMatchStatePosition.java | 23 +--- .../wired/effects/WiredEffectMatchFurni.java | 23 +--- .../InteractionWiredMatchFurniSettings.java | 11 -- .../com/eu/habbo/messages/PacketManager.java | 2 - .../eu/habbo/messages/incoming/Incoming.java | 1 - .../wired/WiredApplySetConditionsEvent.java | 103 ------------------ 7 files changed, 3 insertions(+), 183 deletions(-) delete mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java delete mode 100644 src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java 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 0fe350dd..27c82d91 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 @@ -3,7 +3,6 @@ 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -17,7 +16,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { +public class WiredConditionMatchStatePosition extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; private THashSet settings; @@ -199,24 +198,4 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition } } } - - @Override - public THashSet getMatchFurniSettings() { - return this.settings; - } - - @Override - public boolean shouldMatchState() { - return this.state; - } - - @Override - public boolean shouldMatchRotation() { - return this.direction; - } - - @Override - public boolean shouldMatchPosition() { - return this.position; - } } 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 b6d7cb5e..48983cef 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 @@ -3,7 +3,6 @@ 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -17,7 +16,7 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { +public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT; private THashSet settings; @@ -190,24 +189,4 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi } } } - - @Override - public THashSet getMatchFurniSettings() { - return this.settings; - } - - @Override - public boolean shouldMatchState() { - return this.state; - } - - @Override - public boolean shouldMatchRotation() { - return this.rotation; - } - - @Override - public boolean shouldMatchPosition() { - return this.position; - } } 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 aa19b878..fbd374d4 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 @@ -5,7 +5,6 @@ import com.eu.habbo.habbohotel.gameclients.GameClient; 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.wired.WiredEffectType; @@ -25,7 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings { +public class WiredEffectMatchFurni extends InteractionWiredEffect { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMatchFurni.class); private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT; @@ -242,26 +241,6 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect implements Int } } - @Override - public THashSet getMatchFurniSettings() { - return this.settings; - } - - @Override - public boolean shouldMatchState() { - return this.state; - } - - @Override - public boolean shouldMatchRotation() { - return this.direction; - } - - @Override - public boolean shouldMatchPosition() { - return this.position; - } - static class JsonData { boolean state; boolean direction; 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 deleted file mode 100644 index 6db447f7..00000000 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; - -import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; -import gnu.trove.set.hash.THashSet; - -public interface InteractionWiredMatchFurniSettings { - public THashSet getMatchFurniSettings(); - public boolean shouldMatchState(); - public boolean shouldMatchRotation(); - public boolean shouldMatchPosition(); -} diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index edf209bb..00cdb987 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -65,7 +65,6 @@ import com.eu.habbo.messages.incoming.unknown.RequestResolutionEvent; import com.eu.habbo.messages.incoming.unknown.UnknownEvent1; import com.eu.habbo.messages.incoming.users.*; import com.eu.habbo.messages.incoming.wired.WiredConditionSaveDataEvent; -import com.eu.habbo.messages.incoming.wired.WiredApplySetConditionsEvent; import com.eu.habbo.messages.incoming.wired.WiredEffectSaveDataEvent; import com.eu.habbo.messages.incoming.wired.WiredTriggerSaveDataEvent; import com.eu.habbo.plugin.EventHandler; @@ -580,7 +579,6 @@ public class PacketManager { this.registerHandler(Incoming.WiredTriggerSaveDataEvent, WiredTriggerSaveDataEvent.class); this.registerHandler(Incoming.WiredEffectSaveDataEvent, WiredEffectSaveDataEvent.class); this.registerHandler(Incoming.WiredConditionSaveDataEvent, WiredConditionSaveDataEvent.class); - this.registerHandler(Incoming.WiredApplySetConditionsEvent, WiredApplySetConditionsEvent.class); } void registerUnknown() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index 75223e4c..621a4775 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -155,7 +155,6 @@ public class Incoming { public static final int RequestInventoryItemsEvent = 3150; public static final int ModToolRoomAlertEvent = 3842; public static final int WiredEffectSaveDataEvent = 2281; - public static final int WiredApplySetConditionsEvent = 3373; public static final int CheckPetNameEvent = 2109; public static final int SecureLoginEvent = 2419; public static final int BotSaveSettingsEvent = 2624; diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java deleted file mode 100644 index 1d9266f3..00000000 --- a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.eu.habbo.messages.incoming.wired; - -import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings; -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.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; -import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; -import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -public class WiredApplySetConditionsEvent extends MessageHandler { - - @Override - public int getRatelimit() { - return 500; - } - - @Override - public void handle() throws Exception { - int itemId = this.packet.readInt(); - - // Executing Habbo has to be in a Room - if (!this.client.getHabbo().getRoomUnit().isInRoom()) { - this.client.sendResponse(new BubbleAlertComposer( - BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, - FurnitureMovementError.NO_RIGHTS.errorCode - )); - return; - } - - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - - if (room != null) { - - // Executing Habbo should be able to edit wireds - if (room.hasRights(this.client.getHabbo()) || room.isOwner(this.client.getHabbo())) { - - 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() - .filter(wired -> wired.getId() == itemId) - .findFirst(); - - // If the item exists - if (item.isPresent()) { - HabboItem wiredItem = item.get(); - - // The item should have settings to match furni state, position and rotation - if (wiredItem instanceof InteractionWiredMatchFurniSettings) { - - InteractionWiredMatchFurniSettings wired = (InteractionWiredMatchFurniSettings) wiredItem; - - // Try to apply the set settings to each item - wired.getMatchFurniSettings().forEach(setting -> { - HabboItem matchItem = room.getHabboItem(setting.item_id); - - // Match state - if (wired.shouldMatchState() && matchItem.allowWiredResetState()) { - if (!setting.state.equals(" ") && !matchItem.getExtradata().equals(setting.state)) { - matchItem.setExtradata(setting.state); - room.updateItemState(matchItem); - } - } - - RoomTile oldLocation = room.getLayout().getTile(matchItem.getX(), matchItem.getY()); - double oldZ = matchItem.getZ(); - - // Match Position & Rotation - if(wired.shouldMatchRotation() && !wired.shouldMatchPosition()) { - if(matchItem.getRotation() != setting.rotation && room.furnitureFitsAt(oldLocation, matchItem, setting.rotation, false) == FurnitureMovementError.NONE) { - room.moveFurniTo(matchItem, oldLocation, setting.rotation, null, true); - } - } - else if(wired.shouldMatchPosition()) { - boolean slideAnimation = !wired.shouldMatchRotation() || matchItem.getRotation() == setting.rotation; - RoomTile newLocation = room.getLayout().getTile((short) setting.x, (short) setting.y); - int newRotation = wired.shouldMatchRotation() ? setting.rotation : matchItem.getRotation(); - - if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != matchItem.getRotation()) && room.furnitureFitsAt(newLocation, matchItem, newRotation, true) == FurnitureMovementError.NONE) { - if(room.moveFurniTo(matchItem, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) { - if(slideAnimation) { - room.sendComposer(new FloorItemOnRollerComposer(matchItem, null, oldLocation, oldZ, newLocation, matchItem.getZ(), 0, room).compose()); - } - } - } - } - }); - } - } - } - } - } -} From 5b1ffa5bee4d4747c353dbd8209f6e4162524778 Mon Sep 17 00:00:00 2001 From: Harmonic Date: Sun, 10 Jan 2021 15:30:21 -0800 Subject: [PATCH 69/89] Fixed sql update. Added debug mode check for TooLongFrameException Error. --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 9 ++++++++- .../eu/habbo/habbohotel/commands/AboutCommand.java | 2 +- .../gameserver/decoders/GameMessageHandler.java | 12 ++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index d7f002bd..62e6d755 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -117,5 +117,12 @@ ADD COLUMN `bubble_id` int(3) NULL DEFAULT 31 AFTER `effect`; ALTER TABLE `permissions` ADD `acc_see_tentchat` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `acc_see_whispers`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', 'Tent'); +-- Roombadge command +ALTER TABLE `permissions` ADD `cmd_roombadge` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `cmd_massbadge`; +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.error.cmd_roombadge.no_badge', 'No badge specified!'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_roombadge', 'roombadge'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.description.cmd_roombadge', ':roombadge '); + -- Making items.wired_data column bigger since wired data is saved as JSON now -ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000) \ No newline at end of file +ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000) + diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java index c38796ec..f7130aff 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/AboutCommand.java @@ -16,7 +16,7 @@ public class AboutCommand extends Command { } public static String credits = "Arcturus Morningstar is an opensource project based on Arcturus By TheGeneral \n" + "The Following people have all contributed to this emulator:\n" + - " TheGeneral\n Beny\n Alejandro\n Capheus\n Skeletor\n Harmonic\n Mike\n Remco\n zGrav \n Quadral \n Harmony\n Swirny\n ArpyAge\n Mikkel\n Rodolfo\n Kitt Mustang\n Snaiker\n nttzx\n necmi\n Dome\n Jose Flores\n Cam\n Oliver\n Narzo\n Tenshie\n MartenM\n Ridge\n SenpaiDipper"; + " TheGeneral\n Beny\n Alejandro\n Capheus\n Skeletor\n Harmonic\n Mike\n Remco\n zGrav \n Quadral \n Harmony\n Swirny\n ArpyAge\n Mikkel\n Rodolfo\n Rasmus\n Kitt Mustang\n Snaiker\n nttzx\n necmi\n Dome\n Jose Flores\n Cam\n Oliver\n Narzo\n Tenshie\n MartenM\n Ridge\n SenpaiDipper"; @Override public boolean handle(GameClient gameClient, String[] params) { diff --git a/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageHandler.java b/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageHandler.java index 2da3032e..c85f3315 100644 --- a/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageHandler.java +++ b/src/main/java/com/eu/habbo/networking/gameserver/decoders/GameMessageHandler.java @@ -59,13 +59,13 @@ public class GameMessageHandler extends ChannelInboundHandlerAdapter { ctx.channel().close(); return; } - - if (cause instanceof TooLongFrameException) { - LOGGER.error("Disconnecting client, reason: \"" + cause.getMessage() + "\"."); - } else { - LOGGER.error("Disconnecting client, exception in GameMessageHander.", cause); + if (Emulator.getConfig().getBoolean("debug.mode")) { + if (cause instanceof TooLongFrameException) { + LOGGER.error("Disconnecting client, reason: \"" + cause.getMessage() + "\"."); + } else { + LOGGER.error("Disconnecting client, exception in GameMessageHander.", cause); + } } - ctx.channel().close(); } From a0cfe07ca32a02738dad3acce2edc413be659bc6 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 11 Jan 2021 22:20:06 +0100 Subject: [PATCH 70/89] Readded packet --- .../WiredConditionMatchStatePosition.java | 23 +++- .../WiredConditionNotMatchStatePosition.java | 23 +++- .../wired/effects/WiredEffectMatchFurni.java | 24 +++- .../InteractionWiredMatchFurniSettings.java | 11 ++ .../com/eu/habbo/messages/PacketManager.java | 2 + .../eu/habbo/messages/incoming/Incoming.java | 1 + .../wired/WiredApplySetConditionsEvent.java | 103 ++++++++++++++++++ 7 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java create mode 100644 src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java 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 e489e781..76ece81c 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 @@ -3,6 +3,7 @@ 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -18,7 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class WiredConditionMatchStatePosition extends InteractionWiredCondition { +public class WiredConditionMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public static final WiredConditionType type = WiredConditionType.MATCH_SSHOT; private THashSet settings; @@ -205,6 +206,26 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition } } + @Override + public THashSet getMatchFurniSettings() { + return this.settings; + } + + @Override + public boolean shouldMatchState() { + return this.state; + } + + @Override + public boolean shouldMatchRotation() { + return this.direction; + } + + @Override + public boolean shouldMatchPosition() { + return this.position; + } + static class JsonData { boolean state; boolean position; 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 11684c93..4c9cd092 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 @@ -3,6 +3,7 @@ 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.interfaces.InteractionWiredMatchFurniSettings; import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; import com.eu.habbo.habbohotel.users.HabboItem; @@ -18,7 +19,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition { +public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT; private THashSet settings; @@ -196,6 +197,26 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi } } + @Override + public THashSet getMatchFurniSettings() { + return this.settings; + } + + @Override + public boolean shouldMatchState() { + return this.state; + } + + @Override + public boolean shouldMatchRotation() { + return this.rotation; + } + + @Override + public boolean shouldMatchPosition() { + return this.position; + } + static class JsonData { boolean state; boolean position; 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 fbd374d4..bb615d8d 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 @@ -2,9 +2,9 @@ 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.GameTeamColors; import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; +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.wired.WiredEffectType; @@ -24,7 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -public class WiredEffectMatchFurni extends InteractionWiredEffect { +public class WiredEffectMatchFurni extends InteractionWiredEffect implements InteractionWiredMatchFurniSettings { private static final Logger LOGGER = LoggerFactory.getLogger(WiredEffectMatchFurni.class); private static final WiredEffectType type = WiredEffectType.MATCH_SSHOT; @@ -241,6 +241,26 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { } } + @Override + public THashSet getMatchFurniSettings() { + return this.settings; + } + + @Override + public boolean shouldMatchState() { + return this.state; + } + + @Override + public boolean shouldMatchRotation() { + return this.direction; + } + + @Override + public boolean shouldMatchPosition() { + return this.position; + } + static class JsonData { boolean state; boolean direction; 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 new file mode 100644 index 00000000..6db447f7 --- /dev/null +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/interfaces/InteractionWiredMatchFurniSettings.java @@ -0,0 +1,11 @@ +package com.eu.habbo.habbohotel.items.interactions.wired.interfaces; + +import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; +import gnu.trove.set.hash.THashSet; + +public interface InteractionWiredMatchFurniSettings { + public THashSet getMatchFurniSettings(); + public boolean shouldMatchState(); + public boolean shouldMatchRotation(); + public boolean shouldMatchPosition(); +} diff --git a/src/main/java/com/eu/habbo/messages/PacketManager.java b/src/main/java/com/eu/habbo/messages/PacketManager.java index 00cdb987..ee0c8965 100644 --- a/src/main/java/com/eu/habbo/messages/PacketManager.java +++ b/src/main/java/com/eu/habbo/messages/PacketManager.java @@ -64,6 +64,7 @@ import com.eu.habbo.messages.incoming.trading.*; import com.eu.habbo.messages.incoming.unknown.RequestResolutionEvent; import com.eu.habbo.messages.incoming.unknown.UnknownEvent1; import com.eu.habbo.messages.incoming.users.*; +import com.eu.habbo.messages.incoming.wired.WiredApplySetConditionsEvent; import com.eu.habbo.messages.incoming.wired.WiredConditionSaveDataEvent; import com.eu.habbo.messages.incoming.wired.WiredEffectSaveDataEvent; import com.eu.habbo.messages.incoming.wired.WiredTriggerSaveDataEvent; @@ -579,6 +580,7 @@ public class PacketManager { this.registerHandler(Incoming.WiredTriggerSaveDataEvent, WiredTriggerSaveDataEvent.class); this.registerHandler(Incoming.WiredEffectSaveDataEvent, WiredEffectSaveDataEvent.class); this.registerHandler(Incoming.WiredConditionSaveDataEvent, WiredConditionSaveDataEvent.class); + this.registerHandler(Incoming.WiredApplySetConditionsEvent, WiredApplySetConditionsEvent.class); } void registerUnknown() throws Exception { diff --git a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java index 621a4775..75223e4c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/Incoming.java +++ b/src/main/java/com/eu/habbo/messages/incoming/Incoming.java @@ -155,6 +155,7 @@ public class Incoming { public static final int RequestInventoryItemsEvent = 3150; public static final int ModToolRoomAlertEvent = 3842; public static final int WiredEffectSaveDataEvent = 2281; + public static final int WiredApplySetConditionsEvent = 3373; public static final int CheckPetNameEvent = 2109; public static final int SecureLoginEvent = 2419; public static final int BotSaveSettingsEvent = 2624; diff --git a/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java new file mode 100644 index 00000000..1d9266f3 --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/incoming/wired/WiredApplySetConditionsEvent.java @@ -0,0 +1,103 @@ +package com.eu.habbo.messages.incoming.wired; + +import com.eu.habbo.habbohotel.items.interactions.wired.interfaces.InteractionWiredMatchFurniSettings; +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.messages.incoming.MessageHandler; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertComposer; +import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys; +import com.eu.habbo.messages.outgoing.rooms.items.FloorItemOnRollerComposer; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class WiredApplySetConditionsEvent extends MessageHandler { + + @Override + public int getRatelimit() { + return 500; + } + + @Override + public void handle() throws Exception { + int itemId = this.packet.readInt(); + + // Executing Habbo has to be in a Room + if (!this.client.getHabbo().getRoomUnit().isInRoom()) { + this.client.sendResponse(new BubbleAlertComposer( + BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.key, + FurnitureMovementError.NO_RIGHTS.errorCode + )); + return; + } + + Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + + if (room != null) { + + // Executing Habbo should be able to edit wireds + if (room.hasRights(this.client.getHabbo()) || room.isOwner(this.client.getHabbo())) { + + 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() + .filter(wired -> wired.getId() == itemId) + .findFirst(); + + // If the item exists + if (item.isPresent()) { + HabboItem wiredItem = item.get(); + + // The item should have settings to match furni state, position and rotation + if (wiredItem instanceof InteractionWiredMatchFurniSettings) { + + InteractionWiredMatchFurniSettings wired = (InteractionWiredMatchFurniSettings) wiredItem; + + // Try to apply the set settings to each item + wired.getMatchFurniSettings().forEach(setting -> { + HabboItem matchItem = room.getHabboItem(setting.item_id); + + // Match state + if (wired.shouldMatchState() && matchItem.allowWiredResetState()) { + if (!setting.state.equals(" ") && !matchItem.getExtradata().equals(setting.state)) { + matchItem.setExtradata(setting.state); + room.updateItemState(matchItem); + } + } + + RoomTile oldLocation = room.getLayout().getTile(matchItem.getX(), matchItem.getY()); + double oldZ = matchItem.getZ(); + + // Match Position & Rotation + if(wired.shouldMatchRotation() && !wired.shouldMatchPosition()) { + if(matchItem.getRotation() != setting.rotation && room.furnitureFitsAt(oldLocation, matchItem, setting.rotation, false) == FurnitureMovementError.NONE) { + room.moveFurniTo(matchItem, oldLocation, setting.rotation, null, true); + } + } + else if(wired.shouldMatchPosition()) { + boolean slideAnimation = !wired.shouldMatchRotation() || matchItem.getRotation() == setting.rotation; + RoomTile newLocation = room.getLayout().getTile((short) setting.x, (short) setting.y); + int newRotation = wired.shouldMatchRotation() ? setting.rotation : matchItem.getRotation(); + + if(newLocation != null && newLocation.state != RoomTileState.INVALID && (newLocation != oldLocation || newRotation != matchItem.getRotation()) && room.furnitureFitsAt(newLocation, matchItem, newRotation, true) == FurnitureMovementError.NONE) { + if(room.moveFurniTo(matchItem, newLocation, newRotation, null, !slideAnimation) == FurnitureMovementError.NONE) { + if(slideAnimation) { + room.sendComposer(new FloorItemOnRollerComposer(matchItem, null, oldLocation, oldZ, newLocation, matchItem.getZ(), 0, room).compose()); + } + } + } + } + }); + } + } + } + } + } +} From 3371308395222cc46d9172272be5f68b03093aaa Mon Sep 17 00:00:00 2001 From: Snaiker Date: Thu, 14 Jan 2021 02:56:01 +0000 Subject: [PATCH 71/89] Fix char ; is missing --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index 62e6d755..f87aa41e 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -124,5 +124,5 @@ INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.keys.cmd_roombad INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('commands.description.cmd_roombadge', ':roombadge '); -- Making items.wired_data column bigger since wired data is saved as JSON now -ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000) +ALTER TABLE `items` MODIFY COLUMN `wired_data` varchar(10000); From 48cef2ed70a4dfccedd284c078559ccc637c28bd Mon Sep 17 00:00:00 2001 From: Dank074 Date: Sun, 17 Jan 2021 01:50:17 -0600 Subject: [PATCH 72/89] added plugin event for getting user ip --- .../habbohotel/commands/UserInfoCommand.java | 2 +- .../habbohotel/modtool/ModToolManager.java | 8 +- .../com/eu/habbo/habbohotel/users/Habbo.java | 27 +++++- .../habbo/habbohotel/users/HabboManager.java | 2 +- .../incoming/handshake/SecureLoginEvent.java | 16 ++-- .../handshake/SecureLoginEvent_BACKUP.java | 89 ------------------- .../events/users/UserGetIPAddressEvent.java | 28 ++++++ .../plugin/events/users/UserLoginEvent.java | 5 +- 8 files changed, 68 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java create mode 100644 src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java diff --git a/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java b/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java index fdd621c8..b4a3ca78 100644 --- a/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java +++ b/src/main/java/com/eu/habbo/habbohotel/commands/UserInfoCommand.java @@ -45,7 +45,7 @@ public class UserInfoCommand extends Command { Emulator.getTexts().getValue("command.cmd_userinfo.online") + ": " + (onlineHabbo == null ? Emulator.getTexts().getValue("generic.no") : Emulator.getTexts().getValue("generic.yes")) + "\r" + ((habbo.getRank().hasPermission(Permission.ACC_HIDE_MAIL, true)) ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.email") + ": " + habbo.getMail() + "\r") + ((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_register") + ": " + habbo.getIpRegister() + "\r") + - ((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getClient().getChannel().remoteAddress().toString() + "\r") + + ((habbo.getRank().hasPermission(Permission.ACC_HIDE_IP, true)) || onlineHabbo == null ? "" : Emulator.getTexts().getValue("command.cmd_userinfo.ip_current") + ": " + onlineHabbo.getHabboInfo().getIpLogin() + "\r") + (onlineHabbo != null ? Emulator.getTexts().getValue("command.cmd_userinfo.achievement_score") + ": " + onlineHabbo.getHabboStats().achievementScore + "\r" : "")); ModToolBan ban = Emulator.getGameEnvironment().getModToolManager().checkForBan(habbo.getId()); 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 c891286e..9dbd405a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -505,6 +505,7 @@ public class ModToolManager { return ban; } + @Deprecated public boolean hasIPBan(Channel habbo) { if (habbo == null) return false; @@ -512,9 +513,13 @@ public class ModToolManager { if (habbo.remoteAddress() == null || ((InetSocketAddress) habbo.remoteAddress()).getAddress() == null) return false; + return this.hasIPBan(((InetSocketAddress) habbo.remoteAddress()).getAddress().getHostAddress()); + } + + public boolean hasIPBan(String ipAddress) { boolean banned = false; try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM bans WHERE ip = ? AND (type = 'ip' OR type = 'super') AND ban_expire > ? LIMIT 1")) { - statement.setString(1, ((InetSocketAddress) habbo.remoteAddress()).getAddress().getHostAddress()); + statement.setString(1, ipAddress); statement.setInt(2, Emulator.getIntUnixTimestamp()); try (ResultSet set = statement.executeQuery()) { @@ -525,7 +530,6 @@ public class ModToolManager { } catch (SQLException e) { LOGGER.error("Caught SQL exception", e); } - return banned; } 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 923aeebe..dcc5a05e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/Habbo.java @@ -14,8 +14,10 @@ import com.eu.habbo.messages.outgoing.rooms.FloodCounterComposer; import com.eu.habbo.messages.outgoing.rooms.ForwardToRoomComposer; import com.eu.habbo.messages.outgoing.rooms.users.*; import com.eu.habbo.messages.outgoing.users.*; +import com.eu.habbo.plugin.events.furniture.FurnitureBuildheightEvent; import com.eu.habbo.plugin.events.users.UserCreditsEvent; import com.eu.habbo.plugin.events.users.UserDisconnectEvent; +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; @@ -114,11 +116,31 @@ public class Habbo implements Runnable { } - public void connect() { + public boolean connect() { + String ip = ""; + if (!Emulator.getConfig().getBoolean("networking.tcp.proxy") && this.client.getChannel().remoteAddress() != null) { SocketAddress address = this.client.getChannel().remoteAddress(); + ip = ((InetSocketAddress) address).getAddress().getHostAddress(); + } - if (address != null) this.habboInfo.setIpLogin(((InetSocketAddress) address).getAddress().getHostAddress()); + if (Emulator.getPluginManager().isRegistered(UserGetIPAddressEvent.class, true)) { + UserGetIPAddressEvent event = Emulator.getPluginManager().fireEvent(new UserGetIPAddressEvent(this, ip)); + if (event.hasChangedIP()) { + ip = event.getUpdatedIp(); + } + } + + if (!ip.isEmpty()) { + this.habboInfo.setIpLogin(ip); + } + + if (Emulator.getGameEnvironment().getModToolManager().hasMACBan(this.client)) { + return false; + } + + if (Emulator.getGameEnvironment().getModToolManager().hasIPBan(this.habboInfo.getIpLogin())) { + return false; } this.habboInfo.setMachineID(this.client.getMachineId()); @@ -128,6 +150,7 @@ public class Habbo implements Runnable { Emulator.getGameEnvironment().getRoomManager().loadRoomsForHabbo(this); LOGGER.info("{} logged in from IP {}", this.habboInfo.getUsername(), this.habboInfo.getIpLogin()); + return true; } 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 8975b888..e8bf5f3a 100644 --- a/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/users/HabboManager.java @@ -205,7 +205,7 @@ public class HabboManager { try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM users WHERE ip_register = ? OR ip_current = ? AND id != ? ORDER BY id DESC LIMIT ?")) { statement.setString(1, habbo.getHabboInfo().getIpRegister()); - statement.setString(2, habbo.getClient().getChannel().remoteAddress().toString()); + statement.setString(2, habbo.getHabboInfo().getIpLogin()); statement.setInt(3, habbo.getHabboInfo().getId()); statement.setInt(4, limit); diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index bd63c760..33cc6b5f 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -77,19 +77,13 @@ public class SecureLoginEvent extends MessageHandler { if (this.client.getHabbo() == null) { Habbo habbo = Emulator.getGameEnvironment().getHabboManager().loadHabbo(sso); if (habbo != null) { - if (Emulator.getGameEnvironment().getModToolManager().hasMACBan(this.client)) { - Emulator.getGameServer().getGameClientManager().disposeClient(this.client); - return; - } - if (Emulator.getGameEnvironment().getModToolManager().hasIPBan(this.client.getChannel())) { - Emulator.getGameServer().getGameClientManager().disposeClient(this.client); - return; - } - try { habbo.setClient(this.client); this.client.setHabbo(habbo); - this.client.getHabbo().connect(); + if(!this.client.getHabbo().connect()) { + Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + return; + } if (this.client.getHabbo().getHabboInfo() == null) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); @@ -191,7 +185,7 @@ public class SecureLoginEvent extends MessageHandler { } } - Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress())); + Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getHabbo().getHabboInfo().getIpLogin())); if (Emulator.getConfig().getBoolean("hotel.welcome.alert.enabled")) { final Habbo finalHabbo = habbo; diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java deleted file mode 100644 index a74220f0..00000000 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent_BACKUP.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.eu.habbo.messages.incoming.handshake; - -import com.eu.habbo.Emulator; -import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.users.Habbo; -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.incoming.MessageHandler; -import com.eu.habbo.messages.outgoing.friends.FriendsComposer; -import com.eu.habbo.messages.outgoing.generic.alerts.GenericAlertComposer; -import com.eu.habbo.messages.outgoing.habboway.nux.NewUserIdentityComposer; -import com.eu.habbo.messages.outgoing.handshake.DebugConsoleComposer; -import com.eu.habbo.messages.outgoing.handshake.SecureLoginOKComposer; -import com.eu.habbo.messages.outgoing.handshake.SessionRightsComposer; -import com.eu.habbo.messages.outgoing.modtool.ModToolComposer; -import com.eu.habbo.messages.outgoing.navigator.*; -import com.eu.habbo.messages.outgoing.users.*; -import com.eu.habbo.plugin.events.users.UserLoginEvent; - -import java.util.ArrayList; - -public class SecureLoginEvent_BACKUP extends MessageHandler { - - - @Override - public void handle() throws Exception { - - if (!Emulator.isReady) - return; - - String sso = this.packet.readString(); - - if (this.client.getHabbo() == null) { - Habbo habbo = Emulator.getGameEnvironment().getHabboManager().loadHabbo(sso); - if (habbo != null) { - habbo.setClient(this.client); - this.client.setHabbo(habbo); - this.client.getHabbo().connect(); - //this.client.sendResponse(new DebugConsoleComposer()); - Emulator.getThreading().run(habbo); - Emulator.getGameEnvironment().getHabboManager().addHabbo(habbo); - - ArrayList messages = new ArrayList<>(); - - - messages.add(new SecureLoginOKComposer().compose()); - messages.add(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), 0).compose()); - messages.add(new UserPermissionsComposer(this.client.getHabbo()).compose()); - messages.add(new UserClubComposer(this.client.getHabbo()).compose()); - messages.add(new DebugConsoleComposer(Emulator.debugging).compose()); - messages.add(new UserAchievementScoreComposer(this.client.getHabbo()).compose()); - messages.add(new NewUserIdentityComposer(habbo).compose()); - messages.add(new UserPerksComposer(habbo).compose()); - messages.add(new SessionRightsComposer().compose()); - messages.add(new FavoriteRoomsCountComposer(habbo).compose()); - //messages.add(new FriendsComposer(this.client.getHabbo()).compose()); - //messages.add(new NewUserIdentityComposer().compose()); - //messages.add(new UserDataComposer(this.client.getHabbo()).compose()); - //messages.add(new SessionRightsComposer().compose()); - //messages.add(new MinimailCountComposer().compose()); - //messages.add(new MessengerInitComposer(this.client.getHabbo()).compose()); - //messages.add(new FriendsComposer(this.client.getHabbo()).compose()); - - if (this.client.getHabbo().hasPermission(Permission.ACC_SUPPORTTOOL)) { - messages.add(new ModToolComposer(this.client.getHabbo()).compose()); - } - - this.client.sendResponses(messages); - - //Hardcoded - this.client.sendResponse(new NewNavigatorMetaDataComposer()); - this.client.sendResponse(new NewNavigatorLiftedRoomsComposer()); - this.client.sendResponse(new NewNavigatorCollapsedCategoriesComposer()); - this.client.sendResponse(new NewNavigatorSavedSearchesComposer(this.client.getHabbo().getHabboInfo().getSavedSearches())); - this.client.sendResponse(new NewNavigatorEventCategoriesComposer()); - //this.client.sendResponse(new HotelViewComposer()); - //this.client.sendResponse(new UserHomeRoomComposer(this.client.getHabbo().getHabboInfo().getHomeRoom(), this.client.getHabbo().getHabboInfo().getHomeRoom())); - //this.client.sendResponse(new UserEffectsListComposer()); - - - Emulator.getPluginManager().fireEvent(new UserLoginEvent(habbo, this.client.getChannel().localAddress())); - - } else { - this.client.sendResponse(new GenericAlertComposer("Can't connect *sadpanda*")); - - this.client.getChannel().close(); - } - } - } -} diff --git a/src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java new file mode 100644 index 00000000..c77b3639 --- /dev/null +++ b/src/main/java/com/eu/habbo/plugin/events/users/UserGetIPAddressEvent.java @@ -0,0 +1,28 @@ +package com.eu.habbo.plugin.events.users; + +import com.eu.habbo.habbohotel.users.Habbo; + +public class UserGetIPAddressEvent extends UserEvent{ + public final String oldIp; + + private String updatedIp; + private boolean changedIP = false; + + public UserGetIPAddressEvent(Habbo habbo, String ip) { + super(habbo); + this.oldIp = ip; + } + + public void setUpdatedIp(String updatedIp) { + this.updatedIp = updatedIp; + this.changedIP = true; + } + + public boolean hasChangedIP() { + return changedIP; + } + + public String getUpdatedIp() { + return updatedIp; + } +} diff --git a/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java b/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java index 15268bcb..d864a5fb 100644 --- a/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java +++ b/src/main/java/com/eu/habbo/plugin/events/users/UserLoginEvent.java @@ -6,10 +6,9 @@ import java.net.SocketAddress; public class UserLoginEvent extends UserEvent { - public final SocketAddress ip; + public final String ip; - - public UserLoginEvent(Habbo habbo, SocketAddress ip) { + public UserLoginEvent(Habbo habbo, String ip) { super(habbo); this.ip = ip; From 4cf11336cfc9e9bee9c9a5612eb9a2923169ea07 Mon Sep 17 00:00:00 2001 From: Thijmen Date: Tue, 19 Jan 2021 06:12:51 -0500 Subject: [PATCH 73/89] Add Docker support --- Dockerfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a4cda773 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM maven:latest AS builder + +# Copy the Emulator sources to the container +COPY . . +# Package it +RUN mvn package && mv /target/Habbo*-with-dependencies.jar /target/Habbo.jar + +# Use Java 8 for running +FROM java:8 AS runner + +# Copy the generated source +COPY --from=builder /target/Habbo.jar / + +# Save the script to wait for the database, among running the Arcturus Emulator +RUN echo "#!/bin/bash \n java -jar /Habbo.jar" > /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Run the Emulator with Java +ENTRYPOINT ["/entrypoint.sh"] From a9b73d23d0a6ab5a3dac8142215dae300a2cf667 Mon Sep 17 00:00:00 2001 From: TheOleg Date: Wed, 20 Jan 2021 18:11:16 -0500 Subject: [PATCH 74/89] Update Dockerfile - run emulator in UTF-8 mode --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a4cda773..e045ce45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ FROM java:8 AS runner COPY --from=builder /target/Habbo.jar / # Save the script to wait for the database, among running the Arcturus Emulator -RUN echo "#!/bin/bash \n java -jar /Habbo.jar" > /entrypoint.sh +RUN echo "#!/bin/bash \n java -Dfile.encoding=UTF-8 -jar /Habbo.jar" > /entrypoint.sh RUN chmod +x /entrypoint.sh # Run the Emulator with Java From 80d58364a54af3be135b798730c8b4632718d64e Mon Sep 17 00:00:00 2001 From: Remco Date: Sat, 23 Jan 2021 15:25:46 +0100 Subject: [PATCH 75/89] Moved bot SQLs to another sql file --- sqlupdates/2_4_0 to 3_0_BETA_1.sql | 7 ------- sqlupdates/3_0_BETA_1 to 3_0_0-RC-1.sql | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 sqlupdates/3_0_BETA_1 to 3_0_0-RC-1.sql diff --git a/sqlupdates/2_4_0 to 3_0_BETA_1.sql b/sqlupdates/2_4_0 to 3_0_BETA_1.sql index 79299b38..cbd02a7b 100644 --- a/sqlupdates/2_4_0 to 3_0_BETA_1.sql +++ b/sqlupdates/2_4_0 to 3_0_BETA_1.sql @@ -112,10 +112,3 @@ ADD COLUMN `bubble_id` int(3) NULL DEFAULT 31 AFTER `effect`; -- Permissions to see tent chat ALTER TABLE `permissions` ADD `acc_see_tentchat` ENUM('0', '1') NOT NULL DEFAULT '0' AFTER `acc_see_whispers`; INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('hotel.room.tent.prefix', 'Tent'); - --- Wired variables for bots -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.name', '%name%'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.roomname', '%roomname%'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.user_count', '%user_count%'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.owner', '%owner%'); -INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.item_count', '%item_count%'); \ No newline at end of file diff --git a/sqlupdates/3_0_BETA_1 to 3_0_0-RC-1.sql b/sqlupdates/3_0_BETA_1 to 3_0_0-RC-1.sql new file mode 100644 index 00000000..dfb1f885 --- /dev/null +++ b/sqlupdates/3_0_BETA_1 to 3_0_0-RC-1.sql @@ -0,0 +1,6 @@ +-- Wired variables for bots +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.name', '%name%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.roomname', '%roomname%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.user_count', '%user_count%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.owner', '%owner%'); +INSERT INTO `emulator_texts` (`key`, `value`) VALUES ('wired.variable.item_count', '%item_count%'); From 433e02497c1374bdebee3289c8e1cc73f86a1c2f Mon Sep 17 00:00:00 2001 From: Remco Date: Sat, 23 Jan 2021 18:56:04 +0100 Subject: [PATCH 76/89] Refactored WiredConditionNotMatchStatePosition --- .../WiredConditionNotMatchStatePosition.java | 205 +----------------- 1 file changed, 2 insertions(+), 203 deletions(-) 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 4c9cd092..bc29186d 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 @@ -1,233 +1,32 @@ 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.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.wired.WiredConditionType; -import com.eu.habbo.habbohotel.wired.WiredHandler; -import com.eu.habbo.habbohotel.wired.WiredMatchFurniSetting; -import com.eu.habbo.messages.ClientMessage; -import com.eu.habbo.messages.ServerMessage; -import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -public class WiredConditionNotMatchStatePosition extends InteractionWiredCondition implements InteractionWiredMatchFurniSettings { +public class WiredConditionNotMatchStatePosition extends WiredConditionMatchStatePosition { public static final WiredConditionType type = WiredConditionType.NOT_MATCH_SSHOT; - private THashSet settings; - - private boolean state; - private boolean position; - private boolean rotation; - public WiredConditionNotMatchStatePosition(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); - this.settings = new THashSet<>(); } public WiredConditionNotMatchStatePosition(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 boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (this.settings.isEmpty()) - return true; - - THashSet s = new THashSet<>(); - - for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.item_id); - - if (item != null) { - boolean stateMatches = !this.state || item.getExtradata().equals(setting.state); - boolean positionMatches = !this.position || (setting.x == item.getX() && setting.y == item.getY()); - boolean directionMatches = !this.rotation || setting.rotation == item.getRotation(); - - if (!stateMatches || !positionMatches || !directionMatches) - return true; - } else { - s.add(setting); - } - } - - if (!s.isEmpty()) { - for (WiredMatchFurniSetting setting : s) { - this.settings.remove(setting); - } - } - - return false; - } - - @Override - public String getWiredData() { - return WiredHandler.getGsonBuilder().create().toJson(new WiredConditionMatchStatePosition.JsonData( - this.state, - this.position, - this.rotation, - 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.rotation = 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.rotation = data[3].equals("1"); - this.position = data[4].equals("1"); - } - } - - @Override - public void onPickUp() { - this.settings.clear(); - this.state = false; - this.rotation = false; - this.position = false; + return !super.execute(roomUnit, room, stuff); } @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.item_id); - - message.appendInt(this.getBaseItem().getSpriteId()); - message.appendInt(this.getId()); - message.appendString(""); - message.appendInt(4); - message.appendInt(this.state ? 1 : 0); - message.appendInt(this.rotation ? 1 : 0); - message.appendInt(this.position ? 1 : 0); - message.appendInt(10); - message.appendInt(0); - message.appendInt(this.getType().code); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(ClientMessage packet) { - packet.readInt(); - - this.state = packet.readInt() == 1; - this.rotation = packet.readInt() == 1; - this.position = packet.readInt() == 1; - - packet.readString(); - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null) - return true; - - int count = packet.readInt(); - if (count > Emulator.getConfig().getInt("hotel.wired.furni.selection.count")) return false; - - this.settings.clear(); - - for (int i = 0; i < count; i++) { - int itemId = packet.readInt(); - 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; - } - - 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.item_id); - if (item == null) { - remove.add(setting); - } - } - - for (WiredMatchFurniSetting setting : remove) { - this.settings.remove(setting); - } - } - } - - @Override - public THashSet getMatchFurniSettings() { - return this.settings; - } - - @Override - public boolean shouldMatchState() { - return this.state; - } - - @Override - public boolean shouldMatchRotation() { - return this.rotation; - } - - @Override - public boolean shouldMatchPosition() { - return this.position; - } - - 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; - } - } } From ba145e61136f2f14279b63a1abc36b2bea14644f Mon Sep 17 00:00:00 2001 From: Remco Date: Sat, 23 Jan 2021 19:51:56 +0100 Subject: [PATCH 77/89] Fixed daily respects --- src/main/java/com/eu/habbo/core/CleanerThread.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/core/CleanerThread.java b/src/main/java/com/eu/habbo/core/CleanerThread.java index b9a721dc..10dcc784 100644 --- a/src/main/java/com/eu/habbo/core/CleanerThread.java +++ b/src/main/java/com/eu/habbo/core/CleanerThread.java @@ -144,8 +144,8 @@ public class CleanerThread implements Runnable { if (Emulator.isReady) { for (Habbo habbo : Emulator.getGameEnvironment().getHabboManager().getOnlineHabbos().values()) { - habbo.getHabboStats().petRespectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect"); - habbo.getHabboStats().respectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect.pets"); + habbo.getHabboStats().respectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect"); + habbo.getHabboStats().petRespectPointsToGive = Emulator.getConfig().getInt("hotel.daily.respect.pets"); } } } From c14746a05f44a65ebb56ed1d4b5dd34656d014a9 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Thu, 28 Jan 2021 01:34:59 -0600 Subject: [PATCH 78/89] add option to force encryption --- .../eu/habbo/messages/incoming/handshake/SecureLoginEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index 33cc6b5f..6b83322c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -57,7 +57,7 @@ public class SecureLoginEvent extends MessageHandler { if (!Emulator.isReady) return; - if (Emulator.getCrypto().isEnabled() && !this.client.isHandshakeFinished()) { + if (Emulator.getConfig().getBoolean("encryption.forced", false) && Emulator.getCrypto().isEnabled() && !this.client.isHandshakeFinished()) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); return; } From 5851162a63933b8df65edb706bebf273f8637515 Mon Sep 17 00:00:00 2001 From: Remco Date: Fri, 29 Jan 2021 19:08:41 +0100 Subject: [PATCH 79/89] Bot now only serves once when the distance is more than reach distance --- .../eu/habbo/habbohotel/bots/ButlerBot.java | 59 +++++++++++++------ .../runnables/RoomUnitWalkToRoomUnit.java | 6 +- 2 files changed, 42 insertions(+), 23 deletions(-) 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 89a66272..ab81bb10 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java @@ -58,58 +58,78 @@ public class ButlerBot extends Bot { @Override public void onUserSay(final RoomChatMessage message) { - if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE)) + if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || this.getRoom() == null) { return; + } + + double distanceBetweenBotAndHabbo = this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation()); + + if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance")) { - if (this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance")) if (message.getUnfilteredMessage() != null) { for (Map.Entry, Integer> set : serveItems.entrySet()) { - for (String s : set.getKey()) { - if (message.getUnfilteredMessage().toLowerCase().contains(s)) { + for (String keyword : set.getKey()) { + + // Check if the string contains a certain keyword using a regex. + // If keyword = tea, teapot wouldn't trigger it. + if (message.getUnfilteredMessage().toLowerCase().matches("\\b" + keyword + "\\b")) { + + // Enable plugins to cancel this event BotServerItemEvent serveEvent = new BotServerItemEvent(this, message.getHabbo(), set.getValue()); if (Emulator.getPluginManager().fireEvent(serveEvent).isCancelled()) { return; } + // Start give handitem process if (this.getRoomUnit().canWalk()) { - final String key = s; - final Bot b = this; - b.lookAt(serveEvent.habbo); + final String key = keyword; + final Bot bot = this; - final List tasks = new ArrayList(); + // Step 1: Look at Habbo + bot.lookAt(serveEvent.habbo); + + // Step 2: Prepare tasks for when the Bot (carrying the handitem) reaches the Habbo + final List tasks = new ArrayList<>(); + tasks.add(() -> System.out.println("Serving drinks!")); tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId)); tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0)); tasks.add(() -> { if(this.getRoom() != null) { - String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()); - if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) { - b.talk(msg); + String botMessage = Emulator.getTexts() + .getValue("bots.butler.given") + .replace("%key%", key) + .replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()); + + if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{ botMessage })) { + bot.talk(botMessage); } } }); - List failedReached = new ArrayList(); + List failedReached = new ArrayList<>(); failedReached.add(() -> { - if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) { - for (Runnable t : tasks) { - t.run(); + if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) { + System.out.println("Failed reached!"); + for (Runnable task : tasks) { + task.run(); } } }); + // Give bot the handitem that it's going to give the Habbo Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId)); - if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) { + if (distanceBetweenBotAndHabbo > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) { Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3))); } else { Emulator.getThreading().run(failedReached.get(0), 1000); } } else { - this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId); - if(this.getRoom() != null) { - String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", s).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()); + this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId); + + String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", keyword).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername()); if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) { this.talk(msg); } @@ -120,5 +140,6 @@ public class ButlerBot extends Bot { } } } + } } } 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 296490e7..3ff6ae37 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -42,17 +42,15 @@ public class RoomUnitWalkToRoomUnit implements Runnable { if (this.goalTile == null) { this.findNewLocation(); Emulator.getThreading().run(this, 500); - } - - if (this.goalTile == null) return; + } if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { for (Runnable r : this.targetReached) { Emulator.getThreading().run(r); - WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{this.walker}); + WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{ this.walker }); } } else { Emulator.getThreading().run(this, 500); From fe31b37aa108b583cf9f174e58eb737bad35e68c Mon Sep 17 00:00:00 2001 From: Remco Date: Fri, 29 Jan 2021 19:28:18 +0100 Subject: [PATCH 80/89] Bot now only serves once when the distance is more than reach distance --- src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java | 2 -- 1 file changed, 2 deletions(-) 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 ab81bb10..b5acb9f2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java @@ -90,7 +90,6 @@ public class ButlerBot extends Bot { // Step 2: Prepare tasks for when the Bot (carrying the handitem) reaches the Habbo final List tasks = new ArrayList<>(); - tasks.add(() -> System.out.println("Serving drinks!")); tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId)); tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0)); @@ -110,7 +109,6 @@ public class ButlerBot extends Bot { List failedReached = new ArrayList<>(); failedReached.add(() -> { if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) { - System.out.println("Failed reached!"); for (Runnable task : tasks) { task.run(); } From e4f2a792e84ab642642a132b1a6343234ee7d5cb Mon Sep 17 00:00:00 2001 From: Remco Date: Fri, 29 Jan 2021 23:53:55 +0100 Subject: [PATCH 81/89] Added logging for SecureLoginEvent --- .../habbo/messages/incoming/handshake/SecureLoginEvent.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index 6b83322c..6a7f4084 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -59,6 +59,7 @@ public class SecureLoginEvent extends MessageHandler { if (Emulator.getConfig().getBoolean("encryption.forced", false) && Emulator.getCrypto().isEnabled() && !this.client.isHandshakeFinished()) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + LOGGER.warn("Encryption is forced and TLS Handshake isn't finished! Closed connection..."); return; } @@ -66,11 +67,13 @@ public class SecureLoginEvent extends MessageHandler { if (Emulator.getPluginManager().fireEvent(new SSOAuthenticationEvent(sso)).isCancelled()) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + LOGGER.info("SSO Authentication is cancelled by a plugin. Closed connection..."); return; } if (sso.isEmpty()) { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + LOGGER.warn("Client is trying to connect without SSO ticket! Closed connection..."); return; } @@ -216,6 +219,7 @@ public class SecureLoginEvent extends MessageHandler { } } else { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); + LOGGER.warn("Someone tried to login with a non-existing SSO token! Closed connection..."); } } else { Emulator.getGameServer().getGameClientManager().disposeClient(this.client); From 610144851a0ebeec9b86c68801534a1c1f4d0c93 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Fri, 29 Jan 2021 19:31:26 -0600 Subject: [PATCH 82/89] fixed availabilitystatus packet --- .../incoming/handshake/SecureLoginEvent.java | 4 +-- .../eu/habbo/messages/outgoing/Outgoing.java | 2 +- .../AvailabilityStatusMessageComposer.java | 27 +++++++++++++++++++ .../handshake/SessionRightsComposer.java | 20 -------------- 4 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/eu/habbo/messages/outgoing/handshake/AvailabilityStatusMessageComposer.java delete mode 100644 src/main/java/com/eu/habbo/messages/outgoing/handshake/SessionRightsComposer.java diff --git a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java index 6a7f4084..3e13a26a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/handshake/SecureLoginEvent.java @@ -21,7 +21,7 @@ import com.eu.habbo.messages.outgoing.generic.alerts.MessagesForYouComposer; import com.eu.habbo.messages.outgoing.habboway.nux.NewUserIdentityComposer; import com.eu.habbo.messages.outgoing.handshake.DebugConsoleComposer; import com.eu.habbo.messages.outgoing.handshake.SecureLoginOKComposer; -import com.eu.habbo.messages.outgoing.handshake.SessionRightsComposer; +import com.eu.habbo.messages.outgoing.handshake.AvailabilityStatusMessageComposer; import com.eu.habbo.messages.outgoing.handshake.PingComposer; import com.eu.habbo.messages.outgoing.inventory.InventoryAchievementsComposer; import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer; @@ -120,7 +120,7 @@ public class SecureLoginEvent extends MessageHandler { messages.add(new UserClothesComposer(this.client.getHabbo()).compose()); messages.add(new NewUserIdentityComposer(habbo).compose()); messages.add(new UserPermissionsComposer(this.client.getHabbo()).compose()); - messages.add(new SessionRightsComposer().compose()); + messages.add(new AvailabilityStatusMessageComposer(true, false, true).compose()); messages.add(new PingComposer().compose()); messages.add(new DebugConsoleComposer(Emulator.debugging).compose()); messages.add(new UserAchievementScoreComposer(this.client.getHabbo()).compose()); diff --git a/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java b/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java index e627c771..fb84490b 100644 --- a/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java +++ b/src/main/java/com/eu/habbo/messages/outgoing/Outgoing.java @@ -84,7 +84,7 @@ public class Outgoing { public final static int RoomScoreComposer = 482; public final static int DoorbellAddUserComposer = 2309; public final static int SecureLoginOKComposer = 2491; - public final static int SessionRightsComposer = 2033; + public final static int AvailabilityStatusMessageComposer = 2033; public final static int GuildMemberUpdateComposer = 265; public final static int RoomFloorItemsComposer = 1778; public final static int InventoryItemsComposer = 994; diff --git a/src/main/java/com/eu/habbo/messages/outgoing/handshake/AvailabilityStatusMessageComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/handshake/AvailabilityStatusMessageComposer.java new file mode 100644 index 00000000..d65cc78c --- /dev/null +++ b/src/main/java/com/eu/habbo/messages/outgoing/handshake/AvailabilityStatusMessageComposer.java @@ -0,0 +1,27 @@ +package com.eu.habbo.messages.outgoing.handshake; + +import com.eu.habbo.messages.ServerMessage; +import com.eu.habbo.messages.outgoing.MessageComposer; +import com.eu.habbo.messages.outgoing.Outgoing; + +public class AvailabilityStatusMessageComposer extends MessageComposer { + private final boolean isOpen; + private final boolean isShuttingDown; + private final boolean isAuthenticHabbo; + + public AvailabilityStatusMessageComposer(boolean isOpen, boolean isShuttingDown, boolean isAuthenticHabbo) { + this.isOpen = isOpen; + this.isShuttingDown = isShuttingDown; + this.isAuthenticHabbo = isAuthenticHabbo; + } + + @Override + protected ServerMessage composeInternal() { + this.response.init(Outgoing.AvailabilityStatusMessageComposer); + + this.response.appendBoolean(isOpen);//isOpen + this.response.appendBoolean(isShuttingDown);//onShutdown + this.response.appendBoolean(isAuthenticHabbo);//isAuthenticHabbo + return this.response; + } +} diff --git a/src/main/java/com/eu/habbo/messages/outgoing/handshake/SessionRightsComposer.java b/src/main/java/com/eu/habbo/messages/outgoing/handshake/SessionRightsComposer.java deleted file mode 100644 index b442e4e0..00000000 --- a/src/main/java/com/eu/habbo/messages/outgoing/handshake/SessionRightsComposer.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.eu.habbo.messages.outgoing.handshake; - -import com.eu.habbo.messages.ServerMessage; -import com.eu.habbo.messages.outgoing.MessageComposer; -import com.eu.habbo.messages.outgoing.Outgoing; - -public class SessionRightsComposer extends MessageComposer { - private static final boolean unknownBooleanOne = true; //true - private static final boolean unknownBooleanTwo = false; - - @Override - protected ServerMessage composeInternal() { - this.response.init(Outgoing.SessionRightsComposer); - - this.response.appendBoolean(unknownBooleanOne); - this.response.appendBoolean(true); - this.response.appendBoolean(true); - return this.response; - } -} From 64b75a0be6b950d2d1e14388cd9d7f0ebf4cdaca Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 1 Feb 2021 19:09:11 +0100 Subject: [PATCH 83/89] Fixed wired Condition: Trigger is NOT on furni --- .../WiredConditionNotTriggerOnFurni.java | 131 +----------------- .../WiredConditionTriggerOnFurni.java | 14 +- 2 files changed, 14 insertions(+), 131 deletions(-) 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 f80f7df6..21ea027e 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 @@ -1,27 +1,16 @@ 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.rooms.Room; import com.eu.habbo.habbohotel.rooms.RoomUnit; -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.ClientMessage; -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 WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { +public class WiredConditionNotTriggerOnFurni extends WiredConditionTriggerOnFurni { public static final WiredConditionType type = WiredConditionType.NOT_ACTOR_ON_FURNI; - private THashSet items = new THashSet<>(); - public WiredConditionNotTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); } @@ -32,129 +21,19 @@ public class WiredConditionNotTriggerOnFurni extends InteractionWiredCondition { @Override public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { - if (roomUnit == null) return false; + if (roomUnit == null) + return false; + this.refresh(); if (this.items.isEmpty()) return true; - THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); - return this.items.stream().noneMatch(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("{")) { - 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 = 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(); + return !triggerOnFurni(roomUnit, room); } @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().code); - message.appendInt(0); - message.appendInt(0); - } - - @Override - public boolean saveData(ClientMessage packet) { - - packet.readInt(); - packet.readString(); - - int count = packet.readInt(); - 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(packet.readInt()); - - if (item != null) { - this.items.add(item); - } - } - } - - 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 (item.getRoomId() != room.getId()) - items.add(item); - } - } - - this.items.removeAll(items); - } - - 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/WiredConditionTriggerOnFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/conditions/WiredConditionTriggerOnFurni.java index 733c8581..250d4751 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 @@ -22,7 +22,7 @@ import java.util.stream.Collectors; public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI; - private THashSet items = new THashSet<>(); + protected THashSet items = new THashSet<>(); public WiredConditionTriggerOnFurni(ResultSet set, Item baseItem) throws SQLException { super(set, baseItem); @@ -42,10 +42,14 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { if (this.items.isEmpty()) return false; + return triggerOnFurni(roomUnit, room); + } + + protected boolean triggerOnFurni(RoomUnit roomUnit, Room room) { /* - * 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles. - * 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items - * */ + * 1. If a Habbo IS NOT walking we only have to check if the Habbo is on one of the selected tiles. + * 2. If a Habbo IS walking we have to check if the next tile in the walking path is one of the selected items + * */ if (!roomUnit.isWalking()) { THashSet itemsAtUser = room.getItemsAt(roomUnit.getCurrentLocation()); return this.items.stream().anyMatch(itemsAtUser::contains); @@ -158,7 +162,7 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition { return true; } - private void refresh() { + protected void refresh() { THashSet items = new THashSet<>(); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); From d7e96d94753dfc7f1f16bdcfc5e8b7ffcb5bff9b Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 2 Feb 2021 18:18:08 +0100 Subject: [PATCH 84/89] Mannequin save look event now checks for acc_anyroomowner --- .../incoming/rooms/items/MannequinSaveLookEvent.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java index 5def4dee..4e46eb30 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java @@ -1,16 +1,19 @@ package com.eu.habbo.messages.incoming.rooms.items; 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.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.messages.incoming.MessageHandler; public class MannequinSaveLookEvent extends MessageHandler { @Override public void handle() throws Exception { - Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); + Habbo habbo = this.client.getHabbo(); + Room room = habbo.getHabboInfo().getCurrentRoom(); - if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId()) + if (room == null || !room.isOwner(habbo)) return; HabboItem item = room.getHabboItem(this.packet.readInt()); From 4c096ae8d14c5a951ac707bf78242b17c113a19b Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 2 Feb 2021 18:21:02 +0100 Subject: [PATCH 85/89] Mannequin save look event now checks for acc_anyroomowner --- .../incoming/rooms/items/MannequinSaveLookEvent.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java index 4e46eb30..6713af89 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveLookEvent.java @@ -1,7 +1,6 @@ package com.eu.habbo.messages.incoming.rooms.items; 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.Habbo; import com.eu.habbo.habbohotel.users.HabboItem; @@ -25,7 +24,7 @@ public class MannequinSaveLookEvent extends MessageHandler { StringBuilder look = new StringBuilder(); - for (String s : this.client.getHabbo().getHabboInfo().getLook().split("\\.")) { + for (String s : habbo.getHabboInfo().getLook().split("\\.")) { if (!s.contains("hr") && !s.contains("hd") && !s.contains("he") && !s.contains("ea") && !s.contains("ha") && !s.contains("fa")) { look.append(s).append("."); } @@ -36,9 +35,9 @@ public class MannequinSaveLookEvent extends MessageHandler { } if (data.length == 3) { - item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]); + item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + data[2]); } else { - item.setExtradata(this.client.getHabbo().getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + this.client.getHabbo().getHabboInfo().getUsername() + "'s look."); + item.setExtradata(habbo.getHabboInfo().getGender().name().toLowerCase() + ":" + look + ":" + habbo.getHabboInfo().getUsername() + "'s look."); } item.needsUpdate(true); From 2bb55a8e3897cba3a65121ea86c1aa0460410a02 Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 3 Feb 2021 17:53:00 +0100 Subject: [PATCH 86/89] MannequinSaveNameEvent now checks for acc_anyroomowner --- .../messages/incoming/rooms/items/MannequinSaveNameEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java index 7715ffd2..ad09fc3c 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/rooms/items/MannequinSaveNameEvent.java @@ -9,7 +9,7 @@ public class MannequinSaveNameEvent extends MessageHandler { @Override public void handle() throws Exception { Room room = this.client.getHabbo().getHabboInfo().getCurrentRoom(); - if (room == null || this.client.getHabbo().getHabboInfo().getId() != room.getOwnerId()) + if (room == null || !room.isOwner(this.client.getHabbo())) return; HabboItem item = room.getHabboItem(this.packet.readInt()); From 35f81f96c4eb5f7b373198fc6e81d21dd96b0b1d Mon Sep 17 00:00:00 2001 From: Dank074 Date: Wed, 3 Feb 2021 19:16:50 -0600 Subject: [PATCH 87/89] fix ban behavior for empty machine id/ip address --- .../eu/habbo/habbohotel/modtool/ModToolManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 9dbd405a..9bb9f5da 100644 --- a/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java +++ b/src/main/java/com/eu/habbo/habbohotel/modtool/ModToolManager.java @@ -428,6 +428,16 @@ public class ModToolManager { return bans; } + //if machine id is empty, downgrade ban type to IP ban + if( (type == ModToolBanType.MACHINE || type == ModToolBanType.SUPER) && (offlineInfo == null || offlineInfo.getMachineID().isEmpty())) { + type = ModToolBanType.IP; + } + + //if ip address is empty, downgrade ban type to account ban + if( (type == ModToolBanType.IP || type == ModToolBanType.SUPER) && (offlineInfo == null || offlineInfo.getIpLogin().isEmpty())) { + type = ModToolBanType.ACCOUNT; + } + ModToolBan ban = new ModToolBan(targetUserId, offlineInfo != null ? offlineInfo.getIpLogin() : "offline", offlineInfo != null ? offlineInfo.getMachineID() : "offline", moderator.getHabboInfo().getId(), Emulator.getIntUnixTimestamp() + duration, reason, type, cfhTopic); Emulator.getPluginManager().fireEvent(new SupportUserBannedEvent(moderator, target, ban)); Emulator.getThreading().run(ban); From 8ad3aeb6b20fe3f143750ae06c308b6cdd9ed898 Mon Sep 17 00:00:00 2001 From: Remco Date: Thu, 4 Feb 2021 19:59:16 +0100 Subject: [PATCH 88/89] Fixed game timer threading issue --- .../games/InteractionGameTimer.java | 60 +++++++++---------- .../threading/runnables/games/GameTimer.java | 46 ++++++++++++++ 2 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java 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 1f7396e9..bb868c6d 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 @@ -14,6 +14,7 @@ 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.threading.runnables.games.GameTimer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +64,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { String[] data = set.getString("extra_data").split("\t"); if (data.length >= 2) { - this.baseTime = Integer.valueOf(data[1]); + this.baseTime = Integer.parseInt(data[1]); this.timeNow = this.baseTime; } @@ -149,33 +150,6 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (this.needsUpdate() || this.needsDelete()) { super.run(); } - - if (this.getRoomId() == 0) { - this.threadActive = false; - return; - } - - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - if (room == null || !this.isRunning || this.isPaused) { - this.threadActive = false; - return; - } - - this.timeNow--; - if (this.timeNow < 0) this.timeNow = 0; - - if (this.timeNow > 0) { - this.threadActive = true; - Emulator.getThreading().run(this, 1000); - } else { - this.threadActive = false; - this.timeNow = 0; - this.endGame(room); - WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); - } - - room.updateItem(this); } @Override @@ -248,7 +222,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (!this.threadActive) { this.threadActive = true; - Emulator.getThreading().run(this, 1000); + Emulator.getThreading().run(new GameTimer(this), 1000); } } else if (client != null) { if (!(room.hasRights(client.getHabbo()) || client.getHabbo().hasPermission(Permission.ACC_ANYROOMOWNER))) @@ -271,7 +245,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (!this.threadActive) { this.threadActive = true; - Emulator.getThreading().run(this); + Emulator.getThreading().run(new GameTimer(this)); } } } else { @@ -285,7 +259,7 @@ public class InteractionGameTimer extends HabboItem implements Runnable { if (!this.threadActive) { this.threadActive = true; - Emulator.getThreading().run(this, 1000); + Emulator.getThreading().run(new GameTimer(this), 1000); } } @@ -350,10 +324,30 @@ public class InteractionGameTimer extends HabboItem implements Runnable { } public boolean isRunning() { - return isRunning; + return this.isRunning; } public void setRunning(boolean running) { - isRunning = running; + this.isRunning = running; + } + + public void setThreadActive(boolean threadActive) { + this.threadActive = threadActive; + } + + public boolean isPaused() { + return this.isPaused; + } + + public void reduceTime() { + this.timeNow--; + } + + public int getTimeNow() { + return this.timeNow; + } + + public void setTimeNow(int timeNow) { + this.timeNow = timeNow; } } 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 new file mode 100644 index 00000000..f1e903e7 --- /dev/null +++ b/src/main/java/com/eu/habbo/threading/runnables/games/GameTimer.java @@ -0,0 +1,46 @@ +package com.eu.habbo.threading.runnables.games; + +import com.eu.habbo.Emulator; +import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer; +import com.eu.habbo.habbohotel.rooms.Room; +import com.eu.habbo.habbohotel.wired.WiredHandler; +import com.eu.habbo.habbohotel.wired.WiredTriggerType; + +public class GameTimer implements Runnable { + + private final InteractionGameTimer timer; + + public GameTimer(InteractionGameTimer timer) { + this.timer = timer; + } + + @Override + public void run() { + if (timer.getRoomId() == 0) { + timer.setRunning(false); + return; + } + + Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(timer.getRoomId()); + + if (room == null || !timer.isRunning() || timer.isPaused()) { + timer.setThreadActive(false); + return; + } + + timer.reduceTime(); + if (timer.getTimeNow() < 0) timer.setTimeNow(0); + + if (timer.getTimeNow() > 0) { + timer.setThreadActive(true); + Emulator.getThreading().run(this, 1000); + } else { + timer.setThreadActive(false); + timer.setTimeNow(0); + timer.endGame(room); + WiredHandler.handle(WiredTriggerType.GAME_ENDS, null, room, new Object[]{}); + } + + room.updateItem(timer); + } +} From f527527787feec0751cf90ec1eaf90d2e8da4b10 Mon Sep 17 00:00:00 2001 From: Remco Date: Thu, 4 Feb 2021 21:05:38 +0100 Subject: [PATCH 89/89] Gifting yourself won't progress achievements anymore --- .../incoming/catalog/CatalogBuyItemAsGiftEvent.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java index 7504c50a..13ffb72a 100644 --- a/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java +++ b/src/main/java/com/eu/habbo/messages/incoming/catalog/CatalogBuyItemAsGiftEvent.java @@ -336,7 +336,10 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler { return; } - AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftGiver")); + if (this.client.getHabbo().getHabboInfo().getId() != userId) { + AchievementManager.progressAchievement(this.client.getHabbo(), Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftGiver")); + } + if (habbo != null) { habbo.getClient().sendResponse(new AddHabboItemComposer(gift)); habbo.getClient().getHabbo().getInventory().getItemsComponent().addItem(gift); @@ -351,7 +354,9 @@ public class CatalogBuyItemAsGiftEvent extends MessageHandler { habbo.getClient().sendResponse(new BubbleAlertComposer(BubbleAlertKeys.RECEIVED_BADGE.key, keys)); } - AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver")); + if (this.client.getHabbo().getHabboInfo().getId() != userId) { + AchievementManager.progressAchievement(userId, Emulator.getGameEnvironment().getAchievementManager().getAchievement("GiftReceiver")); + } if (!this.client.getHabbo().hasPermission(Permission.ACC_INFINITE_CREDITS)) { if (totalCredits > 0) {