Class ConfigurableFile
- All Implemented Interfaces:
Configurable
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 Summary
ConstructorsConstructorDescriptionConfigurableFile(T loader, @Nullable String folder, String name) Constructs a newConfigurableFilewith the specified loader, folder, and name.ConfigurableFile(T loader, String name) Constructs a newConfigurableFilewith the specified loader and name. -
Method Summary
Modifier and TypeMethodDescriptionvoidsetResourcePath(String resourcePath) Sets the resource path for this configuration file.setUpdatable(boolean updatable) Sets whether this configuration file should be updatable.Methods inherited from class me.croabeast.file.YAMLFile
equals, equals, getConfiguration, getResource, hashCode, reload, save, save, saveDefaults, saveDefaults, setResourcePath, toString, update, updateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface me.croabeast.file.Configurable
asSectionMap, asUnitMap, contains, contains, get, get, getConfiguration, getKeys, getKeys, getSection, getSections, getSections, set, toStringList
-
Constructor Details
-
ConfigurableFile
public ConfigurableFile(T loader, @Nullable @Nullable String folder, String name) throws IOException Constructs a newConfigurableFilewith 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 benull).name- The name of the YAML file (without extension).- Throws:
IOException- if an I/O error occurs during file initialization.
-
ConfigurableFile
Constructs a newConfigurableFilewith 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
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:
setResourcePathin classYAMLFile- Parameters:
resourcePath- the resource path to set.- Throws:
NullPointerException- ifresourcePathis blank.
-
setUpdatable
Sets whether this configuration file should be updatable.When set to
true, the file can be updated via theYAMLFile.update()method.- Parameters:
updatable-trueif the file should be updatable;falseotherwise.- Returns:
- this
ConfigurableFileinstance for method chaining.
-