Class EldoConfig

java.lang.Object
de.eldoria.eldoutilities.configuration.EldoConfig
Direct Known Subclasses:
Configuration

public abstract class EldoConfig extends Object
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
    Modifier and Type
    Field
    Description
    protected final org.bukkit.plugin.Plugin
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    EldoConfig(org.bukkit.plugin.Plugin plugin)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final org.bukkit.configuration.file.FileConfiguration
    Get the underlying file configuration.
    Map<String,org.bukkit.configuration.file.FileConfiguration>
     
    static Level
    getLogLevel(org.bukkit.plugin.Plugin plugin)
    Checks if a plugin is in debug state.
    static EldoConfig
    getMainConfig(org.bukkit.plugin.Plugin plugin)
    Get the main config.
    final org.bukkit.plugin.Plugin
     
    final int
    Get the config version.
    protected void
    Called after constructor and before reload.
    boolean
     
    protected final org.bukkit.configuration.file.FileConfiguration
    loadConfig(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.FileConfiguration
    loadConfig(Path configPath, @Nullable Consumer<org.bukkit.configuration.file.FileConfiguration> defaultCreator, boolean reload)
     
    final void
    Discards any unsaved changes in the config and reloads the config files
    protected void
    Invalidates the cached config objects and reloads.
    final void
    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 set
    protected final boolean
    setIfAbsent(org.bukkit.configuration.ConfigurationSection section, String path, Object value)
    Set a value if not set
    final void
    setVersion(int version, boolean save)
    Set the config version

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • plugin

      protected final org.bukkit.plugin.Plugin plugin
  • Constructor Details

    • EldoConfig

      public EldoConfig(org.bukkit.plugin.Plugin plugin)
  • Method Details

    • getLogLevel

      public static Level getLogLevel(org.bukkit.plugin.Plugin plugin)
      Checks if a plugin is in debug state.
      Returns:
      true if plugin is in debug state.
    • getMainConfig

      public static EldoConfig getMainConfig(org.bukkit.plugin.Plugin plugin)
      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

      protected final boolean setIfAbsent(String path, Object value)
      Set a value if not set
      Parameters:
      path - path in section
      value - 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 - section
      path - path in section
      value - 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 function
      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 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 version
      save - true to save after set.
    • getConfigs

      public Map<String,org.bukkit.configuration.file.FileConfiguration> getConfigs()
    • init

      protected void init()
      Called after constructor and before reload.

      Initialize everything here.

    • isMainConfig

      public boolean isMainConfig()