This repository was archived by the owner on Sep 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Plugin Configs
GrafDimenzio edited this page Jun 23, 2020
·
7 revisions
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)
If you need a own config file like you can just create one in your Own Folder that 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";
}
}
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");
}
}
}