WiredEffectTriggerStacks now saves as json

This commit is contained in:
Remco 2021-01-04 07:09:37 -05:00
parent eb00da28ef
commit a849328412

View File

@ -156,32 +156,40 @@ public class WiredEffectTriggerStacks extends InteractionWiredEffect {
@Override @Override
public String getWiredData() { public String getWiredData() {
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t"); return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.getDelay(),
if (this.items != null && !this.items.isEmpty()) { this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
for (HabboItem item : this.items) { ));
wiredData.append(item.getId()).append(";");
}
}
return wiredData.toString();
} }
@Override @Override
public void loadWiredData(ResultSet set, Room room) throws SQLException { public void loadWiredData(ResultSet set, Room room) throws SQLException {
this.items = new THashSet<>(); this.items = new THashSet<>();
String[] wiredData = set.getString("wired_data").split("\t"); String wiredData = set.getString("wired_data");
if (wiredData.length >= 1) { if (wiredData.startsWith("{")) {
this.setDelay(Integer.valueOf(wiredData[0])); JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
} this.setDelay(data.delay);
if (wiredData.length == 2) { for (Integer id: data.itemIds) {
if (wiredData[1].contains(";")) { HabboItem item = room.getHabboItem(id);
for (String s : wiredData[1].split(";")) { if (item != null) {
HabboItem item = room.getHabboItem(Integer.valueOf(s)); this.items.add(item);
}
}
} else {
String[] wiredDataOld = wiredData.split("\t");
if (item != null) if (wiredDataOld.length >= 1) {
this.items.add(item); 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() { protected long requiredCooldown() {
return 250; return 250;
} }
static class JsonData {
int delay;
List<Integer> itemIds;
public JsonData(int delay, List<Integer> itemIds) {
this.delay = delay;
this.itemIds = itemIds;
}
}
} }