1+
2+ using CounterStrikeSharp . API ;
3+ using CounterStrikeSharp . API . Core ;
4+ using CounterStrikeSharp . API . Core . Attributes . Registration ;
5+ using CounterStrikeSharp . API . Core . Plugin ;
6+ using CustomCommands . Services ;
7+
8+ namespace CustomCommands . Controller ;
9+ public class EventManager : IEventManager
10+ {
11+ private readonly IPluginGlobals PluginGlobals ;
12+ private readonly CustomCommands PluginContext ;
13+ private readonly IReplaceTagsFunctions ReplaceTagsFunctions ;
14+
15+ public EventManager ( IPluginGlobals PluginGlobals , IPluginContext PluginContext , IReplaceTagsFunctions ReplaceTagsFunctions )
16+ {
17+ this . PluginGlobals = PluginGlobals ;
18+ this . PluginContext = ( ( PluginContext as PluginContext ) ! . Plugin as CustomCommands ) ! ;
19+ this . ReplaceTagsFunctions = ReplaceTagsFunctions ;
20+ }
21+
22+ [ GameEventHandler ]
23+ public HookResult OnPlayerDisconnect ( EventPlayerDisconnect @event , GameEventInfo _ )
24+ {
25+ PluginGlobals . centerClientOn . RemoveAll ( p => p . ClientId == @event . Userid . UserId ) ;
26+
27+ return HookResult . Continue ;
28+ }
29+
30+ public void RegisterListeners ( )
31+ {
32+ PluginContext . RegisterListener < Listeners . OnTick > ( ( ) =>
33+ {
34+ // Client Print To Center
35+ if ( PluginGlobals . centerClientOn != null && PluginGlobals . centerClientOn . Count ! > 0 )
36+ {
37+ foreach ( var player in PluginGlobals . centerClientOn )
38+ {
39+ var targetPlayer = Utilities . GetPlayerFromUserid ( player . ClientId ) ;
40+ if ( player != null && targetPlayer != null )
41+ {
42+ targetPlayer . PrintToCenterHtml ( player . Message , 1 ) ;
43+ }
44+ }
45+ }
46+
47+
48+ // Server Print To Center
49+ if ( PluginGlobals . centerServerOn . IsRunning )
50+ {
51+ Utilities . GetPlayers ( ) . ForEach ( controller =>
52+ {
53+ if ( controller == null || ! controller . IsValid ) return ;
54+
55+ string message = ReplaceTagsFunctions . ReplaceMessageTags ( PluginGlobals . centerServerOn . Message , controller ) ;
56+ controller . PrintToCenterHtml ( message , 1 ) ;
57+ } ) ;
58+ }
59+ } ) ;
60+ }
61+ }
0 commit comments