WiredConditionNotFurniHaveHabbo now saves as JSON

This commit is contained in:
Remco 2021-01-04 22:38:20 +01:00
parent 3488c8ad36
commit 87ff24e409

View File

@ -14,13 +14,13 @@ import com.eu.habbo.habbohotel.wired.WiredConditionType;
import com.eu.habbo.habbohotel.wired.WiredHandler; import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.messages.ClientMessage; import com.eu.habbo.messages.ClientMessage;
import com.eu.habbo.messages.ServerMessage; import com.eu.habbo.messages.ServerMessage;
import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet; 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.Collection; import java.util.Collection;
import java.util.Map; import java.util.List;
import java.util.stream.Collectors;
public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition { public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO; public static final WiredConditionType type = WiredConditionType.NOT_FURNI_HAVE_HABBO;
@ -66,33 +66,43 @@ public class WiredConditionNotFurniHaveHabbo 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.all ? "1" : "0") + ":"); this.all,
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("{")) {
WiredConditionFurniHaveHabbo.JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, WiredConditionFurniHaveHabbo.JsonData.class);
this.all = data.all;
if (data.length >= 1) { for(int id : data.itemIds) {
this.all = (data[0].equals("1")); HabboItem item = room.getHabboItem(id);
if (data.length == 2) { if (item != null) {
String[] items = data[1].split(";"); this.items.add(item);
}
}
} else {
String[] data = wiredData.split(":");
for (String s : items) { if (data.length >= 1) {
HabboItem item = room.getHabboItem(Integer.valueOf(s)); this.all = (data[0].equals("1"));
if (item != null) if (data.length == 2) {
this.items.add(item); String[] items = data[1].split(";");
for (String s : items) {
HabboItem item = room.getHabboItem(Integer.parseInt(s));
if (item != null)
this.items.add(item);
}
} }
} }
} }
@ -169,4 +179,14 @@ public class WiredConditionNotFurniHaveHabbo extends InteractionWiredCondition {
this.items.remove(item); this.items.remove(item);
} }
} }
static class JsonData {
boolean all;
List<Integer> itemIds;
public JsonData(boolean all, List<Integer> itemIds) {
this.all = all;
this.itemIds = itemIds;
}
}
} }