Package redempt.redlib.config
Class ConversionManager
java.lang.Object
redempt.redlib.config.ConversionManager
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionRegisters a string converter to this ConversionManageraddConverter
(ConfigType<T> type, TypeConverter<T> converter) Registers a converter to this ConversionManager<T> TypeConverter<T>
getConverter
(ConfigType<T> type) Gets the TypeConverter for a given type<T> StringConverter<T>
getStringConverter
(ConfigType<T> type) Gets a StringConverter for a given typeClass<?>
Loads a class by name, using a cache
-
Constructor Details
-
ConversionManager
public ConversionManager(org.bukkit.plugin.Plugin plugin)
-
-
Method Details
-
loadClass
Loads a class by name, using a cache- Parameters:
name
- The name of the class to load- Returns:
- The class
-
getConverter
Gets the TypeConverter for a given type- Type Parameters:
T
- The parameter type- Parameters:
type
- The ConfigType- Returns:
- The TypeConverter, making a new one if none exists for the given type
-
addConverter
public <T> ConversionManager addConverter(Class<T> clazz, Function<String, T> loader, Function<T, String> saver) Registers a string converter to this ConversionManager- Type Parameters:
T
- The type- Parameters:
clazz
- The class type the converter is forloader
- A function to convert a string to the given typesaver
- A function to convert the given type to a string- Returns:
- This ConversionManager
-
addConverter
Registers a converter to this ConversionManager- Type Parameters:
T
- The type- Parameters:
type
- The type the converter is forconverter
- The converter- Returns:
- This ConversionManager
-
getStringConverter
Gets a StringConverter for a given type- Type Parameters:
T
- The type- Parameters:
type
- The type to get a StringConverter for- Returns:
- The StringConverter associated with the given type
- Throws:
IllegalStateException
- If a StringConverter does not exist for the given type
-