java.lang.Object
studio.magemonkey.codex.mccore.config.Config
Direct Known Subclasses:
LanguageConfig

public class Config extends Object
Handles configs for files other than the default config.yml

Slightly modified version of the one from the bukkit tutorial Source: http://wiki.bukkit.org/Configuration_API_Reference

  • Constructor Summary

    Constructors
    Constructor
    Description
    Config(org.bukkit.plugin.java.JavaPlugin plugin, String name)
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addSavable(ISavable savable, String basePath)
    Adds a savable object to the config for automatic saving
    void
    Checks the configuration for default values, copying default values over if they are not set.
    void
    Clears all of the data in the config
    static void
    clear(org.bukkit.configuration.ConfigurationSection config)
    Clears all of the data in the configuration section
    void
    Deletes the savable from the config
    org.bukkit.configuration.file.FileConfiguration
     
    Retrieves the file of the configuration
     
    org.bukkit.plugin.java.JavaPlugin
     
    void
    Reloads the config
    void
    Saves if there are savables added
    void
    Saves the config
    void
    Saves the default config if no file exists yet
    static void
    setDefaults(org.bukkit.configuration.ConfigurationSection config)
    Deprecated.
    use FileConfiguration.options().copyDefaults(true) instead
    void
    Trims excess (non-default) values from the configuration
    static void
    trim(org.bukkit.configuration.ConfigurationSection config)
    A recursive method to trim the non-default values from a config

    Methods inherited from class java.lang.Object

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

    • Config

      public Config(org.bukkit.plugin.java.JavaPlugin plugin, String name)
      Constructor
      Parameters:
      plugin - plugin reference
      name - file name
  • Method Details

    • setDefaults

      @Deprecated public static void setDefaults(org.bukkit.configuration.ConfigurationSection config)
      Deprecated.
      use FileConfiguration.options().copyDefaults(true) instead

      A recursive method to set the defaults of the config

      Only defaults that aren't set in the current config are copied over so that user changes aren't overwritten.

      Parameters:
      config - config section to set the defaults for
    • trim

      public static void trim(org.bukkit.configuration.ConfigurationSection config)

      A recursive method to trim the non-default values from a config

      This is for clearing unnecessary values from settings configs

      Parameters:
      config - configuration section to trim
    • clear

      public static void clear(org.bukkit.configuration.ConfigurationSection config)

      Clears all of the data in the configuration section

      This doesn't save the config so if you want the changes to be reflected in the actual file, call the saveConfig() method after doing this.

    • getPlugin

      public org.bukkit.plugin.java.JavaPlugin getPlugin()
      Returns:
      plugin owning this config file
    • getFile

      public String getFile()
      Returns:
      name of the file this config saves to
    • clear

      public void clear()

      Clears all of the data in the config

      This doesn't save the config so if you want the changes to be reflected in the actual file, call the saveConfig() method after doing this.

    • save

      public void save()
      Saves if there are savables added
    • addSavable

      public void addSavable(ISavable savable, String basePath)
      Adds a savable object to the config for automatic saving
      Parameters:
      savable - savable object
      basePath - base path for it
    • deleteSavable

      public void deleteSavable(ISavable savable)
      Deletes the savable from the config
      Parameters:
      savable - savable to delete
    • reloadConfig

      public void reloadConfig()
      Reloads the config
    • getConfig

      public org.bukkit.configuration.file.FileConfiguration getConfig()
      Returns:
      config file
    • getConfigFile

      public File getConfigFile()

      Retrieves the file of the configuration

      Returns:
      the file of the configuration
    • saveConfig

      public void saveConfig()
      Saves the config
    • saveDefaultConfig

      public void saveDefaultConfig()
      Saves the default config if no file exists yet
    • checkDefaults

      public void checkDefaults()

      Checks the configuration for default values, copying default values over if they are not set. Once finished, the config is saved so the user can see the changes.

      This acts differently than saveDefaultConfig() as the config can already exist for this method. This is more for making sure users do not erase needed values from settings configs.

    • trim

      public void trim()

      Trims excess (non-default) values from the configuration

      Any values that weren't in the default configuration are removed

      This is primarily used for settings configs