Package ch.njol.skript.classes
Class YggdrasilSerializer<T extends YggdrasilSerializable>
java.lang.Object
ch.njol.yggdrasil.YggdrasilSerializer<T>
ch.njol.skript.classes.Serializer<T>
ch.njol.skript.classes.YggdrasilSerializer<T>
- All Implemented Interfaces:
ClassResolver
Serializer that allows Yggdrasil to automatically serialize classes that extend YggdrasilSerializable.
-
Field Summary
Fields inherited from class ch.njol.skript.classes.Serializer
info -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the class should be instantiated using its nullary constructor or not.Deprecated, for removal: This API element is subject to removal in a future version.final voiddeserialize(T o, Fields f) Deserializes an object.booleanNot currently used (everything happens on Bukkit's main thread).final FieldsSerialises the given object.Methods inherited from class ch.njol.skript.classes.Serializer
canBeInstantiated, deserialize, deserialize, getClass, getID, newInstance
-
Constructor Details
-
YggdrasilSerializer
public YggdrasilSerializer()
-
-
Method Details
-
serialize
Description copied from class:SerializerSerialises the given object.Use return new
Fields(this); to emulate the default behaviour.This method must be thread-safe. Use
Task.callSync(Callable)if you need to serialise on Bukkit's main thread.- Specified by:
serializein classSerializer<T extends YggdrasilSerializable>- Parameters:
o- The object to serialise- Returns:
- A Fields object representing the object's fields to serialise. Must not be null.
- Throws:
NotSerializableException- If this object could not be serialized
-
deserialize
public final void deserialize(T o, Fields f) throws StreamCorruptedException, NotSerializableException Description copied from class:YggdrasilSerializerDeserializes an object.Use fields.
setFields(o); to emulate the default behaviour.- Specified by:
deserializein classSerializer<T extends YggdrasilSerializable>- Parameters:
o- The object to deserialize as returned byYggdrasilSerializer.newInstance(Class).f- The fields read from stream- Throws:
StreamCorruptedException- If deserialization failed because the data read from stream is incomplete or invalid.NotSerializableException
-
deserialize
Deprecated, for removal: This API element is subject to removal in a future version.Deserialises an object from a string returned by this serializer or an earlier version thereof.This method should only return null if the input is invalid (i.e. not produced by
Serializer.serialize(Object)or an older version of that method)This method must only be called from Bukkit's main thread if
mustSyncDeserialization()returned true.- Overrides:
deserializein classSerializer<T extends YggdrasilSerializable>- Parameters:
s-- Returns:
- The deserialised object or null if the input is invalid. An error message may be logged to specify the cause.
-
mustSyncDeserialization
public boolean mustSyncDeserialization()Description copied from class:SerializerNot currently used (everything happens on Bukkit's main thread).- Specified by:
mustSyncDeserializationin classSerializer<T extends YggdrasilSerializable>- Returns:
- Whether deserialisation must be done on Bukkit's main thread.
-
canBeInstantiated
public boolean canBeInstantiated()Description copied from class:SerializerReturns whether the class should be instantiated using its nullary constructor or not. Return false if the class has no nullary constructor or if you do not have control over the source of the class (e.g. if it's from an API).You must override and use
Serializer.deserialize(Fields)if this method returns false (Serializer.deserialize(Object, Fields)will no be used anymore in this case).- Specified by:
canBeInstantiatedin classSerializer<T extends YggdrasilSerializable>
-