From 49b4dae33aa4c40b83808e69dcae26e22f119738 Mon Sep 17 00:00:00 2001 From: Moderocky Date: Tue, 31 Dec 2024 12:57:29 +0000 Subject: [PATCH] Fix serialisation equality issue. --- .../skript/classes/data/SkriptClasses.java | 34 ++++++++++++++++++- src/main/java/ch/njol/skript/util/Date.java | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java index f3e02109153..67f50d7405e 100644 --- a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java +++ b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java @@ -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; @@ -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() { + + @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?") diff --git a/src/main/java/ch/njol/skript/util/Date.java b/src/main/java/ch/njol/skript/util/Date.java index c1d5a552bac..1f95e3e071f 100644 --- a/src/main/java/ch/njol/skript/util/Date.java +++ b/src/main/java/ch/njol/skript/util/Date.java @@ -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 *