From a849328412a554814b7fe3b10e9fd85d41f22eb9 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 4 Jan 2021 07:09:37 -0500 Subject: [PATCH] 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; + } + } }