java.lang.Object
de.craftsblock.craftsnet.api.codec.registry.TypeCodecRegistry<C,P>
- Type Parameters:
C- the codec type being registeredP- 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 Summary
Modifier and TypeMethodDescription@NotNull @Unmodifiable Collection<Class<?>>Retrieves all known types currently registered in the codec registry.Retrieves the codec associated with the given class type.@NotNull @Unmodifiable Collection<CodecPair<?,C>> Retrieves allcodec pairscurrently registered in this registry.@NotNull @Unmodifiable Collection<C>Retrieves allcodecscurrently registered in this registry.booleanChecks whether a codec exists for the given class type.booleanisRegistered(C codec) Checks if the given codec is already registered.Registers a new codec into the registry.voidunregister(C codec) Unregisters the given codec from the registry.
-
Method Details
-
register
Registers a new codec into the registry.- Parameters:
codec- The codec instance to register.- Returns:
- The previously registered codec for the same type, or
nullif none existed.
-
unregister
Unregisters the given codec from the registry.- Parameters:
codec- The codec to remove.
-
isRegistered
Checks if the given codec is already registered.- Parameters:
codec- The codec to check.- Returns:
trueif registered, otherwisefalse.
-
getCodec
Retrieves the codec associated with the given class type.- Parameters:
type- The target class.- Returns:
- The associated codec, or
nullif none found.
-
hasCodec
Checks whether a codec exists for the given class type.- Parameters:
type- The target class.- Returns:
trueif a codec exists, otherwisefalse.
-
getCodecs
Retrieves allcodecscurrently registered in this registry.- Returns:
- An unmodifiable
Collectionof allcodecs.
-
getCodecPairs
Retrieves allcodec pairscurrently registered in this registry.- Returns:
- An unmodifiable
Collectionof allcodec pairs.
-
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
Collectionof registeredClasstypes.
-