11using System . Text . Json ;
22using CounterStrikeSharp . API . Core ;
3+ using CounterStrikeSharp . API . Modules . Entities . Constants ;
34using CustomCommands . Model ;
45using Microsoft . Extensions . Logging ;
56
@@ -8,9 +9,11 @@ namespace CustomCommands.Interfaces;
89public 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 ) ;
0 commit comments