You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><code>Config</code> provides a simple interface for reading and writing YAML configuration files. Config files are stored in the plugin's data folder and persist across server restarts.</p>
158
+
<p><code>Config</code> provides a simple interface for reading and writing configuration files. Config files are stored in the plugin's data folder and persist across server restarts.</p>
159
+
<p>Supported formats: <strong>TOML</strong> (default), <strong>JSON</strong>, and <strong>properties</strong>.</p>
<li><code>name</code> (<code>str | None</code>) — File name (without <code>.yml</code>extension). If <code>None</code>, uses the default <code>config.yml</code>.</li>
167
+
<li><code>name</code> (<code>str | None</code>) — File name (without extension). If <code>None</code>, uses the script name.</li>
167
168
<li><code>defaults</code> (<code>dict[str, Any] | None</code>) — Default values to merge into the config if they don't already exist.</li>
169
+
<li><code>format</code> (<code>str</code>) — File format: <code>"toml"</code> (default), <code>"json"</code>, or <code>"properties"</code>.</li>
`Config` provides a simple interface for reading and writing YAML configuration files. Config files are stored in the plugin's data folder and persist across server restarts.
8
+
`Config` provides a simple interface for reading and writing configuration files. Config files are stored in the plugin's data folder and persist across server restarts.
9
+
10
+
Supported formats: **TOML** (default), **JSON**, and **properties**.
9
11
10
12
---
11
13
12
14
## Constructor
13
15
14
16
```python
15
-
Config(name=None, defaults=None)
17
+
Config(name=None, defaults=None, format="toml")
16
18
```
17
19
18
20
Load or create a configuration file.
19
21
20
22
-**Parameters:**
21
-
-`name` (`str | None`) — File name (without `.yml`extension). If `None`, uses the default `config.yml`.
23
+
-`name` (`str | None`) — File name (without extension). If `None`, uses the script name.
22
24
-`defaults` (`dict[str, Any] | None`) — Default values to merge into the config if they don't already exist.
25
+
-`format` (`str`) — File format: `"toml"` (default), `"json"`, or `"properties"`.
23
26
24
27
```python
25
-
# Default config.yml
28
+
# Default config.toml
26
29
config = Config()
27
30
28
31
# Named config
29
32
bans = Config("bans")
30
33
34
+
# JSON format
35
+
data = Config("data", format="json")
36
+
37
+
# Properties format
38
+
props = Config("server", format="properties")
39
+
31
40
# With defaults
32
41
settings = Config("settings", defaults={
33
42
"spawn_protection_radius": 16,
@@ -50,7 +59,7 @@ The entire config as a dictionary.
0 commit comments