Skip to content

Commit

Permalink
Fix serialisation equality issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky committed Dec 31, 2024
1 parent fa169ca commit 49b4dae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import ch.njol.skript.util.visual.VisualEffects;
import ch.njol.yggdrasil.Fields;

import java.io.NotSerializableException;
import java.io.StreamCorruptedException;
import java.util.Iterator;
import java.util.Locale;
Expand Down Expand Up @@ -352,7 +353,38 @@ public String toVariableNameString(final Timeperiod o) {
"subtract a day from {_yesterday}",
"# now {_yesterday} represents the date 24 hours before now")
.since("1.4")
.serializer(new YggdrasilSerializer<>()));
.serializer(new Serializer<Date>() {

@Override
public Fields serialize(Date date) {
Fields fields = new Fields();
fields.putPrimitive("time", date.getTime());
return fields;
}


@Override
protected Date deserialize(Fields fields)
throws StreamCorruptedException {
long time = fields.getPrimitive("time", long.class);
return new Date(time);
}

@Override
public void deserialize(Date date, Fields fields) {
throw new IllegalStateException("Cannot deserialize to an existing date object.");
}

@Override
public boolean mustSyncDeserialization() {
return false;
}

@Override
protected boolean canBeInstantiated() {
return false;
}
}));

Classes.registerClass(new ClassInfo<>(Direction.class, "direction")
.user("directions?")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/util/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Timespan difference(Date other) {
public Date plus(Timespan other) {
return new Date(getTime() + other.getAs(Timespan.TimePeriod.MILLISECOND));
}

/**
* Get a new instance of this Date with the subtracted timespan
*
Expand Down

0 comments on commit 49b4dae

Please sign in to comment.