Configs & Translations
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 certain 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 broadcastTime { get; set; } = 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",
Author = "Dimenzio",
Description = "My First Awesome Plugin", // A Description for your Plugin
LoadPriority = 0
SynapseMajor = 2,
SynapseMinor = 7,
SynapsePatch = 0,
Version = "v.1.0.0" //The Current Version of your Plugin
)]
public class PluginClass : AbstractPlugin
{
[Config(section = "FirstPlugin")]
public MyPluginConfiguration Config { get; set; }
public override void Load()
{
Logger.Get.Info("Hello World");
SynapseController.Server.Events.Player.PlayerLeaveEvent += OnLeave;
}
public void OnLeave(Synapse.Api.Events.SynapseEventArguments.PlayerLeaveEventArgs ev)
{
Map.Get.SendBroadcast(Config.broadcastTime, "A Player left the Server");
}
}
public class MyPluginConfiguration : AbstractConfigSection
{
[Description("How long the Broadcast should be shown")]
public ushort broadcastTime { get; set; } = 5;
}
}
The Config fields will be reloaded by Synapse so you don't have to worry needing to update this.
The Synapse Translation system allows you to add multiple translations to your Plugin so that the hoster can easily just choose the one that they want
First of all create a Class which inherit from
IPluginTranslation
(You can find it in the namespace Synapse.Translation
) and add all fields in it which you need for your Translation. Then if you want to explain a certain config inside the translation file, add the attribute Description
to the fields.Example
using Synapse.Translation;
namespace FirstPlugin
{
public class PluginTranslation : IPluginTranslation
{
public string Broadcast { get; set; } = "A Player left the Server"
}
}
After this add a field with the type
SynapseTranslation<YourTranslationClassHere>
to your plugin class and give it the Attribute Synapse.Api.Plugin.SynapseTranslation
Now can you Add Translations of Your Plugin inside the Load method and get the currently Active Translation with
.ActiveTranslation
Example:
using Synapse.Api;
using Synapse.Api.Plugin;
using Synapse.Translation;
namespace FirstPlugin
{
[PluginInformation(
Name = "FirstPlugin",
Author = "Dimenzio",
Description = "My First Awesome Plugin",
LoadPriority = 0,
SynapseMajor = 2,
SynapseMinor = 7,
SynapsePatch = 0,
Version = "v.1.0.0" //The Current Version of your Plugin
)]
public class PluginClass : AbstractPlugin
{
[Config(section = "FirstPlugin")]
public static PluginConfig Config { get; set; } //It doesn't have to be static but it made it easier to access
[SynapseTranslation]
public static new SynapseTranslation<PluginTranslation> Translation { get; set; }
public override void Load()
{
Logger.Get.Info("Hello World");
PluginTranslation.AddTranslation(new PluginTranslation()); // This Creates the default Translation for English
PluginTranslation.AddTranslation(new PluginTranslation
{
Broadcast = "Ein Spieler hat den Server Verlassen"
}, "GERMAN");
SynapseController.Server.Events.Player.PlayerLeaveEvent += OnLeave;
}
public void OnLeave(Synapse.Api.Events.SynapseEventArguments.PlayerLeaveEventArgs ev)
{
Map.Get.SendBroadcast(Config.broadcastTime, Translation.ActiveTranslation.Broadcast);
}
}
public class PluginConfig : AbstractConfigSection
{
[Description("How long the Broadcast should be shown")]
public ushort broadcastTime { get; set; } = 5;
}
public class PluginTranslation : IPluginTranslation
{
[Description("The Message that is shown when someones leave")]
public string Broadcast { get; set; } = "A Player left the Server"
}
}
The
new
(line 23) is needed in this case Because it prevents from accessing the old Translation System which you could access with plugin.TranslationA Documentation for the SYML will follow in the future
Last modified 1yr ago