7
7
namespace CustomCommands . Services ;
8
8
public class RegisterCommands : IRegisterCommands
9
9
{
10
- private readonly ILogger < CustomCommands > Logger ;
11
- private readonly IMessageManager MessageManager ;
12
- private readonly IPluginGlobals PluginGlobals ;
13
- private readonly PluginContext PluginContext ;
14
- private readonly IPluginUtilities PluginUtilities ;
15
- private readonly ICooldownManager CooldownManager ;
10
+ private readonly ILogger < CustomCommands > _logger ;
11
+ private readonly IMessageManager _messageManager ;
12
+ private readonly IPluginGlobals _pluginGlobals ;
13
+ private readonly PluginContext _pluginContext ;
14
+ private readonly IPluginUtilities _pluginUtilities ;
15
+ private readonly ICooldownManager _cooldownManager ;
16
16
17
17
public RegisterCommands ( ILogger < CustomCommands > Logger , IMessageManager MessageManager ,
18
18
IPluginGlobals PluginGlobals , IPluginContext PluginContext ,
19
19
IPluginUtilities PluginUtilities , ICooldownManager CooldownManager )
20
20
{
21
- this . Logger = Logger ;
22
- this . MessageManager = MessageManager ;
23
- this . PluginGlobals = PluginGlobals ;
24
- this . PluginContext = ( PluginContext as PluginContext ) ! ;
25
- this . PluginUtilities = PluginUtilities ;
26
- this . CooldownManager = CooldownManager ;
21
+ _logger = Logger ;
22
+ _messageManager = MessageManager ;
23
+ _pluginGlobals = PluginGlobals ;
24
+ _pluginContext = ( PluginContext as PluginContext ) ! ;
25
+ _pluginUtilities = PluginUtilities ;
26
+ _cooldownManager = CooldownManager ;
27
27
}
28
28
29
29
public void AddCommands ( Commands cmd )
30
30
{
31
31
if ( ! cmd . IsRegisterable )
32
32
return ;
33
33
34
- var pluginContext = ( PluginContext . Plugin as CustomCommands ) ! ;
35
-
36
- pluginContext . AddCommand ( cmd . Command , cmd . Description ,
34
+ var context = ( _pluginContext . Plugin as CustomCommands ) ! ;
35
+
36
+ context . AddCommand ( cmd . Command , cmd . Description ,
37
37
[ CommandHelper ( whoCanExecute : CommandUsage . CLIENT_ONLY ) ]
38
38
( player , info ) =>
39
39
{
@@ -45,7 +45,7 @@ public void AddCommands(Commands cmd)
45
45
// Check if the command has arguments and if it does, check if the command exists and is the right one
46
46
if ( info . ArgCount > 1 )
47
47
{
48
- var findcommand = PluginGlobals . CustomCommands . Find ( x => x . Command == command . Command && x . Argument == info . ArgString ) ;
48
+ var findcommand = _pluginGlobals . CustomCommands . Find ( x => x . Command == command . Command && x . Argument == info . ArgString ) ;
49
49
// Check if the command is the right one with the right arguments
50
50
if ( findcommand is null )
51
51
{
@@ -71,32 +71,32 @@ public void AddCommands(Commands cmd)
71
71
72
72
// Check if the player has the permission to use the command
73
73
if ( command ! . Permission ? . PermissionList . Count > 0 && command . Permission != null )
74
- if ( ! PluginUtilities . RequiresPermissions ( player , command . Permission ) )
74
+ if ( ! _pluginUtilities . RequiresPermissions ( player , command . Permission ) )
75
75
return ;
76
76
77
77
// Check if the command is on cooldown
78
- if ( CooldownManager . IsCommandOnCooldown ( player , command ) ) return ;
78
+ if ( _cooldownManager . IsCommandOnCooldown ( player , command ) ) return ;
79
79
80
80
// Set the cooldown for the command if it has a cooldown set
81
- CooldownManager . SetCooldown ( player , command ) ;
81
+ _cooldownManager . SetCooldown ( player , command ) ;
82
82
83
83
// Sending the message to the player
84
- MessageManager . SendMessage ( player , command ) ;
85
-
86
- // Execute the server commands
87
- PluginUtilities . ExecuteServerCommands ( command , player ) ;
84
+ _messageManager . SendMessage ( player , command ) ;
88
85
89
86
// Execute the client commands
90
- PluginUtilities . ExecuteClientCommands ( command , player ) ;
87
+ _pluginUtilities . ExecuteClientCommands ( command , player ) ;
91
88
92
89
// Execute the client commands from the server
93
- PluginUtilities . ExecuteClientCommandsFromServer ( command , player ) ;
90
+ _pluginUtilities . ExecuteClientCommandsFromServer ( command , player ) ;
91
+
92
+ // Execute the server commands
93
+ _pluginUtilities . ExecuteServerCommands ( command , player ) ;
94
94
} ) ;
95
95
}
96
96
97
97
public void CheckForDuplicateCommands ( )
98
98
{
99
- var comms = PluginGlobals . CustomCommands ;
99
+ var comms = _pluginGlobals . CustomCommands ;
100
100
var duplicateCommands = new List < Commands > ( ) ;
101
101
var commandNames = new List < string > ( ) ;
102
102
@@ -119,32 +119,32 @@ public void CheckForDuplicateCommands()
119
119
return ;
120
120
121
121
// Log the duplicate commands
122
- Logger . LogError ( $ "------------------------------------------------------------------------") ;
123
- Logger . LogError ( $ "{ PluginGlobals . Config . LogPrefix } Duplicate commands found, removing them from the list. Please check your config file for duplicate commands and remove them.") ;
122
+ _logger . LogError ( $ "------------------------------------------------------------------------") ;
123
+ _logger . LogError ( $ "{ _pluginGlobals . Config . LogPrefix } Duplicate commands found, removing them from the list. Please check your config file for duplicate commands and remove them.") ;
124
124
for ( int i = 0 ; i < comms . Count ; i ++ )
125
125
{
126
126
if ( duplicateCommands . Contains ( comms [ i ] ) )
127
127
{
128
- Logger . LogError ( $ "{ PluginGlobals . Config . LogPrefix } Duplicate command found index { i + 1 } : ") ;
129
- Logger . LogError ( $ "{ PluginGlobals . Config . LogPrefix } - { comms [ i ] . Title } ") ;
130
- Logger . LogError ( $ "{ PluginGlobals . Config . LogPrefix } - { comms [ i ] . Description } ") ;
131
- Logger . LogError ( $ "{ PluginGlobals . Config . LogPrefix } - { comms [ i ] . Command } ") ;
128
+ _logger . LogError ( $ "{ _pluginGlobals . Config . LogPrefix } Duplicate command found index { i + 1 } : ") ;
129
+ _logger . LogError ( $ "{ _pluginGlobals . Config . LogPrefix } - { comms [ i ] . Title } ") ;
130
+ _logger . LogError ( $ "{ _pluginGlobals . Config . LogPrefix } - { comms [ i ] . Description } ") ;
131
+ _logger . LogError ( $ "{ _pluginGlobals . Config . LogPrefix } - { comms [ i ] . Command } ") ;
132
132
continue ;
133
133
}
134
134
135
135
comms . Add ( comms [ i ] ) ;
136
136
}
137
- Logger . LogError ( $ "------------------------------------------------------------------------") ;
137
+ _logger . LogError ( $ "------------------------------------------------------------------------") ;
138
138
}
139
139
140
140
public void ConvertingCommandsForRegister ( )
141
141
{
142
142
var newCmds = new List < Commands > ( ) ;
143
143
144
- foreach ( var cmd in PluginGlobals . CustomCommands )
144
+ foreach ( var cmd in _pluginGlobals . CustomCommands )
145
145
{
146
- var splitCommands = PluginUtilities . SplitStringByCommaOrSemicolon ( cmd . Command ) ;
147
- splitCommands = PluginUtilities . AddCSSTagsToAliases ( splitCommands . ToList ( ) ) ;
146
+ var splitCommands = _pluginUtilities . SplitStringByCommaOrSemicolon ( cmd . Command ) ;
147
+ splitCommands = _pluginUtilities . AddCSSTagsToAliases ( splitCommands . ToList ( ) ) ;
148
148
149
149
foreach ( var split in splitCommands )
150
150
{
@@ -173,6 +173,6 @@ public void ConvertingCommandsForRegister()
173
173
}
174
174
}
175
175
176
- PluginGlobals . CustomCommands = newCmds ;
176
+ _pluginGlobals . CustomCommands = newCmds ;
177
177
}
178
178
}
0 commit comments