mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-27 00:40:52 +01:00
WiredEffectMoveFurniAway now saves as json
This commit is contained in:
parent
74e631f00a
commit
4afdf1b4b0
@ -21,6 +21,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
|
public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
|
||||||
public static final WiredEffectType type = WiredEffectType.FLEE;
|
public static final WiredEffectType type = WiredEffectType.FLEE;
|
||||||
@ -98,29 +99,36 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getWiredData() {
|
public String getWiredData() {
|
||||||
StringBuilder wiredData = new StringBuilder(this.getDelay() + "\t");
|
return WiredHandler.getGsonBuilder().create().toJson(new JsonData(
|
||||||
|
this.getDelay(),
|
||||||
if (this.items != null && !this.items.isEmpty()) {
|
this.items.stream().map(HabboItem::getId).collect(Collectors.toList()))
|
||||||
for (HabboItem item : this.items) {
|
);
|
||||||
wiredData.append(item.getId()).append(";");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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").split("\t");
|
String wiredData = set.getString("wired_data");
|
||||||
|
|
||||||
if (wiredData.length >= 1) {
|
if (wiredData.startsWith("{")) {
|
||||||
this.setDelay(Integer.valueOf(wiredData[0]));
|
JsonData data = WiredHandler.getGsonBuilder().create().fromJson(wiredData, JsonData.class);
|
||||||
|
this.setDelay(data.delay);
|
||||||
|
for (Integer id: data.itemIds) {
|
||||||
|
HabboItem item = room.getHabboItem(id);
|
||||||
|
if (item != null) {
|
||||||
|
this.items.add(item);
|
||||||
}
|
}
|
||||||
if (wiredData.length == 2) {
|
}
|
||||||
if (wiredData[1].contains(";")) {
|
} else {
|
||||||
for (String s : wiredData[1].split(";")) {
|
String[] wiredDataOld = wiredData.split("\t");
|
||||||
HabboItem item = room.getHabboItem(Integer.valueOf(s));
|
|
||||||
|
if (wiredDataOld.length >= 1) {
|
||||||
|
this.setDelay(Integer.parseInt(wiredDataOld[0]));
|
||||||
|
}
|
||||||
|
if (wiredDataOld.length == 2) {
|
||||||
|
if (wiredDataOld[1].contains(";")) {
|
||||||
|
for (String s : wiredDataOld[1].split(";")) {
|
||||||
|
HabboItem item = room.getHabboItem(Integer.parseInt(s));
|
||||||
|
|
||||||
if (item != null)
|
if (item != null)
|
||||||
this.items.add(item);
|
this.items.add(item);
|
||||||
@ -128,6 +136,7 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPickUp() {
|
public void onPickUp() {
|
||||||
@ -206,4 +215,14 @@ public class WiredEffectMoveFurniAway extends InteractionWiredEffect {
|
|||||||
protected long requiredCooldown() {
|
protected long requiredCooldown() {
|
||||||
return 495;
|
return 495;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class JsonData {
|
||||||
|
int delay;
|
||||||
|
List<Integer> itemIds;
|
||||||
|
|
||||||
|
public JsonData(int delay, List<Integer> itemIds) {
|
||||||
|
this.delay = delay;
|
||||||
|
this.itemIds = itemIds;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user