Skip to content

Commit 139e34a

Browse files
committed
set some vars to var. added clone function to object
1 parent 879328c commit 139e34a

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

CustomCommands/CustomCommands.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ public override void Load(bool hotReload)
6161
{
6262
PluginGlobals.CustomCommands = comms;
6363

64-
comms = RegisterCommands.CheckForDuplicateCommands(comms);
64+
PluginGlobals.CustomCommands = RegisterCommands.CheckForDuplicateCommands(comms);
65+
6566
// Add commands from the JSON file to the server
66-
foreach (var cmd in comms)
67+
foreach (var cmd in PluginGlobals.CustomCommands)
6768
RegisterCommands.AddCommands(cmd);
6869
}
6970
}

CustomCommands/Model/CommandsConfig.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
namespace CustomCommands.Model;
22

3-
public class Commands
3+
public class Commands : ICloneable
44
{
55
public Guid ID { get; set; } = Guid.NewGuid();
6+
public string? Argument { get; set; }
67
public string Title { get; set; } = "";
78
public string Description { get; set; } = "Description";
89
public string Command { get; set; } = "";
@@ -13,18 +14,44 @@ public class Commands
1314
public List<string> ServerCommands { get; set; } = new();
1415
public List<string> ClientCommands { get; set; } = new();
1516
public List<string> ClientCommandsFromServer { get; set; } = new();
16-
public Permission Permission { get; set; } = new();
17+
public Permission? Permission { get; set; } = new();
18+
19+
public object Clone()
20+
{
21+
return new Commands()
22+
{
23+
ID = ID,
24+
Argument = Argument,
25+
Title = Title,
26+
Description = Description,
27+
Command = Command,
28+
Cooldown = Cooldown,
29+
Message = Message,
30+
CenterMessage = CenterMessage,
31+
PrintTo = PrintTo,
32+
ServerCommands = new List<string>(ServerCommands),
33+
ClientCommands = new List<string>(ClientCommands),
34+
ClientCommandsFromServer = new List<string>(ClientCommandsFromServer),
35+
Permission = Permission?.Clone() as Permission
36+
};
37+
}
1738
}
1839
public class Cooldown
1940
{
2041
public int CooldownTime { get; set; } = 0;
2142
public bool IsGlobal { get; set; } = false;
2243
public string CooldownMessage { get; set; } = "";
2344
}
24-
public class Permission
45+
public class Permission : ICloneable
2546
{
2647
public bool RequiresAllPermissions { get; set; } = false;
2748
public List<string> PermissionList { get; set; } = new();
49+
50+
public object Clone()
51+
{
52+
return MemberwiseClone();
53+
}
54+
2855
}
2956
public class CenterElement
3057
{

CustomCommands/Services/CooldownManager.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ public bool IsCommandOnCooldown(CCSPlayerController player, Commands cmd)
4242
/// <returns>True if the command is on cooldown, false otherwise.</returns>
4343
public bool IsCommandOnCooldownWithCondition(Func<CooldownTimer, bool> predicate, CCSPlayerController player, Commands cmd)
4444
{
45-
int index = PluginGlobals.CooldownTimer.FindIndex(x => predicate(x) && x.CooldownTime > DateTime.Now);
45+
var index = PluginGlobals.CooldownTimer.FindIndex(x => predicate(x) && x.CooldownTime > DateTime.Now);
4646

4747
if (index != -1)
4848
{
49-
double totalSeconds = PluginGlobals.CooldownTimer[index].CooldownTime.Subtract(DateTime.Now).TotalSeconds;
50-
int totalSecondsRounded = (int)Math.Round(totalSeconds);
51-
string timeleft = totalSecondsRounded.ToString();
52-
string message = "";
49+
var totalSeconds = (double)PluginGlobals.CooldownTimer[index].CooldownTime.Subtract(DateTime.Now).TotalSeconds;
50+
var totalSecondsRounded = (int)Math.Round(totalSeconds);
51+
var timeleft = totalSecondsRounded.ToString();
52+
var message = "";
5353

5454
// This is ugly as fuck
5555
try
5656
{
57-
Cooldown cooldown = JsonSerializer.Deserialize<Cooldown>(cmd.Cooldown.GetRawText());
57+
var cooldown = JsonSerializer.Deserialize<Cooldown>(cmd.Cooldown.GetRawText());
5858
Console.WriteLine(cooldown.CooldownMessage);
5959
string[] replaceTimeleft = {cooldown.CooldownMessage.Replace("{TIMELEFT}", timeleft)};
6060
message = ReplaceTagsFunctions.ReplaceTags(replaceTimeleft, player)[0];

0 commit comments

Comments
 (0)