-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plugin.cs
123 lines (107 loc) · 3.61 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using Exiled.API.Enums;
using HarmonyLib;
using ServerSpecificSyncer.Features;
using UserSettings.ServerSpecific;
#if EXILED
using System;
using Exiled.API.Features;
#elif NWAPI
using PluginAPI.Core;
#endif
namespace ServerSpecificSyncer
{
/// <summary>
/// Load the plugin to send datas to player
/// </summary>
public class Plugin
#if EXILED
: Plugin<Config, Translation>
#endif
{
#if EXILED
/// <summary>
/// Gets the author of the plugin.
/// </summary>
public override string Author => "Sky";
/// <summary>
/// Gets the name shown in the Loader.
/// </summary>
public override string Name => "ServerSpecificSyncer";
/// <summary>
/// Gets the version of the plugin.
/// </summary>
public override Version Version => new Version(1, 0, 1);
/// <summary>
/// Gets the prefix used for configs.
/// </summary>
public override string Prefix => "ss_syncer";
/// <summary>
/// Gets the plugin priority.
/// </summary>
public override PluginPriority Priority => PluginPriority.First;
#endif
private static Config _staticConfig;
/// <summary>
/// Gets the <see cref="Config"/> instance. Can be null if the plugin is not enabled.
/// </summary>
public static Config StaticConfig => _staticConfig ??= Instance?.Config;
/// <summary>
/// Gets the <see cref="Plugin"/> instance. can be null if the plugin is not enabled.
/// </summary>
public static Plugin Instance { get; private set; }
private Harmony _harmony;
#if EXILED
/// <summary>
/// When the plugin is enabled.
/// </summary>
public override void OnEnabled()
{
Exiled.Events.Handlers.Player.Verified += EventHandler.Verified;
Exiled.Events.Handlers.Player.Left += EventHandler.Left;
Exiled.Events.Handlers.Player.ChangingGroup += EventHandler.ChangingGroup;
GenericEnable();
base.OnEnabled();
}
#elif NWAPI
[PluginAPI.Core.Attributes.PluginConfig("config.yml")]
public Config Config;
[PluginAPI.Core.Attributes.PluginEntryPoint("ServerSpecificSyncer", "1.0.1", "sync all plugins to one server specific", "sky")]
public void OnEnabled()
{
if (Config == null)
{
Log.Error("can't load plugin, because Config is malformed/invalid.");
return;
}
if (!Config.IsEnabled)
return;
PluginAPI.Events.EventManager.RegisterEvents<EventHandler>(this);
GenericEnable();
Log.Info("ServerSpecificSyncer@1.0.0 has been enabled!");
}
#endif
private void GenericEnable()
{
Instance = this;
#if DEBUG
Menu.RegisterAll();
StaticConfig.Debug = true;
#endif
_harmony = new Harmony("fr.sky.patches");
_harmony.PatchAll();
ServerSpecificSettingsSync.ServerOnSettingValueReceived += EventHandler.OnReceivingInput;
}
/// <summary>
/// Get the loaded Translations, depending on using EXILED or NWAPI.
/// </summary>
/// <returns>The loaded translation. Can be null if the plugin is not enabled.</returns>
public static Translation GetTranslation()
{
#if EXILED
return Instance?.Translation;
#elif NWAPI
return StaticConfig?.Translation;
#endif
}
}
}