Skip to main content

IMoBroSettings

Provides access to the plugin's settings values.

note

The settings fields need to be defined in the mobro_plugin_config.json file.
See In-depth: Plugin Settings for more details.

Supported Types

Settings values are transferred as strings and converted to the requested type T. The following types are supported:

TUse for
stringstring and select fields
boolcheckbox fields
doublenumber fields
intnumber fields that only accept whole numbers

Requesting any other type, or a value that can't be converted (e.g. 2.5 as int), throws a PluginSettingsException.

Functions

GetValue<T>(string): T

Retrieves the current value of a setting.

Parameters

NameTypeDescription
keystringThe name of the settings field.

Returns

The current value of the setting.

Throws

  • PluginSettingsException: If the setting has no value, or the value can't be converted to T.

Example

var updateFrequency = _settings.GetValue<int>("update_frequency");
tip

Let the PluginSettingsException thrown by GetValue<T> propagate from Init(). MoBro then reports a settings error for the affected field instead of a generic plugin error.


GetValue<T>(string, T): T

Retrieves the current value of a setting, or the given default value if the setting has no value.

Parameters

NameTypeDescription
keystringThe name of the settings field.
defaultValueTThe value to return if the setting has no value.

Throws

  • PluginSettingsException: If a value is set but can't be converted to T.

Example

var processCount = _settings.GetValue("num_processes", 5);

TryGetValue<T>(string, out T): bool

Attempts to retrieve the current value of a setting.

Parameters

NameTypeDescription
keystringThe name of the settings field.
valueT (out)Contains the value if the setting has one; otherwise the default value of T.

Returns

true if the setting has a value; otherwise false.

Example

if (_settings.TryGetValue<string>("api_key", out var apiKey))
{
_apiClient.Authenticate(apiKey);
}