mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 23:46:28 +01:00
WiredConditionTriggerOnFurni now saves as JSON
This commit is contained in:
parent
ac1c6a3d9b
commit
ad84ef423e
@ -16,6 +16,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 WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
||||||
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
|
public static final WiredConditionType type = WiredConditionType.TRIGGER_ON_FURNI;
|
||||||
@ -67,27 +69,35 @@ public class WiredConditionTriggerOnFurni 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("{")) {
|
||||||
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
||||||
|
|
||||||
for (String s : data) {
|
for(int id : data.itemIds) {
|
||||||
HabboItem item = room.getHabboItem(Integer.parseInt(s));
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
this.items.add(item);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,4 +178,12 @@ public class WiredConditionTriggerOnFurni extends InteractionWiredCondition {
|
|||||||
public WiredConditionOperator operator() {
|
public WiredConditionOperator operator() {
|
||||||
return WiredConditionOperator.AND;
|
return WiredConditionOperator.AND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class JsonData {
|
||||||
|
List<Integer> itemIds;
|
||||||
|
|
||||||
|
public JsonData(List<Integer> itemIds) {
|
||||||
|
this.itemIds = itemIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user