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 Details

    • plugin

      protected final Plugin plugin
  • Constructor Details

    • EldoConfig

      public EldoConfig(Plugin plugin)
  • Method Details

    • getLogLevel

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

      public static EldoConfig getMainConfig(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(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 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 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 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

      public final Plugin getPlugin()
    • getConfig

      public final 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,FileConfiguration> getConfigs()
    • init

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

      Initialize everything here.

    • isMainConfig

      public boolean isMainConfig()