From 737c51989bd3090c33049307b2218c7ce7829e91 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 18 Jan 2025 16:11:00 -0700 Subject: [PATCH] Adds in warps --- AriasServerUtils/ASUModSystem.cs | 5 ++ AriasServerUtils/EventHandler.cs | 86 ++++++++++++++++++- AriasServerUtils/Globals.cs | 14 +++ .../assets/ariasserverutils/lang/en.json | 9 +- AriasServerUtils/modinfo.json | 4 +- 5 files changed, 114 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index dcb1b58..6efd6d2 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -124,6 +124,11 @@ namespace AriasServerUtils .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand(); + + api.ChatCommands.Create("setwarp").RequiresPlayer().WithDescription("Creates a new server warp").HandleWith(Events.HandleWarpUpdate).WithArgs(parsers.OptionalWord("name")); + api.ChatCommands.Create("warp").RequiresPlayer().WithDescription("Warp to the specified server warp").HandleWith(Events.HandleWarp).WithArgs(parsers.OptionalWord("name")); + api.ChatCommands.Create("delwarp").RequiresPlayer().WithDescription("Deletes the specified warp").HandleWith(Events.HandleWarpDelete).WithArgs(parsers.OptionalWord("name")); + api.ChatCommands.Create("warps").RequiresPlayer().WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); } private void OnPlayerDC(IServerPlayer byPlayer) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 9f491be..01f300f 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -12,7 +12,7 @@ namespace AriasServerUtils { internal static TextCommandResult HandleASU(TextCommandCallingArgs args) { - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu" }))); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps" }))); } internal static TextCommandResult HandleClearSpawn(TextCommandCallingArgs args) @@ -221,5 +221,89 @@ namespace AriasServerUtils return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); } + + internal static TextCommandResult HandleWarp(TextCommandCallingArgs args) + { + string name = "default"; + if (args.ArgCount > 0) name = args[0] as string ?? "default"; + + if (args.Caller.Player is IServerPlayer isp) + { + if (ServerUtilities.serverWarps.warps.ContainsKey(name)) + { + + ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + } + else + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-fail", name)); + + } + + } + + return TextCommandResult.Success(); + } + + internal static TextCommandResult HandleWarpDelete(TextCommandCallingArgs args) + { + string name = "default"; + if (args.ArgCount > 0) name = args[0] as string ?? "default"; + + if (args.Caller.Player is IServerPlayer isp) + { + if (isp.HasPrivilege(Privilege.controlserver) || !ServerUtilities.config.onlyAdminsCreateWarps) + { + ServerUtilities.serverWarps.warps.Remove(name); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-del")); + } + else + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-no")); + } + } + + return TextCommandResult.Success(); + } + + internal static TextCommandResult HandleWarpList(TextCommandCallingArgs args) + { + List warps = new List(); + foreach (string id in ServerUtilities.serverWarps.warps.Keys) + { + warps.Add(id); + } + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:warp-list", warps.Count, string.Join(", ", warps))); + } + + internal static TextCommandResult HandleWarpUpdate(TextCommandCallingArgs args) + { + string name = "default"; + if (args.ArgCount > 0) name = args[0] as string ?? "default"; + + if (args.Caller.Player is IServerPlayer isp) + { + if (isp.HasPrivilege(Privilege.controlserver) || !ServerUtilities.config.onlyAdminsCreateWarps) + { + ServerUtilities.serverWarps.warps[name] = Warp.Create(isp); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + + } + else + { + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-no")); + } + } + + return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index eba4c15..8d8f85e 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Vintagestory.API.Server; namespace AriasServerUtils { @@ -24,6 +25,19 @@ namespace AriasServerUtils public class Warp { public PlayerPosition Location; + public string CreatedBy; + public DateTime CreatedAt; + + + public static Warp Create(IServerPlayer player) + { + Warp warp = new Warp(); + warp.Location = PlayerPosition.from(player.Entity); + warp.CreatedBy = player.PlayerName; + warp.CreatedAt = DateTime.Now; + + return warp; + } } [Serializable] diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 0dc690a..49bdb1d 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -20,5 +20,12 @@ "help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; Admins can bypass max homes: {1}\n{2}", - "updatedconfig": "[ASU] server config updated" + "updatedconfig": "[ASU] server config updated", + + "warp-tp": "Teleported to warp [{0}]", + "warp-set": "Warp [{0}] created!", + "warp-no": "You lack permissions to manage a warp", + "warp-fail": "Warp [{0}] does not exist", + "warp-del": "Warp [{0}] deleted", + "warp-list": "There are [{0}] total warps\n\n{1}" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 8bcd409..84c6b9d 100644 --- a/AriasServerUtils/modinfo.json +++ b/AriasServerUtils/modinfo.json @@ -3,8 +3,8 @@ "modid": "ariasserverutils", "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-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 04:10 PM", + "version": "1.0.1-dev.2", "dependencies": { "game": "" }