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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal org.bukkit.configuration.file.FileConfigurationGet the underlying file configuration.static LevelgetLogLevel(org.bukkit.plugin.Plugin plugin) Checks if a plugin is in debug state.static EldoConfiggetMainConfig(org.bukkit.plugin.Plugin plugin) Get the main config.final org.bukkit.plugin.Pluginfinal intGet the config version.protected voidinit()Called after constructor and before reload.booleanprotected final org.bukkit.configuration.file.FileConfigurationloadConfig(String path, @Nullable Consumer<org.bukkit.configuration.file.FileConfiguration> defaultCreator, boolean reload) Load a file from a directory inside the plugin directory.protected final org.bukkit.configuration.file.FileConfigurationloadConfig(Path configPath, @Nullable Consumer<org.bukkit.configuration.file.FileConfiguration> defaultCreator, boolean reload) final voidreload()Discards any unsaved changes in the config and reloads the config filesprotected voidInvalidates the cached config objects and reloads.final voidsave()Saves the config to disk.protected voidWrite objects to file configs.protected final booleansetIfAbsent(String path, Object value) Set a value if not setprotected final booleansetIfAbsent(org.bukkit.configuration.ConfigurationSection section, String path, Object value) Set a value if not setfinal voidsetVersion(int version, boolean save) Set the config version
-
Field Details
-
plugin
protected final org.bukkit.plugin.Plugin plugin
-
-
Constructor Details
-
EldoConfig
public EldoConfig(org.bukkit.plugin.Plugin plugin)
-
-
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
protected final boolean setIfAbsent(org.bukkit.configuration.ConfigurationSection section, String path, Object value) 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 org.bukkit.configuration.file.FileConfiguration loadConfig(String path, @Nullable @Nullable Consumer<org.bukkit.configuration.file.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 org.bukkit.configuration.file.FileConfiguration loadConfig(Path configPath, @Nullable @Nullable Consumer<org.bukkit.configuration.file.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
public final org.bukkit.plugin.Plugin getPlugin() -
getConfig
public final org.bukkit.configuration.file.FileConfiguration 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()
-