Skip to content

Commit 61b2e83

Browse files
committed
Moved replacetags to new file, rename triggermessage function
1 parent bbaca90 commit 61b2e83

File tree

2 files changed

+86
-74
lines changed

2 files changed

+86
-74
lines changed

CustomCommands/Functions.cs

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ private void AddCommands(Commands com)
9191
if (!RequiresPermissions(player, com.Permission))
9292
return;
9393

94-
TriggerMessage(player, com);
94+
SendMessage(player, com);
95+
9596
ExecuteServerCommands(com);
9697
});
9798
}
@@ -129,7 +130,8 @@ private void ExecuteServerCommands(Commands cmd)
129130
Server.ExecuteCommand(serverCommand);
130131
}
131132
}
132-
private void TriggerMessage(CCSPlayerController player, Commands cmd)
133+
134+
private void SendMessage(CCSPlayerController player, Commands cmd)
133135
{
134136
switch (cmd.PrintTo)
135137
{
@@ -161,6 +163,7 @@ private void TriggerMessage(CCSPlayerController player, Commands cmd)
161163
break;
162164
}
163165
}
166+
164167
private string[] WrappedLine(dynamic input)
165168
{
166169
List<string> output = new List<string>();
@@ -194,76 +197,4 @@ private string[] WrappedLine(dynamic input)
194197

195198
return output.ToArray();
196199
}
197-
198-
private string[] ReplaceTags(string[] input, CCSPlayerController player)
199-
{
200-
string[] output = new string[input.Length];
201-
202-
for (int i = 0; i < input.Length; i++)
203-
{
204-
output[i] = ReplaceMessageTags(input[i], player);
205-
output[i] = ReplaceColorTags(output[i]);
206-
}
207-
208-
return output;
209-
}
210-
211-
private string ReplaceMessageTags(string input, CCSPlayerController player)
212-
{
213-
SteamID steamId = new SteamID(player.SteamID);
214-
215-
Dictionary<string, string> replacements = new()
216-
{
217-
{"{PREFIX}", PrefixCache ?? "<PREFIX not found>"},
218-
{"{MAP}", NativeAPI.GetMapName() ?? "<MAP not found>"},
219-
{"{TIME}", DateTime.Now.ToString("HH:mm:ss") ?? "<TIME not found>"},
220-
{"{DATE}", DateTime.Now.ToString("dd.MM.yyyy") ?? "<DATE not found>"},
221-
{"{PLAYERNAME}", player.PlayerName ?? "<PLAYERNAME not found>"},
222-
{"{STEAMID2}", steamId.SteamId2 ?? "<STEAMID2 not found>"},
223-
{"{STEAMID3}", steamId.SteamId3 ?? "<STEAMID3 not found>"},
224-
{"{STEAMID32}", steamId.SteamId32.ToString() ?? "<STEAMID32 not found>"},
225-
{"{STEAMID64}", steamId.SteamId64.ToString() ?? "<STEAMID64 not found>"},
226-
{"{SERVERNAME}", ConVar.Find("hostname")!.StringValue ?? "<SERVERNAME not found>"},
227-
{"{IP}", ConVar.Find("ip")!.StringValue ?? "<IP not found>"},
228-
{"{PORT}", ConVar.Find("hostport")!.GetPrimitiveValue<int>().ToString() ?? "<PORT not found>"},
229-
{"{MAXPLAYERS}", Server.MaxPlayers.ToString() ?? "<MAXPLAYERS not found>"},
230-
{"{PLAYERS}",
231-
Utilities.GetPlayers().Count(u => u.PlayerPawn.Value != null && u.PlayerPawn.Value.IsValid).ToString() ?? "<PLAYERS not found>"}
232-
};
233-
234-
foreach (var pair in replacements)
235-
input = input.Replace(pair.Key, pair.Value);
236-
237-
return input;
238-
}
239-
240-
private string ReplaceColorTags(string input)
241-
{
242-
Dictionary<string, string> replacements = new()
243-
{
244-
{"{DEFAULT}", "\u0001"},
245-
{"{WHITE}", "\u0001"},
246-
{"{DARKRED}", "\u0002"},
247-
{"{RED}", "\x03"},
248-
{"{LIGHTRED}", "\u000f"},
249-
{"{GREEN}", "\u0004"},
250-
{"{LIME}", "\u0006"},
251-
{"{OLIVE}", "\u0005"},
252-
{"{ORANGE}", "\u0010"},
253-
{"{GOLD}", "\u0010"},
254-
{"{YELLOW}", "\t"},
255-
{"{BLUE}", "\v"},
256-
{"{DARKBLUE}", "\f"},
257-
{"{LIGHTPURPLE}", "\u0003"},
258-
{"{PURPLE}", "\u000e"},
259-
{"{SILVER}", $"{ChatColors.Silver}"},
260-
{"{BLUEGREY}", "\x0A"},
261-
{"{GREY}", "\x08"},
262-
};
263-
264-
foreach (var pair in replacements)
265-
input = input.Replace(pair.Key, pair.Value);
266-
267-
return input;
268-
}
269200
}

