Skip to content
This repository was archived by the owner on Sep 12, 2020. It is now read-only.

Plugin Configs

GrafDimenzio edited this page Jun 23, 2020 · 7 revisions

Server-Configs

You can use Synapse.Plugin.Config to get the configs that are in server-configs.yml

It is a Yaml Config so you can do Config.GetString("configname","default value"); or Config.GetInt("configname",default value) etc. to get the values

Example:

In the Plugin
Plugin.Config.GetBool("myplugin_enabled",true)

In the Config file
myplugin_enabled: false (or true)

Own-Configs

If you need a own config file, you can just create one in your Own Directory which synapse creates for you.

You just have to get the string OwnPluginFolder in your Plugin and create a file in it.

Example:

using Synapse;

namespace Example
{
    public class Example : Plugin
    {
        public override void OnEnable()
        {
            File.Create(this.OwnPluginFolder + "FileName.txt"); // This will create a FileName.txt in \Synapse\Plugins\Server-{ServerPort}\{Your Plugin Name}
        }

        public override string GetName => "YourPluginName";
    }
}

ReloadConfigsEvent

Your main Plugin class which inheritance from Synapse.Plugin contains a ConfigReloadEvent which is activated by Synapse when all Configs should be reloaded try to always implement this with your Configs so that the Owner can reload them

Example:

using Synapse;

namespace Example
{
    public class Example : Plugin
    {
        string exampleConfig;

        public override void OnEnable()
        {
            ReloadConfigs(); //This will initialise the Configs The first time the Server starts
            this.ConfigReloadEvent += ReloadConfigs; //This will Refresh always the Configs if the Owner want
        }

        public override string GetName => "YourPluginName";

        public void ReloadConfigs()
        {
            exampleConfig = Plugin.GetString("example","Hello World");
        }
    }
}

Clone this wiki locally