Package redempt.redlib.configmanager
Class ConfigManager
java.lang.Object
redempt.redlib.configmanager.ConfigManager
Loads config values into variables annotated with
ConfigValue-
Constructor Summary
ConstructorsConstructorDescriptionConfigManager(File file) Initiates a ConfigManager using a specific file for the configConfigManager(Path path) Initiates a ConfigManager using a specific path for the configConfigManager(org.bukkit.plugin.Plugin plugin) Instantiates a ConfigManager with the default config name config.yml in the plugin's data folderConfigManager(org.bukkit.plugin.Plugin plugin, String name) Instantiates a ConfigManager with a specific config name in the plugin's config folder -
Method Summary
Modifier and TypeMethodDescription<T> ConfigManagerAdds a type converter, which will attempt to convert a String from config to another type that is not usually able to be stored in configstatic <T> ConfigCollection<T>collection(Class<T> clazz, Collection<T> toWrap, T... elements) Creates a ConfigCollection from a given type with initial elements.static <T> ConfigCollection<T>collection(Class<T> clazz, ConversionType type, Collection<T> toWrap, T... elements) Creates a ConfigCollection from a given type with initial elements.booleanorg.bukkit.configuration.file.YamlConfigurationprotected <T> redempt.redlib.configmanager.TypeConverter<T>getConverter(Class<T> clazz) static <T> redempt.redlib.configmanager.ConfigList<T>list(Class<T> clazz, ConversionType type, T... elements) Creates a ConfigList from a given type with initial elements.static <T> redempt.redlib.configmanager.ConfigList<T>Creates a ConfigList from a given type with initial elements.load()Loads all values from config into the annotated hook fieldsstatic <K,V> redempt.redlib.configmanager.ConfigMap<K, V> Creates a ConfigMap from a given type.static <K,V> redempt.redlib.configmanager.ConfigMap<K, V> map(Class<K> keyClass, Class<V> valueClass, ConversionType type) Creates a ConfigMap from a given type.static <T> redempt.redlib.configmanager.ConfigMap<String,T> Creates a ConfigMap from a given type.static <T> redempt.redlib.configmanager.ConfigMap<String,T> map(Class<T> clazz, ConversionType type) Creates a ConfigMap from a given type.Register all the hooks for annotated fields in the the given objects.save()Saves all values from the annotated hook fields to configSave default values - initial values in the hook fields - where they do not already exist in the configstatic <T> redempt.redlib.configmanager.ConfigSet<T>set(Class<T> clazz, ConversionType type, T... elements) Creates a ConfigSet from a given type with initial elements.static <T> redempt.redlib.configmanager.ConfigSet<T>Creates a ConfigSet from a given type with initial elements.stringList(String... strings) Instantiates a List of Strings inline
-
Constructor Details
-
ConfigManager
public ConfigManager(org.bukkit.plugin.Plugin plugin) Instantiates a ConfigManager with the default config name config.yml in the plugin's data folder- Parameters:
plugin- The plugin
-
ConfigManager
Instantiates a ConfigManager with a specific config name in the plugin's config folder- Parameters:
plugin- The pluginname- The name of the config file to generate
-
ConfigManager
Initiates a ConfigManager using a specific file for the config- Parameters:
file- The file
-
ConfigManager
Initiates a ConfigManager using a specific path for the config- Parameters:
path- The path
-
-
Method Details
-
stringList
Instantiates a List of Strings inline- Parameters:
strings- The Strings to include in the List- Returns:
- The List of Strings
-
map
Creates a ConfigMap from a given type. A ConfigMap extends LinkedHashMap. The class is not accessible, so store it in a HashMap variable. This method must be used to set the initial value for a variable which loads in a section from config.- Type Parameters:
T- The value type- Parameters:
clazz- The class of the value type- Returns:
- An empty map of the given type, which will be populated when
load()is called
-
map
public static <T> redempt.redlib.configmanager.ConfigMap<String,T> map(Class<T> clazz, ConversionType type) Creates a ConfigMap from a given type. A ConfigMap extends LinkedHashMap. The class is not accessible, so store it in a HashMap variable. This method must be used to set the initial value for a variable which loads in a section from config.- Type Parameters:
T- The value type- Parameters:
clazz- The class of the value typetype- The method which will be used to convert the stored type- Returns:
- An empty map of the given type, which will be populated when
load()is called
-
map
public static <K,V> redempt.redlib.configmanager.ConfigMap<K,V> map(Class<K> keyClass, Class<V> valueClass) Creates a ConfigMap from a given type. A ConfigMap extends LinkedHashMap. The class is not accessible, so store it in a HashMap variable. This method must be used to set the initial value for a variable which loads in a section from config. The key class may only be a type which has converter from string to another type. For obvious reasons, it cannot be a config-mappable object.- Type Parameters:
K- The key typeV- The value type- Parameters:
keyClass- The class of the key typevalueClass- The class of the value type- Returns:
- An empty map of the given type, which will be populated when
load()is called
-
map
public static <K,V> redempt.redlib.configmanager.ConfigMap<K,V> map(Class<K> keyClass, Class<V> valueClass, ConversionType type) Creates a ConfigMap from a given type. A ConfigMap extends LinkedHashMap. The class is not accessible, so store it in a HashMap variable. This method must be used to set the initial value for a variable which loads in a section from config. The key class may only be a type which has converter from string to another type. For obvious reasons, it cannot be a config-mappable object.- Type Parameters:
K- The key typeV- The value type- Parameters:
keyClass- The class of the key typevalueClass- The class of the value typetype- The method which will be used to convert the value type- Returns:
- An empty map of the given type, which will be populated when
load()is called
-
list
Creates a ConfigList from a given type with initial elements. A ConfigList extends ArrayList. The class is not accessible, so store it in an ArrayList variable. This method must be used to set the initial value for a variable which loads a list from config using type converters or mapped objects.- Type Parameters:
T- The type- Parameters:
clazz- The class of the type of the listelements- The elements to initialize the list with- Returns:
- A list of the given type which has been populated with the given elements
-
list
public static <T> redempt.redlib.configmanager.ConfigList<T> list(Class<T> clazz, ConversionType type, T... elements) Creates a ConfigList from a given type with initial elements. A ConfigList extends ArrayList. The class is not accessible, so store it in an ArrayList variable. This method must be used to set the initial value for a variable which loads a list from config using type converters or mapped objects.- Type Parameters:
T- The type- Parameters:
clazz- The class of the type of the listelements- The elements to initialize the list withtype- The method which will be used to convert the stored type- Returns:
- A list of the given type which has been populated with the given elements
-
set
Creates a ConfigSet from a given type with initial elements. A ConfigSet extends LinkedHashSet. The class is not accessible, so store it in a HashSet variable. This method must be used to set the initial value for a variable which loads a set from config using type converters or mapped objects.- Type Parameters:
T- The type- Parameters:
clazz- The class of the type of the listelements- The elements to initialize the list with- Returns:
- A set of the given type which has been populated with the given elements
-
set
public static <T> redempt.redlib.configmanager.ConfigSet<T> set(Class<T> clazz, ConversionType type, T... elements) Creates a ConfigSet from a given type with initial elements. A ConfigSet extends LinkedHashSet. The class is not accessible, so store it in a HashSet variable. This method must be used to set the initial value for a variable which loads a set from config using type converters or mapped objects.- Type Parameters:
T- The type- Parameters:
clazz- The class of the type of the listelements- The elements to initialize the list withtype- The method which will be used to convert the stored type- Returns:
- A set of the given type which has been populated with the given elements
-
collection
public static <T> ConfigCollection<T> collection(Class<T> clazz, ConversionType type, Collection<T> toWrap, T... elements) Creates a ConfigCollection from a given type with initial elements. A ConfigCollection wraps the given collection. This method must be used to set the initial value for a variable which loads a set from config using type converters or mapped objects.- Type Parameters:
T- The type- Parameters:
clazz- The class of the type of the listelements- The elements to initialize the list withtype- The method which will be used to convert the stored typetoWrap- The Collection to wrap- Returns:
- A wrapped collection of the given type which has been populated with the given elements
-
collection
public static <T> ConfigCollection<T> collection(Class<T> clazz, Collection<T> toWrap, T... elements) Creates a ConfigCollection from a given type with initial elements. A ConfigCollection wraps the given collection. This method must be used to set the initial value for a variable which loads a set from config using type converters or mapped objects.- Type Parameters:
T- The type- Parameters:
clazz- The class of the type of the listelements- The elements to initialize the list withtoWrap- The Collection to wrap- Returns:
- A wrapped collection of the given type which has been populated with the given elements
-
addConverter
public <T> ConfigManager addConverter(Class<T> clazz, Function<String, T> load, Function<T, String> save) Adds a type converter, which will attempt to convert a String from config to another type that is not usually able to be stored in config- Type Parameters:
T- The type- Parameters:
clazz- The class of the typeload- A function to convert from a string to the typesave- A function to convert from the type to a string- Returns:
- This ConfigManager
-
getConverter
-
register
Register all the hooks for annotated fields in the the given objects. Pass classes instead if static fields are used.- Parameters:
data- The object to be registered- Returns:
- This ConfigManager
-
configExists
public boolean configExists()- Returns:
- Whether the config file exists
-
saveDefaults
Save default values - initial values in the hook fields - where they do not already exist in the config- Returns:
- This ConfigManager
- Throws:
IllegalStateException- if this ConfigManager has not been registered yet
-
load
Loads all values from config into the annotated hook fields- Returns:
- This ConfigManager
- Throws:
IllegalStateException- if this ConfigManager has not been registered yet
-
save
Saves all values from the annotated hook fields to config- Returns:
- This ConfigManager
- Throws:
IllegalStateException- if this ConfigManager has not been registered yet
-
getConfig
public org.bukkit.configuration.file.YamlConfiguration getConfig()- Returns:
- The configuration this ConfigManager is loading from and saving to
-