Class Converters
java.lang.Object
org.skriptlang.skript.lang.converter.Converters
Converters are used to provide Skript with specific instructions for converting an object to a different type.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <From,To> To[] A method for bulk-converting objects of a specific type using a specific Converter.static <From,To> To A method for converting an object into one of several provided types.static <From,To> To Standard method for converting an object into a different type.static <To> To[]A method for bulk-conversion of objects into one of several provided types.static <To> To[]Standard method for bulk-conversion of objects into a different type.static booleanconverterExists(Class<?> fromType, Class<?> toType) A method for determining whether a Converter offromTypetotoTypeexists.static booleanconverterExists(Class<?> fromType, Class<?>... toTypes) A method for determining whether a direct Converter offromTypeto one of the providedtoTypesexists.static <To> To[]convertStrictly(Object[] from, Class<To> toType) A method for bulk-conversion that guarantees objects oftoTypeare returned.static <To> ToconvertStrictly(Object from, Class<To> toType) A method that guarantees an object oftoTypeis returned.static <From,To> To[] convertUnsafe(From[] from, Class<?> toType, Converter<? super From, ? extends To> converter) A method for bulk-converting objects of a specific type using a specific Converter.static <F,M, T> void This method is to be called after Skript has finished registration.static booleanexactConverterExists(Class<?> fromType, Class<?> toType) A method for determining whether a direct Converter offromTypetotoTypeexists.static <F,T> @Nullable Converter <F, T> getConverter(Class<F> fromType, Class<T> toType) A method for obtaining a Converter that can convert an object offromTypeinto an object oftoType.static <F,T> @Nullable ConverterInfo <F, T> getConverterInfo(Class<F> fromType, Class<T> toType) A method for obtaining the ConverterInfo of a Converter that can convert an object offromTypeinto an object oftoType.static @Unmodifiable List<ConverterInfo<?, ?>> static <F,T> void registerConverter(Class<F> fromType, Class<T> toType, Converter<F, T> converter) Registers a new Converter with Skript's collection of Converters.static <F,T> void registerConverter(Class<F> fromType, Class<T> toType, Converter<F, T> converter, int flags) Registers a new Converter with Skript's collection of Converters.
-
Method Details
-
getConverterInfos
- Returns:
- An unmodifiable list containing all registered
ConverterInfos. Please note that this does not include any special Converters resolved by Skript during runtime. This method ONLY returns converters explicitly registered during registration. Thus, it is recommended to usegetConverter(Class, Class).
-
registerConverter
public static <F,T> void registerConverter(Class<F> fromType, Class<T> toType, Converter<F, T> converter) Registers a new Converter with Skript's collection of Converters.- Parameters:
fromType- The type to convert from.toType- The type to convert to.converter- A Converter for converting objects offromTypetotoType.
-
registerConverter
public static <F,T> void registerConverter(Class<F> fromType, Class<T> toType, Converter<F, T> converter, int flags) Registers a new Converter with Skript's collection of Converters.- Parameters:
fromType- The type to convert from.toType- The type to convert to.converter- A Converter for converting objects offromTypetotoType.flags- Flags to set for the Converter. Flags can be found underConverter.
-
createChainedConverters
public static <F,M, void createChainedConverters()T> This method is to be called after Skript has finished registration. It allowsChainedConverters to be created so that Skript may do more complex conversions involving multiple converters. -
exactConverterExists
A method for determining whether a direct Converter offromTypetotoTypeexists. Unlike other methods of this class, it is not the case thatSkript.isAcceptRegistrations()must returnfalsefor this method to be used.- Parameters:
fromType- The type to convert from.toType- The type to convert to.- Returns:
- Whether a direct Converter of
fromTypetotoTypeexists.
-
converterExists
A method for determining whether a Converter offromTypetotoTypeexists.- Parameters:
fromType- The type to convert from.toType- The type to convert to.- Returns:
- Whether a Converter of
fromTypetotoTypeexists.
-
converterExists
A method for determining whether a direct Converter offromTypeto one of the providedtoTypesexists.- Parameters:
fromType- The type to convert from.toTypes- The types to attempt converting to.- Returns:
- Whether a Converter of
fromTypeto one of the providedtoTypesexists.
-
getConverter
@Nullable public static <F,T> @Nullable Converter<F,T> getConverter(Class<F> fromType, Class<T> toType) A method for obtaining a Converter that can convert an object offromTypeinto an object oftoType.- Parameters:
fromType- The type to convert from.toType- The type to convert to.- Returns:
- A Converter capable of converting an object of
fromTypeinto an object oftoType. Will return null if no such Converter exists.
-
getConverterInfo
@Nullable public static <F,T> @Nullable ConverterInfo<F,T> getConverterInfo(Class<F> fromType, Class<T> toType) A method for obtaining the ConverterInfo of a Converter that can convert an object offromTypeinto an object oftoType.- Parameters:
fromType- The type to convert from.toType- The type to convert to.- Returns:
- The ConverterInfo of a Converter capable of converting an object of
fromTypeinto an object oftoType. Will return null if no such Converter exists.
-
convert
Standard method for converting an object into a different type.- Parameters:
from- The object to convert.toType- The type thatfromshould be converted into.- Returns:
- An object of
toType, or null iffromcouldn't be successfully converted.
-
convert
A method for converting an object into one of several provided types.- Parameters:
from- The object to convert.toTypes- A list of types that should be tried for convertingfrom.- Returns:
- An object of one of the provided
toTypes, or null iffromcouldn't successfully be converted.
-
convert
Standard method for bulk-conversion of objects into a different type.- Parameters:
from- The objects to convert.toType- The type thatfromshould be converted into.- Returns:
- Objects of
toType. Will return null iffromis null. Please note that the returned array may not be the same size asfrom. This can happen if an object contained withinfromis not successfully converted.
-
convert
public static <To> To[] convert(Object @Nullable [] from, Class<? extends To>[] toTypes, Class<To> superType) A method for bulk-conversion of objects into one of several provided types.- Parameters:
from- The objects to convert.toTypes- A list of types that should be tried for converting each object.superType- A parent type of all providedtoTypes.- Returns:
- Objects of
superType. Will return any empty array iffromis null. Please note that the returned array may not be the same size asfrom. This can happen if an object contained withinfromis not successfully converted. And, of course, the returned array may contain objects of a different type.
-
convert
public static <From,To> To[] convert(From[] from, Class<To> toType, Converter<? super From, ? extends To> converter) A method for bulk-converting objects of a specific type using a specific Converter.- Parameters:
from- The objects to convert.toType- The type to convert into.converter- The converter to use for conversion.- Returns:
- Objects of
toType. Please note that the returned array may not be the same size asfrom. This can happen if an object contained withinfromis not successfully converted.
-
convertStrictly
A method that guarantees an object oftoTypeis returned.- Parameters:
from- The object to convert.toType- The type to convert into.- Returns:
- An object of
toType. - Throws:
ClassCastException- Iffromcannot be converted.
-
convertStrictly
A method for bulk-conversion that guarantees objects oftoTypeare returned.- Parameters:
from- The object to convert.toType- The type to convert into.- Returns:
- Objects of
toType. The returned array will be the same size asfrom. - Throws:
ClassCastException- If any of the provided objects cannot be converted.
-
convertUnsafe
public static <From,To> To[] convertUnsafe(From[] from, Class<?> toType, Converter<? super From, ? extends To> converter) A method for bulk-converting objects of a specific type using a specific Converter.- Parameters:
from- The objects to convert.toType- A superclass for all objects to be converted.converter- The converter to use for conversion.- Returns:
- Objects of
toType. Please note that the returned array may not be the same size asfrom. This can happen if an object contained withinfromis not successfully converted. - Throws:
ArrayStoreException- IftoTypeis not a superclass of all objects returned by the converter.ClassCastException- IftoTypeis not ofTo.
-