Skip to content

Commit 2673a93

Browse files
committed
2 parents 12258fb + 02d8e16 commit 2673a93

File tree

7 files changed

+63
-16
lines changed

7 files changed

+63
-16
lines changed

CustomCommands/Interfaces/IPluginUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IPluginUtilities
1818
/// </summary>
1919
/// <param name="input"></param>
2020
/// <returns></returns>
21-
string[] AddCSSTagsToAliases(string[] input);
21+
string[] AddCSSTagsToAliases(List<string> input);
2222

2323
/// <summary>
2424
/// Splits a string by comma, semicolon, or whitespace characters.

CustomCommands/Services/MessageManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void PrintToCenterClient(CCSPlayerController player, Commands cmd)
6060
{
6161
CustomCommands plugin = (PluginContext.Plugin as CustomCommands)!;
6262

63-
string message = ReplaceTagsFunctions.ReplaceLanguageTags(cmd.Message);
63+
string message = ReplaceTagsFunctions.ReplaceLanguageTags(cmd.CenterMessage.Message);
6464
message = ReplaceTagsFunctions.ReplaceMessageTags(message, player);
6565

6666
var CenterClientElement = new CenterClientElement

CustomCommands/Services/PluginUtilities.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,63 @@ public PluginUtilities(IPluginGlobals PluginGlobals, IReplaceTagsFunctions Repla
2626
public string[] GettingCommandsFromString(string commands)
2727
{
2828
string[] splitCommands = SplitStringByCommaOrSemicolon(commands);
29+
List<string> commandsList = new List<string>();
30+
// Removes arguments from the command when spaces are present
31+
for (int i = 0; i < splitCommands.Length; i++)
32+
{
33+
if (splitCommands[i].Contains(' '))
34+
{
35+
Logger.LogInformation($"Contains space!");
36+
if (splitCommands[i].IndexOf(' ') == 0)
37+
{
38+
commandsList.Add(splitCommands[i]);
39+
continue;
40+
}
41+
Logger.LogInformation($"Is multiple args");
42+
string sub = splitCommands[i].Substring(0, splitCommands[i].IndexOf(' '));
43+
Logger.LogInformation($"Sub: {sub}");
44+
if (commandsList.Contains(sub))
45+
{
46+
Logger.LogInformation("In IF");
47+
continue;
48+
}
49+
50+
if (!contains)
51+
commandsList.Add(sub);
52+
}
53+
else
54+
{
55+
if (!commandsList.Contains(splitCommands[i]))
56+
commandsList.Add(splitCommands[i]);
57+
}
58+
}
59+
60+
61+
foreach (var command in commandsList)
62+
{
63+
Logger.LogInformation($"Command: {command}");
64+
}
2965

3066
if (PluginGlobals.Config.RegisterCommandsAsCSSFramework)
31-
return AddCSSTagsToAliases(splitCommands);
67+
return AddCSSTagsToAliases(commandsList);
3268

33-
return splitCommands;
69+
70+
return commandsList.ToArray();
3471
}
3572

36-
public string[] AddCSSTagsToAliases(string[] input)
73+
public string[] AddCSSTagsToAliases(List<string> input)
3774
{
38-
for (int i = 0; i < input.Length; i++)
75+
for (int i = 0; i < input.Count; i++)
3976
{
4077
if (!input[i].StartsWith("css_"))
4178
input[i] = "css_" + input[i];
4279
}
43-
return input;
80+
return input.ToArray();
4481
}
4582

4683
public string[] SplitStringByCommaOrSemicolon(string str)
4784
{
48-
return Regex.Split(str, ",|;|\\s")
85+
return Regex.Split(str, "[,;]")
4986
.Where(s => !string.IsNullOrEmpty(s))
5087
.ToArray();
5188
}

CustomCommands/Services/RegisterCommands.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ public void AddCommands(Commands cmd)
3838

3939
for (int i = 0; i < aliases.Length; i++)
4040
{
41-
plugin.AddCommand(aliases[i], cmd.Description,
41+
string alias = aliases[i];
42+
// System.Console.WriteLine($"Pre Command: {alias}.");
43+
plugin.AddCommand(alias, cmd.Description,
4244
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
4345
(player, info) =>
4446
{
4547
if (player == null)
4648
return;
47-
48-
if (info.ArgCount < aliases[i].Split(' ').Length)
49+
System.Console.WriteLine($"Post Command: {alias}.");
50+
51+
if (info.ArgCount < alias.Split(' ').Length)
4952
{
50-
player.PrintToChat($"This command requires at least {aliases[i].Split(' ').Length-1} arguments.");
53+
player.PrintToChat($"This command requires at least {alias.Split(' ').Length-1} arguments.");
5154
return;
5255
}
5356

@@ -56,7 +59,7 @@ public void AddCommands(Commands cmd)
5659
// Check if the command has arguments and if it does, check if the command really exists in the list
5760
if (info.ArgCount > 1)
5861
{
59-
var findcommand = PluginGlobals.CustomCommands.Find(x => x.Command.Contains(aliases[i] + $" {info.ArgString}"));
62+
var findcommand = PluginGlobals.CustomCommands.Find(x => x.Command.Contains(alias + $" {info.ArgString}"));
6063
// Check if the command is equal to the found command
6164
if (findcommand! != command)
6265
return;

CustomCommands/Services/ReplaceTagsFunction.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public string[] ReplaceTags(dynamic input, CCSPlayerController player)
3737
List<string> output = WrappedLine(input);
3838

3939
for (int i = 0; i < output.Count; i++)
40-
output[i] = ReplaceLanguageTags(input[i]);
40+
output[i] = ReplaceLanguageTags(output[i]);
4141

4242
output = WrappedLine(output.ToArray());
4343

@@ -184,6 +184,13 @@ public List<string> WrappedLine(dynamic input)
184184
Logger.LogError($"{PluginGlobals.Config.LogPrefix} Message is not a string or array");
185185
break;
186186
}
187+
} else if (input is Array inputArray)
188+
{
189+
foreach (string arrayElement in inputArray)
190+
{
191+
string[] lines = arrayElement.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None) ?? Array.Empty<string>();
192+
output.AddRange(lines);
193+
}
187194
}
188195
else
189196
{

Examples/Cooldown.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ In the Advanced command example you can add a "IsGlobal" flag so the whole serve
2626
"Cooldown": {
2727
"CooldownTime": 5, // required, Cooldown in seconds
2828
"IsGlobal": false, // If true, cooldown will be global for all users
29-
"CooldownMessage": "This command is on cooldown for {TIME} more seconds!"
29+
"CooldownMessage": "This command is on cooldown for {TIMELEFT} more seconds!"
3030
},
3131
"Message": "Cool cooldown message!",
3232
"PrintTo": 0

Examples/ServerCommands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Its always recommended to Permission to the command so not every player can use
5959
"Message": "Getting Kicked",
6060
"PrintTo": 0,
6161
"ServerCommands": [
62-
"kick {USERID}" // Tags work for commands as well
62+
"css_kick #{USERID}" // Tags work for commands as well. This command works with Simple Admin
6363
]
6464
}
6565
]

0 commit comments

Comments
 (0)