mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-19 07:56:26 +01:00
WiredTriggerFurniStateToggled now saves as JSON
This commit is contained in:
parent
75b61b1809
commit
b8ea8fcd1b
@ -16,12 +16,13 @@ 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 WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
|
public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
|
||||||
private static final WiredTriggerType type = WiredTriggerType.STATE_CHANGED;
|
private static final WiredTriggerType type = WiredTriggerType.STATE_CHANGED;
|
||||||
|
|
||||||
private THashSet<HabboItem> items;
|
private THashSet<HabboItem> items;
|
||||||
private String message = "";
|
|
||||||
|
|
||||||
public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException {
|
public WiredTriggerFurniStateToggled(ResultSet set, Item baseItem) throws SQLException {
|
||||||
super(set, baseItem);
|
super(set, baseItem);
|
||||||
@ -55,31 +56,32 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getWiredData() {
|
public String getWiredData() {
|
||||||
StringBuilder wiredData = new StringBuilder(super.getDelay() + ":\t:");
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
||||||
|
this.items.stream().map(HabboItem::getId).collect(Collectors.toList())
|
||||||
if (this.items != null) {
|
));
|
||||||
if (!this.items.isEmpty()) {
|
|
||||||
for (HabboItem item : this.items) {
|
|
||||||
wiredData.append(item.getId()).append(";");
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
wiredData.append("\t");
|
|
||||||
}
|
|
||||||
|
|
||||||
return wiredData.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||||
this.items = new THashSet<>();
|
this.items = new THashSet<>();
|
||||||
String wiredData = set.getString("wired_data");
|
String wiredData = set.getString("wired_data");
|
||||||
|
|
||||||
|
if (wiredData.startsWith("{")) {
|
||||||
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
||||||
|
super.setDelay(1000);
|
||||||
|
for (Integer id: data.itemIds) {
|
||||||
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
if (item != null) {
|
||||||
|
this.items.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (wiredData.split(":").length >= 3) {
|
if (wiredData.split(":").length >= 3) {
|
||||||
super.setDelay(Integer.valueOf(wiredData.split(":")[0]));
|
super.setDelay(Integer.parseInt(wiredData.split(":")[0]));
|
||||||
this.message = wiredData.split(":")[1];
|
|
||||||
|
|
||||||
if (!wiredData.split(":")[2].equals("\t")) {
|
if (!wiredData.split(":")[2].equals("\t")) {
|
||||||
for (String s : wiredData.split(":")[2].split(";")) {
|
for (String s : wiredData.split(":")[2].split(";")) {
|
||||||
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
HabboItem item = room.getHabboItem(Integer.parseInt(s));
|
||||||
|
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.items.add(item);
|
this.items.add(item);
|
||||||
@ -87,11 +89,11 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickUp() {
|
public void onPickUp() {
|
||||||
this.items.clear();
|
this.items.clear();
|
||||||
this.message = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,7 +128,7 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
|
|||||||
}
|
}
|
||||||
message.appendInt(this.getBaseItem().getSpriteId());
|
message.appendInt(this.getBaseItem().getSpriteId());
|
||||||
message.appendInt(this.getId());
|
message.appendInt(this.getId());
|
||||||
message.appendString(this.message);
|
message.appendString("");
|
||||||
message.appendInt(0);
|
message.appendInt(0);
|
||||||
message.appendInt(0);
|
message.appendInt(0);
|
||||||
message.appendInt(this.getType().code);
|
message.appendInt(this.getType().code);
|
||||||
@ -153,4 +155,12 @@ public class WiredTriggerFurniStateToggled extends InteractionWiredTrigger {
|
|||||||
public boolean isTriggeredByRoomUnit() {
|
public boolean isTriggeredByRoomUnit() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class JsonData {
|
||||||
|
List<Integer> itemIds;
|
||||||
|
|
||||||
|
public JsonData(List<Integer> itemIds) {
|
||||||
|
this.itemIds = itemIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user