Skip to content

Commit d57eeb7

Browse files
committed
fixed infinite depnc loop, fixed example file error message
1 parent ab31dd1 commit d57eeb7

File tree

7 files changed

+54
-52
lines changed

7 files changed

+54
-52
lines changed

CustomCommands/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/.vs
22
/bin
3-
/obj
3+
/obj
4+
5+
TestingCommands.json

CustomCommands/Interfaces/IPluginUtilities.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ public interface IPluginUtilities
88
string[] SplitStringByCommaOrSemicolon(string str);
99
void ExecuteServerCommands(Commands cmd, CCSPlayerController player);
1010
bool RequiresPermissions(CCSPlayerController player, Permission permissions);
11-
string PadLeftColorTag(string input);
1211
}

CustomCommands/Services/LoadJson.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ public List<Commands> GetCommandsFromJsonFiles(string path)
1818
{
1919
var comms = new List<Commands>();
2020

21+
string defaultconfigpath = Path.Combine(path, "Commands.json");
22+
2123
CheckForExampleFile(path);
2224

2325
var pathofcommands = Path.Combine(path, "Commands");
24-
var defaultconfigpath = Path.Combine(path, "Commands.json");
2526

2627
var files = new List<string>();
2728

@@ -34,7 +35,6 @@ public List<Commands> GetCommandsFromJsonFiles(string path)
3435
files.Add(defaultconfigpath);
3536
Logger.LogInformation("Found default config file.");
3637
}
37-
//
3838
else if (!File.Exists(defaultconfigpath) && files.Count == 0)
3939
{
4040
Logger.LogWarning("No Config file found. Please create plugins/CustomCommands/Commands.json or in plugins/CustomCommands/Commands/<name>.json");
@@ -58,14 +58,20 @@ public List<Commands> GetCommandsFromJsonFiles(string path)
5858
// Check if the Command.json file exists. If not replace it with the example file
5959
public void CheckForExampleFile(string path)
6060
{
61+
if (Directory.Exists(Path.Combine(path, "Commands")))
62+
{
63+
var files = Directory.GetFiles(Path.Combine(path, "Commands"), "*.json", SearchOption.AllDirectories);
64+
if (files.Length > 0)
65+
return;
66+
}
67+
6168
var defaultconfigpath = Path.Combine(path, "Commands.json");
6269
var exampleconfigpath = Path.Combine(path, "Commands.example.json");
6370
if (!File.Exists(defaultconfigpath))
6471
{
6572
File.Copy(exampleconfigpath, defaultconfigpath);
6673
Logger.LogInformation("Created default config file.");
6774
}
68-
6975
}
7076
public bool IsValidJsonSyntax(string path)
7177
{

CustomCommands/Services/PluginUtilities.cs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -98,41 +98,4 @@ public bool RequiresPermissions(CCSPlayerController player, Permission permissio
9898
return true;
9999
}
100100
}
101-
/// <summary>
102-
/// Moves the color tag one space the the left if it's not already there.
103-
/// Because the game doesn't support color tags at the start of a string.
104-
/// </summary>
105-
/// <param name="input"></param>
106-
/// <returns></returns>
107-
public string PadLeftColorTag(string input)
108-
{
109-
string[] colorTagList = new string[] {
110-
"{DEFAULT}",
111-
"{WHITE}",
112-
"{DARKRED}",
113-
"{RED}",
114-
"{LIGHTRED}",
115-
"{GREEN}",
116-
"{LIME}",
117-
"{OLIVE}",
118-
"{ORANGE}",
119-
"{GOLD}",
120-
"{YELLOW}",
121-
"{BLUE}",
122-
"{DARKBLUE}",
123-
"{LIGHTPURPLE}",
124-
"{PURPLE}",
125-
"{SILVER}",
126-
"{BLUEGREY}",
127-
"{GREY}",
128-
};
129-
foreach (var colorTag in colorTagList)
130-
{
131-
if (input.StartsWith(colorTag))
132-
{
133-
return " " + input;
134-
}
135-
}
136-
return input;
137-
}
138101
}

CustomCommands/Services/RegisterCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public void AddCommands(Commands com)
3838
if (player == null) return;
3939

4040
var command = com;
41+
42+
Logger.LogInformation(info.ArgCount.ToString());
4143
if (info.ArgCount > 0)
42-
{
4344
command = PluginGlobals.CustomCommands.Find(x => x.Command.Contains(aliases[i])) ?? com;
44-
}
4545

4646
if (command.Permission.PermissionList.Count > 0 && command.Permission != null)
4747
if (!PluginUtilities.RequiresPermissions(player, command.Permission))

CustomCommands/Services/ReplaceTagsFunction.cs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@ public class ReplaceTagsFunctions : IReplaceTagsFunctions
1515
private readonly IPluginGlobals PluginGlobals;
1616
private readonly PluginContext PluginContext;
1717
private readonly ILogger<CustomCommands> Logger;
18-
private readonly IPluginUtilities PluginUtilities;
1918

2019
public ReplaceTagsFunctions(IPluginGlobals PluginGlobals, IPluginContext PluginContext,
21-
ILogger<CustomCommands> Logger, IPluginUtilities PluginUtilities)
20+
ILogger<CustomCommands> Logger)
2221
{
2322
this.PluginGlobals = PluginGlobals;
2423
this.PluginContext = (PluginContext as PluginContext)!;
2524
this.Logger = Logger;
26-
this.PluginUtilities = PluginUtilities;
2725
}
2826

2927
public string[] ReplaceTags(string[] input, CCSPlayerController player)
@@ -96,7 +94,7 @@ public string ReplaceMessageTags(string input, CCSPlayerController player)
9694
public string ReplaceColorTags(string input)
9795
{
9896
// PadLeft the color tag if it's not already there because the game doesn't support color tags at the start of a string.
99-
input = PluginUtilities.PadLeftColorTag(input);
97+
input = PadLeftColorTag(input);
10098

10199
Dictionary<string, string> replacements = new()
102100
{
@@ -164,4 +162,42 @@ public string[] WrappedLine(dynamic input)
164162

165163
return output.ToArray();
166164
}
165+
166+
/// <summary>
167+
/// Moves the color tag one space the the left if it's not already there.
168+
/// Because the game doesn't support color tags at the start of a string.
169+
/// </summary>
170+
/// <param name="input"></param>
171+
/// <returns></returns>
172+
private string PadLeftColorTag(string input)
173+
{
174+
string[] colorTagList = new string[] {
175+
"{DEFAULT}",
176+
"{WHITE}",
177+
"{DARKRED}",
178+
"{RED}",
179+
"{LIGHTRED}",
180+
"{GREEN}",
181+
"{LIME}",
182+
"{OLIVE}",
183+
"{ORANGE}",
184+
"{GOLD}",
185+
"{YELLOW}",
186+
"{BLUE}",
187+
"{DARKBLUE}",
188+
"{LIGHTPURPLE}",
189+
"{PURPLE}",
190+
"{SILVER}",
191+
"{BLUEGREY}",
192+
"{GREY}",
193+
};
194+
foreach (var colorTag in colorTagList)
195+
{
196+
if (input.StartsWith(colorTag))
197+
{
198+
return " " + input;
199+
}
200+
}
201+
return input;
202+
}
167203
}

CustomCommands/test.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,3 @@
99
* [ ] check if command args works
1010
* [ ] check if duplicated commands still wont work with this feature
1111
* [ ] check if toggle feature works
12-
13-
14-
15-
test

0 commit comments

Comments
 (0)