Package com.viaversion.nbt.conversion
Class ConverterRegistry
java.lang.Object
com.viaversion.nbt.conversion.ConverterRegistry
A registry mapping tags and value types to converters.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,T extends Tag>
TconvertToTag(V value) Converts the given value to a tag.static <T extends Tag,V>
VconvertToValue(T tag) Converts the given tag to a value.static <T extends Tag,V>
voidregister(Class<T> tag, Class<? extends V> type, TagConverter<T, V> converter) Registers a converter.static <T extends Tag,V>
voidunregister(Class<T> tag, Class<V> type) Unregisters a converter.
-
Constructor Details
-
ConverterRegistry
public ConverterRegistry()
-
-
Method Details
-
register
public static <T extends Tag,V> void register(Class<T> tag, Class<? extends V> type, TagConverter<T, V> converter) Registers a converter.- Type Parameters:
T- Tag type to convert from.V- Value type to convert to.- Parameters:
tag- Tag type class to register the converter to.type- Value type class to register the converter to.converter- Converter to register.- Throws:
IllegalArgumentException- if the tag or type are already registered
-
unregister
Unregisters a converter.- Type Parameters:
T- Tag type to unregister.V- Value type to unregister.- Parameters:
tag- Tag type class to unregister.type- Value type class to unregister.
-
convertToValue
@Nullable public static <T extends Tag,V> V convertToValue(@Nullable T tag) throws ConversionException Converts the given tag to a value.- Type Parameters:
T- Tag type to convert from.V- Value type to convert to.- Parameters:
tag- Tag to convert.- Returns:
- The converted value.
- Throws:
ConversionException- If a suitable converter could not be found.
-
convertToTag
@Nullable public static <V,T extends Tag> T convertToTag(@Nullable V value) throws ConversionException Converts the given value to a tag.- Type Parameters:
V- Value type to convert from.T- Tag type to convert to.- Parameters:
value- Value to convert.- Returns:
- The converted tag.
- Throws:
ConversionException- If a suitable converter could not be found.
-