1
1
using System . Text . Json ;
2
2
using CounterStrikeSharp . API . Core ;
3
+ using CounterStrikeSharp . API . Modules . Entities . Constants ;
3
4
using CustomCommands . Model ;
4
5
using Microsoft . Extensions . Logging ;
5
6
@@ -8,9 +9,11 @@ namespace CustomCommands.Interfaces;
8
9
public class CooldownManager : ICooldownManager
9
10
{
10
11
public IPluginGlobals PluginGlobals { get ; }
11
- public CooldownManager ( IPluginGlobals PluginGlobals )
12
+ public IReplaceTagsFunctions ReplaceTagsFunctions { get ; }
13
+ public CooldownManager ( IPluginGlobals PluginGlobals , IReplaceTagsFunctions ReplaceTagsFunctions )
12
14
{
13
15
this . PluginGlobals = PluginGlobals ;
16
+ this . ReplaceTagsFunctions = ReplaceTagsFunctions ;
14
17
}
15
18
16
19
/// <summary>
@@ -38,15 +41,25 @@ public bool IsCommandOnCooldownWithCondition(Func<CooldownTimer, bool> predicate
38
41
39
42
if ( index != - 1 )
40
43
{
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 ( ) ;
43
47
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
+ {
48
60
message = $ "This command is for { timeleft } seconds on cooldown";
49
-
61
+ }
62
+
50
63
player . PrintToChat ( $ "{ PluginGlobals . Config . Prefix } { message } ") ;
51
64
52
65
return true ;
@@ -69,10 +82,9 @@ public void AddToCooldownList(bool isGlobal, int playerID, Guid commandID, int c
69
82
CommandID = commandID ,
70
83
CooldownTime = DateTime . Now . AddSeconds ( cooldownTime )
71
84
} ;
72
- Console . WriteLine ( "Cooldown 2" ) ;
85
+
73
86
if ( isGlobal )
74
87
{
75
- Console . WriteLine ( "Cooldown 3" ) ;
76
88
int index = PluginGlobals . CooldownTimer . FindIndex ( x =>
77
89
x . IsGlobal == true
78
90
&& x . CommandID == commandID ) ;
0 commit comments