Configs - SynapseSL/Synapse GitHub Wiki
Config.syml
The config.syml
is the file which Synapse stores all plugin information, even yours.
First of all create a Class which inherit from AbstractConfigSection
or IConfigSection
and add all fields in it which you need for your Config.
Then if you want to explain a certian config inside the config.syml
, add the attribute Description
to the fields.
Example:
using Synapse.Config
namespace FirstPlugin
{
public class MyPluginConfiguration : AbstractConfigSection
{
[Description("How long the Broadcast should be shown")]
public ushort broadcasTime = 5;
}
}
After this add a field to your plugin class and give it the Attribute Synapse.Api.Plugin.Config
(optionally you can give the Section a name by adding section = "MySectionName"
)
Example:
using Synapse.Api;
using Synapse.Api.Plugin;
namespace FirstPlugin
{
[PluginInformation(
Name = "FirstPlugin", //The Name of Your Plugin
Author = "Dimenzio", // Your Name
Description = "My First Awesome Plugin", // A Description for your Plugin
LoadPriority = 0, //When your Plugin should get loaded (use 0 if you don't know how to use it)
SynapseMajor = 2, //The Synapse Version for which this Plugin was created for (SynapseMajor.SynapseMinor.SynapsePatch => 2.4.1)
SynapseMinor = 4,
SynapsePatch = 1,
Version = "v.1.0.0" //The Current Version of your Plugin
)]
public class PluginClass : AbstractPlugin
{
[Synapse.Api.Plugin.Config(section = "FirstPlugin")]
public static MyPluginConfiguration Config; //It doesn't have to be static but it made it easier to access
public override void Load()
{
Logger.Get.Info("Hello World");
SynapseController.Server.Events.Player.PlayerLeaveEvent += OnLeave;
}
public void OnLeave(Synapse.Api.Events.SynapseEventArguments.PlayerLeaveEventArgs ev)
{
ev.Player.SendBroadcast(Config.broadcastTime, "A Player left the Server");
}
}
public class MyPluginConfiguration : AbstractConfigSection
{
[Description("How long the Broadcast should be shown")]
public ushort broadcastTime = 5;
}
}
The Config fields will be reloaded by Synapse so you don't have to worry needing to update this.
Translation
Every plugin can create a translation file in which all translations for the plugin is stored.
In order to utilze it you have to create a Dictionary<string, string>
and use PluginClass.Translation.CreateTranslations(dictionary)
After this you can get the translation with PluginClass.Translation.GetTranslation(key)
Example:
using Synapse.Api;
using Synapse.Api.Plugin;
namespace FirstPlugin
{
[PluginInformation(
Name = "FirstPlugin", //The Name of Your Plugin
Author = "Dimenzio", // Your Name
Description = "My First Awesome Plugin", // A Description for your Plugin
LoadPriority = 0, //When your Plugin should get loaded (use 0 if you don't know how to use it)
SynapseMajor = 2, //The Synapse Version for which this Plugin was created for (SynapseMajor.SynapseMinor.SynapsePatch => 2.4.1)
SynapseMinor = 4,
SynapsePatch = 1,
Version = "v.1.0.0" //The Current Version of your Plugin
)]
public class PluginClass : AbstractPlugin
{
[Synapse.Api.Plugin.Config(section = "FirstPlugin")]
public static MyPluginConfiguration Config; //It doesn't have to be static but it made it easier to access
public override void Load()
{
Logger.Get.Info("Hello World");
SynapseController.Server.Events.Player.PlayerLeaveEvent += OnLeave;
var trans = new Dictionary<string,string>
{
{ "leavemessage" , "A Player left the Server" }
};
this.Translation.CreateTranslations(trans);
}
public void OnLeave(Synapse.Api.Events.SynapseEventArguments.PlayerLeaveEventArgs ev)
{
ev.Player.SendBroadcast(Config.broadcasTime, this.Translation.GetTranslation("leavemessage"));
}
}
public class MyPluginConfiguration : AbstractConfigSection
{
[Description("How long the Broadcast should be shown")]
public ushort broadcasTime = 5;
}
}
The translations will be reloaded by Synapse so you don't have to worry needing to update this.