Class Converters

java.lang.Object
ch.njol.skript.registrations.Converters

public abstract class Converters extends Object
Contains all registered converters and allows operating with them.
  • Method Details

    • getConverters

      public static List<Converter.ConverterInfo<?,​?>> getConverters()
    • registerConverter

      public static <F,​ T> void registerConverter(Class<F> from, Class<T> to, Converter<F,​T> converter)
      Registers a converter.
      Parameters:
      from - Type that the converter converts from.
      to - Type that the converter converts to.
      converter - Actual converter.
    • registerConverter

      public static <F,​ T> void registerConverter(Class<F> from, Class<T> to, Converter<F,​T> converter, int options)
    • createMissingConverters

      public static void createMissingConverters()
    • convert

      public static <F,​ T> @Nullable T convert(@Nullable F o, Class<T> to)
      Converts the given value to the desired type. If you want to convert multiple values of the same type you should use getConverter(Class, Class) to get a converter to convert the values.
      Parameters:
      o -
      to -
      Returns:
      The converted value or null if no converter exists or the converter returned null for the given value.
    • convert

      public static <F,​ T> @Nullable T convert(@Nullable F o, Class<? extends T>[] to)
      Converts an object into one of the given types.

      This method does not convert the object if it is already an instance of any of the given classes.

      Parameters:
      o -
      to -
      Returns:
      The converted object
    • convertArray

      public static <T> @Nullable T[] convertArray(@Nullable Object[] o, Class<T> to)
      Converts all entries in the given array to the desired type, using convert(Object, Class) to convert every single value. If you want to convert an array of values of a known type, consider using convert(Object[], Class, Converter) for much better performance.
      Parameters:
      o -
      to -
      Returns:
      A T[] array without null elements
    • convertArray

      public static <T> T[] convertArray(@Nullable Object[] o, Class<? extends T>[] to, Class<T> superType)
      Converts multiple objects into any of the given classes.
      Parameters:
      o -
      to -
      superType - The component type of the returned array
      Returns:
      The converted array
    • convertStrictly

      public static <T> T[] convertStrictly(Object[] original, Class<T> to) throws ClassCastException
      Strictly converts an array to a non-null array of the specified class. Uses registered Converters to convert.
      Parameters:
      original - The array to convert
      to - What to convert original to
      Returns:
      original converted to an array of to
      Throws:
      ClassCastException - if one of original's elements cannot be converted to a to
    • convertStrictly

      public static <T> T convertStrictly(Object original, Class<T> to) throws ClassCastException
      Strictly converts an object to the specified class
      Parameters:
      original - The object to convert
      to - What to convert original to
      Returns:
      original converted to a to
      Throws:
      ClassCastException - if original could not be converted to a to
    • converterExists

      public static boolean converterExists(Class<?> from, Class<?> to)
      Tests whether a converter between the given classes exists.
      Parameters:
      from -
      to -
      Returns:
      Whether a converter exists
    • converterExists

      public static boolean converterExists(Class<?> from, Class<?>... to)
    • getConverter

      public static <F,​ T> @Nullable Converter<? super F,​? extends T> getConverter(Class<F> from, Class<T> to)
      Gets a converter
      Parameters:
      from -
      to -
      Returns:
      the converter or null if none exist
    • getConverterInfo

      public static <F,​ T> @Nullable Converter.ConverterInfo<? super F,​? extends T> getConverterInfo(Class<F> from, Class<T> to)
      Gets a converter that has been registered before.
      Parameters:
      from -
      to -
      Returns:
      The converter info or null if no converters were found.
    • convertUnsafe

      public static <F,​ T> T[] convertUnsafe(F[] from, Class<?> to, Converter<? super F,​? extends T> conv)
      Parameters:
      from -
      to -
      conv -
      Returns:
      The converted array
      Throws:
      ArrayStoreException - if the given class is not a superclass of all objects returned by the converter
    • convert

      public static <F,​ T> T[] convert(F[] from, Class<T> to, Converter<? super F,​? extends T> conv)