Guide
Load layered settings in your plugin with the Configs plugin, read values, walk arrays and handle errors.
This guide shows how a plugin loads its settings with the Configs plugin. The examples are in Python. The functions are the same in every language, see Import Functions for how your language calls them.
Add the dependency
Declare configs in the manifest of your plugin, so it is loaded before yours:
Where to keep the files
Name every file after your plugin, <name>.<kind>.jsonc, and keep it in the standard places:
| Where | What to keep |
|---|---|
The plugin folder, <name>.settings.jsonc | Defaults shipped with the package |
configs/<name>/<name>.settings.jsonc | Edits of the server owner |
data/<name>/<name>.translations.jsonc | Translations and saved state |
pkgs/<name>/ | Temporary files that can be created again |
The plugin name in the file name matters: several packages are installed into one environment folder, and files with the same name would overwrite each other.
A plugin that comes with companion plugins of its own may keep all their files in one shared folder named after the main plugin. Each file is still named after the plugin it belongs to. For example, the permissions plugins keep their edits in configs/permissions/ and their translations in data/permissions/.
Read the settings
Pass the three paths to ReadMultiple in loading order: package, configs, data. A later file overrides the keys of an earlier one, and files that do not exist are skipped.
Read and ReadMultiple return a handle, or 0 on failure. GetError returns the reason. Free the handle with Delete when you are done.
The merge is one level deep: a top-level key from a later file replaces the whole value of that key. Keep that in mind when you design nested settings.
Read values
Every getter takes the handle, a key and a default value:
| Function | Returns |
|---|---|
GetBool(config, key, default) | bool |
GetInt(config, key, default) | int64 |
GetFloat(config, key, default) | double |
GetString(config, key, default) | string |
GetAsBool, GetAsInt, GetAsFloat, GetAsString | The value converted to the requested type |
HasKey(config, key) | Whether the key exists |
A number read from a file is stored as a floating-point value, so GetInt returns the default for it. Read whole numbers from files with GetAsInt. GetInt reads the values written with SetInt.
Objects and arrays
The handle works like a cursor that points at one node. The Jump* functions move it, and getters read relative to the current node.
A key can be a path with / between the parts: GetString(config, "Database/Host", "") reads a nested value without moving the cursor. The special key ##this## stands for the current node itself, which is how the elements of an array are read.
| Function | Moves the cursor to |
|---|---|
JumpKey(config, key, create) | The child with this key. With create the child is created if missing |
JumpFirst, JumpLast | The first or last child |
JumpNext, JumpPrev | The next or previous sibling |
JumpN(config, n) | The child number n |
JumpBack | The parent |
JumpRoot | The root |
GetSize returns the number of children, GetName the name of the current node, and IsObject, IsArray, IsString and the other Is* functions tell its type.
Build and change a config
Make creates an empty config. Set* functions write a value under a key of the current node, and Push* functions append to the current array.
Merge(config, other) copies the keys of another config into this one, and RemoveKey and Clear delete nodes.
The Config class
In languages with class support the generated bindings include a Config class. It is created with Read, ReadMultiple or Make, has the functions above as methods and frees the handle by itself. See the Using Classes page of your language.
The full list of functions with their signatures is on the API Hub.