mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-31 12:22:36 +01:00
WiredTriggerHabboWalkOnFurni now saves as JSON
This commit is contained in:
parent
c6af5baa70
commit
069bffb907
@ -16,12 +16,12 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
|
||||
public static final WiredTriggerType type = WiredTriggerType.WALKS_ON_FURNI;
|
||||
|
||||
private THashSet<HabboItem> items;
|
||||
private String message = "";
|
||||
|
||||
public WiredTriggerHabboWalkOnFurni(ResultSet set, Item baseItem) throws SQLException {
|
||||
super(set, baseItem);
|
||||
@ -73,7 +73,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
|
||||
}
|
||||
message.appendInt(this.getBaseItem().getSpriteId());
|
||||
message.appendInt(this.getId());
|
||||
message.appendString(this.message);
|
||||
message.appendString("");
|
||||
message.appendInt(0);
|
||||
message.appendInt(0);
|
||||
message.appendInt(this.getType().code);
|
||||
@ -99,32 +99,27 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
|
||||
|
||||
@Override
|
||||
public String getWiredData() {
|
||||
StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:");
|
||||
|
||||
if (!this.items.isEmpty()) {
|
||||
List<HabboItem> toRemove = new ArrayList<>(0);
|
||||
for (HabboItem item : this.items) {
|
||||
if (item.getRoomId() == this.getRoomId()) {
|
||||
wiredData.append(item.getId()).append(";");
|
||||
} else {
|
||||
toRemove.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
this.items.removeAll(toRemove);
|
||||
} else
|
||||
wiredData.append("\t");
|
||||
|
||||
return wiredData.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");
|
||||
|
||||
if (wiredData.startsWith("{")) {
|
||||
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
||||
for (Integer id: data.itemIds) {
|
||||
HabboItem item = room.getHabboItem(id);
|
||||
if (item != null) {
|
||||
this.items.add(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (wiredData.split(":").length >= 3) {
|
||||
super.setDelay(Integer.valueOf(wiredData.split(":")[0]));
|
||||
this.message = wiredData.split(":")[1];
|
||||
super.setDelay(Integer.parseInt(wiredData.split(":")[0]));
|
||||
|
||||
if (!wiredData.split(":")[2].equals("\t")) {
|
||||
for (String s : wiredData.split(":")[2].split(";")) {
|
||||
@ -132,7 +127,7 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
|
||||
continue;
|
||||
|
||||
try {
|
||||
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
||||
HabboItem item = room.getHabboItem(Integer.parseInt(s));
|
||||
|
||||
if (item != null)
|
||||
this.items.add(item);
|
||||
@ -142,15 +137,23 @@ public class WiredTriggerHabboWalkOnFurni extends InteractionWiredTrigger {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickUp() {
|
||||
this.items.clear();
|
||||
this.message = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTriggeredByRoomUnit() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static class JsonData {
|
||||
List<Integer> itemIds;
|
||||
|
||||
public JsonData(List<Integer> itemIds) {
|
||||
this.itemIds = itemIds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user