From e776a6bb9e6e628bb27e706d6d4097d582c81993 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 18 Jan 2025 15:34:51 -0700 Subject: [PATCH] Adds a config flag for managing warps --- AriasServerUtils/ASUModSystem.cs | 18 +++++++++++++++++- AriasServerUtils/EventHandler.cs | 10 ++++++++++ AriasServerUtils/{ModConfig.cs => Globals.cs} | 14 ++++++++++++++ AriasServerUtils/modinfo.json | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) rename AriasServerUtils/{ModConfig.cs => Globals.cs} (51%) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 7e0589b..dcb1b58 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -20,6 +20,9 @@ namespace AriasServerUtils internal static Dictionary mPlayerData = new Dictionary(); + internal static Warps serverWarps = new Warps(); + + internal static string[] saveInvTypes = new string[] { GlobalConstants.hotBarInvClassName, GlobalConstants.backpackInvClassName, @@ -107,9 +110,16 @@ namespace AriasServerUtils .HandleWith(Events.HandleUpdateASUBypass) .EndSubCommand() .WithDescription("Updates the ASU mod configuration") + .BeginSubCommand("onlyAdminManageWarps") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Bool("manageWarps") + ) + .WithDescription("DANGER: This updates the flag allowing anybody to create warps, even non-admins. It is recommended to leave this alone. The default is true/on/yes") + .HandleWith(Events.HandleUpdateASUMgrWarps) + .EndSubCommand() .EndSubCommand() .BeginSubCommand("help") - .RequiresPlayer() .RequiresPrivilege(Privilege.chat) .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") @@ -223,6 +233,8 @@ namespace AriasServerUtils public void SaveGlobalConfig() { API.StoreModConfig(config, GetConfigurationFile("global", ModConfigType.Global)); + + API.StoreModConfig(serverWarps, GetConfigurationFile("warps", ModConfigType.Global)); } private void OnGameReady() @@ -232,6 +244,10 @@ namespace AriasServerUtils config = API.LoadModConfig(GetConfigurationFile("global", ModConfigType.Global)); if (config == null) config = new ASUModConfig(); + + // -> Step 2. Load Mod Warps <- + serverWarps = API.LoadModConfig(GetConfigurationFile("warps", ModConfigType.Global)); + if (serverWarps == null) serverWarps = new Warps(); } public string GetConfigurationFile(string sName, ModConfigType type) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index f378e84..9f491be 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -211,5 +211,15 @@ namespace AriasServerUtils return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUMgrWarps(TextCommandCallingArgs args) + { + if (args[0] is bool mgr) + ServerUtilities.config.onlyAdminsCreateWarps = mgr; + else ServerUtilities.config.onlyAdminsCreateWarps = true; + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } } } \ No newline at end of file diff --git a/AriasServerUtils/ModConfig.cs b/AriasServerUtils/Globals.cs similarity index 51% rename from AriasServerUtils/ModConfig.cs rename to AriasServerUtils/Globals.cs index d16e04e..eba4c15 100644 --- a/AriasServerUtils/ModConfig.cs +++ b/AriasServerUtils/Globals.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace AriasServerUtils { @@ -13,8 +14,21 @@ namespace AriasServerUtils { public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; + public bool onlyAdminsCreateWarps { get; set; } = true; public PlayerPosition Spawn { get; set; } } + + [Serializable] + public class Warp + { + public PlayerPosition Location; + } + + [Serializable] + public class Warps + { + public Dictionary warps = new Dictionary(); + } } \ No newline at end of file diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 5247ac9..8bcd409 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -4,7 +4,7 @@ "name": "Aria's Server Utilities", "authors": ["zontreck"], "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 03:18 PM", - "version": "1.0.1", + "version": "1.0.1-dev.1", "dependencies": { "game": "" }