Settings - markvaaz/ScarletCore GitHub Wiki
The Settings class provides BepInEx configuration management for V Rising mods. It simplifies creating, reading, and managing configuration entries with a fluent API.
using ScarletCore.Data;
var settings = new Settings(MyPluginInfo.PLUGIN_GUID, this);
- BepInEx configuration integration
- Fluent API for section management
- Type-safe configuration entries
- Automatic file persistence
- Configuration validation
Adds a new configuration entry.
settings.Add("General", "EnableFeature", true, "Enable main feature");
Parameters:
-
section
- Configuration section name -
key
- Configuration key identifier -
defaultValue
- Default value if not found -
description
- Description of the setting
Retrieves the value of a configuration entry.
var isEnabled = settings.Get<bool>("EnableFeature");
Parameters:
-
key
- Configuration key to retrieve
Returns: The configuration value
Sets the value of an existing configuration entry.
settings.Set("EnableFeature", false);
Parameters:
-
key
- Configuration key to update -
value
- New value to set
Checks if a configuration entry exists.
bool exists = settings.Has("EnableFeature");
Parameters:
-
key
- Configuration key to check
Returns: True if the key exists
Saves the configuration to disk. (the saving is normaly done automatically by BepInEx)
settings.Save();
Cleans up resources and clears entries.
settings.Dispose();
Use the Section method for fluent configuration setup.
settings.Section("General")
.Add("EnableFeature", true, "Enable main feature")
.Add("MaxItems", 100, "Maximum number of items");
Adds a configuration entry to the section and returns the section for chaining.
section.Add("MaxPlayers", 50, "Maximum player count");
Parameters:
-
key
- Configuration key identifier -
defaultValue
- Default value -
description
- Description of the setting
Returns: SettingsSection for method chaining
Gets all configuration entry keys.
var keys = settings.Keys;
Gets all configuration entry values.
var values = settings.Values;
Configuration files are stored in:
BepInEx/config/{PluginGuid}.cfg
Organize settings into logical sections:
- General - Core plugin settings (URLs, intervals, toggles)
- Customization - User-facing text and formatting
- Admin - Administrative feature toggles
- Features - Specific feature configurations
Use fluent API for cleaner configuration setup:
Settings.Section("General")
.Add("Setting1", defaultValue1, "Description 1")
.Add("Setting2", defaultValue2, "Description 2")
.Add("Setting3", defaultValue3, "Description 3");
Implement settings reload functionality:
public static void ReloadSettings() {
Settings.Dispose();
LoadSettings();
}
Use clear, descriptive configuration keys and detailed descriptions:
generalSection.Add("MessageInterval", 0.2f, "Interval in seconds between sending messages.\nUseful to prevent rate limiting.");
using ScarletCore.Data;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("markvaaz.ScarletCore")]
public class Plugin : BasePlugin {
public static Settings Settings { get; private set; }
public override void Load() {
Settings = new Settings(MyPluginInfo.PLUGIN_GUID, this);
LoadSettings();
}
public override bool Unload() {
Settings.Dispose();
return true;
}
public static void LoadSettings() {
// General configuration
var generalSection = Settings.Section("General");
generalSection
.Add("AdminWebhookURL", "null", "Admin Webhook URL for notifications")
.Add("EnableBatching", true, "Enable message batching to avoid rate limiting")
.Add("MessageInterval", 0.2f, "Interval in seconds between messages");
// Customization settings
var customSection = Settings.Section("Customization");
customSection
.Add("LoginMessageFormat", "{playerName} has joined the game.", "Login message format")
.Add("GlobalPrefix", "[Global] {playerName}:", "Global chat prefix")
.Add("ClanPrefix", "[Clan][{clanName}] {playerName}:", "Clan chat prefix");
// Feature toggles
var adminSection = Settings.Section("Admin");
adminSection
.Add("AdminGlobalMessages", true, "Send global messages to admin webhook")
.Add("AdminLoginMessages", true, "Send login messages to admin webhook")
.Add("AdminPvpMessages", true, "Send PvP messages to admin webhook");
}
public static void ReloadSettings() {
Settings.Dispose();
LoadSettings();
}
}