WiredEffectMoveRotateFurni now saves as json

This commit is contained in:
Remco 2021-01-04 06:03:19 -05:00
parent 8a3361ec5e
commit 9341d164a9

View File

@ -80,35 +80,45 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
@Override @Override
public String getWiredData() { public String getWiredData() {
THashSet<HabboItem> items = new THashSet<>(this.items.size() / 2); THashSet<HabboItem> itemsToRemove = new THashSet<>(this.items.size() / 2);
Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId()); Room room = Emulator.getGameEnvironment().getRoomManager().getRoom(this.getRoomId());
for (HabboItem item : this.items) { for (HabboItem item : this.items) {
if (item.getRoomId() != this.getRoomId() || (room != null && room.getHabboItem(item.getId()) == null)) if (item.getRoomId() != this.getRoomId() || (room != null && room.getHabboItem(item.getId()) == null))
items.add(item); itemsToRemove.add(item);
} }
for (HabboItem item : items) { for (HabboItem item : itemsToRemove) {
this.items.remove(item); this.items.remove(item);
} }
StringBuilder data = new StringBuilder(this.direction + "\t" + return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
this.rotation + "\t" + this.direction,
this.getDelay() + "\t"); this.rotation,
this.getDelay(),
for (HabboItem item : this.items) { this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
data.append(item.getId()).append("\r"); ));
}
return data.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");
String[] data = set.getString("wired_data").split("\t"); if (wiredData.startsWith("{")) {
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
this.setDelay(data.delay);
this.direction = data.direction;
this.rotation = data.rotation;
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) { if (data.length == 4) {
try { try {
@ -127,6 +137,7 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
} }
} }
} }
}
@Override @Override
public void onPickUp() { public void onPickUp() {
@ -303,4 +314,18 @@ public class WiredEffectMoveRotateFurni extends InteractionWiredEffect implement
public void cycle(Room room) { public void cycle(Room room) {
this.itemCooldowns.clear(); this.itemCooldowns.clear();
} }
static class JsonData {
int direction;
int rotation;
int delay;
List<Integer> itemIds;
public JsonData(int direction, int rotation, int delay, List<Integer> itemIds) {
this.direction = direction;
this.rotation = rotation;
this.delay = delay;
this.itemIds = itemIds;
}
}
} }