Class EldoConfig
java.lang.Object
de.eldoria.eldoutilities.configuration.EldoConfig
- Direct Known Subclasses:
Configuration
A wrapper class for
FileConfiguration
.
This class can also be act as a main config which holds references to external configuration files.
- Since:
- 1.1.0
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal FileConfiguration
Get the underlying file configuration.static Level
getLogLevel
(Plugin plugin) Checks if a plugin is in debug state.static EldoConfig
getMainConfig
(Plugin plugin) Get the main config.final Plugin
final int
Get the config version.protected void
init()
Called after constructor and before reload.boolean
protected final FileConfiguration
loadConfig
(String path, @Nullable Consumer<FileConfiguration> defaultCreator, boolean reload) Load a file from a directory inside the plugin directory.protected final FileConfiguration
loadConfig
(Path configPath, @Nullable Consumer<FileConfiguration> defaultCreator, boolean reload) final void
reload()
Discards any unsaved changes in the config and reloads the config filesprotected void
Invalidates the cached config objects and reloads.final void
save()
Saves the config to disk.protected void
Write objects to file configs.protected final boolean
setIfAbsent
(String path, Object value) Set a value if not setprotected final boolean
setIfAbsent
(ConfigurationSection section, String path, Object value) Set a value if not setfinal void
setVersion
(int version, boolean save) Set the config version
-
Field Details
-
plugin
-
-
Constructor Details
-
EldoConfig
-
-
Method Details
-
getLogLevel
Checks if a plugin is in debug state.- Returns:
- true if plugin is in debug state.
-
getMainConfig
Get the main config.Also refered as the config.yml
- Returns:
- file configuration for the main config.
-
save
public final void save()Saves the config to disk. -
saveConfigs
protected void saveConfigs()Write objects to file configs.This message will be called first, when
save()
is called.writeConfigs()
will be called afterwards. -
reload
public final void reload()Discards any unsaved changes in the config and reloads the config files -
reloadConfigs
protected void reloadConfigs()Invalidates the cached config objects and reloads.Called after
readConfigs()
}.All configs are already reloaded.
-
setIfAbsent
Set a value if not set- Parameters:
path
- path in sectionvalue
- value to set- Returns:
- true if the value was not present and was set.
-
setIfAbsent
Set a value if not set- Parameters:
section
- sectionpath
- path in sectionvalue
- value to set- Returns:
- true if the value was not present and was set.
-
loadConfig
protected final FileConfiguration loadConfig(String path, @Nullable @Nullable Consumer<FileConfiguration> defaultCreator, boolean reload) Load a file from a directory inside the plugin directory.Directory and or file will be created if not exits.
- Parameters:
path
- path to the file. the file ending .yml is appended by the functiondefaultCreator
- Creator of config setting, if the file is not present. If the creator is null and the file does not exist null will be returned.reload
- forces to load the file configuration from disk even if it was already loaded- Returns:
- file configuration or null if something went wrong.
- Throws:
ExternalConfigException
- When load config is invoked on a eldo config which is not the main config.
-
loadConfig
protected final FileConfiguration loadConfig(Path configPath, @Nullable @Nullable Consumer<FileConfiguration> defaultCreator, boolean reload) - Parameters:
configPath
- path to the file.defaultCreator
- Creator of config setting, if the file is not present. If the creator is null and the file does not exist null will be returned.reload
- forces to load the file configuration from disk even if it was already loaded- Returns:
- File configuration which was already loaded, loaded or created.
- Throws:
ExternalConfigException
- When load config is invoked on a eldo config which is not the main config.
-
getPlugin
-
getConfig
Get the underlying file configuration.- Returns:
- file configuration for the main config.
-
getVersion
public final int getVersion()Get the config version.- Returns:
- config version or -1 if not set.
-
setVersion
public final void setVersion(int version, boolean save) Set the config version- Parameters:
version
- new config versionsave
- true to save after set.
-
getConfigs
-
init
protected void init()Called after constructor and before reload.Initialize everything here.
-
isMainConfig
public boolean isMainConfig()
-