PluginConfig
Namespace Mc.Scripting.Configuration · Kind class (sealed)
public sealed class PluginConfigPlugin-scoped access to configuration files (plugin.Config) and the data folder.
Properties
Section titled “Properties”| Member | Description |
|---|---|
string DataFolder { get; } |
The plugin’s data folder (plugins/<id>/), created on first access. |
DataFolder
Section titled “DataFolder”public string DataFolder { get; }The plugin’s data folder (plugins/<id>/), created on first access. Put every file the plugin writes here.
Methods
Section titled “Methods”| Member | Description |
|---|---|
Load<T> |
Loads (and creates, with defaults, when missing) a JSON config file in the data folder. |
string? ReadText(string fileName) |
Reads a text file of the data folder, null when it does not exist. |
void WriteText(string fileName, string text) |
Writes a text file of the data folder atomically (temp file + rename). |
Load<T>
Section titled “Load<T>”public Config<T> Load<T>(JsonTypeInfo<T> typeInfo, string fileName = "config.json") where T : class, new()Loads (and creates, with defaults, when missing) a JSON config file in the data folder.
Type parameters
T: The configuration class.
Parameters
| Name | Type | Description |
|---|---|---|
typeInfo |
JsonTypeInfo<T> |
Source-generated type info, e.g. MyJson.Default.HomesConfig. |
fileName |
string = "config.json" |
The file name (default “config.json”). |
Returns Config<T>: The config. It is a resource of the plugin: watchers stop when the plugin unloads.
ReadText
Section titled “ReadText”public string? ReadText(string fileName)Reads a text file of the data folder, null when it does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
fileName |
string |
The file name. |
Returns string?
Throws
System.ArgumentException: The name is rooted, contains..or an invalid character, or resolves outside the data folder.
WriteText
Section titled “WriteText”public void WriteText(string fileName, string text)Writes a text file of the data folder atomically (temp file + rename).
Parameters
| Name | Type | Description |
|---|---|---|
fileName |
string |
The file name. |
text |
string |
The content. |