Begin adding cooldowns to specific commands

This commit is contained in:
zontreck 2025-03-06 18:16:13 -07:00
parent 107f502736
commit 85f728babf
7 changed files with 204 additions and 3 deletions

View file

@ -8,6 +8,7 @@ using Vintagestory.API.Common.Entities;
using Vintagestory.API.Config;
using Vintagestory.API.MathTools;
using Vintagestory.API.Server;
using Vintagestory.API.Util;
using Vintagestory.GameContent;
namespace AriasServerUtils
@ -72,6 +73,7 @@ namespace AriasServerUtils
api.Event.ServerRunPhase(EnumServerRunPhase.GameReady, OnGameReady);
api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown);
api.Event.Timer(OnCheckModDirty, 20);
api.Event.Timer(OnCheckPlayerCooldowns, 1);
api.Event.PlayerDeath += OnPlayerDeath;
api.Event.PlayerJoin += OnPlayerJoin;
api.Event.PlayerDisconnect += OnPlayerDC;
@ -163,6 +165,27 @@ namespace AriasServerUtils
api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP);
}
private void OnCheckPlayerCooldowns()
{
foreach (var cdEntry in ServerUtilities.mPlayerData)
{
List<CooldownType> toRemove = new();
foreach (var cd in cdEntry.Value.ActiveCooldowns)
{
if (cd.Value < TimeUtil.GetUnixEpochTimestamp())
{
toRemove.Add(cd.Key);
}
}
foreach (var item in toRemove)
{
cdEntry.Value.ActiveCooldowns.Remove(item);
}
if (toRemove.Count > 0) MarkDirty();
}
}
public static void NewBackCacheForPlayer(IServerPlayer player)
{
@ -290,7 +313,10 @@ namespace AriasServerUtils
config = API.LoadModConfig<ASUModConfig>(GetConfigurationFile("global", ModConfigType.Global));
if (config == null) config = new ASUModConfig();
// -> Step 2. Load Mod Warps <-
// Step 2. Check if there are new or missing cooldowns
config.SanityCheckCooldowns();
// -> Step 3. Load Mod Warps <-
serverWarps = API.LoadModConfig<Warps>(GetConfigurationFile("warps", ModConfigType.Global));
if (serverWarps == null) serverWarps = new Warps();
}