mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-19 07:56:26 +01:00
WiredEffectToggleRandom now saves as json
This commit is contained in:
parent
39d20520cb
commit
eb00da28ef
@ -192,35 +192,46 @@ public class WiredEffectToggleRandom 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.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.clear();
|
this.items.clear();
|
||||||
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(";")) {
|
|
||||||
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
|
||||||
|
|
||||||
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
|
if (item instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.items.add(item);
|
this.items.add(item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String[] wiredDataOld = wiredData.split("\t");
|
||||||
|
|
||||||
|
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 instanceof InteractionFreezeBlock || item instanceof InteractionGameTimer || item instanceof InteractionCrackable)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item != null)
|
||||||
|
this.items.add(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,4 +247,14 @@ public class WiredEffectToggleRandom extends InteractionWiredEffect {
|
|||||||
public WiredEffectType getType() {
|
public WiredEffectType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class JsonData {
|
||||||
|
int delay;
|
||||||
|
List<Integer> itemIds;
|
||||||
|
|
||||||
|
public JsonData(int delay, List<Integer> itemIds) {
|
||||||
|
this.delay = delay;
|
||||||
|
this.itemIds = itemIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user