1
- using CounterStrikeSharp . API ;
2
- using CounterStrikeSharp . API . Core ;
1
+ using CounterStrikeSharp . API . Core ;
3
2
using CounterStrikeSharp . API . Core . Attributes ;
4
- using CounterStrikeSharp . API . Modules . Utils ;
5
- using CustomCommands . Model ;
3
+ using CustomCommands . Interfaces ;
6
4
using Microsoft . Extensions . Logging ;
7
- using System . Text . Json ;
8
5
9
6
namespace CustomCommands ;
10
7
11
- [ MinimumApiVersion ( 98 ) ]
8
+ [ MinimumApiVersion ( 142 ) ]
12
9
public partial class CustomCommands : BasePlugin , IPluginConfig < CustomCommandsConfig >
13
10
{
14
11
public override string ModuleName => "CustomCommands" ;
15
- public override string ModuleVersion => "1.0.7 " ;
12
+ public override string ModuleVersion => "1.0.8 " ;
16
13
public override string ModuleAuthor => "HerrMagic" ;
17
14
public override string ModuleDescription => "Create your own commands per config" ;
18
15
19
- private List < CenterClientElement > centerClientOn = new ( ) ;
20
- private CenterServerElement centerServerOn = new ( ) ;
21
-
22
- private List < CCSPlayerController > PlayerList = new ( ) ;
23
16
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
+ }
25
31
26
32
public void OnConfigParsed ( CustomCommandsConfig config )
27
33
{
@@ -32,52 +38,25 @@ public override void Load(bool hotReload)
32
38
{
33
39
if ( ! Config . IsPluginEnabled )
34
40
{
35
- Console . WriteLine ( $ "{ Config . LogPrefix } { ModuleName } is disabled") ;
41
+ Logger . LogInformation ( $ "{ Config . LogPrefix } { ModuleName } is disabled") ;
36
42
return ;
37
43
}
38
-
39
- Console . WriteLine (
44
+
45
+ Logger . LogInformation (
40
46
$ "CustomCommands has been loaded, and the hot reload flag was { hotReload } , path is { ModulePath } ") ;
41
47
42
- if ( Config . Prefix != PrefixCache )
43
- PrefixCache = Config . Prefix ;
48
+ PluginGlobals . Config = Config ;
44
49
45
- var comms = LoadCommandsFromJson ( ) ;
50
+ var comms = LoadJson . LoadCommandsFromJson ( ModuleDirectory ) ;
46
51
47
- RegisterListeners ( ) ;
52
+ EventManager . RegisterListeners ( ) ;
48
53
49
-
50
54
if ( comms != null )
51
55
{
52
- comms = CheckForDuplicateCommands ( comms ) ;
56
+ comms = RegisterCommands . CheckForDuplicateCommands ( comms ) ;
57
+ // Add commands from the JSON file to the server
53
58
foreach ( var com in comms )
54
- AddCommands ( com ) ;
59
+ RegisterCommands . AddCommands ( com ) ;
55
60
}
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
- } ) ;
82
61
}
83
62
}
0 commit comments