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 boolean
converterExists
(Class<?> fromType, Class<?> toType) A method for determining whether a Converter offromType
totoType
exists.static boolean
converterExists
(Class<?> fromType, Class<?>... toTypes) A method for determining whether a direct Converter offromType
to one of the providedtoTypes
exists.static <To> To[]
convertStrictly
(Object[] from, Class<To> toType) A method for bulk-conversion that guarantees objects oftoType
are returned.static <To> To
convertStrictly
(Object from, Class<To> toType) A method that guarantees an object oftoType
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 boolean
exactConverterExists
(Class<?> fromType, Class<?> toType) A method for determining whether a direct Converter offromType
totoType
exists.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 offromType
into 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 offromType
into 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
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
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 offromType
totoType
.
-
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 offromType
totoType
.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. -
exactConverterExists
A method for determining whether a direct Converter offromType
totoType
exists. Unlike other methods of this class, it is not the case thatSkript.isAcceptRegistrations()
must returnfalse
for this method to be used.- Parameters:
fromType
- The type to convert from.toType
- The type to convert to.- Returns:
- Whether a direct Converter of
fromType
totoType
exists.
-
converterExists
A method for determining whether a Converter offromType
totoType
exists.- Parameters:
fromType
- The type to convert from.toType
- The type to convert to.- Returns:
- Whether a Converter of
fromType
totoType
exists.
-
converterExists
A method for determining whether a direct Converter offromType
to one of the providedtoTypes
exists.- Parameters:
fromType
- The type to convert from.toTypes
- The types to attempt converting to.- Returns:
- Whether a Converter of
fromType
to one of the providedtoTypes
exists.
-
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 offromType
into 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
fromType
into 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 offromType
into 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
fromType
into 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 thatfrom
should be converted into.- Returns:
- An object of
toType
, or null iffrom
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 convertingfrom
.- Returns:
- An object of one of the provided
toTypes
, or null iffrom
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 thatfrom
should be converted into.- Returns:
- Objects of
toType
. Will return null iffrom
is null. Please note that the returned array may not be the same size asfrom
. This can happen if an object contained withinfrom
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 providedtoTypes
.- Returns:
- Objects of
superType
. Will return any empty array iffrom
is null. Please note that the returned array may not be the same size asfrom
. This can happen if an object contained withinfrom
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 asfrom
. This can happen if an object contained withinfrom
is not successfully converted.
-
convertStrictly
A method that guarantees an object oftoType
is returned.- Parameters:
from
- The object to convert.toType
- The type to convert into.- Returns:
- An object of
toType
. - Throws:
ClassCastException
- Iffrom
cannot be converted.
-
convertStrictly
A method for bulk-conversion that guarantees objects oftoType
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 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 withinfrom
is not successfully converted. - Throws:
ArrayStoreException
- IftoType
is not a superclass of all objects returned by the converter.ClassCastException
- IftoType
is not ofTo
.
-