From 31e069938cac1140b5d7f381f9c556c93370379f Mon Sep 17 00:00:00 2001 From: Beny Date: Mon, 16 Nov 2020 12:12:24 +0100 Subject: [PATCH] Some wired saves as JSON now --- .../WiredConditionMatchStatePosition.java | 6 +- .../WiredConditionNotMatchStatePosition.java | 6 +- .../wired/effects/WiredEffectBotClothes.java | 40 +++++-- .../effects/WiredEffectBotFollowHabbo.java | 37 +++++- .../effects/WiredEffectBotGiveHandItem.java | 36 +++++- .../wired/effects/WiredEffectBotTalk.java | 42 +++++-- .../effects/WiredEffectBotTalkToHabbo.java | 41 +++++-- .../wired/effects/WiredEffectBotTeleport.java | 60 +++++++--- .../effects/WiredEffectBotWalkToFurni.java | 59 +++++++--- .../WiredEffectChangeFurniDirection.java | 84 +++++++++----- .../WiredEffectGiveHotelviewHofPoints.java | 37 ++++-- .../wired/effects/WiredEffectGiveRespect.java | 39 +++++-- .../wired/effects/WiredEffectGiveReward.java | 89 ++++++++++----- .../wired/effects/WiredEffectGiveScore.java | 37 +++++- .../effects/WiredEffectGiveScoreToTeam.java | 42 +++++-- .../wired/effects/WiredEffectJoinTeam.java | 34 +++++- .../wired/effects/WiredEffectKickHabbo.java | 42 +++++-- .../wired/effects/WiredEffectLeaveTeam.java | 21 +++- .../wired/effects/WiredEffectMatchFurni.java | 106 +++++++++--------- .../wired/effects/WiredEffectWhisper.java | 38 +++++-- .../wired/WiredChangeDirectionSetting.java | 4 +- .../habbo/habbohotel/wired/WiredHandler.java | 9 ++ .../wired/WiredMatchFurniSetting.java | 6 +- 23 files changed, 677 insertions(+), 238 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 27f1ed0e..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 @@ -49,7 +49,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition message.appendInt(this.settings.size()); for (WiredMatchFurniSetting item : this.settings) - message.appendInt(item.itemId); + message.appendInt(item.item_id); message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); @@ -105,7 +105,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition THashSet s = new THashSet<>(); for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.itemId); + HabboItem item = room.getHabboItem(setting.item_id); if (item != null) { if (this.state) { @@ -187,7 +187,7 @@ public class WiredConditionMatchStatePosition extends InteractionWiredCondition THashSet remove = new THashSet<>(); for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.itemId); + HabboItem item = room.getHabboItem(setting.item_id); if (item == null) { remove.add(setting); } 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 054806d4..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 @@ -43,7 +43,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi THashSet s = new THashSet<>(); for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.itemId); + HabboItem item = room.getHabboItem(setting.item_id); if (item != null) { boolean stateMatches = !this.state || item.getExtradata().equals(setting.state); @@ -124,7 +124,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi message.appendInt(this.settings.size()); for (WiredMatchFurniSetting item : this.settings) - message.appendInt(item.itemId); + message.appendInt(item.item_id); message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); @@ -178,7 +178,7 @@ public class WiredConditionNotMatchStatePosition extends InteractionWiredConditi THashSet remove = new THashSet<>(); for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.itemId); + HabboItem item = room.getHabboItem(setting.item_id); if (item == null) { remove.add(setting); } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java index 51fee02b..f0a5b3f8 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotClothes.java @@ -8,9 +8,11 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; 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.messages.incoming.wired.WiredSaveException; +import com.google.gson.Gson; import java.sql.ResultSet; import java.sql.SQLException; @@ -91,19 +93,29 @@ public class WiredEffectBotClothes extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "" + ((char) 9) + "" + - this.botName + ((char) 9) + - this.botLook; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.botLook, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(((char) 9) + ""); + String wiredData = set.getString("wired_data"); - if (data.length >= 3) { - this.setDelay(Integer.valueOf(data[0])); - this.botName = data[1]; - this.botLook = data[2]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.botName = data.bot_name; + this.botLook = data.look; + } + else { + String[] data = wiredData.split(((char) 9) + ""); + + if (data.length >= 3) { + this.setDelay(Integer.valueOf(data[0])); + this.botName = data[1]; + this.botLook = data[2]; + } + + this.needsUpdate(true); } } @@ -129,4 +141,16 @@ public class WiredEffectBotClothes extends InteractionWiredEffect { public void setBotLook(String botLook) { this.botLook = botLook; } + + static class JsonData { + String bot_name; + String look; + int delay; + + public JsonData(String bot_name, String look, int delay) { + this.bot_name = bot_name; + this.look = look; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java index 34c1352c..ee1b28b1 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotFollowHabbo.java @@ -10,6 +10,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.incoming.wired.WiredSaveException; @@ -119,17 +120,29 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + this.botName; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(((char) 9) + ""); + String wiredData = set.getString("wired_data"); - if (data.length == 3) { - this.setDelay(Integer.valueOf(data[0])); - this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0); - this.botName = data[2]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.mode = data.mode; + this.botName = data.bot_name; + } + else { + String[] data = wiredData.split(((char) 9) + ""); + + if (data.length == 3) { + this.setDelay(Integer.valueOf(data[0])); + this.mode = (data[1].equalsIgnoreCase("1") ? 1 : 0); + this.botName = data[2]; + } + + this.needsUpdate(true); } } @@ -144,4 +157,16 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + String bot_name; + int mode; + int delay; + + public JsonData(String bot_name, int mode, int delay) { + this.bot_name = bot_name; + this.mode = mode; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index e69f2000..27fc7888 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -135,17 +135,29 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "" + ((char) 9) + "" + this.itemId + "" + ((char) 9) + "" + this.botName; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.itemId, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(((char) 9) + ""); + String wiredData = set.getString("wired_data"); - if (data.length == 3) { - this.setDelay(Integer.valueOf(data[0])); - this.itemId = Integer.valueOf(data[1]); - this.botName = data[2]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.itemId = data.item_id; + this.botName = data.bot_name; + } + else { + String[] data = wiredData.split(((char) 9) + ""); + + if (data.length == 3) { + this.setDelay(Integer.valueOf(data[0])); + this.itemId = Integer.valueOf(data[1]); + this.botName = data[2]; + } + + this.needsUpdate(true); } } @@ -160,4 +172,16 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + String bot_name; + int item_id; + int delay; + + public JsonData(String bot_name, int item_id, int delay) { + this.bot_name = bot_name; + this.item_id = item_id; + this.delay = delay; + } + } } 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 91cb6f37..0b7b0d3a 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 @@ -122,19 +122,31 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + "" + this.botName + "" + ((char) 9) + "" + this.message; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String d = set.getString("wired_data"); - String[] data = d.split(((char) 9) + ""); + String wiredData = set.getString("wired_data"); - if (data.length == 4) { - this.setDelay(Integer.valueOf(data[0])); - this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0; - this.botName = data[2]; - this.message = data[3]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.mode = data.mode; + this.botName = data.bot_name; + this.message = data.message; + } + else { + String[] data = wiredData.split(((char) 9) + ""); + + if (data.length == 4) { + this.setDelay(Integer.valueOf(data[0])); + this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0; + this.botName = data[2]; + this.message = data[3]; + } + + this.needsUpdate(true); } } @@ -174,4 +186,18 @@ public class WiredEffectBotTalk extends InteractionWiredEffect { protected long requiredCooldown() { return 500; } + + static class JsonData { + String bot_name; + int mode; + String message; + int delay; + + public JsonData(String bot_name, int mode, String message, int delay) { + this.bot_name = bot_name; + this.mode = mode; + this.message = message; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTalkToHabbo.java index b475ec29..85d93546 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 @@ -145,18 +145,31 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "" + ((char) 9) + "" + this.mode + "" + ((char) 9) + "" + this.botName + "" + ((char) 9) + "" + this.message; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, this.mode, this.message, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(((char) 9) + ""); + String wiredData = set.getString("wired_data"); - if (data.length == 4) { - this.setDelay(Integer.valueOf(data[0])); - this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0; - this.botName = data[2]; - this.message = data[3]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.mode = data.mode; + this.botName = data.bot_name; + this.message = data.message; + } + else { + String[] data = wiredData.split(((char) 9) + ""); + + if (data.length == 4) { + this.setDelay(Integer.valueOf(data[0])); + this.mode = data[1].equalsIgnoreCase("1") ? 1 : 0; + this.botName = data[2]; + this.message = data[3]; + } + + this.needsUpdate(true); } } @@ -172,4 +185,18 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + String bot_name; + int mode; + String message; + int delay; + + public JsonData(String bot_name, int mode, String message, int delay) { + this.bot_name = bot_name; + this.mode = mode; + this.message = message; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java index c057f63e..07bbac6f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotTeleport.java @@ -25,6 +25,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; public class WiredEffectBotTeleport extends InteractionWiredEffect { public static final WiredEffectType type = WiredEffectType.BOT_TELEPORT; @@ -184,38 +185,57 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t" + this.botName + ";"); + ArrayList itemIds = new ArrayList<>(); - if (this.items != null && !this.items.isEmpty()) { + if (this.items != null) { for (HabboItem item : this.items) { if (item.getRoomId() != 0) { - wiredData.append(item.getId()).append(";"); + itemIds.add(item.getId()); } } } - return wiredData.toString(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { this.items = new THashSet<>(); - String[] wiredData = set.getString("wired_data").split("\t"); - if (wiredData.length >= 2) { - this.setDelay(Integer.valueOf(wiredData[0])); - String[] data = wiredData[1].split(";"); + String wiredData = set.getString("wired_data"); - if (data.length > 1) { - this.botName = data[0]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.botName = data.bot_name; - for (int i = 1; i < data.length; i++) { - HabboItem item = room.getHabboItem(Integer.valueOf(data[i])); + for(int itemId : data.items) { + HabboItem item = room.getHabboItem(itemId); - if (item != null) - this.items.add(item); + if (item != null) + this.items.add(item); + } + } + else { + String[] wiredDataSplit = set.getString("wired_data").split("\t"); + + if (wiredDataSplit.length >= 2) { + this.setDelay(Integer.valueOf(wiredDataSplit[0])); + String[] data = wiredDataSplit[1].split(";"); + + if (data.length > 1) { + this.botName = data[0]; + + for (int i = 1; i < data.length; i++) { + HabboItem item = room.getHabboItem(Integer.valueOf(data[i])); + + if (item != null) + this.items.add(item); + } } } + + this.needsUpdate(true); } } @@ -225,4 +245,16 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect { this.items.clear(); this.setDelay(0); } + + static class JsonData { + String bot_name; + List items; + int delay; + + public JsonData(String bot_name, List items, int delay) { + this.bot_name = bot_name; + this.items = items; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java index 0e34aea6..be2cccd6 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotWalkToFurni.java @@ -130,38 +130,57 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t" + this.botName + ";"); + ArrayList itemIds = new ArrayList<>(); - if (this.items != null && !this.items.isEmpty()) { + if (this.items != null) { for (HabboItem item : this.items) { if (item.getRoomId() != 0) { - wiredData.append(item.getId()).append(";"); + itemIds.add(item.getId()); } } } - return wiredData.toString(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.botName, itemIds, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { this.items = new ArrayList<>(); - String[] wiredData = set.getString("wired_data").split("\t"); - if (wiredData.length > 1) { - this.setDelay(Integer.valueOf(wiredData[0])); - String[] data = wiredData[1].split(";"); + String wiredData = set.getString("wired_data"); - if (data.length >= 1) { - this.botName = data[0]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.botName = data.bot_name; - for (int i = 1; i < data.length; i++) { - HabboItem item = room.getHabboItem(Integer.valueOf(data[i])); + for(int itemId : data.items) { + HabboItem item = room.getHabboItem(itemId); - if (item != null) - this.items.add(item); + if (item != null) + this.items.add(item); + } + } + else { + String[] wiredDataSplit = set.getString("wired_data").split("\t"); + + if (wiredDataSplit.length >= 2) { + this.setDelay(Integer.valueOf(wiredDataSplit[0])); + String[] data = wiredDataSplit[1].split(";"); + + if (data.length > 1) { + this.botName = data[0]; + + for (int i = 1; i < data.length; i++) { + HabboItem item = room.getHabboItem(Integer.valueOf(data[i])); + + if (item != null) + this.items.add(item); + } } } + + this.needsUpdate(true); } } @@ -171,4 +190,16 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect { this.botName = ""; this.setDelay(0); } + + static class JsonData { + String bot_name; + List items; + int delay; + + public JsonData(String bot_name, List items, int delay) { + this.bot_name = bot_name; + this.items = items; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java index 2cf32aba..0ce892d7 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectChangeFurniDirection.java @@ -16,6 +16,8 @@ import gnu.trove.set.hash.THashSet; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { @@ -114,45 +116,63 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder data = new StringBuilder(this.getDelay() + "\t" + this.startRotation.getValue() + "\t" + this.blockedAction + "\t" + this.items.size()); - - for (Map.Entry entry : this.items.entrySet()) { - data.append("\t").append(entry.getKey().getId()).append(":").append(entry.getValue().direction.getValue()).append(":").append(entry.getValue().rotation); - } - - return data.toString(); + ArrayList settings = new ArrayList<>(this.items.values()); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.startRotation, this.blockedAction, settings, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split("\t"); - if (data.length >= 4) { - this.setDelay(Integer.parseInt(data[0])); - this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1])); - this.blockedAction = Integer.parseInt(data[2]); + this.items.clear(); - int itemCount = Integer.parseInt(data[3]); + String wiredData = set.getString("wired_data"); - if (itemCount > 0) { - for (int i = 4; i < data.length; i++) { - String[] subData = data[i].split(":"); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.startRotation = data.start_direction; + this.blockedAction = data.blocked_action; - if (subData.length >= 2) { - HabboItem item = room.getHabboItem(Integer.parseInt(subData[0])); + for(WiredChangeDirectionSetting setting : data.items) { + HabboItem item = room.getHabboItem(setting.item_id); - if (item != null) { - int rotation = item.getRotation(); + if (item != null) { + this.items.put(item, setting); + } + } + } + else { + String[] data = wiredData.split("\t"); - if(subData.length > 2) { - rotation = Integer.parseInt(subData[2]); + if (data.length >= 4) { + this.setDelay(Integer.parseInt(data[0])); + this.startRotation = RoomUserRotation.fromValue(Integer.parseInt(data[1])); + this.blockedAction = Integer.parseInt(data[2]); + + int itemCount = Integer.parseInt(data[3]); + + if (itemCount > 0) { + for (int i = 4; i < data.length; i++) { + String[] subData = data[i].split(":"); + + if (subData.length >= 2) { + HabboItem item = room.getHabboItem(Integer.parseInt(subData[0])); + + if (item != null) { + int rotation = item.getRotation(); + + if (subData.length > 2) { + rotation = Integer.parseInt(subData[2]); + } + + this.items.put(item, new WiredChangeDirectionSetting(item.getId(), rotation, RoomUserRotation.fromValue(Integer.parseInt(subData[1])))); } - - this.items.put(item, new WiredChangeDirectionSetting(item.getId(), rotation, RoomUserRotation.fromValue(Integer.parseInt(subData[1])))); } } } } + + this.needsUpdate(true); } } @@ -181,7 +201,7 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { message.appendInt(this.getId()); message.appendString(""); message.appendInt(2); - message.appendInt(this.startRotation.getValue()); + message.appendInt(this.startRotation != null ? this.startRotation.getValue() : 0); message.appendInt(this.blockedAction); message.appendInt(0); message.appendInt(this.getType().code); @@ -264,4 +284,18 @@ public class WiredEffectChangeFurniDirection extends InteractionWiredEffect { protected long requiredCooldown() { return 495; } + + static class JsonData { + RoomUserRotation start_direction; + int blocked_action; + List items; + int delay; + + public JsonData(RoomUserRotation start_direction, int blocked_action, List items, int delay) { + this.start_direction = start_direction; + this.blocked_action = blocked_action; + this.items = items; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java index 5bca3009..0bd62164 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveHotelviewHofPoints.java @@ -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 gnu.trove.procedure.TObjectProcedure; @@ -101,21 +102,31 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "\t" + this.amount; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.amount, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wireData = set.getString("wired_data"); - this.amount = 0; + String wiredData = set.getString("wired_data"); - 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.amount = data.amount; + this.setDelay(data.delay); + } + else { + this.amount = 0; - try { - this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]); - } catch (Exception e) { + if (wiredData.split("\t").length >= 2) { + super.setDelay(Integer.valueOf(wiredData.split("\t")[0])); + + try { + this.amount = Integer.valueOf(this.getWiredData().split("\t")[1]); + } catch (Exception e) { + } } + + this.needsUpdate(true); } } @@ -129,4 +140,14 @@ public class WiredEffectGiveHotelviewHofPoints extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + int amount; + int delay; + + public JsonData(int amount, int delay) { + this.amount = amount; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java index 233a97e9..4a3b966f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveRespect.java @@ -10,6 +10,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 gnu.trove.procedure.TObjectProcedure; @@ -101,22 +102,32 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "\t" + this.respects; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.respects, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wireData = set.getString("wired_data"); - String[] data = wireData.split("\t"); - this.respects = 0; + String wiredData = set.getString("wired_data"); - if (data.length >= 2) { - super.setDelay(Integer.valueOf(data[0])); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.respects = data.amount; + this.setDelay(data.delay); + } + else { + String[] data = wiredData.split("\t"); + this.respects = 0; - try { - this.respects = Integer.valueOf(data[1]); - } catch (Exception e) { + if (data.length >= 2) { + super.setDelay(Integer.valueOf(data[0])); + + try { + this.respects = Integer.valueOf(data[1]); + } catch (Exception e) { + } } + + this.needsUpdate(true); } } @@ -130,4 +141,14 @@ public class WiredEffectGiveRespect extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + int amount; + int delay; + + public JsonData(int amount, int delay) { + this.amount = amount; + this.delay = delay; + } + } } \ No newline at end of file diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java index e61973e9..f4c3a2ba 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveReward.java @@ -56,43 +56,52 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { @Override public String getWiredData() { - StringBuilder data = new StringBuilder(this.limit + ":" + this.given + ":" + this.rewardTime + ":" + (this.uniqueRewards ? 1 : 0) + ":" + this.limitationInterval + ":" + this.getDelay() + ":"); - if (this.rewardItems.isEmpty()) { - data.append("\t"); - } else { - for (WiredGiveRewardItem item : this.rewardItems) { - data.append(item.toString()).append(";"); - } - } - - return data.toString(); + ArrayList rewards = new ArrayList<>(this.rewardItems); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.limit, this.given, this.rewardTime, this.uniqueRewards, this.limitationInterval, rewards, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(":"); - if (data.length > 0) { - this.limit = Integer.valueOf(data[0]); - this.given = Integer.valueOf(data[1]); - this.rewardTime = Integer.valueOf(data[2]); - this.uniqueRewards = data[3].equals("1"); - this.limitationInterval = Integer.valueOf(data[4]); - this.setDelay(Integer.valueOf(data[5])); + String wiredData = set.getString("wired_data"); - if (data.length > 6) { - if (!data[6].equalsIgnoreCase("\t")) { - String[] items = data[6].split(";"); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.limit = data.limit; + this.given = data.given; + this.rewardTime = data.reward_time; + this.uniqueRewards = data.unique_rewards; + this.limitationInterval = data.limit_interval; + this.rewardItems.clear(); + this.rewardItems.addAll(data.rewards); + } + else { + String[] data = wiredData.split(":"); + if (data.length > 0) { + this.limit = Integer.valueOf(data[0]); + this.given = Integer.valueOf(data[1]); + this.rewardTime = Integer.valueOf(data[2]); + this.uniqueRewards = data[3].equals("1"); + this.limitationInterval = Integer.valueOf(data[4]); + this.setDelay(Integer.valueOf(data[5])); - this.rewardItems.clear(); + if (data.length > 6) { + if (!data[6].equalsIgnoreCase("\t")) { + String[] items = data[6].split(";"); - for (String s : items) { - try { - this.rewardItems.add(new WiredGiveRewardItem(s)); - } catch (Exception e) { + this.rewardItems.clear(); + + for (String s : items) { + try { + this.rewardItems.add(new WiredGiveRewardItem(s)); + } catch (Exception e) { + } } } } + + this.needsUpdate(true); } } } @@ -167,8 +176,7 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { @Override public boolean saveData(ClientMessage packet, GameClient gameClient) { if (gameClient.getHabbo().hasPermission(Permission.ACC_SUPERWIRED)) { - packet.readInt(); - + int argsLength = packet.readInt(); this.rewardTime = packet.readInt(); this.uniqueRewards = packet.readInt() == 1; this.limit = packet.readInt(); @@ -196,11 +204,10 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { return false; } - WiredHandler.dropRewards(this.getId()); - - packet.readString(); packet.readInt(); this.setDelay(packet.readInt()); + + WiredHandler.dropRewards(this.getId()); return true; } @@ -217,4 +224,24 @@ public class WiredEffectGiveReward extends InteractionWiredEffect { protected long requiredCooldown() { return 0; } + + static class JsonData { + int limit; + int given; + int reward_time; + boolean unique_rewards; + int limit_interval; + List rewards; + int delay; + + public JsonData(int limit, int given, int reward_time, boolean unique_rewards, int limit_interval, List rewards, int delay) { + this.limit = limit; + this.given = given; + this.reward_time = reward_time; + this.unique_rewards = unique_rewards; + this.limit_interval = limit_interval; + this.rewards = rewards; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java index 58b4c87d..5a326356 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScore.java @@ -10,6 +10,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.incoming.wired.WiredSaveException; @@ -87,17 +88,29 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { @Override public String getWiredData() { - return this.score + ";" + this.count + ";" + this.getDelay(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.score, this.count, this.getDelay())); } @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 == 3) { - this.score = Integer.valueOf(data[0]); - this.count = Integer.valueOf(data[1]); - this.setDelay(Integer.valueOf(data[2])); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.score = data.score; + this.count = data.count; + this.setDelay(data.delay); + } + else { + String[] data = wiredData.split(";"); + + if (data.length == 3) { + this.score = Integer.valueOf(data[0]); + this.count = Integer.valueOf(data[1]); + this.setDelay(Integer.valueOf(data[2])); + } + + this.needsUpdate(true); } } @@ -181,4 +194,16 @@ public class WiredEffectGiveScore extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + int score; + int count; + int delay; + + public JsonData(int score, int count, int delay) { + this.score = score; + this.count = count; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java index 8761d7d9..dcbc1481 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectGiveScoreToTeam.java @@ -11,6 +11,7 @@ import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; 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.messages.incoming.wired.WiredSaveException; @@ -59,18 +60,31 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect { @Override public String getWiredData() { - return this.points + ";" + this.count + ";" + this.teamColor.type + ";" + this.getDelay(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.points, this.count, this.teamColor, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(";"); + String wiredData = set.getString("wired_data"); - if (data.length == 4) { - this.points = Integer.valueOf(data[0]); - this.count = Integer.valueOf(data[1]); - this.teamColor = GameTeamColors.values()[Integer.valueOf(data[2])]; - this.setDelay(Integer.valueOf(data[3])); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.points = data.score; + this.count = data.count; + this.teamColor = data.team; + this.setDelay(data.delay); + } + else { + String[] data = set.getString("wired_data").split(";"); + + if (data.length == 4) { + this.points = Integer.valueOf(data[0]); + this.count = Integer.valueOf(data[1]); + this.teamColor = GameTeamColors.values()[Integer.valueOf(data[2])]; + this.setDelay(Integer.valueOf(data[3])); + } + + this.needsUpdate(true); } } @@ -140,4 +154,18 @@ public class WiredEffectGiveScoreToTeam extends InteractionWiredEffect { return true; } + + static class JsonData { + int score; + int count; + GameTeamColors team; + int delay; + + public JsonData(int score, int count, GameTeamColors team, int delay) { + this.score = score; + this.count = count; + this.team = team; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java index f09e1a8a..8d367009 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectJoinTeam.java @@ -12,6 +12,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.incoming.wired.WiredSaveException; @@ -60,19 +61,30 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "\t" + this.teamColor.type + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.teamColor, this.getDelay())); } @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 >= 1) { - this.setDelay(Integer.valueOf(data[0])); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.teamColor = data.team; + } + else { + String[] data = set.getString("wired_data").split("\t"); - if (data.length >= 2) { - this.teamColor = GameTeamColors.values()[Integer.valueOf(data[1])]; + if (data.length >= 1) { + this.setDelay(Integer.valueOf(data[0])); + + if (data.length >= 2) { + this.teamColor = GameTeamColors.values()[Integer.valueOf(data[1])]; + } } + + this.needsUpdate(true); } } @@ -146,4 +158,14 @@ public class WiredEffectJoinTeam extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + GameTeamColors team; + int delay; + + public JsonData(GameTeamColors team, int delay) { + this.team = team; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java index d2e0bfcf..e0f2ecd2 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectKickHabbo.java @@ -12,6 +12,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.incoming.wired.WiredSaveException; @@ -70,24 +71,35 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "\t" + this.message; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - try { - String[] data = set.getString("wired_data").split("\t"); + String wiredData = set.getString("wired_data"); - if (data.length >= 1) { - this.setDelay(Integer.valueOf(data[0])); + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.message = data.message; + } + else { + try { + String[] data = set.getString("wired_data").split("\t"); - if (data.length >= 2) { - this.message = data[1]; + if (data.length >= 1) { + this.setDelay(Integer.valueOf(data[0])); + + if (data.length >= 2) { + this.message = data[1]; + } } + } catch (Exception e) { + this.message = ""; + this.setDelay(0); } - } catch (Exception e) { - this.message = ""; - this.setDelay(0); + + this.needsUpdate(true); } } @@ -155,4 +167,14 @@ public class WiredEffectKickHabbo extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + String message; + int delay; + + public JsonData(String message, int delay) { + this.message = message; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java index 10668834..deff061e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectLeaveTeam.java @@ -11,6 +11,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.incoming.wired.WiredSaveException; @@ -55,12 +56,20 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + ""; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - this.setDelay(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.setDelay(data.delay); + } + else { + this.setDelay(Integer.valueOf(wiredData)); + } } @Override @@ -119,4 +128,12 @@ public class WiredEffectLeaveTeam extends InteractionWiredEffect { this.setDelay(delay); return true; } + + static class JsonData { + int delay; + + public JsonData(int delay) { + this.delay = delay; + } + } } 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 e94a865a..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 @@ -2,9 +2,8 @@ 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.InteractionMultiHeight; -import com.eu.habbo.habbohotel.items.interactions.InteractionRoller; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.HabboItem; @@ -52,7 +51,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { return true; for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.itemId); + HabboItem item = room.getHabboItem(setting.item_id); if (item != null) { if (this.state && (this.checkForWiredResetPermission && item.allowWiredResetState())) { if (!setting.state.equals(" ") && !item.getExtradata().equals(setting.state)) { @@ -92,58 +91,49 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { @Override public String getWiredData() { this.refresh(); - - StringBuilder data = new StringBuilder(this.settings.size() + ":"); - - if (this.settings.isEmpty()) { - data.append(";"); - } else { - Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); - - for (WiredMatchFurniSetting item : this.settings) { - HabboItem i; - - if (room != null) { - i = room.getHabboItem(item.itemId); - - if (i != null) { - data.append(item.toString(this.checkForWiredResetPermission && i.allowWiredResetState())).append(";"); - } - } - } - } - - data.append(":").append(this.state ? 1 : 0).append(":").append(this.direction ? 1 : 0).append(":").append(this.position ? 1 : 0).append(":").append(this.getDelay()); - - return data.toString(); + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.state, this.direction, this.position, new ArrayList(this.settings), this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String[] data = set.getString("wired_data").split(":"); + String wiredData = set.getString("wired_data"); - int itemCount = Integer.parseInt(data[0]); - - String[] items = data[1].split(Pattern.quote(";")); - - for (int i = 0; i < items.length; i++) { - try { - - String[] stuff = items[i].split(Pattern.quote("-")); - - if (stuff.length >= 5) { - this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4]))); - } - - } catch (Exception e) { - LOGGER.error("Caught exception", e); - } + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.state = data.state; + this.direction = data.direction; + this.position = data.position; + this.settings.clear(); + this.settings.addAll(data.items); } + else { + String[] data = set.getString("wired_data").split(":"); - this.state = data[2].equals("1"); - this.direction = data[3].equals("1"); - this.position = data[4].equals("1"); - this.setDelay(Integer.parseInt(data[5])); + int itemCount = Integer.parseInt(data[0]); + + String[] items = data[1].split(Pattern.quote(";")); + + for (int i = 0; i < items.length; i++) { + try { + + String[] stuff = items[i].split(Pattern.quote("-")); + + if (stuff.length >= 5) { + this.settings.add(new WiredMatchFurniSetting(Integer.parseInt(stuff[0]), stuff[1], Integer.parseInt(stuff[2]), Integer.parseInt(stuff[3]), Integer.parseInt(stuff[4]))); + } + + } catch (Exception e) { + LOGGER.error("Caught exception", e); + } + } + + this.state = data[2].equals("1"); + this.direction = data[3].equals("1"); + this.position = data[4].equals("1"); + this.setDelay(Integer.parseInt(data[5])); + this.needsUpdate(true); + } } @Override @@ -169,7 +159,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { message.appendInt(this.settings.size()); for (WiredMatchFurniSetting item : this.settings) - message.appendInt(item.itemId); + message.appendInt(item.item_id); message.appendInt(this.getBaseItem().getSpriteId()); message.appendInt(this.getId()); @@ -239,7 +229,7 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { THashSet remove = new THashSet<>(); for (WiredMatchFurniSetting setting : this.settings) { - HabboItem item = room.getHabboItem(setting.itemId); + HabboItem item = room.getHabboItem(setting.item_id); if (item == null) { remove.add(setting); } @@ -250,4 +240,20 @@ public class WiredEffectMatchFurni extends InteractionWiredEffect { } } } + + static class JsonData { + boolean state; + boolean direction; + boolean position; + List items; + int delay; + + public JsonData(boolean state, boolean direction, boolean position, List items, int delay) { + this.state = state; + this.direction = direction; + this.position = position; + this.items = items; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java index 4d27e3cd..56d6f35e 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectWhisper.java @@ -6,11 +6,9 @@ import com.eu.habbo.habbohotel.items.Item; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredEffect; import com.eu.habbo.habbohotel.items.interactions.InteractionWiredTrigger; import com.eu.habbo.habbohotel.permissions.Permission; -import com.eu.habbo.habbohotel.rooms.Room; -import com.eu.habbo.habbohotel.rooms.RoomChatMessage; -import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles; -import com.eu.habbo.habbohotel.rooms.RoomUnit; +import com.eu.habbo.habbohotel.rooms.*; import com.eu.habbo.habbohotel.users.Habbo; +import com.eu.habbo.habbohotel.wired.WiredChangeDirectionSetting; import com.eu.habbo.habbohotel.wired.WiredEffectType; import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredTriggerType; @@ -123,17 +121,27 @@ public class WiredEffectWhisper extends InteractionWiredEffect { @Override public String getWiredData() { - return this.getDelay() + "\t" + this.message; + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(this.message, this.getDelay())); } @Override public void loadWiredData(ResultSet set, Room room) throws SQLException { - String wireData = set.getString("wired_data"); - this.message = ""; + String wiredData = set.getString("wired_data"); - if (wireData.split("\t").length >= 2) { - super.setDelay(Integer.valueOf(wireData.split("\t")[0])); - this.message = wireData.split("\t")[1]; + if(wiredData.startsWith("{")) { + JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class); + this.setDelay(data.delay); + this.message = data.message; + } + else { + this.message = ""; + + if (wiredData.split("\t").length >= 2) { + super.setDelay(Integer.valueOf(wiredData.split("\t")[0])); + this.message = wiredData.split("\t")[1]; + } + + this.needsUpdate(true); } } @@ -152,4 +160,14 @@ public class WiredEffectWhisper extends InteractionWiredEffect { public boolean requiresTriggeringUser() { return true; } + + static class JsonData { + String message; + int delay; + + public JsonData(String message, int delay) { + this.message = message; + this.delay = delay; + } + } } diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java index 03644549..748bff4f 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredChangeDirectionSetting.java @@ -3,12 +3,12 @@ package com.eu.habbo.habbohotel.wired; import com.eu.habbo.habbohotel.rooms.RoomUserRotation; public class WiredChangeDirectionSetting { - public final int itemId; + public final int item_id; public int rotation; public RoomUserRotation direction; public WiredChangeDirectionSetting(int itemId, int rotation, RoomUserRotation direction) { - this.itemId = itemId; + this.item_id = itemId; this.rotation = rotation; this.direction = direction; } diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java index ec7db738..9f27ad78 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredHandler.java @@ -27,6 +27,7 @@ import com.eu.habbo.plugin.events.furniture.wired.WiredConditionFailedEvent; import com.eu.habbo.plugin.events.furniture.wired.WiredStackExecutedEvent; import com.eu.habbo.plugin.events.furniture.wired.WiredStackTriggeredEvent; import com.eu.habbo.plugin.events.users.UserWiredRewardReceived; +import com.google.gson.GsonBuilder; import gnu.trove.set.hash.THashSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,6 +47,8 @@ public class WiredHandler { public static int MAXIMUM_FURNI_SELECTION = 5; public static int TELEPORT_DELAY = 500; + private static GsonBuilder gsonBuilder = null; + public static boolean handle(WiredTriggerType triggerType, RoomUnit roomUnit, Room room, Object[] stuff) { if (triggerType == WiredTriggerType.CUSTOM) return false; @@ -247,6 +250,12 @@ public class WiredHandler { return executed; } + public static GsonBuilder getGsonBuilder() { + if(gsonBuilder == null) { + gsonBuilder = new GsonBuilder(); + } + return gsonBuilder; + } public static boolean executeEffectsAtTiles(THashSet tiles, final RoomUnit roomUnit, final Room room, final Object[] stuff) { for (RoomTile tile : tiles) { diff --git a/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java b/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java index ea6797f1..7771450b 100644 --- a/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java +++ b/src/main/java/com/eu/habbo/habbohotel/wired/WiredMatchFurniSetting.java @@ -1,14 +1,14 @@ package com.eu.habbo.habbohotel.wired; public class WiredMatchFurniSetting { - public final int itemId; + public final int item_id; public final String state; public final int rotation; public final int x; public final int y; public WiredMatchFurniSetting(int itemId, String state, int rotation, int x, int y) { - this.itemId = itemId; + this.item_id = itemId; this.state = state.replace("\t\t\t", " "); this.rotation = rotation; this.x = x; @@ -21,7 +21,7 @@ public class WiredMatchFurniSetting { } public String toString(boolean includeState) { - return this.itemId + "-" + (this.state.isEmpty() || !includeState ? " " : this.state) + "-" + this.rotation + "-" + this.x + "-" + this.y; + return this.item_id + "-" + (this.state.isEmpty() || !includeState ? " " : this.state) + "-" + this.rotation + "-" + this.x + "-" + this.y; } }