Skip to content

PluginConfig

Namespace Mc.Scripting.Configuration · Kind class (sealed)

public sealed class PluginConfig

Plugin-scoped access to configuration files (plugin.Config) and the data folder.

Member Description
string DataFolder { get; } The plugin’s data folder (plugins/<id>/), created on first access.
public string DataFolder { get; }

The plugin’s data folder (plugins/<id>/), created on first access. Put every file the plugin writes here.

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).
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.

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.
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.