-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPlugin.cs
More file actions
166 lines (141 loc) · 4.79 KB
/
Plugin.cs
File metadata and controls
166 lines (141 loc) · 4.79 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System.Linq;
using System.Reflection;
using HarmonyLib;
using LabApi.Events.CustomHandlers;
using SSMenuSystem.Features;
using UserSettings.ServerSpecific;
using Log = SSMenuSystem.Features.Log;
using System;
using JetBrains.Annotations;
using LabApi.Loader;
#if EXILED
using Exiled.API.Features;
#else
using LabApi.Loader.Features.Plugins;
#endif
namespace SSMenuSystem
{
/// <summary>
/// Load the plugin to send datas to player
/// </summary>
// ReSharper disable once ClassNeverInstantiated.Global
public class Plugin : Plugin<Config
#if EXILED
, Translation
#endif
>
{
/// <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 => "SS-Menu System";
/// <summary>
/// Gets the version of the plugin.
/// </summary>
public override Version Version => new(2, 1, 0);
#if EXILED
/// <inheritdoc/>
public override Version RequiredExiledVersion => new(9, 5, 0);
/// <summary>
/// Gets the prefix used for configs.
/// </summary>
public override string Prefix => "ss_menu_system";
#else
/// <summary>
/// Gets the plugin translations.
/// </summary>
public Translation Translation { get; private set; }
/// <inheritdoc />
public override string Description => "Convert all Server-Specifics Settings created by plugins into menu. Help for multi-plugin comptability and organization.";
/// <inheritdoc />
public override Version RequiredApiVersion => new(1, 0, 0);
#endif
/// <summary>
/// Gets the <see cref="Plugin"/> instance. can be null if the plugin is not enabled.
/// </summary>
[CanBeNull]
public static Plugin Instance { get; private set; }
private Harmony _harmony;
private EventHandler _handler;
#if EXILED
/// <inheritdoc/>
public override void OnEnabled()
{
GenericEnable();
base.OnEnabled();
}
/// <inheritdoc />
public override void OnDisabled()
{
GenericDisable();
base.OnDisabled();
}
#else
/// <inheritdoc />
public override void Enable()
{
if (Config == null)
{
Log.Error("can't load plugin, because Config is malformed/invalid.");
return;
}
if (!Config.IsEnabled)
return;
_handler = new EventHandler();
CustomHandlersManager.RegisterEventsHandler(_handler);
GenericEnable();
Log.Info($"{Name}@{Version} has been enabled!");
}
/// <summary>
/// <inheritdoc />
/// </summary>
public override void LoadConfigs()
{
if (!this.TryLoadConfig("translation.yml", out Translation translation))
{
Log.Error("There is an error while loading translation. Using default one.");
translation = new();
}
Translation = translation;
base.LoadConfigs();
}
/// <inheritdoc />
public override void Disable()
{
GenericDisable();
Log.Info($"{Name}@{Version} has been disabled!");
}
#endif
private void GenericEnable()
{
Menu.RegisterAll();
Instance = this;
_harmony = new Harmony("fr.sky.patches");
_harmony.PatchAll();
_handler = new EventHandler();
CustomHandlersManager.RegisterEventsHandler(_handler);
Menu.RegisterQueuedAssemblies();
#if DEBUG
Log.Warn("EXPERIMENTAL VERSION IS ACTIVATED. BE AWARD OF BUGS CAN BE DONE. NOT STABLE VERSION.");
Menu.RegisterPin(new[]{new SSTextArea(null, "this pinned content is related to the called assembly\nwith Menu.UnregisterPin() you just unregister ONLY pinned settings by the called assembly.", SSTextArea.FoldoutMode.CollapsedByDefault, "This is a pinned content.")});
Config!.Debug = true;
#endif
ServerSpecificSettingsSync.ServerOnSettingValueReceived += EventHandler.OnReceivingInput;
}
private void GenericDisable()
{
Menu.UnregisterAll();
CustomHandlersManager.UnregisterEventsHandler(_handler);
ServerSpecificSettingsSync.ServerOnSettingValueReceived -= EventHandler.OnReceivingInput;
Instance = null;
_harmony.UnpatchAll(_harmony.Id);
_harmony = null;
_handler = null;
Log.Info($"{Name}@{Version} has been disabled!");
}
}
}