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