Guides › Development

Plugin settings

How settings work

Package metadata describes settings; users keep their values in YAML:

File Purpose
conf/<name>.conf.dist Packaged defaults and comments, named by config in plugin.json.
settings.json Labels, types, limits and options for both GUI and TUI forms.
server.yaml Portable values under plugins.<id>.settings.
local.yaml Optional machine-specific overrides using the same structure.

Before setup or launch, LonelyIce generates .runtime/configs/modules/<name>.conf and matching startup environment values for the core. Generated files are replaced; user edits belong in YAML. A plugin without config gets no Settings group. This guide extends Your first plugin; see the field reference and YAML configuration.

1. Add the config

conf/greeter.conf.dist:

#
# example.greeter
#

[worldserver]

#
#    Greeter.Enable
#        Description: Greet players when they log in.
#        Default:     1 - (Enabled)
#                     0 - (Disabled)
#

Greeter.Enable = 1

#
#    Greeter.Message
#        Description: The text sent on login.
#        Default:     "Welcome to the server!"
#

Greeter.Message = "Welcome to the server!"

and name it in plugin.json:

"config": "conf/greeter.conf.dist"

AddPlugin copies the conf folder into the laid-out plugin. The config's name is the file name without .dist: greeter.conf.

2. Read the values

#include "Chat.h"
#include "Config.h"
#include "Player.h"
#include "ScriptMgr.h"

class GreeterPlayerScript : public PlayerScript
{
public:
    GreeterPlayerScript() : PlayerScript("GreeterPlayerScript", { PLAYERHOOK_ON_LOGIN }) { }

    void OnPlayerLogin(Player* player) override
    {
        if (!sConfigMgr->GetOption<bool>("Greeter.Enable", true))
            return;
        ChatHandler(player->GetSession()).SendSysMessage(
            sConfigMgr->GetOption<std::string>("Greeter.Message", "Welcome to the server!"));
    }
};

With LonelyIce, values come from the merged YAML profile, falling back to the plugin's packaged defaults. For example:

plugins:
  example.greeter:
    version: "1.0.0"
    enabled: true
    settings:
      Greeter.Enable: true
      Greeter.Message: "Welcome to our realm!"

Dots in setting keys are literal. YAML booleans, integers, decimals and strings keep their types. LonelyIce derives core .conf files and AC_* environment overrides from these values; the latter preserve exact strings and take precedence in the server. A plain worldserver reads its own .conf.dist, module .conf files and environment; it does not load LonelyIce's YAML profile itself.

3. Describe the Settings group

settings.json next to plugin.json:

{
  "group": { "en": "Greeter", "ru": "Приветствие" },
  "hint":  { "en": "What players see when they log in", "ru": "Что видят игроки при входе" },
  "fields": [
    { "key": "Greeter.Enable", "type": "bool", "apply": "reload",
      "label": { "en": "Greet on login", "ru": "Приветствовать при входе" } },
    { "key": "Greeter.Message", "type": "string", "apply": "reload",
      "label": { "en": "Message", "ru": "Сообщение" },
      "hint": { "en": "Sent as a system message", "ru": "Отправляется системным сообщением" } }
  ]
}

The launcher finds settings.json in the plugin folder by itself. "settings" in plugin.json can instead name another file or hold the same object inline. A bare array of fields is also accepted; the group is then named after the plugin and its hint is the plugin's description.

The group appears in the Settings tab under Plugins, sorted by group name. On the Plugins page the plugin gets a gear button that opens it.

Field types

type Control YAML value
bool checkbox Boolean.
int number field Integer; invalid, fractional and out-of-range input is rejected.
float number field Finite decimal; bounds are validated.
string text field Exact text.
choice drop-down The selected option's value.

Other keys of a field:

Key Meaning
key The config option. Required.
label, hint Localized strings (an object of language → text, or a plain string). label defaults to the key.
min, max Numbers, for int and float.
options For choice: [ { "value": "0", "label": { "en": "Off" } }, ... ]. Values may be written as numbers or strings.
default Shown when neither the config nor the .dist has the key.
apply now, reload or restart (the default); see below.

A field without key or with an unknown type is left out without a message. A settings.json that is not valid JSON adds an entry to the launcher's events, and the plugin gets no group.

label, hint, group and option labels are shown in the launcher's language, then English, then any language present. A real example with every common type is settings.json of playerbots or lonelyice.citizens.

What saving does

Saving writes changed values under plugins.<id>.settings, preserves unknown fields and updates an existing local override where one exists. It does not edit packaged defaults or generated .conf files.

The TUI saves for the next server start. The GUI restarts its own running server for fields marked reload or restart. The schema's apply describes runtime behavior for plugin authors, rather than promising a live YAML reload. reload config and hooks such as OnAfterConfigLoad remain available to low-level core callers, but reloading an already-generated file does not apply new YAML or replace startup environment overrides.

Select a different profile with --settings <path/to/server.yaml>. The sibling local.yaml is loaded automatically; relative machine paths are resolved against the profile directory.

Checklist

  • Every key in settings.json exists in the .dist, with a sensible default.
  • min and max match what your code accepts; the code still validates, since the file can be edited by hand.
  • apply is restart unless your code really re-reads the value.
  • Texts have at least an en entry.