Class ConfigurationSerializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>

java.lang.Object
ch.njol.yggdrasil.YggdrasilSerializer<T>
ch.njol.skript.classes.Serializer<T>
ch.njol.skript.classes.ConfigurationSerializer<T>
All Implemented Interfaces:
ClassResolver

public class ConfigurationSerializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable> extends Serializer<T>
Uses strings for serialisation because the whole ConfigurationSerializable interface is badly documented, and especially DelegateDeserialization doesn't work well with Yggdrasil.
  • Constructor Details

    • ConfigurationSerializer

      public ConfigurationSerializer()
  • Method Details

    • serialize

      public Fields serialize(T o) throws NotSerializableException
      Description copied from class: Serializer
      Serialises 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:
      serialize in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      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
    • mustSyncDeserialization

      public boolean mustSyncDeserialization()
      Description copied from class: Serializer
      Not currently used (everything happens on Bukkit's main thread).
      Specified by:
      mustSyncDeserialization in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      Returns:
      Whether deserialisation must be done on Bukkit's main thread.
    • canBeInstantiated

      public boolean canBeInstantiated()
      Description copied from class: Serializer
      Returns 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:
      canBeInstantiated in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
    • deserialize

      protected T deserialize(Fields fields) throws StreamCorruptedException
      Description copied from class: Serializer
      Used to deserialise Bukkit objects and other stuff that cannot be instantiated, e.g. a plugin may and should not create a new instance of World, but use Bukkit.getWorld(String) to get an existing world object.
      Overrides:
      deserialize in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      Parameters:
      fields - The Fields object that holds the information about the serialised object
      Returns:
      The deserialised object. Must not be null (throw an exception instead).
      Throws:
      StreamCorruptedException - If the given data is invalid or incomplete
    • serializeCS

      public static String serializeCS(org.bukkit.configuration.serialization.ConfigurationSerializable o)
    • deserializeCS

      @Nullable public static <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> T deserializeCS(String s, Class<T> c)
    • newInstance

      @Nullable public <E extends T> E newInstance(Class<E> c)
      Description copied from class: YggdrasilSerializer
      Creates a new instance of the given class.
      Overrides:
      newInstance in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      Parameters:
      c - The class as read from stream
      Returns:
      A new instance of the given class. Must not be null if YggdrasilSerializer.canBeInstantiated(Class) returned true.
    • deserialize

      public void deserialize(T o, Fields fields) throws StreamCorruptedException
      Description copied from class: YggdrasilSerializer
      Deserializes an object.

      Use fields.setFields(o); to emulate the default behaviour.

      Specified by:
      deserialize in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      Parameters:
      o - The object to deserialize as returned by YggdrasilSerializer.newInstance(Class).
      fields - The fields read from stream
      Throws:
      StreamCorruptedException - If deserialization failed because the data read from stream is incomplete or invalid.
    • deserialize

      @Deprecated @Nullable public T deserialize(String s)
      Deprecated.
      Description copied from class: Serializer
      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 Serializer.mustSyncDeserialization() returned true.

      Overrides:
      deserialize in class Serializer<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      Parameters:
      s -
      Returns:
      The deserialised object or null if the input is invalid. An error message may be logged to specify the cause.
    • deserializeCSOld

      @Deprecated @Nullable public static <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> T deserializeCSOld(String s, Class<T> c)
      Deprecated.