Class TypeCodecRegistry<C extends Codec<?,?>,P extends CodecPair<?,?>>

java.lang.Object
de.craftsblock.craftsnet.api.codec.registry.TypeCodecRegistry<C,P>
Type Parameters:
C - the codec type being registered
P - the pair type that wraps the codec and its target class
Direct Known Subclasses:
TypeDecoderRegistry, TypeEncoderRegistry

public abstract sealed class TypeCodecRegistry<C extends Codec<?,?>,P extends CodecPair<?,?>> extends Object permits TypeDecoderRegistry<D>, TypeEncoderRegistry<E>
A base registry class for managing codecs that handle conversion between types.

This abstract class handles registration, lookup, and unregistration of codecs, where each codec is associated with a target type.

The registry supports generic resolution of codec types through reflection, and allows type-safe handling of codec pairs using a specialized CodecPair subclass.

Since:
3.5.0
  • Method Details

    • register

      @Nullable public C register(@NotNull C codec)
      Registers a new codec into the registry.
      Parameters:
      codec - The codec instance to register.
      Returns:
      The previously registered codec for the same type, or null if none existed.
    • unregister

      public void unregister(@NotNull C codec)
      Unregisters the given codec from the registry.
      Parameters:
      codec - The codec to remove.
    • isRegistered

      public boolean isRegistered(@NotNull C codec)
      Checks if the given codec is already registered.
      Parameters:
      codec - The codec to check.
      Returns:
      true if registered, otherwise false.
    • getCodec

      @Nullable public C getCodec(@Nullable @Nullable Class<?> type)
      Retrieves the codec associated with the given class type.
      Parameters:
      type - The target class.
      Returns:
      The associated codec, or null if none found.
    • hasCodec

      public boolean hasCodec(@Nullable @Nullable Class<?> type)
      Checks whether a codec exists for the given class type.
      Parameters:
      type - The target class.
      Returns:
      true if a codec exists, otherwise false.
    • getCodecs

      @NotNull public @NotNull @Unmodifiable Collection<C> getCodecs()
      Retrieves all codecs currently registered in this registry.
      Returns:
      An unmodifiable Collection of all codecs.
    • getCodecPairs

      @NotNull public @NotNull @Unmodifiable Collection<CodecPair<?,C>> getCodecPairs()
      Retrieves all codec pairs currently registered in this registry.
      Returns:
      An unmodifiable Collection of all codec pairs.
    • getAllKnownTypes

      @NotNull public @NotNull @Unmodifiable Collection<Class<?>> getAllKnownTypes()
      Retrieves all known types currently registered in the codec registry.

      This collection represents all classes for which a codec has been registered, providing a snapshot of all supported target types.

      Returns:
      An unmodifiable Collection of registered Class types.