Class Config

java.lang.Object
com.github.darksoulq.abyssallib.common.config.Config

public class Config extends Object
A wrapper for Bukkit's YamlConfiguration that provides a fluent API, support for Codec serialization, and manual comment injection.

This class allows for easy management of configuration files located within a plugin's data folder.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Represents a specific value within the configuration.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Config(String pluginId, String name)
    Constructs a new Config instance in the plugin's root config folder.
    Config(String pluginId, String name, String subfolder)
    Constructs a new Config instance located in a subfolder.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addComment(String path, String... commentLines)
    Associates one or more comment lines with a configuration path.
    void
    Reloads the configuration from the disk.
    void
    Saves the current configuration state to the disk and injects defined comments.
    <T> Config.Value<T>
    value(String path, T defaultValue)
    Defines a configuration value with a default fallback.
    <T> Config.Value<T>
    value(String path, T defaultValue, Codec<T> codec)
    Defines a configuration value that requires a Codec for serialization.

    Methods inherited from class Object

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

    • Config

      public Config(String pluginId, String name, String subfolder)
      Constructs a new Config instance located in a subfolder.
      Parameters:
      pluginId - The ID/name of the plugin (used for the root folder).
      name - The name of the YAML file (without extension).
      subfolder - The subfolder within the plugin's config directory.
    • Config

      public Config(String pluginId, String name)
      Constructs a new Config instance in the plugin's root config folder.
      Parameters:
      pluginId - The ID/name of the plugin.
      name - The name of the YAML file (without extension).
  • Method Details

    • value

      public <T> Config.Value<T> value(String path, T defaultValue)
      Defines a configuration value with a default fallback.
      Type Parameters:
      T - The type of the value.
      Parameters:
      path - The YAML path (e.g., "settings.enabled").
      defaultValue - The value to use and save if the path does not exist.
      Returns:
      A Config.Value object to interact with this configuration node.
    • value

      public <T> Config.Value<T> value(String path, T defaultValue, Codec<T> codec)
      Defines a configuration value that requires a Codec for serialization.
      Type Parameters:
      T - The type of the value.
      Parameters:
      path - The YAML path.
      defaultValue - The default value fallback.
      codec - The codec used to encode/decode the value.
      Returns:
      A Config.Value object.
    • addComment

      public void addComment(String path, String... commentLines)
      Associates one or more comment lines with a configuration path.
      Parameters:
      path - The configuration path to comment.
      commentLines - The lines of text to add as comments.
    • save

      public void save()
      Saves the current configuration state to the disk and injects defined comments.
      Throws:
      RuntimeException - If an IOException occurs during saving.
    • reload

      public void reload()
      Reloads the configuration from the disk.
      Throws:
      RuntimeException - If the file is invalid or inaccessible.