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:

my_plugin.pplugin
{
  "$schema": "https://raw.githubusercontent.com/untrustedmodders/plugify/refs/heads/main/schemas/plugin.schema.json",
  "name": "my_plugin",
  "version": "1.0.0",
  "language": "python3",
  "description": "An example plugin",
  "author": "Your Name",
  "website": "https://example.com",
  "license": "MIT",
  "entry": "my_plugin.MyPlugin",
  "dependencies": [
    { "name": "configs" }
  ]
}

Where to keep the files

Name every file after your plugin, <name>.<kind>.jsonc, and keep it in the standard places:

WhereWhat to keep
The plugin folder, <name>.settings.jsoncDefaults shipped with the package
configs/<name>/<name>.settings.jsoncEdits of the server owner
data/<name>/<name>.translations.jsoncTranslations 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.

my_plugin.py
import os
from plugify.plugin import Plugin
from plugify.pps import configs


class MyPlugin(Plugin):
    def plugin_start(self):
        file = f"{self.name}.settings.jsonc"
        config = configs.ReadMultiple([
            os.path.join(self.location, file),
            os.path.join(self.configs_dir, self.name, file),
            os.path.join(self.data_dir, self.name, file),
        ])
        if not config:
            print("Failed to load settings: " + configs.GetError())
            return

        self.greeting = configs.GetString(config, "Greeting", "Hello")
        self.max_players = configs.GetAsInt(config, "MaxPlayers", 10)
        self.enabled = configs.GetBool(config, "Enabled", True)

        configs.Delete(config)

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:

FunctionReturns
GetBool(config, key, default)bool
GetInt(config, key, default)int64
GetFloat(config, key, default)double
GetString(config, key, default)string
GetAsBool, GetAsInt, GetAsFloat, GetAsStringThe 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.

my_plugin.settings.jsonc
{
  "Database": {
    "Host": "localhost",
    "Port": 3306
  },
  "Admins": ["alice", "bob"]
}
# Step into an object, read, step back
if configs.JumpKey(config, "Database", False):
    host = configs.GetString(config, "Host", "")
    port = configs.GetAsInt(config, "Port", 0)
    configs.JumpBack(config)

# Walk an array
admins = []
if configs.JumpKey(config, "Admins", False):
    if configs.JumpFirst(config):
        while True:
            admins.append(configs.GetAsString(config, "##this##", ""))
            if not configs.JumpNext(config):
                break
        configs.JumpBack(config)
    configs.JumpBack(config)

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.

FunctionMoves the cursor to
JumpKey(config, key, create)The child with this key. With create the child is created if missing
JumpFirst, JumpLastThe first or last child
JumpNext, JumpPrevThe next or previous sibling
JumpN(config, n)The child number n
JumpBackThe parent
JumpRootThe 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.

config = configs.Make()
configs.SetString(config, "Greeting", "Hello")
configs.SetArray(config, "Admins")
configs.JumpKey(config, "Admins", False)
configs.PushString(config, "alice")
configs.JumpRoot(config)

text = configs.RootToJsonString(config)
configs.Delete(config)

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.