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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <From,
To> @Nullable To A method for converting an object into one of several provided types.static <From,
To> @Nullable To Standard method for converting an object into a different type.static <From,
To> To[] A method for bulk-converting objects of a specific type using a specific Converter.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 boolean
converterExists
(Class<?> fromType, Class<?> toType) static boolean
converterExists
(Class<?> fromType, Class<?>... toTypes) static <To> To[]
convertStrictly
(Object[] from, Class<To> toType) A method for bulk-conversion that guarantees objects of 'toType' are returned.static <To> To
convertStrictly
(Object from, Class<To> toType) A method that guarantees an object of 'toType' is 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 <F,
T> @Nullable Converter<F, T> getConverter
(Class<F> fromType, Class<T> toType) A method for obtaining a Converter that can convert an object of 'fromType' into an object of 'toType'.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 of 'fromType' into an object of 'toType'.static @Unmodifiable List<ConverterInfo<?,
?>> static <F,
T> void registerConverter
(Class<F> from, Class<T> to, Converter<F, T> converter) Registers a new Converter with Skript's collection of Converters.static <F,
T> void registerConverter
(Class<F> from, Class<T> to, 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
ConverterInfo
s. 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
Registers a new Converter with Skript's collection of Converters.- Parameters:
from
- The type to convert from.to
- The type to convert to.converter
- A Converter for converting objects of type 'from' to type 'to'.
-
registerConverter
public static <F,T> void registerConverter(Class<F> from, Class<T> to, Converter<F, T> converter, int flags) Registers a new Converter with Skript's collection of Converters.- Parameters:
from
- The type to convert from.to
- The type to convert to.converter
- A Converter for converting objects of type 'from' to type 'to'.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 allowsChainedConverter
s to be created so that Skript may do more complex conversions involving multiple converters. -
converterExists
- Returns:
- Whether a Converter capable of converting 'fromType' to 'toType' exists.
-
converterExists
- Returns:
- Whether a Converter capable of converting 'fromType' to one of the provided 'toTypes' exists.
-
getConverter
A method for obtaining a Converter that can convert an object of 'fromType' into an object of 'toType'.- Parameters:
fromType
- The type to convert from.toType
- The type to convert to.- Returns:
- A Converter capable of converting an object of 'fromType' into an object of 'toType'. Will return null if no such Converter exists.
-
getConverterInfo
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 of 'fromType' into an object of 'toType'.- 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 'fromType' into an object of 'toType'. 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 that 'from' should be converted into.- Returns:
- An object of 'toType', or null if 'from' couldn'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 converting 'from'.- Returns:
- An object of one of the provided 'toTypes', or null if 'from' couldn'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 that 'from' should be converted into.- Returns:
- Objects of 'toType'. Will return null if 'from' is null. Please note that the returned array may not be the same size as 'from'. This can happen if an object contained within 'from' is 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 provided 'toTypes'.- Returns:
- Objects of 'superType'. Will return any empty array if 'from' is null. Please note that the returned array may not be the same size as 'from'. This can happen if an object contained within 'from' is 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 as 'from'. This can happen if an object contained within 'from' is not successfully converted.
-
convertStrictly
A method that guarantees an object of 'toType' is returned.- Parameters:
from
- The object to convert.toType
- The type to convert into.- Returns:
- An object of 'toType'.
- Throws:
ClassCastException
- If 'from' cannot be converted.
-
convertStrictly
A method for bulk-conversion that guarantees objects of 'toType' are 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 as 'from'.
- 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 as 'from'. This can happen if an object contained within 'from' is not successfully converted.
- Throws:
ArrayStoreException
- If 'toType' is not a superclass of all objects returned by the converter.ClassCastException
- If 'toType' is not of 'T'.
-