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.
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:
-
Method Summary
Modifier and TypeMethodDescriptiondefault SectionMappable.SetasSectionMap(String path) Converts a configuration section into aSectionMappable.Set.default <U extends ConfigurableUnit>
UnitMappable.Set<U> Converts a configuration section into aUnitMappable.Setby applying a transformation function.default booleanChecks if the configuration contains a specific key, considering default values.default booleanChecks if the configuration contains a specific key.default <T> TRetrieves a value from the configuration at the specified path and attempts to cast it to the given type.default <T> TRetrieves a value from the configuration at the specified path, returning a default if the key does not exist.@NotNull org.bukkit.configuration.file.FileConfigurationGets the primary configuration associated with this configurable instance.Retrieves all top-level keys within a specified configuration section.Retrieves all keys within a specified configuration section.default @Nullable org.bukkit.configuration.ConfigurationSectiongetSection(String path) Retrieves a configuration section from the specified path.getSections(String path) Retrieves all top-level subsections within a specified configuration section.getSections(String path, boolean deep) Retrieves all subsections within a specified configuration section.static @NotNull Configurableof(org.bukkit.configuration.file.FileConfiguration section) Creates a newConfigurableinstance from a givenFileConfiguration.default <T> voidSets a value in the configuration at the specified path.static SectionMappable.SettoSectionMap(@Nullable org.bukkit.configuration.ConfigurationSection section, @Nullable String path) Converts a configuration section into aSectionMappable.Setinstance.toStringList(String path) Retrieves a list of strings from the configuration at the specified path.toStringList(org.bukkit.configuration.ConfigurationSection section, String path) Converts a configuration section's value into a list of strings.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
FileConfigurationinstance (nevernull).
-
get
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
nullif casting fails.
-
get
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
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
Checks if the configuration contains a specific key.- Parameters:
path- the path to check.ignoresDefault- whether to ignore default values.- Returns:
trueif the path exists, otherwisefalse.
-
contains
Checks if the configuration contains a specific key, considering default values.- Parameters:
path- the path to check.- Returns:
trueif the path exists, otherwisefalse.
-
getSection
Retrieves a configuration section from the specified path.- Parameters:
path- the path to the configuration section.- Returns:
- the
ConfigurationSectionat the specified path, ornullif not found.
-
toStringList
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
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
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
ConfigurationSectionobjects.
-
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
ConfigurationSectionobjects.
-
asSectionMap
Converts a configuration section into aSectionMappable.Set.- Parameters:
path- the path to the configuration section.- Returns:
- a
SectionMappable.Setrepresenting 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 aUnitMappable.Setby 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 aConfigurationSectioninto aConfigurableUnit.- Returns:
- a
UnitMappable.Setcontaining 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 aSectionMappable.Setinstance.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.Setrepresenting the mapped configuration sections.
-
of
Creates a newConfigurableinstance from a givenFileConfiguration.The returned
Configurableis a functional instance whosegetConfiguration()method returns the specifiedFileConfiguration. This method is useful for integrating with configuration management systems.- Parameters:
section- the file configuration to wrap.- Returns:
- a new
Configurableinstance.
-