Package redempt.redlib.config
Class ConfigManager
java.lang.Object
redempt.redlib.config.ConfigManager
Serializes and deserializes configuration data into objects and fields
-
Method Summary
Modifier and TypeMethodDescription<T> ConfigManagerRegisters a string converter to this ConfigManager<T> ConfigManageraddConverter(ConfigType<T> type, TypeConverter<T> converter) Registers a converter to this ConfigManagerstatic ConfigManagerCreates a ConfigManager targetting a specific config file, which will be created if it does not existstatic ConfigManagerCreates a ConfigManager targetting a specific config file, which will be created if it does not existstatic ConfigManagercreate(org.bukkit.plugin.Plugin plugin) Creates a ConfigManager for the default config in a plugin's data folder, called config.ymlstatic ConfigManagerCreates a ConfigManager for a file in a plugin's data folderorg.bukkit.configuration.file.FileConfiguration<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 typeload()Loads all values from the current in-memory config into the targetreload()Loads the config from disk, then loads all values into the targetsave()Saves all of the values from the target to configSaves only values which are not already specified in configSpecifies the given Class to load config values to and save config values from.Specifies the given Object to load config values to and save config values from.
-
Method Details
-
create
Creates a ConfigManager targetting a specific config file, which will be created if it does not exist- Parameters:
file- The config file to manage- Returns:
- The ConfigManager
-
create
Creates a ConfigManager targetting a specific config file, which will be created if it does not exist- Parameters:
path- The config file to manage- Returns:
- The ConfigManager
-
create
Creates a ConfigManager for a file in a plugin's data folder- Parameters:
plugin- The plugin whose data folder should be usedconfigName- The name of the config file to manage- Returns:
- The ConfigManager
-
create
Creates a ConfigManager for the default config in a plugin's data folder, called config.yml- Parameters:
plugin- The plugin whose data folder should be used- Returns:
- The ConfigManager
-
target
Specifies the given Object to load config values to and save config values from. The Object must be from a ConfigMappable class, and all of its non-transient fields will be worked with.- Parameters:
obj- The Object to operate on- Returns:
- This ConfigManager
-
target
Specifies the given Class to load config values to and save config values from. The Class's static non-transient fields will be worked with.- Parameters:
clazz- The Class to operate on- Returns:
- This ConfigManager
-
save
Saves all of the values from the target to config- Returns:
- This ConfigManager
-
saveDefaults
Saves only values which are not already specified in config- Returns:
- This ConfigManager
-
load
Loads all values from the current in-memory config into the target- Returns:
- This ConfigManager
-
reload
Loads the config from disk, then loads all values into the target- Returns:
- This ConfigManager
-
getConfig
public org.bukkit.configuration.file.FileConfiguration getConfig()- Returns:
- The configuration file wrapped by this ConfigManager
-
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> ConfigManager addConverter(Class<T> clazz, Function<String, T> loader, Function<T, String> saver) Registers a string converter to this ConfigManager- 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 ConfigManager
-
addConverter
Registers a converter to this ConfigManager- Type Parameters:
T- The type- Parameters:
type- The type the converter is forconverter- The converter- Returns:
- This ConfigManager
-
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
-