Skip to content

From Bukkit Configuration

Alexander Söderberg edited this page Dec 31, 2020 · 4 revisions

Configurate is different from Bukkit's configuration in a number of ways, and there are some definite 'gotchas' due to different design decisions. This page gives an overview of some of the key differences, but Javadocs and examples provide more thorough details about idiomatic Configurate usage.

No dotted keys

Where on Bukkit a value can be accessed directly by a dotted string, Configurate represents its paths as Object[]s. This means there are no magic characters -- so keys can contain any character.

Bukkit Configurate
config.get("main.settings") config.node("main", "settings").getString()

Nodes are automatically created

Accessing a node will always return an object. To detect if a node is actually set, use the isVirtual() method on ConfigurationNode. This means there's no more checking if a value at a path is a section and creating the section -- instead just get the node and start working with it!

Separation of loading and configuration

ConfigurationNodes, which store configuration data, are entirely separate from ConfigurationLoaders, which handle loading and saving to a specific configuration format. This allows the same code to work with any format, or even convert between formats without having to know anything about where a configuration came from. This means loading a configuration is somewhat different:

Bukkit Configurate
Configuration conf = YAMLConfiguration.loadConfiguration(file); final YamlConfigurationLoader loader = YamlConfigurationLoader.builder().path(path).build(); final ConfigurationNode conf = loader.load()

Additionally, most options determining how a configuration is represented (indent, block or flow style, etc) are controlled by the loader rather than the configuration itself.

Serializing complex types

Bukkit configurations have specific methods for working with Bukkit types. Configurate on the other hand is a standalone configuration API. It converts from specific types using Type Serializers, accessed through the get(TypeToken<T> type, Object default) method.

Bukkit Configurate
conf.getLocation("a.b") conf.node("a", "b").get(Location.class)

Configurate also has an integrated object mapper that removes a lot of the boilerplate of extracting data from configurations. See its documentation for more details.