Class ConfigurableFile

java.lang.Object
me.croabeast.file.YAMLFile
me.croabeast.file.ConfigurableFile
All Implemented Interfaces:
Configurable

public class ConfigurableFile extends YAMLFile implements Configurable
Represents a YAML file that supports configuration management by implementing the Configurable interface.

ConfigurableFile extends YAMLFile to provide a concrete implementation for interacting with YAML configuration files. It enables loading, saving, and updating configuration settings, and exposes the underlying FileConfiguration for further manipulation.

This class is intended for use in Bukkit plugins where configuration files need to be managed dynamically. It offers constructors that accept a loader object, an optional folder name, and a file name, and it throws an IOException if an I/O error occurs during initialization.

Example usage:


 try {
     ConfigurableFile configFile = new ConfigurableFile(plugin, "config", "settings");
     // Set resource path if needed
     configFile.setResourcePath("config/settings.yml");

     // Modify the configuration
     configFile.set("key", "value");

     // Save changes
     configFile.save();
 } catch (IOException e) {
     e.printStackTrace();
 }
 

See Also:
  • Constructor Details

    • ConfigurableFile

      public ConfigurableFile(T loader, @Nullable @Nullable String folder, String name) throws IOException
      Constructs a new ConfigurableFile with the specified loader, folder, and name.

      The file is created in the given folder within the plugin's data directory, and the YAML configuration is loaded.

      Type Parameters:
      T - The type of the loader object.
      Parameters:
      loader - The loader object used to retrieve the data folder and resources.
      folder - The folder where the file is located (may be null).
      name - The name of the YAML file (without extension).
      Throws:
      IOException - if an I/O error occurs during file initialization.
    • ConfigurableFile

      public ConfigurableFile(T loader, String name) throws IOException
      Constructs a new ConfigurableFile with the specified loader and name.

      The file is created in the plugin's data folder, and the YAML configuration is loaded.

      Type Parameters:
      T - The type of the loader object.
      Parameters:
      loader - The loader object used to retrieve the data folder and resources.
      name - The name of the YAML file (without extension).
      Throws:
      IOException - if an I/O error occurs during file initialization.
  • Method Details

    • setResourcePath

      public void setResourcePath(String resourcePath) throws NullPointerException
      Sets the resource path for this configuration file.

      The resource path is used to locate the default resource in the JAR to be saved to the file system.

      Overrides:
      setResourcePath in class YAMLFile
      Parameters:
      resourcePath - the resource path to set.
      Throws:
      NullPointerException - if resourcePath is blank.
    • setUpdatable

      public ConfigurableFile setUpdatable(boolean updatable)
      Sets whether this configuration file should be updatable.

      When set to true, the file can be updated via the YAMLFile.update() method.

      Parameters:
      updatable - true if the file should be updatable; false otherwise.
      Returns:
      this ConfigurableFile instance for method chaining.