From bd120215754224bf2dd956536ef662ac026f3cb6 Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 5 Jun 2025 12:18:07 -0700 Subject: [PATCH] Some refactoring work Add command aliases Begin adding the sethomemount command Part of #6 --- AriasServerUtils/EventHandler.cs | 24 ++++++++++++++++----- AriasServerUtils/Globals.cs | 1 + AriasServerUtils/ModSystems/ASUServer.cs | 27 ++++++++++++------------ AriasServerUtils/PlayerData.cs | 10 ++++++++- AriasServerUtils/modinfo.json | 4 ++-- 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 6869045..6b19245 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Vintagestory.API.Common; +using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; @@ -126,8 +127,10 @@ namespace AriasServerUtils if (data.Homes.ContainsKey(homeName)) { + Home home = data.Homes[homeName]; ServerUtilities.NewBackCacheForPlayer(isp); - data.Homes[homeName].Location.Merge(isp.Entity); + + home.Location.Merge(isp.Entity, unmount: !home.CanHaveMount); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-tp")); } @@ -199,6 +202,12 @@ namespace AriasServerUtils if (args.Caller.Player is IServerPlayer isp) { + + if (args.Command.FullName == "sethomemount") + { + // Check for the gears and pay here, or show error. + } + bool bypass = isOp && ServerUtilities.config.AdminsBypassMaxHomes; var data = ServerUtilities.GetPlayerData(isp); @@ -207,6 +216,13 @@ namespace AriasServerUtils data.Homes[homeName] = Home.MakeHome(args.Caller.Player.Entity, homeName); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-set")); + + + if (args.Command.FullName == "sethomemount") + { + // Enable mount in the home + data.Homes[homeName].CanHaveMount = true; + } } else { @@ -355,15 +371,13 @@ namespace AriasServerUtils if (ServerUtilities.serverWarps.warps.ContainsKey(name)) { + Warp warp = ServerUtilities.serverWarps.warps[name]; ServerUtilities.NewBackCacheForPlayer(isp); - ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); + warp.Location.Merge(isp.Entity, unmount: !warp.CanHaveMount); ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-tp", name)); - - - data.ActiveCooldowns.Add(CooldownType.Warp, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.Warp)) + TimeUtil.GetUnixEpochTimestamp()); ServerUtilities.MarkDirty(); } diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 3436bbf..7a9ead4 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -93,6 +93,7 @@ namespace AriasServerUtils public PlayerPosition Location; public string CreatedBy; public DateTime CreatedAt; + public bool CanHaveMount = false; public static Warp Create(IServerPlayer player) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 36a590d..e640c0e 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -99,19 +99,20 @@ namespace AriasServerUtils - api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn); - api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn); - api.ChatCommands.Create("delspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleClearSpawn); + api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn).WithAlias("ss"); + api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn).WithAlias("s"); + api.ChatCommands.Create("delspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleClearSpawn).WithAlias("ds"); //api.ChatCommands.Create("test_death").RequiresPlayer().RequiresPrivilege(Privilege.controlserver).HandleWith(TestDeath); var parsers = api.ChatCommands.Parsers; api.ChatCommands.Create("restoreinv").RequiresPlayer().WithArgs(parsers.OnlinePlayer("player")).HandleWith(Events.HandleReturnItems).WithDescription("Returns items to a player in the event of a problem").RequiresPrivilege(Privilege.controlserver); - api.ChatCommands.Create("sethome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Creates a home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSetHome); - api.ChatCommands.Create("home").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Teleports you to home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleGoHome); - api.ChatCommands.Create("delhome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Deletes a home entry").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleDelHome); - api.ChatCommands.Create("homes").RequiresPlayer().WithDescription("Lists your homes").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleListHomes); + api.ChatCommands.Create("sethome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Creates a home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSetHome).WithAlias("sh"); + api.ChatCommands.Create("home").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Teleports you to home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleGoHome).WithAlias("h"); + api.ChatCommands.Create("delhome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Deletes a home entry").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleDelHome).WithAlias("dh"); + api.ChatCommands.Create("homes").RequiresPlayer().WithDescription("Lists your homes").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleListHomes).WithAlias("lh"); + api.ChatCommands.Create("sethomemount").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Create a home with the ability to take a mount with you. Costs [undefined] gears.").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSetHome).WithAlias("shm", "shb"); api.ChatCommands.Create("asu") .RequiresPrivilege(Privilege.chat) @@ -263,16 +264,16 @@ namespace AriasServerUtils .EndSubCommand() .EndSubCommand(); - api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); - api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp); - api.ChatCommands.Create("delwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Deletes the specified warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpDelete); - api.ChatCommands.Create("warps").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList); + api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate).WithAlias("sw"); + api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp).WithAlias("w"); + api.ChatCommands.Create("delwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Deletes the specified warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpDelete).WithAlias("dw"); + api.ChatCommands.Create("warps").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList).WithAlias("lw"); - api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); + api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack).WithAlias("b"); api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.OptionalInt("maxDist", defaultValue: -1)).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); - api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns); + api.ChatCommands.Create("listcooldowns").RequiresPrivilege(Privilege.chat).WithDescription("Lists the cooldown settings on the server, as well as your own active cooldowns if applicable.").HandleWith(Events.HandleListCooldowns).WithAlias("lc"); } private TextCommandResult TestSleep(TextCommandCallingArgs args) diff --git a/AriasServerUtils/PlayerData.cs b/AriasServerUtils/PlayerData.cs index baec1b3..efb9db3 100644 --- a/AriasServerUtils/PlayerData.cs +++ b/AriasServerUtils/PlayerData.cs @@ -31,8 +31,15 @@ namespace AriasServerUtils } - public void Merge(Entity entity) + public void Merge(Entity entity, bool unmount = true) { + if (entity is EntityPlayer player) + { + if (unmount && player.MountedOn.Entity != null) + { + player.TryUnmount(); + } + } entity.TeleportTo(new BlockPos(X, Y, Z, Dimension)); entity.Pos.SetYaw(Yaw); entity.Pos.Pitch = Pitch; @@ -88,6 +95,7 @@ namespace AriasServerUtils public class Home { public PlayerPosition Location { get; set; } + public bool CanHaveMount = false; public static Home MakeHome(Entity player, string homeName) { diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index cc1577f..506a13a 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: 05-7-2025 @ 12:21 PM MST", - "version": "1.0.11", + "description": "A collection of server utilities\n\nBuild Date: 06-05-2025 @ 11:56 AM MST", + "version": "1.1.0-dev.1", "dependencies": { "game": "" }