From 54e8d8a4d584d2e1f2b698852010acd2d9c9ddcd Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 6 Mar 2025 18:39:12 -0700 Subject: [PATCH] oops, forgot to commit the ASU Update Cooldowns commands --- AriasServerUtils/ASUModSystem.cs | 48 +++++++++ AriasServerUtils/EventHandler.cs | 98 +++++++++++++++++++ AriasServerUtils/Globals.cs | 19 ++-- .../assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 2 +- 5 files changed, 159 insertions(+), 9 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index ad0a547..5921fc8 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -148,6 +148,54 @@ namespace AriasServerUtils .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position") .HandleWith(Events.HandleUpdateASURTPMax) .EndSubCommand() + .BeginSubCommand("cooldowns") + .WithDescription("Commands related to all the various cooldowns") + .BeginSubCommand("back") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /back (Default is 5s)") + .HandleWith(Events.HandleUpdateASUCDBack) + .EndSubCommand() + .BeginSubCommand("warp") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /warp (Default is 10s)") + .HandleWith(Events.HandleUpdateASUCDWarp) + .EndSubCommand() + .BeginSubCommand("home") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /home (Default is 5s)") + .HandleWith(Events.HandleUpdateASUCDHome) + .EndSubCommand() + .BeginSubCommand("spawn") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /spawn (Default is 5s)") + .HandleWith(Events.HandleUpdateASUCDSpawn) + .EndSubCommand() + .BeginSubCommand("rtp") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Word("cooldown") + ) + .WithDescription("Updates the cooldown time on /rtp (Default is 30s)") + .HandleWith(Events.HandleUpdateASUCDRTP) + .EndSubCommand() + .BeginSubCommand("reset") + .RequiresPrivilege(Privilege.controlserver) + .WithDescription("Resets all cooldowns to default values") + .HandleWith(Events.HandleUpdateASUCDReset) + .EndSubCommand() + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") .RequiresPrivilege(Privilege.chat) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 5529cf4..9386346 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -442,5 +442,103 @@ namespace AriasServerUtils return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUCDBack(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Back] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Back] = "5s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDWarp(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Warp] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Warp] = "10s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDHome(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Home] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Home] = "5s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDSpawn(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.Spawn] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.Spawn] = "5s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDRTP(TextCommandCallingArgs args) + { + if (args[0] is string CD) + { + ServerUtilities.config.Cooldowns[CooldownType.RTP] = CD; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + ServerUtilities.config.Cooldowns[CooldownType.RTP] = "30s"; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } + } + + internal static TextCommandResult HandleUpdateASUCDReset(TextCommandCallingArgs args) + { + ServerUtilities.config.Cooldowns = ServerUtilities.config.GetDefaultCooldowns(); + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 37be46e..bf1dd29 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.ConstrainedExecution; using Vintagestory.API.Server; namespace AriasServerUtils @@ -13,6 +14,15 @@ namespace AriasServerUtils [Serializable] public class ASUModConfig { + private readonly static Dictionary m_defaultCD = new Dictionary{ + + { CooldownType.Home, "5s" }, + { CooldownType.Warp, "10s" }, + { CooldownType.Spawn, "5s" }, + { CooldownType.RTP, "30s" }, + { CooldownType.Back, "5s" } + }; + public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; @@ -30,14 +40,7 @@ namespace AriasServerUtils public Dictionary GetDefaultCooldowns() { - return new Dictionary{ - - { CooldownType.Home, "5s" }, - { CooldownType.Warp, "10s" }, - { CooldownType.Spawn, "5s" }, - { CooldownType.RTP, "30s" }, - { CooldownType.Back, "5s" } - }; + return m_defaultCD; } public void SanityCheckCooldowns() diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 52606b7..5f983f0 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -21,6 +21,7 @@ "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; \nAdmins can bypass max homes: {1}\nMax back positions: {2}\n\n{3}", "updatedconfig": "[ASU] server config updated", + "config-value-reset": "[ASU] server config value reset to default", "warp-tp": "Teleported to warp [{0}]", "warp-set": "Warp [{0}] created!", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 97ff8fd..4259fac 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,7 +3,7 @@ "modid": "ariasserverutils", "name": "Aria's Server Utilities", "authors": ["zontreck"], - "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:16 PM MST", + "description": "A collection of server utilities\n\nBuild Date: 03-06-2025 @ 6:37 PM MST", "version": "1.0.4", "dependencies": { "game": ""