A powerful API for plugin config and file management, created for SerenityJS.
- Create and read YAML configuration files for your plugin.
- Config files automatically update missing keys in existing configs.
- Read and write plugin data to world, player, or server storage.
-
Install the Plugin: Install the latest version to your SerenityJS server's
pluginsdirectory. -
Install the Typings: Install the NPM package into your plugin project's folder.
#npm npm install serenity-config #yarn yarn add serenity-config #bun bun add serenity-config
Note
If you are having trouble with this step, try adding --prefix <path/to/your/plugin/project> at the end of the command.
-
Import into your Plugin: In your plugin's main file, import the
SConfigPluginclass.import type { SConfigPlugin } from "serenity-config";
-
Resolve the Plugin Instance: Once your plugin is initialized, resolve the
SConfigPlugininstance that you have installed so you can use its features.import { Plugin } from "@serenityjs/plugins"; import type { SConfigPlugin } from "serenity-config"; class ExamplePlugin extends Plugin { n public onInitialize(): void { // The resolve method fetches the SConfigPlugin instance from the plugin you installed. const { Properties, Storage, StorageType } = this.resolve<SConfigPlugin>("serenity-config")!; // Notice the use of `!` can be unsafe if the plugin is not loaded correctly. } }
For full examples, check out the source. SConfig has examples for both types in its SConfigPlugin class.
Example Usage
const properties = new Properties<ExampleProperties>(
this,
"properties.yaml",
EXAMPLE_PROPERTIES_TEMPLATE
);
properties.getValue("debug");
const storage = new Storage<ExampleStorage>(
StorageType.Player,
"players.sqlite",
EXAMPLE_STORAGE_TEMPLATE
);
storage.setValue("example", true)