Skip to content

Commit 06b0532

Browse files
authored
Merge a88c773 into 55b137e
2 parents 55b137e + a88c773 commit 06b0532

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

Diff for: CustomCommands/Services/CooldownManager.cs

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using CounterStrikeSharp.API.Core;
3+
using CounterStrikeSharp.API.Modules.Entities.Constants;
34
using CustomCommands.Model;
45
using Microsoft.Extensions.Logging;
56

@@ -8,9 +9,11 @@ namespace CustomCommands.Interfaces;
89
public class CooldownManager : ICooldownManager
910
{
1011
public IPluginGlobals PluginGlobals { get; }
11-
public CooldownManager(IPluginGlobals PluginGlobals)
12+
public IReplaceTagsFunctions ReplaceTagsFunctions { get; }
13+
public CooldownManager(IPluginGlobals PluginGlobals, IReplaceTagsFunctions ReplaceTagsFunctions)
1214
{
1315
this.PluginGlobals = PluginGlobals;
16+
this.ReplaceTagsFunctions = ReplaceTagsFunctions;
1417
}
1518

1619
/// <summary>
@@ -38,15 +41,25 @@ public bool IsCommandOnCooldownWithCondition(Func<CooldownTimer, bool> predicate
3841

3942
if (index != -1)
4043
{
41-
string timeleft = PluginGlobals.CooldownTimer[index].CooldownTime.Subtract(DateTime.Now).Seconds.ToString();
42-
string message = "";
44+
double totalSeconds = PluginGlobals.CooldownTimer[index].CooldownTime.Subtract(DateTime.Now).TotalSeconds;
45+
int totalSecondsRounded = (int)Math.Round(totalSeconds);
46+
string timeleft = totalSecondsRounded.ToString();
4347

44-
// Check if cmd.Cooldown is a Cooldown object
45-
if (cmd.Cooldown is Cooldown cooldown)
46-
message = cooldown.CooldownMessage.Replace("{TIME}", timeleft);
47-
else
48+
string message = "";
49+
50+
// This is ugly as fuck
51+
try
52+
{
53+
Cooldown cooldown = JsonSerializer.Deserialize<Cooldown>(cmd.Cooldown.GetRawText());
54+
Console.WriteLine(cooldown.CooldownMessage);
55+
string[] replaceTimeleft = {cooldown.CooldownMessage.Replace("{TIMELEFT}", timeleft)};
56+
message = ReplaceTagsFunctions.ReplaceTags(replaceTimeleft, player)[0];
57+
}
58+
catch (JsonException)
59+
{
4860
message = $"This command is for {timeleft} seconds on cooldown";
49-
61+
}
62+
5063
player.PrintToChat($"{PluginGlobals.Config.Prefix}{message}");
5164

5265
return true;
@@ -69,10 +82,9 @@ public void AddToCooldownList(bool isGlobal, int playerID, Guid commandID, int c
6982
CommandID = commandID,
7083
CooldownTime = DateTime.Now.AddSeconds(cooldownTime)
7184
};
72-
Console.WriteLine("Cooldown 2");
85+
7386
if (isGlobal)
7487
{
75-
Console.WriteLine("Cooldown 3");
7688
int index = PluginGlobals.CooldownTimer.FindIndex(x =>
7789
x.IsGlobal == true
7890
&& x.CommandID == commandID);

Diff for: CustomCommands/Services/EventManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void RegisterListeners()
5252
{
5353
Utilities.GetPlayers().ForEach(controller =>
5454
{
55-
if (controller == null || !controller.IsValid) return;
55+
if (!controller.IsValid || controller.SteamID == 0) return;
5656

5757
string message = ReplaceTagsFunctions.ReplaceLanguageTags(PluginGlobals.centerServerOn.Message);
5858
message = ReplaceTagsFunctions.ReplaceMessageTags(message, controller);

0 commit comments

Comments
 (0)