CustomCommands/ReplaceTags.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using CounterStrikeSharp.API;
2+
using CounterStrikeSharp.API.Core;
3+
using CounterStrikeSharp.API.Modules.Cvars;
4+
using CounterStrikeSharp.API.Modules.Entities;
5+
using CounterStrikeSharp.API.Modules.Utils;
6+
7+
namespace CustomCommands;
8+
public partial class CustomCommands
9+
{
10+
private string[] ReplaceTags(string[] input, CCSPlayerController player)
11+
{
12+
string[] output = new string[input.Length];
13+
14+
for (int i = 0; i < input.Length; i++)
15+
{
16+
output[i] = ReplaceMessageTags(input[i], player);
17+
output[i] = ReplaceColorTags(output[i]);
18+
}
19+
20+
return output;
21+
}
22+
23+
private string ReplaceMessageTags(string input, CCSPlayerController player)
24+
{
25+
SteamID steamId = new SteamID(player.SteamID);
26+
27+
Dictionary<string, string> replacements = new()
28+
{
29+
{"{PREFIX}", PrefixCache ?? "<PREFIX not found>"},
30+
{"{MAP}", NativeAPI.GetMapName() ?? "<MAP not found>"},
31+
{"{TIME}", DateTime.Now.ToString("HH:mm:ss") ?? "<TIME not found>"},
32+
{"{DATE}", DateTime.Now.ToString("dd.MM.yyyy") ?? "<DATE not found>"},
33+
{"{PLAYERNAME}", player.PlayerName ?? "<PLAYERNAME not found>"},
34+
{"{STEAMID2}", steamId.SteamId2 ?? "<STEAMID2 not found>"},
35+
{"{STEAMID3}", steamId.SteamId3 ?? "<STEAMID3 not found>"},
36+
{"{STEAMID32}", steamId.SteamId32.ToString() ?? "<STEAMID32 not found>"},
37+
{"{STEAMID64}", steamId.SteamId64.ToString() ?? "<STEAMID64 not found>"},
38+
{"{SERVERNAME}", ConVar.Find("hostname")!.StringValue ?? "<SERVERNAME not found>"},
39+
{"{IP}", ConVar.Find("ip")!.StringValue ?? "<IP not found>"},
40+
{"{PORT}", ConVar.Find("hostport")!.GetPrimitiveValue<int>().ToString() ?? "<PORT not found>"},
41+
{"{MAXPLAYERS}", Server.MaxPlayers.ToString() ?? "<MAXPLAYERS not found>"},
42+
{"{PLAYERS}",
43+
Utilities.GetPlayers().Count(u => u.PlayerPawn.Value != null && u.PlayerPawn.Value.IsValid).ToString() ?? "<PLAYERS not found>"}
44+
};
45+
46+
foreach (var pair in replacements)
47+
input = input.Replace(pair.Key, pair.Value);
48+
49+
return input;
50+
}
51+
52+
private string ReplaceColorTags(string input)
53+
{
54+
Dictionary<string, string> replacements = new()
55+
{
56+
{"{DEFAULT}", "\u0001"},
57+
{"{WHITE}", "\u0001"},
58+
{"{DARKRED}", "\u0002"},
59+
{"{RED}", "\x03"},
60+
{"{LIGHTRED}", "\u000f"},
61+
{"{GREEN}", "\u0004"},
62+
{"{LIME}", "\u0006"},
63+
{"{OLIVE}", "\u0005"},
64+
{"{ORANGE}", "\u0010"},
65+
{"{GOLD}", "\u0010"},
66+
{"{YELLOW}", "\t"},
67+
{"{BLUE}", "\v"},
68+
{"{DARKBLUE}", "\f"},
69+
{"{LIGHTPURPLE}", "\u0003"},
70+
{"{PURPLE}", "\u000e"},
71+
{"{SILVER}", $"{ChatColors.Silver}"},
72+
{"{BLUEGREY}", "\x0A"},
73+
{"{GREY}", "\x08"},
74+
};
75+
76+
foreach (var pair in replacements)
77+
input = input.Replace(pair.Key, pair.Value);
78+
79+
return input;
80+
}
81+
}

0 commit comments

Comments
 (0)