@@ -20,9 +20,6 @@ public ChatService(ILogger<ChatService> logger, IPluginContext pluginContext) :
20
20
21
21
public override void Initialize ( bool hotReload )
22
22
{
23
- this . Plugin . AddCommandListener ( "say" , this . OnSay ) ;
24
- this . Plugin . AddCommandListener ( "say_team" , this . OnSayTeam ) ;
25
-
26
23
ChatPrefix = ( ( this . Plugin as ChatServicePlugin ) ! . Config . ChatPrefix ) ;
27
24
}
28
25
@@ -31,15 +28,34 @@ public override void OnServiceInitialized(IService service)
31
28
if ( service is ICommandService commandService )
32
29
{
33
30
this . CommandService = commandService ;
31
+
32
+ this . Plugin . AddCommandListener ( "say" , this . OnSay ) ;
33
+ this . Plugin . AddCommandListener ( "say_team" , this . OnSayTeam ) ;
34
34
}
35
35
}
36
36
37
- public override void Shutdown ( bool hotReload )
37
+ private void RemoveListeners ( )
38
38
{
39
39
this . Plugin . RemoveCommandListener ( "say" , this . OnSay , HookMode . Pre ) ;
40
40
this . Plugin . RemoveCommandListener ( "say_team" , this . OnSayTeam , HookMode . Pre ) ;
41
41
}
42
42
43
+ public override void OnServiceShutdown ( IService service )
44
+ {
45
+ if ( service is ICommandService )
46
+ {
47
+ this . RemoveListeners ( ) ;
48
+ }
49
+ }
50
+
51
+ public override void Shutdown ( bool hotReload )
52
+ {
53
+ if ( this . CommandService == null )
54
+ return ;
55
+
56
+ this . RemoveListeners ( ) ;
57
+ }
58
+
43
59
public void PrintToChat ( CCSPlayerController player , string message )
44
60
{
45
61
player . CPrintToChat ( message ) ;
0 commit comments