diff --git a/src/main/Cacher.java b/src/main/misc/Cacher.java similarity index 99% rename from src/main/Cacher.java rename to src/main/misc/Cacher.java index fda0a87..be593c1 100644 --- a/src/main/Cacher.java +++ b/src/main/misc/Cacher.java @@ -1,4 +1,4 @@ -package main; +package main.misc; import java.io.*; import java.nio.file.Files; diff --git a/src/main/OSValidator.java b/src/main/misc/OSValidator.java similarity index 98% rename from src/main/OSValidator.java rename to src/main/misc/OSValidator.java index 913efdf..3fb1c7b 100644 --- a/src/main/OSValidator.java +++ b/src/main/misc/OSValidator.java @@ -1,4 +1,4 @@ -package main; +package main.misc; public class OSValidator { diff --git a/src/main/misc/StringifyAble.java b/src/main/misc/StringifyAble.java new file mode 100644 index 0000000..61e9b9e --- /dev/null +++ b/src/main/misc/StringifyAble.java @@ -0,0 +1,15 @@ +package main.misc; + +/** + * Created by Jonas on 14/06/18. + * This interface defines an object which can FULLY be represented as a String (all fields). An object must be able to be recreated having the String representation + */ +public interface StringifyAble { + + String stringify(); + + //the object before calling this function will typically have no real point, this is some kind of constructor + // (this implies that the Object should probably have a constructor just calling this function) + void constructFromString(String str); + +} diff --git a/src/main/protocol/hostreplacer/HostReplacerFactory.java b/src/main/protocol/hostreplacer/HostReplacerFactory.java index d860254..8ac66f3 100644 --- a/src/main/protocol/hostreplacer/HostReplacerFactory.java +++ b/src/main/protocol/hostreplacer/HostReplacerFactory.java @@ -1,6 +1,6 @@ package main.protocol.hostreplacer; -import main.OSValidator; +import main.misc.OSValidator; /** * Created by Jonas on 04/04/18. diff --git a/src/main/protocol/memory/habboclient/HabboClientFactory.java b/src/main/protocol/memory/habboclient/HabboClientFactory.java index 09b4707..0770ba5 100644 --- a/src/main/protocol/memory/habboclient/HabboClientFactory.java +++ b/src/main/protocol/memory/habboclient/HabboClientFactory.java @@ -1,6 +1,6 @@ package main.protocol.memory.habboclient; -import main.OSValidator; +import main.misc.OSValidator; import main.protocol.memory.habboclient.linux.LinuxHabboClient; /** diff --git a/src/main/ui/scheduler/ScheduleItem.java b/src/main/ui/scheduler/ScheduleItem.java index fc6a74c..cbb87d0 100644 --- a/src/main/ui/scheduler/ScheduleItem.java +++ b/src/main/ui/scheduler/ScheduleItem.java @@ -4,6 +4,7 @@ import javafx.beans.InvalidationListener; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; +import main.misc.StringifyAble; import main.protocol.HMessage; import main.protocol.HPacket; @@ -13,15 +14,19 @@ import java.util.List; /** * Created by Jonas on 07/04/18. */ -public class ScheduleItem { +public class ScheduleItem implements StringifyAble { - private SimpleIntegerProperty indexProperty; - private SimpleBooleanProperty pausedProperty; - private SimpleObjectProperty delayProperty; - private SimpleObjectProperty packetProperty; - private SimpleObjectProperty destinationProperty; + private SimpleIntegerProperty indexProperty = null; + private SimpleBooleanProperty pausedProperty = null; + private SimpleObjectProperty delayProperty = null; + private SimpleObjectProperty packetProperty = null; + private SimpleObjectProperty destinationProperty = null; ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Side destination) { + construct(index, paused, delay, packet, destination); + } + + private void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Side destination) { this.indexProperty = new SimpleIntegerProperty(index); this.pausedProperty = new SimpleBooleanProperty(paused); this.delayProperty = new SimpleObjectProperty<>(delay); @@ -29,6 +34,10 @@ public class ScheduleItem { this.destinationProperty = new SimpleObjectProperty<>(destination); } + ScheduleItem(String stringifyAbleRepresentation) { + constructFromString(stringifyAbleRepresentation); + } + public SimpleIntegerProperty getIndexProperty() { return indexProperty; } @@ -90,4 +99,33 @@ public class ScheduleItem { } } + @Override + public String stringify() { + StringBuilder b = new StringBuilder(); + b .append(indexProperty.get()) + .append("\t") + .append(pausedProperty.get() ? "true" : "false") + .append("\t") + .append(delayProperty.get().toString()) + .append("\t") + .append(packetProperty.get().toString()) + .append("\t") + .append(destinationProperty.get().name()); + return b.toString(); + } + + @Override + public void constructFromString(String str) { + String[] parts = str.split("\t"); + if (parts.length == 5) { + int index = Integer.parseInt(parts[0]); + boolean paused = parts[1].equals("true"); + Interval delay = new Interval(parts[2]); + HPacket packet = new HPacket(parts[3]); + HMessage.Side side = parts[4].equals(HMessage.Side.TOSERVER.name()) ? HMessage.Side.TOSERVER : HMessage.Side.TOCLIENT; + + construct(index, paused, delay, packet, side); + + } + } } diff --git a/src/main/ui/scheduler/Scheduler.fxml b/src/main/ui/scheduler/Scheduler.fxml index 3cebc8f..3042cdc 100644 --- a/src/main/ui/scheduler/Scheduler.fxml +++ b/src/main/ui/scheduler/Scheduler.fxml @@ -65,10 +65,13 @@ - + - + + + + @@ -76,7 +79,7 @@ - + +