1- using CounterStrikeSharp . API ;
2- using CounterStrikeSharp . API . Core ;
1+ using CounterStrikeSharp . API . Core ;
32using CounterStrikeSharp . API . Core . Attributes ;
4- using CounterStrikeSharp . API . Modules . Utils ;
5- using CustomCommands . Model ;
3+ using CustomCommands . Interfaces ;
64using Microsoft . Extensions . Logging ;
7- using System . Text . Json ;
85
96namespace CustomCommands ;
107
11- [ MinimumApiVersion ( 98 ) ]
8+ [ MinimumApiVersion ( 142 ) ]
129public partial class CustomCommands : BasePlugin , IPluginConfig < CustomCommandsConfig >
1310{
1411 public override string ModuleName => "CustomCommands" ;
15- public override string ModuleVersion => "1.0.7 " ;
12+ public override string ModuleVersion => "1.0.8 " ;
1613 public override string ModuleAuthor => "HerrMagic" ;
1714 public override string ModuleDescription => "Create your own commands per config" ;
1815
19- private List < CenterClientElement > centerClientOn = new ( ) ;
20- private CenterServerElement centerServerOn = new ( ) ;
21-
22- private List < CCSPlayerController > PlayerList = new ( ) ;
2316 public CustomCommandsConfig Config { get ; set ; } = new ( ) ;
24- private string PrefixCache = "" ;
17+ private readonly IRegisterCommands RegisterCommands ;
18+ private readonly IPluginGlobals PluginGlobals ;
19+ private readonly ILoadJson LoadJson ;
20+ private readonly IEventManager EventManager ;
21+
22+ public CustomCommands ( IRegisterCommands RegisterCommands , ILogger < CustomCommands > Logger ,
23+ IPluginGlobals PluginGlobals , ILoadJson LoadJson , IEventManager EventManager )
24+ {
25+ this . Logger = Logger ;
26+ this . RegisterCommands = RegisterCommands ;
27+ this . PluginGlobals = PluginGlobals ;
28+ this . LoadJson = LoadJson ;
29+ this . EventManager = EventManager ;
30+ }
2531
2632 public void OnConfigParsed ( CustomCommandsConfig config )
2733 {
@@ -32,52 +38,25 @@ public override void Load(bool hotReload)
3238 {
3339 if ( ! Config . IsPluginEnabled )
3440 {
35- Console . WriteLine ( $ "{ Config . LogPrefix } { ModuleName } is disabled") ;
41+ Logger . LogInformation ( $ "{ Config . LogPrefix } { ModuleName } is disabled") ;
3642 return ;
3743 }
38-
39- Console . WriteLine (
44+
45+ Logger . LogInformation (
4046 $ "CustomCommands has been loaded, and the hot reload flag was { hotReload } , path is { ModulePath } ") ;
4147
42- if ( Config . Prefix != PrefixCache )
43- PrefixCache = Config . Prefix ;
48+ PluginGlobals . Config = Config ;
4449
45- var comms = LoadCommandsFromJson ( ) ;
50+ var comms = LoadJson . LoadCommandsFromJson ( ModuleDirectory ) ;
4651
47- RegisterListeners ( ) ;
52+ EventManager . RegisterListeners ( ) ;
4853
49-
5054 if ( comms != null )
5155 {
52- comms = CheckForDuplicateCommands ( comms ) ;
56+ comms = RegisterCommands . CheckForDuplicateCommands ( comms ) ;
57+ // Add commands from the JSON file to the server
5358 foreach ( var com in comms )
54- AddCommands ( com ) ;
59+ RegisterCommands . AddCommands ( com ) ;
5560 }
56-
57- if ( hotReload )
58- InitializeLists ( ) ;
59- }
60-
61- private List < Commands > ? LoadCommandsFromJson ( )
62- {
63- string jsonPath = Path . Combine ( ModuleDirectory , "Commands.json" ) ;
64- if ( File . Exists ( jsonPath ) )
65- {
66- var json = File . ReadAllText ( jsonPath ) ;
67- return JsonSerializer . Deserialize < List < Commands > > ( json ) ;
68- }
69- else
70- {
71- Logger . LogWarning ( "No Config file found. Please create one" ) ;
72- return null ;
73- }
74- }
75-
76- private void InitializeLists ( )
77- {
78- Utilities . GetPlayers ( ) . ForEach ( controller =>
79- {
80- PlayerList . Add ( controller ) ;
81- } ) ;
8261 }
8362}
0 commit comments