|
| 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 |
| -using Serilog; |
11 |
| - |
12 | 11 | namespace CustomCommands;
|
13 | 12 | public partial class CustomCommands
|
14 | 13 | {
|
@@ -105,14 +104,14 @@ private bool RequiresPermissions(CCSPlayerController player, Permission permissi
|
105 | 104 | if (AdminManager.PlayerHasPermissions(player, new string[]{permission}))
|
106 | 105 | return true;
|
107 | 106 | }
|
108 |
| - 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"); |
109 | 108 | return false;
|
110 | 109 | }
|
111 | 110 | else
|
112 | 111 | {
|
113 | 112 | if (!AdminManager.PlayerHasPermissions(player, permissions.PermissionList.ToArray()))
|
114 | 113 | {
|
115 |
| - 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"); |
116 | 115 | return false;
|
117 | 116 | }
|
118 | 117 | return true;
|
@@ -160,9 +159,51 @@ private void TriggerMessage(CCSPlayerController player, Commands cmd)
|
160 | 159 | break;
|
161 | 160 | }
|
162 | 161 | }
|
163 |
| - private string[] WrappedLine(string input) |
| 162 | + private string[] WrappedLine(dynamic input) |
164 | 163 | {
|
165 |
| - 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; |
166 | 207 | }
|
167 | 208 |
|
168 | 209 | private string ReplaceMessageTags(string input, CCSPlayerController player)
|
|
0 commit comments