77namespace CustomCommands . Services ;
88public class RegisterCommands : IRegisterCommands
99{
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 ;
1616
1717 public RegisterCommands ( ILogger < CustomCommands > Logger , IMessageManager MessageManager ,
1818 IPluginGlobals PluginGlobals , IPluginContext PluginContext ,
1919 IPluginUtilities PluginUtilities , ICooldownManager CooldownManager )
2020 {
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 ;
2727 }
2828
2929 public void AddCommands ( Commands cmd )
3030 {
3131 if ( ! cmd . IsRegisterable )
3232 return ;
3333
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 ,
3737 [ CommandHelper ( whoCanExecute : CommandUsage . CLIENT_ONLY ) ]
3838 ( player , info ) =>
3939 {
@@ -45,7 +45,7 @@ public void AddCommands(Commands cmd)
4545 // Check if the command has arguments and if it does, check if the command exists and is the right one
4646 if ( info . ArgCount > 1 )
4747 {
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 ) ;
4949 // Check if the command is the right one with the right arguments
5050 if ( findcommand is null )
5151 {
@@ -71,32 +71,32 @@ public void AddCommands(Commands cmd)
7171
7272 // Check if the player has the permission to use the command
7373 if ( command ! . Permission ? . PermissionList . Count > 0 && command . Permission != null )
74- if ( ! PluginUtilities . RequiresPermissions ( player , command . Permission ) )
74+ if ( ! _pluginUtilities . RequiresPermissions ( player , command . Permission ) )
7575 return ;
7676
7777 // Check if the command is on cooldown
78- if ( CooldownManager . IsCommandOnCooldown ( player , command ) ) return ;
78+ if ( _cooldownManager . IsCommandOnCooldown ( player , command ) ) return ;
7979
8080 // Set the cooldown for the command if it has a cooldown set
81- CooldownManager . SetCooldown ( player , command ) ;
81+ _cooldownManager . SetCooldown ( player , command ) ;
8282
8383 // 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 ) ;
8885
8986 // Execute the client commands
90- PluginUtilities . ExecuteClientCommands ( command , player ) ;
87+ _pluginUtilities . ExecuteClientCommands ( command , player ) ;
9188
9289 // 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 ) ;
9494 } ) ;
9595 }
9696
9797 public void CheckForDuplicateCommands ( )
9898 {
99- var comms = PluginGlobals . CustomCommands ;
99+ var comms = _pluginGlobals . CustomCommands ;
100100 var duplicateCommands = new List < Commands > ( ) ;
101101 var commandNames = new List < string > ( ) ;
102102
@@ -119,32 +119,32 @@ public void CheckForDuplicateCommands()
119119 return ;
120120
121121 // 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.") ;
124124 for ( int i = 0 ; i < comms . Count ; i ++ )
125125 {
126126 if ( duplicateCommands . Contains ( comms [ i ] ) )
127127 {
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 } ") ;
132132 continue ;
133133 }
134134
135135 comms . Add ( comms [ i ] ) ;
136136 }
137- Logger . LogError ( $ "------------------------------------------------------------------------") ;
137+ _logger . LogError ( $ "------------------------------------------------------------------------") ;
138138 }
139139
140140 public void ConvertingCommandsForRegister ( )
141141 {
142142 var newCmds = new List < Commands > ( ) ;
143143
144- foreach ( var cmd in PluginGlobals . CustomCommands )
144+ foreach ( var cmd in _pluginGlobals . CustomCommands )
145145 {
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 ( ) ) ;
148148
149149 foreach ( var split in splitCommands )
150150 {
@@ -173,6 +173,6 @@ public void ConvertingCommandsForRegister()
173173 }
174174 }
175175
176- PluginGlobals . CustomCommands = newCmds ;
176+ _pluginGlobals . CustomCommands = newCmds ;
177177 }
178178}
0 commit comments