1
1
using System . Text . Json ;
2
2
using CounterStrikeSharp . API . Core ;
3
3
using CustomCommands . Model ;
4
+ using Microsoft . Extensions . Logging ;
4
5
5
6
namespace CustomCommands . Interfaces ;
6
7
@@ -38,8 +39,15 @@ public bool IsCommandOnCooldownWithCondition(Func<CooldownTimer, bool> predicate
38
39
if ( index != - 1 )
39
40
{
40
41
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 } ") ;
43
51
44
52
return true ;
45
53
}
@@ -61,12 +69,14 @@ public void AddToCooldownList(bool isGlobal, int playerID, Guid commandID, int c
61
69
CommandID = commandID ,
62
70
CooldownTime = DateTime . Now . AddSeconds ( cooldownTime )
63
71
} ;
64
-
72
+ Console . WriteLine ( "Cooldown 2" ) ;
65
73
if ( isGlobal )
66
74
{
75
+ Console . WriteLine ( "Cooldown 3" ) ;
67
76
int index = PluginGlobals . CooldownTimer . FindIndex ( x =>
68
77
x . IsGlobal == true
69
78
&& x . CommandID == commandID ) ;
79
+
70
80
if ( index != - 1 )
71
81
PluginGlobals . CooldownTimer [ index ] . CooldownTime = timer . CooldownTime ;
72
82
else
@@ -97,17 +107,19 @@ public void SetCooldown(CCSPlayerController player, Commands cmd)
97
107
switch ( jsonElement . ValueKind )
98
108
{
99
109
case JsonValueKind . Number :
100
- int cooldown = ( int ) cmd . Cooldown ;
110
+
111
+ int cooldown = cmd . Cooldown . GetInt32 ( ) ;
101
112
if ( cooldown == 0 )
102
113
break ;
103
114
104
115
AddToCooldownList ( false , player . UserId ?? 0 , cmd . ID , cooldown ) ;
105
116
break ;
106
117
107
118
case JsonValueKind . Object :
108
- Cooldown cooldownObject = ( Cooldown ) cmd . Cooldown ;
109
119
120
+ var cooldownObject = JsonSerializer . Deserialize < Cooldown > ( cmd . Cooldown . GetRawText ( ) ) ;
110
121
AddToCooldownList ( cooldownObject . IsGlobal , player . UserId ?? 0 , cmd . ID , cooldownObject . CooldownTime ) ;
122
+
111
123
break ;
112
124
113
125
default :
0 commit comments