WiredConditionNotFurniTypeMatch now saves as JSON

This commit is contained in:
Remco 2021-01-04 22:42:13 +01:00
parent 87ff24e409
commit b6b4ac936e

View File

@ -14,6 +14,8 @@ import gnu.trove.set.hash.THashSet;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition { public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS; public static final WiredConditionType type = WiredConditionType.NOT_STUFF_IS;
@ -50,23 +52,37 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
@Override @Override
public String getWiredData() { public String getWiredData() {
this.refresh(); this.refresh();
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
StringBuilder data = new StringBuilder(); this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
));
for (HabboItem item : this.items)
data.append(item.getId()).append(";");
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(";"); if (wiredData.startsWith("{")) {
WiredConditionFurniTypeMatch.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniTypeMatch.JsonData.class);
for (String s : data) for(int id : data.itemIds) {
this.items.add(room.getHabboItem(Integer.valueOf(s))); HabboItem item = room.getHabboItem(id);
if (item != null) {
this.items.add(item);
}
}
} else {
String[] data = set.getString("wired_data").split(";");
for (String s : data) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null) {
this.items.add(item);
}
}
}
} }
@Override @Override
@ -138,4 +154,12 @@ public class WiredConditionNotFurniTypeMatch extends InteractionWiredCondition {
this.items.remove(item); this.items.remove(item);
} }
} }
static class JsonData {
List<Integer> itemIds;
public JsonData(List<Integer> itemIds) {
this.itemIds = itemIds;
}
}
} }