1+ using System . Text . Json ;
2+ using System . Text . Json . Nodes ;
13using CounterStrikeSharp . API ;
24using CounterStrikeSharp . API . Core ;
35using CounterStrikeSharp . API . Modules . Admin ;
46using CounterStrikeSharp . API . Modules . Cvars ;
57using CounterStrikeSharp . API . Modules . Entities ;
6- using CounterStrikeSharp . API . Modules . Entities . Constants ;
78using CounterStrikeSharp . API . Modules . Utils ;
89using CustomCommands . Model ;
9-
10+ using Microsoft . Extensions . Logging ;
1011namespace CustomCommands ;
1112public partial class CustomCommands
1213{
@@ -31,7 +32,49 @@ private void RegisterListeners()
3132
3233 } ) ;
3334 }
35+ private List < Commands > CheckForDuplicateCommands ( List < Commands > comms )
36+ {
37+ List < Commands > duplicateCommands = new ( ) ;
38+ List < Commands > commands = new ( ) ;
39+ List < string > commandNames = new ( ) ;
40+
41+ foreach ( var com in comms )
42+ {
43+ string [ ] aliases = com . Command . Split ( ',' ) ;
44+
45+ foreach ( var alias in aliases )
46+ {
47+ if ( commandNames . Contains ( alias ) )
48+ {
49+ duplicateCommands . Add ( com ) ;
50+ continue ;
51+ }
52+ commandNames . Add ( alias ) ;
53+ }
54+ }
55+
56+ if ( duplicateCommands . Count == 0 )
57+ return comms ;
3458
59+ Logger . LogError ( $ "------------------------------------------------------------------------") ;
60+ Logger . LogError ( $ "{ Config . LogPrefix } Duplicate commands found, removing them from the list. Please check your config file for duplicate commands and remove them.") ;
61+ for ( int i = 0 ; i < comms . Count ; i ++ )
62+ {
63+ if ( duplicateCommands . Contains ( comms [ i ] ) )
64+ {
65+ Logger . LogError ( $ "{ Config . LogPrefix } Duplicate command found index { i + 1 } : ") ;
66+ Logger . LogError ( $ "{ Config . LogPrefix } - { comms [ i ] . Title } ") ;
67+ Logger . LogError ( $ "{ Config . LogPrefix } - { comms [ i ] . Description } ") ;
68+ Logger . LogError ( $ "{ Config . LogPrefix } - { comms [ i ] . Command } ") ;
69+ continue ;
70+ }
71+
72+ commands . Add ( comms [ i ] ) ;
73+ }
74+ Logger . LogError ( $ "------------------------------------------------------------------------") ;
75+
76+ return commands ;
77+ }
3578 private void AddCommands ( Commands com )
3679 {
3780 string [ ] aliases = com . Command . Split ( ',' ) ;
@@ -61,14 +104,14 @@ private bool RequiresPermissions(CCSPlayerController player, Permission permissi
61104 if ( AdminManager . PlayerHasPermissions ( player , new string [ ] { permission } ) )
62105 return true ;
63106 }
64- PrintToChat ( Receiver . Client , player , " You don't have the required permissions to execute this command") ;
107+ player . PrintToChat ( $ " { PrefixCache } You don't have the required permissions to execute this command") ;
65108 return false ;
66109 }
67110 else
68111 {
69112 if ( ! AdminManager . PlayerHasPermissions ( player , permissions . PermissionList . ToArray ( ) ) )
70113 {
71- PrintToChat ( Receiver . Client , player , " You don't have the required permissions to execute this command") ;
114+ player . PrintToChat ( $ " { PrefixCache } You don't have the required permissions to execute this command") ;
72115 return false ;
73116 }
74117 return true ;
@@ -116,14 +159,56 @@ private void TriggerMessage(CCSPlayerController player, Commands cmd)
116159 break ;
117160 }
118161 }
119- private string [ ] WrappedLine ( string input )
162+ private string [ ] WrappedLine ( dynamic input )
120163 {
121- return input . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ;
164+ List < string > output = new List < string > ( ) ;
165+
166+ if ( input is JsonElement jsonElement )
167+ {
168+ switch ( jsonElement . ValueKind )
169+ {
170+ case JsonValueKind . String :
171+ string result = jsonElement . GetString ( ) ! ;
172+ return result ? . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ?? Array . Empty < string > ( ) ;
173+
174+ case JsonValueKind . Array :
175+ foreach ( var arrayElement in jsonElement . EnumerateArray ( ) )
176+ {
177+ string [ ] lines = arrayElement . GetString ( ) ? . Split ( new [ ] { "\r \n " , "\r " , "\n " } , StringSplitOptions . None ) ?? Array . Empty < string > ( ) ;
178+ output . AddRange ( lines ) ;
179+ }
180+ break ;
181+
182+ default :
183+ Logger . LogError ( $ "{ Config . LogPrefix } Message is not a string or array") ;
184+ return Array . Empty < string > ( ) ;
185+ }
186+ }
187+ else
188+ {
189+ Logger . LogError ( $ "{ Config . LogPrefix } Invalid input type") ;
190+ return Array . Empty < string > ( ) ;
191+ }
192+
193+ return output . ToArray ( ) ;
194+ }
195+
196+ private string [ ] ReplaceTags ( string [ ] input , CCSPlayerController player )
197+ {
198+ string [ ] output = new string [ input . Length ] ;
199+
200+ for ( int i = 0 ; i < input . Length ; i ++ )
201+ {
202+ output [ i ] = ReplaceMessageTags ( input [ i ] , player ) ;
203+ output [ i ] = ReplaceColorTags ( output [ i ] ) ;
204+ }
205+
206+ return output ;
122207 }
123208
124209 private string ReplaceMessageTags ( string input , CCSPlayerController player )
125210 {
126- SteamID steamId = new SteamID ( ( ulong ? ) player . UserId ! . Value ?? 0 ) ;
211+ SteamID steamId = new SteamID ( player . SteamID ) ;
127212
128213 Dictionary < string , string > replacements = new ( )
129214 {
0 commit comments