11using System . Text . Json ;
22using CounterStrikeSharp . API . Core ;
33using CustomCommands . Model ;
4+ using Microsoft . Extensions . Logging ;
45
56namespace CustomCommands . Interfaces ;
67
@@ -38,8 +39,15 @@ public bool IsCommandOnCooldownWithCondition(Func<CooldownTimer, bool> predicate
3839 if ( index != - 1 )
3940 {
4041 string timeleft = PluginGlobals . CooldownTimer [ index ] . CooldownTime . Subtract ( DateTime . Now ) . Seconds . ToString ( ) ;
41- player . PrintToChat ( $ "{ PluginGlobals . Config . Prefix } { cmd . Cooldown . CooldownMessage . Replace ( "{TIME}" , timeleft )
42- ?? $ "This command is for { timeleft } seconds on cooldown"} " ) ;
42+ string message = "" ;
43+
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+ message = $ "This command is for { timeleft } seconds on cooldown";
49+
50+ player . PrintToChat ( $ "{ PluginGlobals . Config . Prefix } { message } ") ;
4351
4452 return true ;
4553 }
@@ -61,12 +69,14 @@ public void AddToCooldownList(bool isGlobal, int playerID, Guid commandID, int c
6169 CommandID = commandID ,
6270 CooldownTime = DateTime . Now . AddSeconds ( cooldownTime )
6371 } ;
64-
72+ Console . WriteLine ( "Cooldown 2" ) ;
6573 if ( isGlobal )
6674 {
75+ Console . WriteLine ( "Cooldown 3" ) ;
6776 int index = PluginGlobals . CooldownTimer . FindIndex ( x =>
6877 x . IsGlobal == true
6978 && x . CommandID == commandID ) ;
79+
7080 if ( index != - 1 )
7181 PluginGlobals . CooldownTimer [ index ] . CooldownTime = timer . CooldownTime ;
7282 else
@@ -97,17 +107,19 @@ public void SetCooldown(CCSPlayerController player, Commands cmd)
97107 switch ( jsonElement . ValueKind )
98108 {
99109 case JsonValueKind . Number :
100- int cooldown = ( int ) cmd . Cooldown ;
110+
111+ int cooldown = cmd . Cooldown . GetInt32 ( ) ;
101112 if ( cooldown == 0 )
102113 break ;
103114
104115 AddToCooldownList ( false , player . UserId ?? 0 , cmd . ID , cooldown ) ;
105116 break ;
106117
107118 case JsonValueKind . Object :
108- Cooldown cooldownObject = ( Cooldown ) cmd . Cooldown ;
109119
120+ var cooldownObject = JsonSerializer . Deserialize < Cooldown > ( cmd . Cooldown . GetRawText ( ) ) ;
110121 AddToCooldownList ( cooldownObject . IsGlobal , player . UserId ?? 0 , cmd . ID , cooldownObject . CooldownTime ) ;
122+
111123 break ;
112124
113125 default :
0 commit comments