mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-22 23:10:52 +01:00
WiredConditionFurniTypeMatch now saves as JSON
This commit is contained in:
parent
f8520919ba
commit
da751cca42
@ -14,6 +14,8 @@ import gnu.trove.set.hash.THashSet;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
|
||||
public static final WiredConditionType type = WiredConditionType.STUFF_IS;
|
||||
@ -55,23 +57,37 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
|
||||
@Override
|
||||
public String getWiredData() {
|
||||
this.refresh();
|
||||
|
||||
StringBuilder data = new StringBuilder();
|
||||
|
||||
for (HabboItem item : this.items)
|
||||
data.append(item.getId()).append(";");
|
||||
|
||||
return data.toString();
|
||||
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
||||
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||
this.items.clear();
|
||||
String wiredData = set.getString("wired_data");
|
||||
|
||||
String[] data = set.getString("wired_data").split(";");
|
||||
if (wiredData.startsWith("{")) {
|
||||
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
||||
|
||||
for (String s : data)
|
||||
this.items.add(room.getHabboItem(Integer.valueOf(s)));
|
||||
for(int id : data.itemIds) {
|
||||
HabboItem item = room.getHabboItem(id);
|
||||
|
||||
if (item != null) {
|
||||
this.items.add(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String[] data = wiredData.split(";");
|
||||
|
||||
for (String s : data) {
|
||||
HabboItem item = room.getHabboItem(Integer.parseInt(s));
|
||||
|
||||
if (item != null) {
|
||||
this.items.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,4 +154,12 @@ public class WiredConditionFurniTypeMatch extends InteractionWiredCondition {
|
||||
this.items.remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
static class JsonData {
|
||||
List<Integer> itemIds;
|
||||
|
||||
public JsonData(List<Integer> itemIds) {
|
||||
this.itemIds = itemIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user