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; + } + } }