Skip to content

Commit 149f9af

Browse files
committed
Duplication Check
1 parent 58c048f commit 149f9af

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

CustomCommands/Functions.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using CounterStrikeSharp.API.Modules.Entities.Constants;
77
using CounterStrikeSharp.API.Modules.Utils;
88
using CustomCommands.Model;
9+
using Microsoft.Extensions.Logging;
10+
using Serilog;
911

1012
namespace CustomCommands;
1113
public partial class CustomCommands
@@ -31,7 +33,49 @@ private void RegisterListeners()
3133

3234
});
3335
}
36+
private List<Commands> CheckForDuplicateCommands(List<Commands> comms)
37+
{
38+
List<Commands> duplicateCommands = new();
39+
List<Commands> commands = new();
40+
List<string> commandNames = new();
41+
42+
foreach (var com in comms)
43+
{
44+
string[] aliases = com.Command.Split(',');
45+
46+
foreach (var alias in aliases)
47+
{
48+
if (commandNames.Contains(alias))
49+
{
50+
duplicateCommands.Add(com);
51+
continue;
52+
}
53+
commandNames.Add(alias);
54+
}
55+
}
56+
57+
if (duplicateCommands.Count == 0)
58+
return comms;
3459

60+
Logger.LogError($"------------------------------------------------------------------------");
61+
Logger.LogError($"{Config.LogPrefix} Duplicate commands found, removing them from the list. Please check your config file for duplicate commands and remove them.");
62+
for (int i = 0; i < comms.Count; i++)
63+
{
64+
if(duplicateCommands.Contains(comms[i]))
65+
{
66+
Logger.LogError($"{Config.LogPrefix} Duplicate command found index {i+1}: ");
67+
Logger.LogError($"{Config.LogPrefix} - {comms[i].Title} ");
68+
Logger.LogError($"{Config.LogPrefix} - {comms[i].Description}");
69+
Logger.LogError($"{Config.LogPrefix} - {comms[i].Command}");
70+
continue;
71+
}
72+
73+
commands.Add(comms[i]);
74+
}
75+
Logger.LogError($"------------------------------------------------------------------------");
76+
77+
return commands;
78+
}
3579
private void AddCommands(Commands com)
3680
{
3781
string[] aliases = com.Command.Split(',');
@@ -123,7 +167,7 @@ private string[] WrappedLine(string input)
123167

124168
private string ReplaceMessageTags(string input, CCSPlayerController player)
125169
{
126-
SteamID steamId = new SteamID((ulong?)player.UserId!.Value ?? 0);
170+
SteamID steamId = new SteamID(player.SteamID);
127171

128172
Dictionary<string, string> replacements = new()
129173
{

0 commit comments

Comments
 (0)