-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.cs
142 lines (120 loc) · 4.98 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.API.Interfaces;
using Exiled.Events.EventArgs.Player;
using HarmonyLib;
using KeyBindingServiceMeow.API.Event.EventArgs;
using KeyBindingServiceMeow.KeyApplications.HotKeys;
using KeyBindingServiceMeow.KeyApplications.HotKeys.Setting;
using KeyBindingServiceMeow.KeyBindingComponents.KeyBindingManager;
using KeyBindingServiceMeow.TestCase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using KeyBindingServiceMeow.KeyBindingComponents.KeyHandlers;
using KeyBindingServiceMeow.KeyApplications.PlayerVerification;
// * V1.0.0
// - Initial release
// * V1.0.1
// - Add Debug Info
// * V1.1.0
// - Bind keys to the specific Player rather than bind keys globally.
// * V1.2.0
// - Add KeyBindReady event
// * V1.3.0
// - Fix the issue that player has to press RA key to use key binding. Thanks for the idea from Ruemena
// * V2.0.0
// - Remake everything......
// * V2.1.0
// - Add Player Verification that allows you to detect whether a Player has been verified.
// - Add Command Binding that allows you to bind a custom command to a key
// * V2.1.1
// - Fix the issue that the plugin does not work properly when HintServieMeow is not installed
// * V2.1.2
// - Standardize code style
// * V2.1.3
// - Fix the bug that causes "Collection was modified" error
// * V2.1.4
// - Fix more bugs related to the "Collection was modified" error.
//
// Simple Direction(V2.1.1)
//========================================================================================================
// API: API for other plugins to use
//
// KeyBindingComponents: Basic Components that directly manage, detect and handle the cmd binding
// KeyManager: Subject components, manager the keys in CmdBinding and notify the observers when key was pressed
// KeyHandler: Concrete Observer, Handle the key
//
// KeyManager: Advanced Components based on KeyBindingComponents to provide more advanced features.
// PlayerVerification: Manage the verification of a Player. Verify whether a Player had correctly setup their client.
// HotKeyManager: Manage the hotkeys for a Player. Hotkeys are customizable keys with name, description and other information.
namespace KeyBindingServiceMeow
{
public class Plugin : Plugin<Config>
{
public override string Name => "KeyBindingServiceMeow";
public override string Author => "MeowServer";
public override Version Version => new Version(2, 1, 4);
public override Version RequiredExiledVersion => new Version(8, 0, 0);
public override PluginPriority Priority => PluginPriority.First;
public static Plugin instance;
public override void OnEnabled()
{
CheckRequirements();
instance = this;
Exiled.Events.Handlers.Player.Verified += EventHandler.OnVerified;
Exiled.Events.Handlers.Player.Left += EventHandler.OnLeft;
//Initialize components
CmdBindingTool.ClearKeyBinding();
CommandConvertKeyHandler.Initialize(); //Key Handlers
EventKeyHandler.Initialize();
SettingManager.Initialize(); //Hotkey manager component
if (Config.instance.UseTestCase)
{
HotKeyTestCase.OnEnabled();
EventKeyTestCase.OnEnabled();
VerificationTestCase.OnEnabled();
}
base.OnEnabled();
}
public override void OnDisabled()
{
instance = null;
Exiled.Events.Handlers.Player.Verified -= EventHandler.OnVerified;
Exiled.Events.Handlers.Player.Left -= EventHandler.OnLeft;
CommandConvertKeyHandler.Destruct(); //Key Handlers
EventKeyHandler.Destruct();
SettingManager.Destruct(); //Hotkey manager component
HotKeyTestCase.OnDisabled();
EventKeyTestCase.OnDisabled();
VerificationTestCase.OnDisabled();
base.OnDisabled();
}
private static void CheckRequirements()
{
if (CharacterClassManager.EnableSyncServerCmdBinding == false)
{
throw new Exception("This plugin requires the server to enable enable_sync_command_binding option in config_gameplay.txt.");
}
}
}
internal static class EventHandler
{
public static void OnVerified(VerifiedEventArgs ev)
{
HotKeyManager.Create(ev.Player);
Verifier.Create(ev.Player);
API.Event.Events.InvokeKeyServiceReady(new KeyServiceReadyEventArg(ev.Player));
//Sync and activate CMD binding on client side
CmdBindingTool.SyncBinding(ev.Player);
}
public static void OnLeft(LeftEventArgs ev)
{
HotKeyManager.Destruct(ev.Player);
Verifier.Destruct(ev.Player);
}
}
}