Interface Configurable

All Known Implementing Classes:
ConfigurableFile
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Configurable
Represents an object that can manage and manipulate a FileConfiguration.

The Configurable interface provides a set of utility methods for retrieving, modifying, and navigating configuration data stored in a YAML file. It simplifies access to configuration values, subsections, and lists, and offers methods to convert configuration sections into mappable data structures.

Note: Concrete implementations of this interface should supply the actual FileConfiguration instance by implementing getConfiguration().

Example usage:


 // Create a configurable instance (e.g., via a lambda expression)
 Configurable config = () -> YamlConfiguration.loadConfiguration(new File("config.yml"));

 // Retrieve a string value with a default
 String value = config.get("some.path", "default");

 // Check if a path exists
 boolean exists = config.contains("some.path");

 // Retrieve a list of strings from the configuration section
 List<String> list = Configurable.toStringList(config.getConfiguration(), "list.path");

 // Retrieve subsections as a map
 Map<String, ConfigurationSection> sections = config.getSections("section.path", true);

 // Convert a configuration section to a mappable set of sections
 SectionMappable.Set mapped = config.asSectionMap("section.path");
 

See Also:
  • FileConfiguration
  • YamlConfiguration
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts a configuration section into a SectionMappable.Set.
    default <U extends ConfigurableUnit>
    UnitMappable.Set<U>
    asUnitMap(String path, Function<org.bukkit.configuration.ConfigurationSection,U> function)
    Converts a configuration section into a UnitMappable.Set by applying a transformation function.
    default boolean
    Checks if the configuration contains a specific key, considering default values.
    default boolean
    contains(String path, boolean ignoresDefault)
    Checks if the configuration contains a specific key.
    default <T> T
    get(String path, Class<T> clazz)
    Retrieves a value from the configuration at the specified path and attempts to cast it to the given type.
    default <T> T
    get(String path, T def)
    Retrieves a value from the configuration at the specified path, returning a default if the key does not exist.
    @NotNull org.bukkit.configuration.file.FileConfiguration
    Gets the primary configuration associated with this configurable instance.
    default @NotNull List<String>
    Retrieves all top-level keys within a specified configuration section.
    default @NotNull List<String>
    getKeys(String path, boolean deep)
    Retrieves all keys within a specified configuration section.
    default @Nullable org.bukkit.configuration.ConfigurationSection
    Retrieves a configuration section from the specified path.
    default @NotNull Map<String,org.bukkit.configuration.ConfigurationSection>
    Retrieves all top-level subsections within a specified configuration section.
    default @NotNull Map<String,org.bukkit.configuration.ConfigurationSection>
    getSections(String path, boolean deep)
    Retrieves all subsections within a specified configuration section.
    static @NotNull Configurable
    of(org.bukkit.configuration.file.FileConfiguration section)
    Creates a new Configurable instance from a given FileConfiguration.
    default <T> void
    set(String path, T value)
    Sets a value in the configuration at the specified path.
    toSectionMap(@Nullable org.bukkit.configuration.ConfigurationSection section, @Nullable String path)
    Converts a configuration section into a SectionMappable.Set instance.
    default List<String>
    Retrieves a list of strings from the configuration at the specified path.
    static List<String>
    toStringList(org.bukkit.configuration.ConfigurationSection section, String path)
    Converts a configuration section's value into a list of strings.
    static List<String>
    toStringList(org.bukkit.configuration.ConfigurationSection section, String path, List<String> def)
    Converts a configuration section's value into a list of strings.
  • Method Details

    • getConfiguration

      @NotNull @NotNull org.bukkit.configuration.file.FileConfiguration getConfiguration()
      Gets the primary configuration associated with this configurable instance.
      Returns:
      the FileConfiguration instance (never null).
    • get

      @Nullable default <T> T get(String path, Class<T> clazz)
      Retrieves a value from the configuration at the specified path and attempts to cast it to the given type.
      Type Parameters:
      T - the type of the value.
      Parameters:
      path - the path to the configuration value.
      clazz - the expected class type of the value.
      Returns:
      the value at the specified path, or null if casting fails.
    • get

      default <T> T get(String path, T def)
      Retrieves a value from the configuration at the specified path, returning a default if the key does not exist.
      Type Parameters:
      T - the type of the value.
      Parameters:
      path - the path to the configuration value.
      def - the default value to return if the key does not exist.
      Returns:
      the retrieved value or the default value if not found.
    • set

      default <T> void set(String path, T value)
      Sets a value in the configuration at the specified path.
      Type Parameters:
      T - the type of the value.
      Parameters:
      path - the path to the configuration key.
      value - the value to set.
    • contains

      default boolean contains(String path, boolean ignoresDefault)
      Checks if the configuration contains a specific key.
      Parameters:
      path - the path to check.
      ignoresDefault - whether to ignore default values.
      Returns:
      true if the path exists, otherwise false.
    • contains

      default boolean contains(String path)
      Checks if the configuration contains a specific key, considering default values.
      Parameters:
      path - the path to check.
      Returns:
      true if the path exists, otherwise false.
    • getSection

      @Nullable default @Nullable org.bukkit.configuration.ConfigurationSection getSection(String path)
      Retrieves a configuration section from the specified path.
      Parameters:
      path - the path to the configuration section.
      Returns:
      the ConfigurationSection at the specified path, or null if not found.
    • toStringList

      default List<String> toStringList(String path)
      Retrieves a list of strings from the configuration at the specified path.
      Parameters:
      path - the path to the list.
      Returns:
      a list of strings from the configuration, or an empty list if the path does not exist.
    • getKeys

      @NotNull default @NotNull List<String> getKeys(String path, boolean deep)
      Retrieves all keys within a specified configuration section.
      Parameters:
      path - the section path.
      deep - whether to include keys recursively from nested sections.
      Returns:
      a list of keys under the specified section.
    • getKeys

      @NotNull default @NotNull List<String> getKeys(String path)
      Retrieves all top-level keys within a specified configuration section.
      Parameters:
      path - the section path.
      Returns:
      a list of keys under the specified section.
    • getSections

      @NotNull default @NotNull Map<String,org.bukkit.configuration.ConfigurationSection> getSections(String path, boolean deep)
      Retrieves all subsections within a specified configuration section.
      Parameters:
      path - the section path.
      deep - whether to include nested subsections recursively.
      Returns:
      a map of subsection names to their corresponding ConfigurationSection objects.
    • getSections

      @NotNull default @NotNull Map<String,org.bukkit.configuration.ConfigurationSection> getSections(String path)
      Retrieves all top-level subsections within a specified configuration section.
      Parameters:
      path - the section path.
      Returns:
      a map of subsection names to their corresponding ConfigurationSection objects.
    • asSectionMap

      @NotNull default SectionMappable.Set asSectionMap(String path)
      Converts a configuration section into a SectionMappable.Set.
      Parameters:
      path - the path to the configuration section.
      Returns:
      a SectionMappable.Set representing the configuration section.
    • asUnitMap

      @NotNull default <U extends ConfigurableUnit> UnitMappable.Set<U> asUnitMap(String path, Function<org.bukkit.configuration.ConfigurationSection,U> function)
      Converts a configuration section into a UnitMappable.Set by applying a transformation function.
      Type Parameters:
      U - the type of the configurable unit.
      Parameters:
      path - the path to the configuration section.
      function - the function that transforms a ConfigurationSection into a ConfigurableUnit.
      Returns:
      a UnitMappable.Set containing the transformed units.
    • toStringList

      static List<String> toStringList(org.bukkit.configuration.ConfigurationSection section, String path, List<String> def)
      Converts a configuration section's value into a list of strings.
      Parameters:
      section - the configuration section.
      path - the path within the section.
      def - the default list to return if the key does not exist.
      Returns:
      a list of strings representing the configuration value, or the default list if not found.
    • toStringList

      static List<String> toStringList(org.bukkit.configuration.ConfigurationSection section, String path)
      Converts a configuration section's value into a list of strings.
      Parameters:
      section - the configuration section.
      path - the path within the section.
      Returns:
      a list of strings representing the configuration value, or an empty list if not found.
    • toSectionMap

      @NotNull static SectionMappable.Set toSectionMap(@Nullable @Nullable org.bukkit.configuration.ConfigurationSection section, @Nullable @Nullable String path)
      Converts a configuration section into a SectionMappable.Set instance.

      This method navigates to the desired configuration section, extracts its keys, and groups the subsections based on their priority and permission values. The result is a mappable set that is ordered descendingly.

      Parameters:
      section - the main configuration section.
      path - the path within the configuration.
      Returns:
      a SectionMappable.Set representing the mapped configuration sections.
    • of

      @NotNull static @NotNull Configurable of(org.bukkit.configuration.file.FileConfiguration section)
      Creates a new Configurable instance from a given FileConfiguration.

      The returned Configurable is a functional instance whose getConfiguration() method returns the specified FileConfiguration. This method is useful for integrating with configuration management systems.

      Parameters:
      section - the file configuration to wrap.
      Returns:
      a new Configurable instance.