Class SerializerRegistry

java.lang.Object
dev.crafty.core.config.serializers.SerializerRegistry

public class SerializerRegistry extends Object
Registry for managing configuration serializers. This class allows plugins to register custom serializers for specific types.
  • Method Details

    • getInstance

      public static SerializerRegistry getInstance()
    • registerSerializer

      public <T> void registerSerializer(ConfigSerializer<T> serializer)
      Register a custom serializer.
      Type Parameters:
      T - The type the serializer handles
      Parameters:
      serializer - The serializer to register
    • registerSerializer

      public <T> void registerSerializer(org.bukkit.plugin.Plugin plugin, ConfigSerializer<T> serializer)
      Register a custom serializer for a specific plugin.
      Type Parameters:
      T - The type the serializer handles
      Parameters:
      plugin - The plugin registering the serializer
      serializer - The serializer to register
    • unregisterPlugin

      public void unregisterPlugin(org.bukkit.plugin.Plugin plugin)
      Unregister all serializers for a plugin.
      Parameters:
      plugin - The plugin to unregister serializers for
    • getSerializer

      public <T> Optional<ConfigSerializer<T>> getSerializer(Class<T> type)
      Get a serializer instance for a specific type.
      Type Parameters:
      T - The type
      Parameters:
      type - The type to get a serializer for
      Returns:
      Optional containing the serializer instance, or empty if none found
    • hasSerializer

      public boolean hasSerializer(Class<?> type)
      Check if a serializer is registered for a specific type.
      Parameters:
      type - The type to check
      Returns:
      true if a serializer is registered, false otherwise
    • serialize

      public <T> SectionWrapper serialize(T object)
      Serialize an object to a SectionWrapper using the registered serializer.
      Type Parameters:
      T - The type of the object
      Parameters:
      object - The object to serialize
      Returns:
      SectionWrapper containing the serialized data
    • deserialize

      public <T> Optional<T> deserialize(SectionWrapper wrapper, Class<T> type)
      Deserialize an object from a SectionWrapper using the registered serializer.
      Type Parameters:
      T - The type of the object
      Parameters:
      wrapper - The SectionWrapper containing the serialized data
      type - The type to deserialize to
      Returns:
      The deserialized object
    • getAllSerializers

      public Collection<ConfigSerializer<?>> getAllSerializers()
      Get all registered serializers.
      Returns:
      Collection of all registered serializers