Class RegistrySerializer<R extends org.bukkit.Keyed>

java.lang.Object
ch.njol.yggdrasil.YggdrasilSerializer<R>
ch.njol.skript.classes.Serializer<R>
ch.njol.skript.classes.registry.RegistrySerializer<R>
Type Parameters:
R - Registry class
All Implemented Interfaces:
ClassResolver

public class RegistrySerializer<R extends org.bukkit.Keyed> extends Serializer<R>
Serializer for RegistryClassInfo
  • Constructor Details

    • RegistrySerializer

      public RegistrySerializer(org.bukkit.Registry<R> registry)
  • Method Details

    • serialize

      @NotNull public @NotNull Fields serialize(R o)
      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<R extends org.bukkit.Keyed>
      Parameters:
      o - The object to serialise
      Returns:
      A Fields object representing the object's fields to serialise. Must not be null.
    • deserialize

      protected R 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<R extends org.bukkit.Keyed>
      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
    • 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<R extends org.bukkit.Keyed>
      Returns:
      Whether deserialisation must be done on Bukkit's main thread.
    • canBeInstantiated

      protected 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<R extends org.bukkit.Keyed>
    • deserialize

      public void deserialize(R o, Fields f)
      Description copied from class: YggdrasilSerializer
      Deserializes an object.

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

      Specified by:
      deserialize in class Serializer<R extends org.bukkit.Keyed>
      Parameters:
      o - The object to deserialize as returned by YggdrasilSerializer.newInstance(Class).
      f - The fields read from stream