1
+ using System . Text . Json ;
2
+ using System . Text . Json . Nodes ;
1
3
using CounterStrikeSharp . API ;
2
4
using CounterStrikeSharp . API . Core ;
3
5
using CounterStrikeSharp . API . Modules . Admin ;
4
6
using CounterStrikeSharp . API . Modules . Cvars ;
5
7
using CounterStrikeSharp . API . Modules . Entities ;
6
- using CounterStrikeSharp . API . Modules . Entities . Constants ;
7
8
using CounterStrikeSharp . API . Modules . Utils ;
8
9
using CustomCommands . Model ;
9
-
10
+ using Microsoft . Extensions . Logging ;
10
11
namespace CustomCommands ;
11
12
public partial class CustomCommands
12
13
{
@@ -31,7 +32,49 @@ private void RegisterListeners()
31
32
32
33
} ) ;
33
34
}
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 ;
34
58
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
+ }
35
78
private void AddCommands ( Commands com )
36
79
{
37
80
string [ ] aliases = com . Command . Split ( ',' ) ;
@@ -61,14 +104,14 @@ private bool RequiresPermissions(CCSPlayerController player, Permission permissi
61
104
if ( AdminManager . PlayerHasPermissions ( player , new string [ ] { permission } ) )
62
105
return true ;
63
106
}
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") ;
65
108
return false ;
66
109
}
67
110
else
68
111
{
69
112
if ( ! AdminManager . PlayerHasPermissions ( player , permissions . PermissionList . ToArray ( ) ) )
70
113
{
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") ;
72
115
return false ;
73
116
}
74
117
return true ;
@@ -116,14 +159,56 @@ private void TriggerMessage(CCSPlayerController player, Commands cmd)
116
159
break ;
117
160
}
118
161
}
119
- private string [ ] WrappedLine ( string input )
162
+ private string [ ] WrappedLine ( dynamic input )
120
163
{
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 ;
122
207
}
123
208
124
209
private string ReplaceMessageTags ( string input , CCSPlayerController player )
125
210
{
126
- SteamID steamId = new SteamID ( ( ulong ? ) player . UserId ! . Value ?? 0 ) ;
211
+ SteamID steamId = new SteamID ( player . SteamID ) ;
127
212
128
213
Dictionary < string , string > replacements = new ( )
129
214
{
0 commit comments