Class ConverterRegistry

java.lang.Object
com.viaversion.nbt.conversion.ConverterRegistry

public final class ConverterRegistry extends Object
A registry mapping tags and value types to converters.
  • 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

      public static <T extends Tag, V> void unregister(Class<T> tag, Class<V> type)
      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.