|
| 1 | +using System.Text.Json; |
1 | 2 | using System.Text.RegularExpressions; |
2 | 3 | using CounterStrikeSharp.API; |
3 | 4 | using CounterStrikeSharp.API.Core; |
@@ -56,4 +57,63 @@ public bool RequiresPermissions(CCSPlayerController player, Permission permissio |
56 | 57 | return true; |
57 | 58 | } |
58 | 59 | } |
| 60 | + public bool OnCooldown(CCSPlayerController player, Commands cmd) |
| 61 | + { |
| 62 | + |
| 63 | + |
| 64 | + } |
| 65 | + /// <summary> |
| 66 | + /// Sets the cooldown for the command |
| 67 | + /// </summary> |
| 68 | + /// <param name="player">Need to add the player if the Cooldown is only for a specific player</param> |
| 69 | + /// <param name="cmd"></param> |
| 70 | + public void SetCooldown(CCSPlayerController player, Commands cmd) |
| 71 | + { |
| 72 | + if (cmd.Cooldown is JsonElement jsonElement) |
| 73 | + { |
| 74 | + switch (jsonElement.ValueKind) |
| 75 | + { |
| 76 | + case JsonValueKind.Number: |
| 77 | + int cooldown = (int)cmd.Cooldown; |
| 78 | + |
| 79 | + if (cooldown == 0) |
| 80 | + break; |
| 81 | + |
| 82 | + var timer = new CooldownTimer() { |
| 83 | + IsGlobal = false, |
| 84 | + PlayerID = player.UserId ?? 0, |
| 85 | + CommandID = cmd.ID, |
| 86 | + CooldownTime = DateTime.Now.AddSeconds(cooldown) |
| 87 | + }; |
| 88 | + PluginGlobals.CooldownTimer.Add(timer); |
| 89 | + |
| 90 | + break; |
| 91 | + case JsonValueKind.Object: |
| 92 | + Cooldown cooldownObject = (Cooldown)cmd.Cooldown; |
| 93 | + |
| 94 | + if (cooldownObject.IsGlobal) |
| 95 | + { |
| 96 | + var timerObj = new CooldownTimer() { |
| 97 | + IsGlobal = true, |
| 98 | + CommandID = cmd.ID, |
| 99 | + CooldownTime = DateTime.Now.AddSeconds(cooldownObject.CooldownTime) |
| 100 | + }; |
| 101 | + PluginGlobals.CooldownTimer.Add(timerObj); |
| 102 | + } else { |
| 103 | + var timerObj = new CooldownTimer() { |
| 104 | + IsGlobal = false, |
| 105 | + PlayerID = player.UserId ?? 0, |
| 106 | + CommandID = cmd.ID, |
| 107 | + CooldownTime = DateTime.Now.AddSeconds(cooldownObject.CooldownTime) |
| 108 | + }; |
| 109 | + PluginGlobals.CooldownTimer.Add(timerObj); |
| 110 | + } |
| 111 | + |
| 112 | + break; |
| 113 | + |
| 114 | + default: |
| 115 | + break; |
| 116 | + } |
| 117 | + } |
| 118 | + } |
59 | 119 | } |
0 commit comments