Skip to content

Commit bb729c8

Browse files
fix cooldown bug
1 parent d02bb05 commit bb729c8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Code/FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using LabApi.Features.Permissions;
44
using LabApi.Features.Wrappers;
55
using RemoteAdmin;
6+
using SER.Code.Helpers;
67
using SER.Code.Helpers.Exceptions;
78
using SER.Code.Helpers.Extensions;
89
using SER.Code.Helpers.ResultSystem;
@@ -13,6 +14,7 @@
1314
using SER.Code.ValueSystem;
1415
using SER.Code.VariableSystem.Bases;
1516
using SER.Code.VariableSystem.Variables;
17+
using UnityEngine;
1618
using Console = GameCore.Console;
1719

1820
namespace SER.Code.FlagSystem.Flags;
@@ -252,22 +254,25 @@ public static Result RunAttachedScript(CustomCommand cmd, ScriptExecutor sender,
252254

253255
private static string? HandlePlayer(CustomCommand cmd, Player plr)
254256
{
255-
var hasRank = plr.UserGroup is not { } group || cmd.NeededRanks.All(rank => group.Name != rank);
256-
if (cmd.NeededRanks.Any() && hasRank)
257+
Log.Debug($"handling player in command {cmd.Command}");
258+
if (cmd.NeededRanks.Any())
257259
{
258-
return "This command is reserved for players with a rank: " +
259-
$"{cmd.NeededRanks.JoinStrings(", ")}";
260+
if (plr.UserGroup is not { } group || cmd.NeededRanks.All(rank => group.Name != rank))
261+
{
262+
return "This command is reserved for players with a rank: " +
263+
$"{cmd.NeededRanks.Select(r => $"'{r}'").JoinStrings(" or ")}";
264+
}
260265
}
261266

262267
if (cmd.PlayerCooldown <= TimeSpan.Zero)
263268
{
264269
return null;
265270
}
266-
267-
if (cmd.NextEligableDateForPlayer.TryGetValue(plr, out var nextEligableDate) && nextEligableDate < DateTime.UtcNow)
271+
272+
if (cmd.NextEligableDateForPlayer.TryGetValue(plr, out var nextEligableDate) && nextEligableDate > DateTime.UtcNow)
268273
{
269274
return $"You are on cooldown! You can use this command in " +
270-
$"{(nextEligableDate - DateTime.UtcNow).Seconds} seconds.";
275+
$"{Math.Round((nextEligableDate - DateTime.UtcNow).TotalSeconds, MidpointRounding.AwayFromZero)} seconds.";
271276
}
272277

273278
cmd.NextEligableDateForPlayer[plr] = DateTime.UtcNow + cmd.PlayerCooldown;

0 commit comments

Comments
 (0)