From cd00e620c3d2994b33811f4477c855986e45a16e Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:44:27 -0700 Subject: [PATCH 01/36] Begin to add the admin bypass cooldown option --- AriasServerUtils/ASUModSystem.cs | 8 ++++++++ AriasServerUtils/EventHandler.cs | 12 ++++++++++++ AriasServerUtils/Globals.cs | 3 ++- AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index c688363..b37da69 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -124,6 +124,14 @@ namespace AriasServerUtils .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() + .BeginSubCommand("adminBypassCooldown") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Bool("bypass") + ) + .WithDescription("This flag controls whether admins can or can not bypass the cooldown system") + .HandleWith(Events.HandleUpdateASUBypassCD) + .EndSubCommand() .BeginSubCommand("maxback") .RequiresPrivilege(Privilege.controlserver) .WithArgs( diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 134c08d..05da76e 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -555,5 +555,17 @@ namespace AriasServerUtils return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:config-value-reset")); } + + internal static TextCommandResult HandleUpdateASUBypassCD(TextCommandCallingArgs args) + { + if (args[0] is bool bypass) + { + // Update the bypass + ServerUtilities.config.AdminsBypassCooldowns = bypass; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index 1b8af8c..cd10039 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,13 +22,14 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; - private static readonly int CURRENT_VERSION = 3; + private static readonly int CURRENT_VERSION = 4; public int Version { get; set; } = 0; public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; + public bool AdminsBypassCooldowns { get; set; } = true; public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; public int MaxRTPBlockDistance { get; set; } = 5000; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 2036aac..ea0a11d 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: 03-07-2025 @ 1:28 AM MST", - "version": "1.0.5", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:44 AM MST", + "version": "1.0.6-dev.1", "dependencies": { "game": "" } From 700de94ffe2ad610a67e017e934e3d665c961d74 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 11:49:59 -0700 Subject: [PATCH 02/36] Admins can now bypass cooldowns --- AriasServerUtils/ASUModSystem.cs | 7 +++++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index b37da69..a2eb075 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Vintagestory.API.Client; using Vintagestory.API.Common; using Vintagestory.API.Common.CommandAbbr; @@ -225,6 +226,12 @@ namespace AriasServerUtils { foreach (var cdEntry in ServerUtilities.mPlayerData) { + // Obtain the IServerPlayer instance for this player. + IServerPlayer player = API.Server.Players.First(x => x.PlayerName == cdEntry.Key); + if (player.HasPrivilege(Privilege.controlserver) && ServerUtilities.config.AdminsBypassCooldowns) + { + cdEntry.Value.ActiveCooldowns.Clear(); // Problem solved. + } List toRemove = new(); foreach (var cd in cdEntry.Value.ActiveCooldowns) { diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index ea0a11d..aa3c197 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: 03-07-2025 @ 1:44 AM MST", - "version": "1.0.6-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 11:49 AM MST", + "version": "1.0.6-dev.2", "dependencies": { "game": "" } From c5c605d057128af7b8f84c0cf2d40d92727a1db0 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 11:53:57 -0700 Subject: [PATCH 03/36] Allow admins to bypass the max rtp distance --- AriasServerUtils/ASUModSystem.cs | 8 ++++++++ AriasServerUtils/EventHandler.cs | 12 ++++++++++++ AriasServerUtils/Globals.cs | 5 +++-- AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index a2eb075..6da73de 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -133,6 +133,14 @@ namespace AriasServerUtils .WithDescription("This flag controls whether admins can or can not bypass the cooldown system") .HandleWith(Events.HandleUpdateASUBypassCD) .EndSubCommand() + .BeginSubCommand("adminsBypassRTPMaxDist") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs( + parsers.Bool("bypass") + ) + .WithDescription("This flag would allow admins to go further than the max server RTP distance when manually specifying a distance to RTP") + .HandleWith(Events.HandleUpdateASUBypassRTPMaxDist) + .EndSubCommand() .BeginSubCommand("maxback") .RequiresPrivilege(Privilege.controlserver) .WithArgs( diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 05da76e..4bc6020 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -567,5 +567,17 @@ namespace AriasServerUtils } else return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUBypassRTPMaxDist(TextCommandCallingArgs args) + { + if (args[0] is bool bypass) + { + // Update the flag + ServerUtilities.config.AdminsBypassRTPMaxDistance = bypass; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index cd10039..a98b5cc 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,7 +22,7 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; - private static readonly int CURRENT_VERSION = 4; + private static readonly int CURRENT_VERSION = 5; public int Version { get; set; } = 0; @@ -30,9 +30,10 @@ namespace AriasServerUtils public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; public bool AdminsBypassCooldowns { get; set; } = true; + public bool AdminsBypassRTPMaxDistance { get; set; } = false; public int MaxBackCache { get; set; } = 10; public int PlayerSleepingPercentage { get; set; } = 50; - public int MaxRTPBlockDistance { get; set; } = 5000; + public int MaxRTPBlockDistance { get; set; } = 50000; public Dictionary Cooldowns { get; set; } = new Dictionary(); public Dictionary GetDefaultCooldowns() diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index aa3c197..f4b8f54 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: 03-07-2025 @ 11:49 AM MST", - "version": "1.0.6-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 11:53 AM MST", + "version": "1.0.6-dev.3", "dependencies": { "game": "" } From 29cf4e21b779da6fcd8de00a1dba7579d50fd584 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:05:04 -0700 Subject: [PATCH 04/36] Add a command to list cooldown settings and all active command cooldowns for the current player --- AriasServerUtils/ASUModSystem.cs | 8 +++++--- AriasServerUtils/EventHandler.cs | 22 +++++++++++++++++++++- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 6da73de..c808b5a 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -130,7 +130,7 @@ namespace AriasServerUtils .WithArgs( parsers.Bool("bypass") ) - .WithDescription("This flag controls whether admins can or can not bypass the cooldown system") + .WithDescription("This flag controls whether admins can or can not bypass the cooldown system (Default: true)") .HandleWith(Events.HandleUpdateASUBypassCD) .EndSubCommand() .BeginSubCommand("adminsBypassRTPMaxDist") @@ -138,7 +138,7 @@ namespace AriasServerUtils .WithArgs( parsers.Bool("bypass") ) - .WithDescription("This flag would allow admins to go further than the max server RTP distance when manually specifying a distance to RTP") + .WithDescription("This flag would allow admins to go further than the max server RTP distance when manually specifying a distance to RTP (Default: false)") .HandleWith(Events.HandleUpdateASUBypassRTPMaxDist) .EndSubCommand() .BeginSubCommand("maxback") @@ -162,7 +162,7 @@ namespace AriasServerUtils .WithArgs( parsers.Int("maxDistance") ) - .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position") + .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position (Default is 50000)") .HandleWith(Events.HandleUpdateASURTPMax) .EndSubCommand() .BeginSubCommand("cooldowns") @@ -228,6 +228,8 @@ namespace AriasServerUtils api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack); 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); } private void OnCheckPlayerCooldowns() diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 4bc6020..0cfc261 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -14,7 +14,7 @@ namespace AriasServerUtils { internal static TextCommandResult HandleASU(TextCommandCallingArgs args) { - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back", "rtp" }))); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back", "rtp", "listcooldowns" }))); } internal static TextCommandResult HandleBack(TextCommandCallingArgs args) @@ -579,5 +579,25 @@ namespace AriasServerUtils } else return TextCommandResult.Success(); } + + internal static TextCommandResult HandleListCooldowns(TextCommandCallingArgs args) + { + string sReturn = "SERVER COOLDOWN SETTINGS\n"; + foreach (var cd in ServerUtilities.config.Cooldowns) + { + sReturn += $"{cd.Key}: {cd.Value}\n"; + } + if (args.Caller.Player is IServerPlayer isp) + { + sReturn += "\nYour active cooldowns:"; + foreach (var cd in ServerUtilities.GetPlayerData(isp).ActiveCooldowns) + { + long remain = cd.Value - TimeUtil.GetUnixEpochTimestamp(); + string sCDVal = TimeUtil.EncodeTimeNotation(remain); + sReturn += $"{cd.Key}: {sCDVal}\n"; + } + } + return TextCommandResult.Success(sReturn); + } } } \ No newline at end of file diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f4b8f54..c9e0d43 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: 03-07-2025 @ 11:53 AM MST", - "version": "1.0.6-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:04 PM MST", + "version": "1.0.6-dev.4", "dependencies": { "game": "" } From 1b6586c9e85a54d133e4796a4f7b5a7ea9b67a3d Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:19:34 -0700 Subject: [PATCH 05/36] Fix rtp so that admins can bypass max distance --- AriasServerUtils/EventHandler.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 0cfc261..8a57802 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -58,7 +58,7 @@ namespace AriasServerUtils if (args[0] is int ix) { if (ix == -1) ix = maxDistance; - if (ix > maxDistance) + if (ix > maxDistance && !(ServerUtilities.config.AdminsBypassRTPMaxDistance && isp.HasPrivilege(Privilege.controlserver))) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance)); } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index c9e0d43..b5af4c0 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: 03-07-2025 @ 12:04 PM MST", - "version": "1.0.6-dev.4", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:09 PM MST", + "version": "1.0.6-dev.5", "dependencies": { "game": "" } From 2f1ac319de74742e64a87aafb352482af3a7eedb Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:23:08 -0700 Subject: [PATCH 06/36] Properly fix the rtp position calculator --- AriasServerUtils/RTPFactory.cs | 14 ++++++++------ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ad91bff..3f200a6 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -28,13 +28,15 @@ public class RTPFactory while (tries-- > 0) { - // Generate random X and Z within max RTP distance - bPos.X = (int)vPos.X + rng.Next(0, maxDistance); - bPos.Z = (int)vPos.Z + rng.Next(0, maxDistance); - bPos.Y = 255; + int ixMax = (int)vPos.X + maxDistance; + int ixMin = (int)vPos.X - maxDistance; + int izMax = (int)vPos.Z + maxDistance; + int izMin = (int)vPos.Z - maxDistance; - if (rng.Next(0, 1) == 1) bPos.X = -bPos.X; - if (rng.Next(0, 1) == 1) bPos.Z = -bPos.Z; + // Generate random X and Z within max RTP distance + bPos.X = (int)vPos.X + rng.Next(ixMin, ixMax); + bPos.Z = (int)vPos.Z + rng.Next(izMin, izMax); + bPos.Y = 255; Block lastAboveLast = null; Block lastBlock = null; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index b5af4c0..4626e83 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: 03-07-2025 @ 12:09 PM MST", - "version": "1.0.6-dev.5", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:20 PM MST", + "version": "1.0.6-dev.6", "dependencies": { "game": "" } From 70fe822b0a57e508cb561310c2649a464159ad98 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 12:27:07 -0700 Subject: [PATCH 07/36] Fixes rng to use a seed --- AriasServerUtils/ASUModSystem.cs | 1 + AriasServerUtils/RTPFactory.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index c808b5a..9a44786 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -27,6 +27,7 @@ namespace AriasServerUtils internal static BackCaches backCaches = new BackCaches(); internal static Warps serverWarps = new Warps(); + internal static Random rng = new Random((int)TimeUtil.GetUnixEpochTimestamp()); internal static string[] saveInvTypes = new string[] { diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 3f200a6..8b27e92 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -18,7 +18,7 @@ public class RTPFactory /// A random position +/- max distance from current position. public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance) { - Random rng = new Random(); + Random rng = ServerUtilities.rng; EntityPos vPos = isp.Entity.Pos; BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 4626e83..82c5df4 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: 03-07-2025 @ 12:20 PM MST", - "version": "1.0.6-dev.6", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 12:25 PM MST", + "version": "1.0.6-dev.7", "dependencies": { "game": "" } From 89e483521670625ceb09003672cd124d7b620d99 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 14:10:41 -0700 Subject: [PATCH 08/36] Begin refactoring RTP --- AriasServerUtils/ASUModSystem.cs | 3 +- AriasServerUtils/EventHandler.cs | 24 +-- AriasServerUtils/RTPFactory.cs | 141 +++++++++++++++++- .../assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 4 +- 5 files changed, 146 insertions(+), 27 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 9a44786..84c74af 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -18,7 +18,7 @@ namespace AriasServerUtils { public static string MOD_ID = "ariasserverutils"; public static ASUModConfig config = new ASUModConfig(); - private static ICoreServerAPI API; + internal static ICoreServerAPI API; private static bool bDirty = false; internal static Dictionary backupInventory = new Dictionary(); @@ -79,6 +79,7 @@ namespace AriasServerUtils api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; + api.Event.ChunkColumnLoaded += RTPFactory.ChunkColumnGenerated; //api.Event.PlayerLeave += OnPlayerDC; diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 8a57802..1b5a646 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -74,29 +74,7 @@ namespace AriasServerUtils ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-search")); - - PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance); - if (pPos == null) - { - ps.ActiveCooldowns.Add(CooldownType.RTP, (TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) / 2) + TimeUtil.GetUnixEpochTimestamp()); - ServerUtilities.MarkDirty(); - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); - return TextCommandResult.Success(); - } - Vec2i origin = new((int)isp.Entity.Pos.X, (int)isp.Entity.Pos.Z); - Vec2i npos = new(pPos.X, pPos.Z); - - float distance = RTPFactory.GetDistance(origin, npos); - - pPos.Merge(isp.Entity); - - - ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); - ServerUtilities.MarkDirty(); - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); - + RTPFactory.TryRTP(isp, maxDistance: maxDistance); } return TextCommandResult.Success(); } diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 8b27e92..42c0b51 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -1,9 +1,11 @@ using System; +using System.Collections.Generic; using System.Data; using System.Numerics; using AriasServerUtils; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; +using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.GameContent; @@ -11,6 +13,33 @@ using Vintagestory.GameContent; namespace AriasServerUtils; public class RTPFactory { + + private static List RTPCache = new(); + + /* + if (pPos == null) + { + ps.ActiveCooldowns.Add(CooldownType.RTP, (TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) / 2) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + return TextCommandResult.Success(); + } + Vec2i origin = new((int)isp.Entity.Pos.X, (int)isp.Entity.Pos.Z); + Vec2i npos = new(pPos.X, pPos.Z); + + float distance = RTPFactory.GetDistance(origin, npos); + + pPos.Merge(isp.Entity); + + + ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); + ServerUtilities.MarkDirty(); + + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", distance)); + + */ + /// /// This function searches for a safe position, honoring the max RTP distance in the global configuration /// @@ -23,8 +52,9 @@ public class RTPFactory BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; - int tries = 1000; + int tries = 10000; PlayerPosition PPos = PlayerPosition.from(isp.Entity); + PlayerPosition original = PlayerPosition.from(isp.Entity); while (tries-- > 0) { @@ -41,11 +71,38 @@ public class RTPFactory Block lastAboveLast = null; Block lastBlock = null; Block curBlock; + // Ensure the chunk is loaded before accessing blocks + int chunkX = bPos.X / 32; + int chunkY = bPos.Y / 32; + int chunkZ = bPos.Z / 32; + var chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); + + if (chunk == null) + { + // Chunk doesn't exist, or isn't loaded. + // Teleport the player to the position up in the sky. That way the chunk does get loaded and we can proceed. + PPos.X = bPos.X; + PPos.Y = bPos.Y; + PPos.Z = bPos.Z; + + PPos.Merge(isp.Entity); + } // Scan downwards to find a valid landing spot for (int i = 255; i > 0; i--) { bPos.Y = i; + if (i / 32 != chunkY) + { + chunkY = i / 32; + chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); + if (chunk == null) + { + + PPos.Y = i; + PPos.Merge(isp.Entity); + } + } curBlock = iswa.BlockAccessor.GetBlock(bPos); if (curBlock.MatterState == EnumMatterState.Solid) @@ -58,6 +115,8 @@ public class RTPFactory PPos.Y = bPos.Y + 1; PPos.Z = bPos.Z; + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); + return PPos; } } @@ -67,11 +126,91 @@ public class RTPFactory } } + original.Merge(isp.Entity); + return null; // Return null if no valid position is found after retries } + + /// + /// This function will schedule a task to perform an RTP. + /// + /// Player to be teleported + /// Max distance +/- the current position. + public static void TryRTP(IServerPlayer isp, int maxDistance) + { + var data = new RTPData(isp, maxDistance, 1000, PlayerPosition.from(isp)); + RTPCache.Add(data); + } + public static float GetDistance(Vec2i pos1, Vec2i pos2) { return MathF.Sqrt(MathF.Pow(pos2.X - pos1.X, 2) + MathF.Pow(pos2.Y - pos1.Y, 2)); } + internal static void ChunkColumnGenerated(Vec2i chunkCoord, IWorldChunk[] chunks) + { + throw new NotImplementedException(); + } +} + +public class RTPData +{ + public IServerPlayer player; + public int NumTriesRemaining; + public int MaxDistance; + public PlayerPosition StartPosition; + + public RTPData(IServerPlayer isp, int maxDistance, int tries, PlayerPosition playerPosition) + { + MaxDistance = maxDistance; + player = isp; + NumTriesRemaining = tries; + StartPosition = playerPosition; + } + + public RTPPosition MakeNewPosition() + { + NumTriesRemaining--; + + return new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); + } +} + +public class RTPPosition +{ + int x; + int y; + int z; + + int dimension; + + public RTPPosition(int x, int z, int maxDist, int dim) + { + int minX = x - maxDist; + int maxX = x + maxDist; + int minZ = z - maxDist; + int maxZ = z + maxDist; + + this.x = ServerUtilities.rng.Next(minX, maxX); + this.y = 1; + this.z = ServerUtilities.rng.Next(minZ, maxZ); + + this.dimension = dim; + } + + PlayerPosition GetPlayerPosition() + { + return new PlayerPosition + { + X = x, + Y = y, + Dimension = dimension, + Z = z + }; + } + + BlockPos GetBlockPos() + { + return new BlockPos(new Vec3i(x, y, z), dimension); + } } \ No newline at end of file diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 4498f90..cda0fee 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -35,6 +35,7 @@ "rtp-search": "Searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", + "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", "rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 82c5df4..3cf221e 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: 03-07-2025 @ 12:25 PM MST", - "version": "1.0.6-dev.7", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:32 PM MST", + "version": "1.0.6-dev.8", "dependencies": { "game": "" } From 6e0dbb361a8e0ccd7c1606bf09b634558de21d28 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:02:00 -0700 Subject: [PATCH 09/36] Implement the RTP refactor --- AriasServerUtils/ASUModSystem.cs | 3 +- AriasServerUtils/RTPFactory.cs | 186 ++++++++++++++++++------------- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 114 insertions(+), 79 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 84c74af..e2775d2 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -76,10 +76,11 @@ namespace AriasServerUtils api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown); api.Event.Timer(OnCheckModDirty, 20); api.Event.Timer(OnCheckPlayerCooldowns, 1); + api.Event.Timer(RTPFactory.HandleRTPChecking, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; - api.Event.ChunkColumnLoaded += RTPFactory.ChunkColumnGenerated; + api.Event.ChunkColumnLoaded += RTPFactory.ChunkLoaded; //api.Event.PlayerLeave += OnPlayerDC; diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 42c0b51..8155b8c 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Linq; using System.Numerics; using AriasServerUtils; using Vintagestory.API.Common; @@ -15,6 +16,7 @@ public class RTPFactory { private static List RTPCache = new(); + private static List ChunkChecks = new(); /* if (pPos == null) @@ -41,93 +43,58 @@ public class RTPFactory */ /// - /// This function searches for a safe position, honoring the max RTP distance in the global configuration + /// This function searches for a safe position /// /// The player to be teleported - /// A random position +/- max distance from current position. - public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance) + /// A safe position if able to be found + public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position) { Random rng = ServerUtilities.rng; + IServerPlayer isp = data.player; EntityPos vPos = isp.Entity.Pos; BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; int tries = 10000; PlayerPosition PPos = PlayerPosition.from(isp.Entity); - PlayerPosition original = PlayerPosition.from(isp.Entity); + //PlayerPosition original = PlayerPosition.from(isp.Entity); - while (tries-- > 0) + + // Generate random X and Z within max RTP distance + bPos.X = position.x; + bPos.Z = position.z; + bPos.Y = 255; + + Block lastAboveLast = null; + Block lastBlock = null; + Block curBlock; + + // Scan downwards to find a valid landing spot + for (int i = 255; i > 0; i--) { - int ixMax = (int)vPos.X + maxDistance; - int ixMin = (int)vPos.X - maxDistance; - int izMax = (int)vPos.Z + maxDistance; - int izMin = (int)vPos.Z - maxDistance; + bPos.Y = i; + curBlock = iswa.BlockAccessor.GetBlock(bPos); - // Generate random X and Z within max RTP distance - bPos.X = (int)vPos.X + rng.Next(ixMin, ixMax); - bPos.Z = (int)vPos.Z + rng.Next(izMin, izMax); - bPos.Y = 255; - - Block lastAboveLast = null; - Block lastBlock = null; - Block curBlock; - // Ensure the chunk is loaded before accessing blocks - int chunkX = bPos.X / 32; - int chunkY = bPos.Y / 32; - int chunkZ = bPos.Z / 32; - var chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); - - if (chunk == null) + if (curBlock.MatterState == EnumMatterState.Solid) { - // Chunk doesn't exist, or isn't loaded. - // Teleport the player to the position up in the sky. That way the chunk does get loaded and we can proceed. - PPos.X = bPos.X; - PPos.Y = bPos.Y; - PPos.Z = bPos.Z; + if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && + lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) + { + // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) + PPos.X = bPos.X; + PPos.Y = bPos.Y + 1; + PPos.Z = bPos.Z; - PPos.Merge(isp.Entity); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); + + return PPos; + } } - // Scan downwards to find a valid landing spot - for (int i = 255; i > 0; i--) - { - bPos.Y = i; - if (i / 32 != chunkY) - { - chunkY = i / 32; - chunk = iswa.ChunkProvider.GetUnpackedChunkFast(chunkX, chunkY, chunkZ); - if (chunk == null) - { - - PPos.Y = i; - PPos.Merge(isp.Entity); - } - } - curBlock = iswa.BlockAccessor.GetBlock(bPos); - - if (curBlock.MatterState == EnumMatterState.Solid) - { - if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && - lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) - { - // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) - PPos.X = bPos.X; - PPos.Y = bPos.Y + 1; - PPos.Z = bPos.Z; - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); - - return PPos; - } - } - - lastAboveLast = lastBlock; - lastBlock = curBlock; - } + lastAboveLast = lastBlock; + lastBlock = curBlock; } - original.Merge(isp.Entity); - return null; // Return null if no valid position is found after retries } @@ -138,7 +105,7 @@ public class RTPFactory /// Max distance +/- the current position. public static void TryRTP(IServerPlayer isp, int maxDistance) { - var data = new RTPData(isp, maxDistance, 1000, PlayerPosition.from(isp)); + var data = new RTPData(isp, maxDistance, 100, PlayerPosition.from(isp.Entity)); RTPCache.Add(data); } @@ -147,10 +114,75 @@ public class RTPFactory return MathF.Sqrt(MathF.Pow(pos2.X - pos1.X, 2) + MathF.Pow(pos2.Y - pos1.Y, 2)); } - internal static void ChunkColumnGenerated(Vec2i chunkCoord, IWorldChunk[] chunks) + /// + /// Fired automatically by the internal game timer. This function will handle checking for a RTP Location + /// + /// NOTE: This function will only cause the chunks in question to be force loaded long enough to check their blocks and make sure it is safe to land there. + /// + internal static void HandleRTPChecking() { - throw new NotImplementedException(); + // We want to now loop over the entire cache list. + // We'll then generate a position to check + // We'll also then check the loaded status of the chunk + foreach (var rtp in RTPCache) + { + // Check for any chunks still being checked. + int num = ChunkChecks.Select(x => x.rtp.player.PlayerUID == rtp.player.PlayerUID).Count(); + if (num > 0) continue; + + // Generate a new position + var position = rtp.MakeNewPosition(); + + // Get the world handle, then get chunk size + var worldManager = ServerUtilities.API.WorldManager; + var chunkSize = worldManager.ChunkSize; + + // Generate a chunk load check object. + RTPChunk chunk = new RTPChunk(); + chunk.ChunkX = position.x / chunkSize; + chunk.ChunkZ = position.z / chunkSize; + chunk.dim = position.dimension; + chunk.rtp = rtp; + + // Load the chunk + worldManager.LoadChunkColumnForDimension(chunk.ChunkX, chunk.ChunkZ, chunk.dim); + + // Log the request + ChunkChecks.Add(chunk); + } } + + internal static void ChunkLoaded(Vec2i chunkCoord, IWorldChunk[] chunks) + { + // Get the chunk from the stack + var chunk = ChunkChecks.Where(x => x.ChunkX == chunkCoord.X && x.ChunkZ == chunkCoord.Y).First(); + + // Attempt to find a landing point. + var data = chunk.rtp; + var pos = GetSafePosition(data, data.LastPosition); + + if (pos == null) + { + // Let this get checked again + } + else + { + // Found! Perform teleport and remove the RTP Check + RTPCache.Remove(data); + pos.Merge(data.player.Entity); + } + + // Remove this check + ChunkChecks.Remove(chunk); + } +} + +public class RTPChunk +{ + public int ChunkX; + public int ChunkZ; + public int dim; + public RTPData rtp; } public class RTPData @@ -159,6 +191,7 @@ public class RTPData public int NumTriesRemaining; public int MaxDistance; public PlayerPosition StartPosition; + public RTPPosition LastPosition; public RTPData(IServerPlayer isp, int maxDistance, int tries, PlayerPosition playerPosition) { @@ -171,18 +204,19 @@ public class RTPData public RTPPosition MakeNewPosition() { NumTriesRemaining--; + LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); - return new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); + return LastPosition; } } public class RTPPosition { - int x; - int y; - int z; + public int x; + public int y; + public int z; - int dimension; + public int dimension; public RTPPosition(int x, int z, int maxDist, int dim) { diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 3cf221e..23ebf07 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: 03-07-2025 @ 1:32 PM MST", - "version": "1.0.6-dev.8", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:01 AM MST", + "version": "1.0.6-dev.9", "dependencies": { "game": "" } From 40f8eb40484f96e41025320cc64c6637b23e908f Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:07:03 -0700 Subject: [PATCH 10/36] Attempt to fix a crash when no RTP checks are active that match the chunk generated/loaded. --- AriasServerUtils/RTPFactory.cs | 5 +++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 8155b8c..77d9fe0 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -154,6 +154,11 @@ public class RTPFactory internal static void ChunkLoaded(Vec2i chunkCoord, IWorldChunk[] chunks) { + // Check if this is even a valid check + var num = ChunkChecks.Where(x => x.ChunkX == chunkCoord.X && x.ChunkZ == chunkCoord.Y).Count(); + if (num == 0) return; + + // Get the chunk from the stack var chunk = ChunkChecks.Where(x => x.ChunkX == chunkCoord.X && x.ChunkZ == chunkCoord.Y).First(); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 23ebf07..1dd4911 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: 03-10-2025 @ 10:01 AM MST", - "version": "1.0.6-dev.9", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:06 AM MST", + "version": "1.0.6-dev.10", "dependencies": { "game": "" } From aad44f4c45f3a1c579e3c7e087f39354a3aa4757 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:11:33 -0700 Subject: [PATCH 11/36] Ensure the failed rtp gets removed from the list --- AriasServerUtils/RTPFactory.cs | 9 +++++++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 77d9fe0..45cf750 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -149,6 +149,15 @@ public class RTPFactory // Log the request ChunkChecks.Add(chunk); + + if (rtp.NumTriesRemaining <= 0) + { + // Send failure message to the player + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + // This check needs to be removed from the queue + RTPCache.Remove(rtp); + return; // We modified the list, so abort the loop. + } } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 1dd4911..3352e71 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: 03-10-2025 @ 10:06 AM MST", - "version": "1.0.6-dev.10", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:08 AM MST", + "version": "1.0.6-dev.11", "dependencies": { "game": "" } From 74d85c57e12071988e0ee9d9067e856435a923b9 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:22:58 -0700 Subject: [PATCH 12/36] Patch an infinite loop --- AriasServerUtils/RTPFactory.cs | 2 ++ AriasServerUtils/assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 45cf750..abddf7a 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -132,6 +132,7 @@ public class RTPFactory // Generate a new position var position = rtp.MakeNewPosition(); + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); // Get the world handle, then get chunk size var worldManager = ServerUtilities.API.WorldManager; @@ -178,6 +179,7 @@ public class RTPFactory if (pos == null) { // Let this get checked again + RTPCache.Remove(data); } else { diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index cda0fee..2efe4df 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,6 +34,7 @@ "back": "You've been taken back to your last position", "rtp-search": "Searching for a random position...", + "rtp-progress": "Still searchinf for a random position...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 3352e71..fbc64b5 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: 03-10-2025 @ 10:08 AM MST", - "version": "1.0.6-dev.11", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:22 AM MST", + "version": "1.0.6-dev.12", "dependencies": { "game": "" } From 6598eb44da5ced1ec2b502ec3891024e2b6fb08e Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:36:41 -0700 Subject: [PATCH 13/36] Change method of finding a safe position --- AriasServerUtils/RTPFactory.cs | 58 ++++--------------- .../assets/ariasserverutils/lang/en.json | 2 +- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index abddf7a..3f36d9f 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -49,53 +49,18 @@ public class RTPFactory /// A safe position if able to be found public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position) { - Random rng = ServerUtilities.rng; - IServerPlayer isp = data.player; - EntityPos vPos = isp.Entity.Pos; - BlockPos bPos = new BlockPos(isp.Entity.Pos.Dimension); - IServerWorldAccessor iswa = isp.Entity.World as IServerWorldAccessor; + PlayerPosition PPos = PlayerPosition.from(data.player.Entity); + BlockPos check = new( + x: position.x, + y: 1, + z: position.z, + dim: position.dimension + ); - int tries = 10000; - PlayerPosition PPos = PlayerPosition.from(isp.Entity); - //PlayerPosition original = PlayerPosition.from(isp.Entity); + int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); - - // Generate random X and Z within max RTP distance - bPos.X = position.x; - bPos.Z = position.z; - bPos.Y = 255; - - Block lastAboveLast = null; - Block lastBlock = null; - Block curBlock; - - // Scan downwards to find a valid landing spot - for (int i = 255; i > 0; i--) - { - bPos.Y = i; - curBlock = iswa.BlockAccessor.GetBlock(bPos); - - if (curBlock.MatterState == EnumMatterState.Solid) - { - if (lastBlock != null && lastBlock.BlockMaterial == EnumBlockMaterial.Air && - lastAboveLast != null && lastAboveLast.BlockMaterial == EnumBlockMaterial.Air) - { - // Found a valid spot: curBlock is solid, lastBlock & lastAboveLast are gas (air) - PPos.X = bPos.X; - PPos.Y = bPos.Y + 1; - PPos.Z = bPos.Z; - - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-found", tries)); - - return PPos; - } - } - - lastAboveLast = lastBlock; - lastBlock = curBlock; - } - - return null; // Return null if no valid position is found after retries + PPos.Y = height + 1; + return PPos; } /// @@ -179,13 +144,14 @@ public class RTPFactory if (pos == null) { // Let this get checked again - RTPCache.Remove(data); } else { // Found! Perform teleport and remove the RTP Check RTPCache.Remove(data); pos.Merge(data.player.Entity); + + ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z)))); } // Remove this check diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 2efe4df..6a19efb 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,7 +34,7 @@ "back": "You've been taken back to your last position", "rtp-search": "Searching for a random position...", - "rtp-progress": "Still searchinf for a random position...", + "rtp-progress": "Still searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index fbc64b5..cd1afab 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: 03-10-2025 @ 10:22 AM MST", - "version": "1.0.6-dev.12", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:36 AM MST", + "version": "1.0.6-dev.13", "dependencies": { "game": "" } From 3712399a03b577949f9218a28993b19e4b8d0744 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 10:55:04 -0700 Subject: [PATCH 14/36] Optimize by using the existing helper functions --- AriasServerUtils/RTPFactory.cs | 20 ++++++++------------ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 3f36d9f..5f81d53 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -49,13 +49,9 @@ public class RTPFactory /// A safe position if able to be found public static PlayerPosition GetSafePosition(RTPData data, RTPPosition position) { - PlayerPosition PPos = PlayerPosition.from(data.player.Entity); - BlockPos check = new( - x: position.x, - y: 1, - z: position.z, - dim: position.dimension - ); + PlayerPosition PPos = data.LastPosition.GetPlayerPosition(); + BlockPos check = data.LastPosition.GetBlockPos(); + check.Y = 1; int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); @@ -110,12 +106,12 @@ public class RTPFactory chunk.dim = position.dimension; chunk.rtp = rtp; - // Load the chunk - worldManager.LoadChunkColumnForDimension(chunk.ChunkX, chunk.ChunkZ, chunk.dim); - // Log the request ChunkChecks.Add(chunk); + // Load the chunk + worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); + if (rtp.NumTriesRemaining <= 0) { // Send failure message to the player @@ -214,7 +210,7 @@ public class RTPPosition this.dimension = dim; } - PlayerPosition GetPlayerPosition() + public PlayerPosition GetPlayerPosition() { return new PlayerPosition { @@ -225,7 +221,7 @@ public class RTPPosition }; } - BlockPos GetBlockPos() + public BlockPos GetBlockPos() { return new BlockPos(new Vec3i(x, y, z), dimension); } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index cd1afab..9bd42e7 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: 03-10-2025 @ 10:36 AM MST", - "version": "1.0.6-dev.13", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 10:54 AM MST", + "version": "1.0.6-dev.14", "dependencies": { "game": "" } From 5f99672a9b46e1842e8f20cd79613b6e4b831d90 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 11:04:23 -0700 Subject: [PATCH 15/36] Restore the original RTP search method --- AriasServerUtils/RTPFactory.cs | 37 ++++++++++++++++++++++++++++++++-- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index 5f81d53..d449e6a 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -4,6 +4,7 @@ using System.Data; using System.Linq; using System.Numerics; using AriasServerUtils; +using Microsoft.Win32.SafeHandles; using Vintagestory.API.Common; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; @@ -53,9 +54,41 @@ public class RTPFactory BlockPos check = data.LastPosition.GetBlockPos(); check.Y = 1; - int height = ServerUtilities.API.World.BlockAccessor.GetTerrainMapheightAt(check); + int Y = 255; + bool lastBlockAir = true; + bool lastLastBlockAir = true; + bool curBlockAir = true; + bool safe = false; + for (Y = 255; Y > 1; Y--) + { + // Manually scan downwards + var BA = ServerUtilities.API.World.BlockAccessor; + check.Y = Y; + var current = BA.GetBlock(check); - PPos.Y = height + 1; + if (current.BlockMaterial != EnumBlockMaterial.Air) + { + curBlockAir = false; + } + + + + lastLastBlockAir = lastBlockAir; + lastBlockAir = curBlockAir; + + + if (!curBlockAir && lastBlockAir && lastLastBlockAir) + { + // We found a safe spot to land + check.Y++; + safe = true; + break; + } + } + + if (!safe) return null; + + PPos.Y = check.Y; return PPos; } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 9bd42e7..a385c42 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: 03-10-2025 @ 10:54 AM MST", - "version": "1.0.6-dev.14", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:04 AM MST", + "version": "1.0.6-dev.15", "dependencies": { "game": "" } From c69e1de64b4926524c5055c4710c645865c63218 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 11:18:45 -0700 Subject: [PATCH 16/36] Take world size into account when finding rtp --- AriasServerUtils/RTPFactory.cs | 45 +++++++++++++++++++++------------- AriasServerUtils/modinfo.json | 4 +-- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index d449e6a..ce8de87 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -99,7 +99,7 @@ public class RTPFactory /// Max distance +/- the current position. public static void TryRTP(IServerPlayer isp, int maxDistance) { - var data = new RTPData(isp, maxDistance, 100, PlayerPosition.from(isp.Entity)); + var data = new RTPData(isp, maxDistance, 10, PlayerPosition.from(isp.Entity)); RTPCache.Add(data); } @@ -124,13 +124,24 @@ public class RTPFactory int num = ChunkChecks.Select(x => x.rtp.player.PlayerUID == rtp.player.PlayerUID).Count(); if (num > 0) continue; - // Generate a new position - var position = rtp.MakeNewPosition(); - ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); + + if (rtp.NumTriesRemaining <= 0) + { + // Send failure message to the player + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); + // This check needs to be removed from the queue + RTPCache.Remove(rtp); + return; // We modified the list, so abort the loop. + } // Get the world handle, then get chunk size var worldManager = ServerUtilities.API.WorldManager; var chunkSize = worldManager.ChunkSize; + var worldSize = new Vec3i(worldManager.MapSizeX, worldManager.MapSizeY, worldManager.MapSizeZ); + + // Generate a new position + var position = rtp.MakeNewPosition(worldSize); + //ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); // Generate a chunk load check object. RTPChunk chunk = new RTPChunk(); @@ -145,14 +156,6 @@ public class RTPFactory // Load the chunk worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); - if (rtp.NumTriesRemaining <= 0) - { - // Send failure message to the player - ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); - // This check needs to be removed from the queue - RTPCache.Remove(rtp); - return; // We modified the list, so abort the loop. - } } } @@ -212,10 +215,10 @@ public class RTPData StartPosition = playerPosition; } - public RTPPosition MakeNewPosition() + public RTPPosition MakeNewPosition(Vec3i mapSize) { NumTriesRemaining--; - LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension); + LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize); return LastPosition; } @@ -229,16 +232,24 @@ public class RTPPosition public int dimension; - public RTPPosition(int x, int z, int maxDist, int dim) + public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize) { + + int worldx = mapSize.X / 2; + int worldz = mapSize.Z / 2; + + if (maxDist > worldx) maxDist = worldx / 2; + int minX = x - maxDist; int maxX = x + maxDist; int minZ = z - maxDist; int maxZ = z + maxDist; - this.x = ServerUtilities.rng.Next(minX, maxX); + this.x = ServerUtilities.rng.Next(worldx - minX, worldx + maxX); this.y = 1; - this.z = ServerUtilities.rng.Next(minZ, maxZ); + this.z = ServerUtilities.rng.Next(worldz - minZ, worldz + maxZ); + + this.dimension = dim; } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index a385c42..59f8f79 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: 03-10-2025 @ 11:04 AM MST", - "version": "1.0.6-dev.15", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:18 AM MST", + "version": "1.0.6-dev.16", "dependencies": { "game": "" } From cf7084c1647d2b0febfee6332be2ec89544bb519 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 11:52:35 -0700 Subject: [PATCH 17/36] Add a timeout to a chunk check --- AriasServerUtils/RTPFactory.cs | 37 +++++++++++++++---- .../assets/ariasserverutils/lang/en.json | 2 +- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ce8de87..d1d017e 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -52,7 +52,13 @@ public class RTPFactory { PlayerPosition PPos = data.LastPosition.GetPlayerPosition(); BlockPos check = data.LastPosition.GetBlockPos(); + var BA = ServerUtilities.API.World.BlockAccessor; check.Y = 1; + int height = BA.GetTerrainMapheightAt(check); + if (height >= 0 && height <= 20) return null; + check.Y = height + 1; + PPos.Y = height + 1; + return PPos; int Y = 255; bool lastBlockAir = true; @@ -62,7 +68,6 @@ public class RTPFactory for (Y = 255; Y > 1; Y--) { // Manually scan downwards - var BA = ServerUtilities.API.World.BlockAccessor; check.Y = Y; var current = BA.GetBlock(check); @@ -115,6 +120,15 @@ public class RTPFactory /// internal static void HandleRTPChecking() { + foreach (var chunk in ChunkChecks) + { + chunk.Wait--; + if (chunk.Wait <= 0) + { + ChunkChecks.Remove(chunk); + break; + } + } // We want to now loop over the entire cache list. // We'll then generate a position to check // We'll also then check the loaded status of the chunk @@ -131,6 +145,7 @@ public class RTPFactory ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); // This check needs to be removed from the queue RTPCache.Remove(rtp); + HandleRTPChecking(); return; // We modified the list, so abort the loop. } @@ -141,7 +156,7 @@ public class RTPFactory // Generate a new position var position = rtp.MakeNewPosition(worldSize); - //ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress")); + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-progress", rtp.NumTriesRemaining)); // Generate a chunk load check object. RTPChunk chunk = new RTPChunk(); @@ -176,6 +191,7 @@ public class RTPFactory if (pos == null) { // Let this get checked again + ServerUtilities.API.Logger.Notification("position null: resume search"); } else { @@ -184,6 +200,8 @@ public class RTPFactory pos.Merge(data.player.Entity); ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z)))); + + ServerUtilities.API.Logger.Notification("position found"); } // Remove this check @@ -197,6 +215,7 @@ public class RTPChunk public int ChunkZ; public int dim; public RTPData rtp; + public int Wait = 5; } public class RTPData @@ -218,7 +237,7 @@ public class RTPData public RTPPosition MakeNewPosition(Vec3i mapSize) { NumTriesRemaining--; - LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize); + LastPosition = new RTPPosition((int)player.Entity.Pos.X, (int)player.Entity.Pos.Z, MaxDistance, player.Entity.Pos.Dimension, mapSize, player); return LastPosition; } @@ -232,22 +251,26 @@ public class RTPPosition public int dimension; - public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize) + public RTPPosition(int x, int z, int maxDist, int dim, Vec3i mapSize, IServerPlayer player) { int worldx = mapSize.X / 2; int worldz = mapSize.Z / 2; - if (maxDist > worldx) maxDist = worldx / 2; + if (maxDist > worldx) + { + ServerUtilities.SendMessageTo(player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", maxDist, (worldx))); + maxDist = worldx / 2; + } int minX = x - maxDist; int maxX = x + maxDist; int minZ = z - maxDist; int maxZ = z + maxDist; - this.x = ServerUtilities.rng.Next(worldx - minX, worldx + maxX); + this.x = ServerUtilities.rng.Next(minX, maxX); this.y = 1; - this.z = ServerUtilities.rng.Next(worldz - minZ, worldz + maxZ); + this.z = ServerUtilities.rng.Next(minZ, maxZ); diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 6a19efb..cf23780 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -34,7 +34,7 @@ "back": "You've been taken back to your last position", "rtp-search": "Searching for a random position...", - "rtp-progress": "Still searching for a random position...", + "rtp-progress": "Still searching for a random position... [{0}] tries remaining...", "rtp": "You have been teleported [{0}] blocks away!", "rtp-found": "Found a valid landing position after {0} tries.", "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 59f8f79..db75f3d 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: 03-10-2025 @ 11:18 AM MST", - "version": "1.0.6-dev.16", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:52 AM MST", + "version": "1.0.6-dev.17", "dependencies": { "game": "" } From bda8e49ee1e1e8a1e283106b73bc1fa6d4fa6a58 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 12:03:32 -0700 Subject: [PATCH 18/36] Patch rtp in already loaded chunks --- AriasServerUtils/RTPFactory.cs | 31 +++++++++++++++++++++++++++++-- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index d1d017e..a891813 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -168,9 +168,36 @@ public class RTPFactory // Log the request ChunkChecks.Add(chunk); - // Load the chunk - worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); + // Check if the chunk's coordinates are loaded + var cxCheck = ServerUtilities.API.World.IsFullyLoadedChunk(position.GetBlockPos()); + if (cxCheck) + { + // Process the check here, no need to load + var posX = GetSafePosition(rtp, position); + if (posX == null) + { + // Let this get checked again + ServerUtilities.API.Logger.Notification("position null: resume search"); + } + else + { + // Found! Perform teleport and remove the RTP Check + RTPCache.Remove(rtp); + posX.Merge(rtp.player.Entity); + + ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(rtp.StartPosition.X, rtp.StartPosition.Z), new Vec2i(posX.X, posX.Z)))); + + ServerUtilities.API.Logger.Notification("position found"); + } + + ChunkChecks.Remove(chunk); + } + else + { + // Load the chunk + worldManager.LoadChunkColumnPriority(chunk.ChunkX, chunk.ChunkZ); + } } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index db75f3d..f4dd3b9 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: 03-10-2025 @ 11:52 AM MST", - "version": "1.0.6-dev.17", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 11:55 AM MST", + "version": "1.0.6-dev.18", "dependencies": { "game": "" } From caf12dfadec4cf32657c3b8c6b2a2335f1dbb30e Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 12:04:12 -0700 Subject: [PATCH 19/36] Remove debug --- AriasServerUtils/RTPFactory.cs | 8 ++++---- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index a891813..ef37717 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -177,7 +177,7 @@ public class RTPFactory if (posX == null) { // Let this get checked again - ServerUtilities.API.Logger.Notification("position null: resume search"); + //ServerUtilities.API.Logger.Notification("position null: resume search"); } else { @@ -188,7 +188,7 @@ public class RTPFactory ServerUtilities.SendMessageTo(rtp.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(rtp.StartPosition.X, rtp.StartPosition.Z), new Vec2i(posX.X, posX.Z)))); - ServerUtilities.API.Logger.Notification("position found"); + //ServerUtilities.API.Logger.Notification("position found"); } ChunkChecks.Remove(chunk); @@ -218,7 +218,7 @@ public class RTPFactory if (pos == null) { // Let this get checked again - ServerUtilities.API.Logger.Notification("position null: resume search"); + //ServerUtilities.API.Logger.Notification("position null: resume search"); } else { @@ -228,7 +228,7 @@ public class RTPFactory ServerUtilities.SendMessageTo(data.player, Lang.Get($"{ServerUtilities.MOD_ID}:rtp", GetDistance(new Vec2i(data.StartPosition.X, data.StartPosition.Z), new Vec2i(pos.X, pos.Z)))); - ServerUtilities.API.Logger.Notification("position found"); + //ServerUtilities.API.Logger.Notification("position found"); } // Remove this check diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f4dd3b9..b94b714 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: 03-10-2025 @ 11:55 AM MST", - "version": "1.0.6-dev.18", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 12:03 PM MST", + "version": "1.0.6-dev.19", "dependencies": { "game": "" } From c609dde0ee9944fbf8c39adbd95c147f05ea2f00 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 12:04:31 -0700 Subject: [PATCH 20/36] Release 1.0.6 --- AriasServerUtils/modinfo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index b94b714..e8b5349 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: 03-10-2025 @ 12:03 PM MST", - "version": "1.0.6-dev.19", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 12:04 PM MST", + "version": "1.0.6", "dependencies": { "game": "" } From 9a8b9d154544e77aae2445254dde6f1afd6cf82d Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 17:17:25 -0700 Subject: [PATCH 21/36] Begin to add the player sleeping percentage system --- AriasServerUtils/ASUModSystem.cs | 50 ++++++++++++++++++++++++++++++++ AriasServerUtils/modinfo.json | 4 +-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index e2775d2..27ff056 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -38,6 +38,8 @@ namespace AriasServerUtils GlobalConstants.characterInvClassName }; + List SleepingPlayers { get; set; } + /// /// Method to register all mod blocks /// @@ -76,6 +78,7 @@ namespace AriasServerUtils api.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, OnShutdown); api.Event.Timer(OnCheckModDirty, 20); api.Event.Timer(OnCheckPlayerCooldowns, 1); + api.Event.Timer(OnCheckSleepingPlayers, 5); api.Event.Timer(RTPFactory.HandleRTPChecking, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; @@ -235,6 +238,53 @@ namespace AriasServerUtils 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); } + private void OnCheckSleepingPlayers() + { + if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! + if (config.PlayerSleepingPercentage == 100) return; // Normal behavior + // Iterate over all players, get their entity, check if mounted on a bed. + // If mounted on a bed, check tiredness + int TotalOnline = API.World.AllOnlinePlayers.Length; + int TotalInBed = 0; + + bool isAlreadySleeping = false; + + List BEBs = new(); + + foreach (var player in API.World.AllOnlinePlayers) + { + EntityAgent ePlay = player.Entity; + if (ePlay.MountedOn is BlockEntityBed beb) + { + BEBs.Add(beb); + TotalInBed++; + } + if (ePlay.MountedOn == null) + { + if (SleepingPlayers.Contains(ePlay)) + { + EntityBehaviorTiredness ebt = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + if (ebt != null) + ebt.IsSleeping = false; + } + } + + EntityBehaviorTiredness EBT = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + if (EBT == null) continue; + if (EBT.IsSleeping) isAlreadySleeping = true; + } + + if (isAlreadySleeping) return; // Abort + + SleepingPlayers.Clear(); + + int Percentage = TotalInBed * 100 / TotalOnline; + if (Percentage >= config.PlayerSleepingPercentage) + { + // Call the API to make sleep happen + } + } + private void OnCheckPlayerCooldowns() { foreach (var cdEntry in ServerUtilities.mPlayerData) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index e8b5349..f30a8d5 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: 03-10-2025 @ 12:04 PM MST", - "version": "1.0.6", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 4:37 PM MST", + "version": "1.0.7-dev.1", "dependencies": { "game": "" } From 720dafea871be503721cf1f048591a10d36bdaaf Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 18:57:27 -0700 Subject: [PATCH 22/36] Implement experimental player sleeping percentage handling --- AriasServerUtils/ASUModSystem.cs | 48 ++++++++++++++++++++++++++++---- AriasServerUtils/modinfo.json | 4 +-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 27ff056..215f848 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -38,7 +38,10 @@ namespace AriasServerUtils GlobalConstants.characterInvClassName }; - List SleepingPlayers { get; set; } + List SleepingPlayers { get; set; } = new(); + float OriginalSpeed { get; set; } = 0.0f; + public double Hours { get; private set; } = 0.0; + bool Sleeping { get; set; } = false; /// /// Method to register all mod blocks @@ -76,10 +79,6 @@ 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.Timer(OnCheckSleepingPlayers, 5); - api.Event.Timer(RTPFactory.HandleRTPChecking, 1); api.Event.PlayerDeath += OnPlayerDeath; api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; @@ -241,6 +240,22 @@ namespace AriasServerUtils private void OnCheckSleepingPlayers() { if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! + if (Sleeping) + { + if (API.World.Calendar.TotalHours - Hours >= 7) + { + Sleeping = false; + foreach (var player in SleepingPlayers) + { + EntityBehaviorTiredness ebt = player.GetBehavior("tiredness") as EntityBehaviorTiredness; + ebt.IsSleeping = false; + } + + SleepingPlayers.Clear(); + API.World.Calendar.CalendarSpeedMul = OriginalSpeed; + } + return; + } if (config.PlayerSleepingPercentage == 100) return; // Normal behavior // Iterate over all players, get their entity, check if mounted on a bed. // If mounted on a bed, check tiredness @@ -282,6 +297,22 @@ namespace AriasServerUtils if (Percentage >= config.PlayerSleepingPercentage) { // Call the API to make sleep happen + foreach (var bed in BEBs) + { + if (bed.MountedBy != null) SleepingPlayers.Add(bed.MountedBy); + + // Start sleep + EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior("tiredness") as EntityBehaviorTiredness; + + EBT.IsSleeping = true; + + // Get current calendar speed + OriginalSpeed = API.World.Calendar.CalendarSpeedMul; + Hours = API.World.Calendar.TotalHours; + Sleeping = true; + + API.World.Calendar.CalendarSpeedMul = 4; + } } } @@ -445,6 +476,13 @@ namespace AriasServerUtils // -> Step 3. Load Mod Warps <- serverWarps = API.LoadModConfig(GetConfigurationFile("warps", ModConfigType.Global)); if (serverWarps == null) serverWarps = new Warps(); + + + + API.Event.Timer(OnCheckModDirty, 20); + API.Event.Timer(OnCheckPlayerCooldowns, 1); + API.Event.Timer(OnCheckSleepingPlayers, 5); + API.Event.Timer(RTPFactory.HandleRTPChecking, 1); } public string GetConfigurationFile(string sName, ModConfigType type) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f30a8d5..6d14c13 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: 03-10-2025 @ 4:37 PM MST", - "version": "1.0.7-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 03-10-2025 @ 6:56 PM MST", + "version": "1.0.7-dev.2", "dependencies": { "game": "" } From d2b92f95c51e51021d4a2994de9d436b6543d6db Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 00:37:46 -0700 Subject: [PATCH 23/36] Change method of time acceleration --- AriasServerUtils/ModSystems/ASUClient.cs | 34 +++++ .../ASUServer.cs} | 116 +++++++++++++++++- AriasServerUtils/modinfo.json | 4 +- .../network/ASUTimeAccelPacket.cs | 7 ++ 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 AriasServerUtils/ModSystems/ASUClient.cs rename AriasServerUtils/{ASUModSystem.cs => ModSystems/ASUServer.cs} (84%) create mode 100644 AriasServerUtils/network/ASUTimeAccelPacket.cs diff --git a/AriasServerUtils/ModSystems/ASUClient.cs b/AriasServerUtils/ModSystems/ASUClient.cs new file mode 100644 index 0000000..2f678b3 --- /dev/null +++ b/AriasServerUtils/ModSystems/ASUClient.cs @@ -0,0 +1,34 @@ +using System; +using Vintagestory.API.Client; +using Vintagestory.API.Common; + +public class ASUModClient : ModSystem +{ + public static ICoreClientAPI CAPI; + bool accel = false; + + public override bool ShouldLoad(EnumAppSide forSide) + { + return forSide == EnumAppSide.Client; + } + + public override void StartClientSide(ICoreClientAPI api) + { + CAPI = api; + api.Network.RegisterChannel("asutimeaccel") + .RegisterMessageType() + .SetMessageHandler(onReceiveTimeAccel); + } + + private void onReceiveTimeAccel(ASUTimeAcceleration packet) + { + // Time acceleration handler + accel = packet.Sleeping; + + if (accel) + { + CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + } + else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + } +} \ No newline at end of file diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ModSystems/ASUServer.cs similarity index 84% rename from AriasServerUtils/ASUModSystem.cs rename to AriasServerUtils/ModSystems/ASUServer.cs index 215f848..c5d6d75 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -7,6 +7,7 @@ using Vintagestory.API.Common; using Vintagestory.API.Common.CommandAbbr; using Vintagestory.API.Common.Entities; using Vintagestory.API.Config; +using Vintagestory.API.Datastructures; using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.API.Util; @@ -42,6 +43,7 @@ namespace AriasServerUtils float OriginalSpeed { get; set; } = 0.0f; public double Hours { get; private set; } = 0.0; bool Sleeping { get; set; } = false; + public IServerNetworkChannel ServerNetworkChannel { get; private set; } /// /// Method to register all mod blocks @@ -61,6 +63,14 @@ namespace AriasServerUtils { } + + public override bool ShouldLoad(EnumAppSide side) + { + return side == EnumAppSide.Server; + } + + + // Called on server and client public override void Start(ICoreAPI api) { @@ -86,6 +96,10 @@ namespace AriasServerUtils //api.Event.PlayerLeave += OnPlayerDC; + ServerNetworkChannel = api.Network.RegisterChannel("asutimeaccel") + .RegisterMessageType(); + + api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn); api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn); @@ -223,6 +237,20 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.chat) .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") + .EndSubCommand() + .BeginSubCommand("test") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .BeginSubCommand("sleep") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .HandleWith(TestSleep) + .EndSubCommand() + .BeginSubCommand("calendarspeed") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .HandleWith(TestCalendarSpeed) + .EndSubCommand() .EndSubCommand(); api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); @@ -237,6 +265,78 @@ namespace AriasServerUtils 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); } + private TextCommandResult TestSleep(TextCommandCallingArgs args) + { + // Initiate the sleep process + // Basically run all the same commands as we would on a player in bed + OriginalSpeed = API.World.Calendar.CalendarSpeedMul; + if (args.Caller.Player is IServerPlayer isp) + { + Hours = API.World.Calendar.TotalHours; + SleepingPlayers.Add(isp.Entity); + EntityAgent Agent = isp.Entity; + EntityBehaviorTiredness ebt = Agent.GetBehavior("tiredness") as EntityBehaviorTiredness; + ebt.IsSleeping = true; + ebt.Tiredness = 100; + Sleeping = true; + + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + } + + return TextCommandResult.Success($"Test initiated, original calendar multiplier: '{OriginalSpeed}'"); + } + + private TextCommandResult TestCalendarSpeed(TextCommandCallingArgs args) + { + if (args.Caller.Player is IServerPlayer isp) + { + EntityAgent agent = isp.Entity; + EntityBehaviorTiredness ebt = agent.GetBehavior("tiredness") as EntityBehaviorTiredness; + + SendMessageTo(isp, $"- Current calendar speed: {API.World.Calendar.CalendarSpeedMul}"); + SendMessageTo(isp, $"- Total Hours: {API.World.Calendar.TotalHours}"); + SendMessageTo(isp, $"- Tiredness: {ebt.Tiredness}"); + if (OriginalSpeed == 0) + { + // Apply multiplier + OriginalSpeed = 0.5f; + ebt.IsSleeping = true; + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + + SendMessageTo(isp, "Applied calendar speed multiplier"); + } + else + { + // Unapply multiplier + OriginalSpeed = 0; + ebt.IsSleeping = false; + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = false + }); + + API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + + SendMessageTo(isp, "Restored default calendar speed"); + } + } + + return TextCommandResult.Success(); + } + private void OnCheckSleepingPlayers() { if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! @@ -252,7 +352,14 @@ namespace AriasServerUtils } SleepingPlayers.Clear(); - API.World.Calendar.CalendarSpeedMul = OriginalSpeed; + + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = false + }); + + API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); } return; } @@ -311,7 +418,12 @@ namespace AriasServerUtils Hours = API.World.Calendar.TotalHours; Sleeping = true; - API.World.Calendar.CalendarSpeedMul = 4; + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); } } } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 6d14c13..3aec4e6 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: 03-10-2025 @ 6:56 PM MST", - "version": "1.0.7-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:37 AM MST", + "version": "1.0.7-dev.3", "dependencies": { "game": "" } diff --git a/AriasServerUtils/network/ASUTimeAccelPacket.cs b/AriasServerUtils/network/ASUTimeAccelPacket.cs new file mode 100644 index 0000000..bb66753 --- /dev/null +++ b/AriasServerUtils/network/ASUTimeAccelPacket.cs @@ -0,0 +1,7 @@ +using System; + +[Serializable] +public class ASUTimeAcceleration +{ + public bool Sleeping = false; +} \ No newline at end of file From 3ab3dc099f7a0bd4ec69ee55a6a350d1cde3982c Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 00:55:21 -0700 Subject: [PATCH 24/36] Adds a initial basic version of player sleeping percentage. --- AriasServerUtils/ModSystems/ASUServer.cs | 34 ++++++++++--------- .../assets/ariasserverutils/lang/en.json | 5 ++- AriasServerUtils/modinfo.json | 4 +-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index c5d6d75..31b6bab 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -238,7 +238,7 @@ namespace AriasServerUtils .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand() - .BeginSubCommand("test") + /*.BeginSubCommand("test") .RequiresPlayer() .RequiresPrivilege(Privilege.controlserver) .BeginSubCommand("sleep") @@ -251,7 +251,7 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.controlserver) .HandleWith(TestCalendarSpeed) .EndSubCommand() - .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); @@ -286,7 +286,7 @@ namespace AriasServerUtils Sleeping = true }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); } return TextCommandResult.Success($"Test initiated, original calendar multiplier: '{OriginalSpeed}'"); @@ -313,7 +313,7 @@ namespace AriasServerUtils Sleeping = true }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); SendMessageTo(isp, "Applied calendar speed multiplier"); } @@ -349,6 +349,7 @@ namespace AriasServerUtils { EntityBehaviorTiredness ebt = player.GetBehavior("tiredness") as EntityBehaviorTiredness; ebt.IsSleeping = false; + ebt.Tiredness = 0; } SleepingPlayers.Clear(); @@ -403,6 +404,14 @@ namespace AriasServerUtils int Percentage = TotalInBed * 100 / TotalOnline; if (Percentage >= config.PlayerSleepingPercentage) { + + ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration + { + Sleeping = true + }); + + API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); + // Call the API to make sleep happen foreach (var bed in BEBs) { @@ -412,19 +421,12 @@ namespace AriasServerUtils EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior("tiredness") as EntityBehaviorTiredness; EBT.IsSleeping = true; - - // Get current calendar speed - OriginalSpeed = API.World.Calendar.CalendarSpeedMul; - Hours = API.World.Calendar.TotalHours; - Sleeping = true; - - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. } + + // Get current calendar speed + Hours = API.World.Calendar.TotalHours; + Sleeping = true; } } diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index cf23780..162d5a9 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -40,5 +40,8 @@ "rtp-fail": "Giving up on RTP search. No valid position could be found. Try again later", "rtp-capped": "The distance you tried to go [{0}] is greater than the maximum allowable by the server [{1}]", - "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]" + "cmd-cooldown": "[{0}] is currently on cooldown. You can use this command again in [{1}]", + + "psp": "[ASU] PSP Starting... you do not need to stay in bed", + "psp-ending": "[ASU] PSP Complete" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 3aec4e6..e8035c4 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: 03-11-2025 @ 00:37 AM MST", - "version": "1.0.7-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 00:52 AM MST", + "version": "1.0.7", "dependencies": { "game": "" } From 37a1c8d3619862a254ba7b1fde79a14622e3083f Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 01:05:41 -0700 Subject: [PATCH 25/36] Issue a hotfix for a small issue that happens when no players are online. --- AriasServerUtils/ModSystems/ASUServer.cs | 1 + AriasServerUtils/modinfo.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 31b6bab..61a35d8 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -368,6 +368,7 @@ namespace AriasServerUtils // Iterate over all players, get their entity, check if mounted on a bed. // If mounted on a bed, check tiredness int TotalOnline = API.World.AllOnlinePlayers.Length; + if (TotalOnline == 0) return; // No one on, just abort the checks. int TotalInBed = 0; bool isAlreadySleeping = false; diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index e8035c4..0decec5 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: 03-11-2025 @ 00:52 AM MST", - "version": "1.0.7", + "version": "1.0.7-1", "dependencies": { "game": "" } From 11f52de3f73914c081eb76f2159c26c05a83e9c6 Mon Sep 17 00:00:00 2001 From: zontreck Date: Tue, 11 Mar 2025 01:05:50 -0700 Subject: [PATCH 26/36] Bump version 1.0.8 --- AriasServerUtils/modinfo.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 0decec5..70884e3 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: 03-11-2025 @ 00:52 AM MST", - "version": "1.0.7-1", + "description": "A collection of server utilities\n\nBuild Date: 03-11-2025 @ 1:05 AM MST", + "version": "1.0.8", "dependencies": { "game": "" } From 268834b434f4f73108d2948ed18eec21cdaa907c Mon Sep 17 00:00:00 2001 From: zontreck Date: Thu, 24 Apr 2025 11:35:01 -0700 Subject: [PATCH 27/36] Patch for 1.20.9 --- AriasServerUtils/ModSystems/ASUServer.cs | 8 ++++---- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 61a35d8..b00aa66 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -347,7 +347,7 @@ namespace AriasServerUtils Sleeping = false; foreach (var player in SleepingPlayers) { - EntityBehaviorTiredness ebt = player.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness ebt = player.GetBehavior(); ebt.IsSleeping = false; ebt.Tiredness = 0; } @@ -387,13 +387,13 @@ namespace AriasServerUtils { if (SleepingPlayers.Contains(ePlay)) { - EntityBehaviorTiredness ebt = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness ebt = ePlay.GetBehavior(); if (ebt != null) ebt.IsSleeping = false; } } - EntityBehaviorTiredness EBT = ePlay.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness EBT = ePlay.GetBehavior(); if (EBT == null) continue; if (EBT.IsSleeping) isAlreadySleeping = true; } @@ -419,7 +419,7 @@ namespace AriasServerUtils if (bed.MountedBy != null) SleepingPlayers.Add(bed.MountedBy); // Start sleep - EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior("tiredness") as EntityBehaviorTiredness; + EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior(); EBT.IsSleeping = true; bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 70884e3..faddc0d 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: 03-11-2025 @ 1:05 AM MST", - "version": "1.0.8", + "description": "A collection of server utilities\n\nBuild Date: 04-24-2025 @ 11:26 AM MST", + "version": "1.0.9", "dependencies": { "game": "" } From 7ca713e42a1921ca69da89b3b4561ff61c4651bb Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 12:36:01 -0700 Subject: [PATCH 28/36] Fix: #4 --- AriasServerUtils/EventHandler.cs | 2 +- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 1b5a646..b284c3d 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -344,7 +344,7 @@ namespace AriasServerUtils ServerUtilities.NewBackCacheForPlayer(isp); ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity); - ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name)); + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-tp", name)); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index faddc0d..93e2621 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: 04-24-2025 @ 11:26 AM MST", - "version": "1.0.9", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:34 PM MST", + "version": "1.0.10-dev.1", "dependencies": { "game": "" } From 4c585f647eb8998616a6af35be6167b2337f1ef0 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 12:40:50 -0700 Subject: [PATCH 29/36] Remove old deprecated code in RTPFactory --- AriasServerUtils/RTPFactory.cs | 36 ---------------------------------- AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ef37717..d2544a2 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -59,42 +59,6 @@ public class RTPFactory check.Y = height + 1; PPos.Y = height + 1; return PPos; - - int Y = 255; - bool lastBlockAir = true; - bool lastLastBlockAir = true; - bool curBlockAir = true; - bool safe = false; - for (Y = 255; Y > 1; Y--) - { - // Manually scan downwards - check.Y = Y; - var current = BA.GetBlock(check); - - if (current.BlockMaterial != EnumBlockMaterial.Air) - { - curBlockAir = false; - } - - - - lastLastBlockAir = lastBlockAir; - lastBlockAir = curBlockAir; - - - if (!curBlockAir && lastBlockAir && lastLastBlockAir) - { - // We found a safe spot to land - check.Y++; - safe = true; - break; - } - } - - if (!safe) return null; - - PPos.Y = check.Y; - return PPos; } /// diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 93e2621..bc18a83 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-3-2025 @ 12:34 PM MST", - "version": "1.0.10-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:40 PM MST", + "version": "1.0.10-dev.2", "dependencies": { "game": "" } From e56a123cb8daa3b25fd20777a9f45e2adde87633 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 12:53:44 -0700 Subject: [PATCH 30/36] #5: Add debug to player sleeping percentage --- AriasServerUtils/EventHandler.cs | 11 +++++++++++ AriasServerUtils/ModSystems/ASUClient.cs | 3 ++- AriasServerUtils/ModSystems/ASUServer.cs | 18 +++++++++++------- AriasServerUtils/modinfo.json | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index b284c3d..b4af602 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -7,6 +7,7 @@ using Vintagestory.API.Config; using Vintagestory.API.MathTools; using Vintagestory.API.Server; using Vintagestory.API.Util; +using Vintagestory.GameContent; namespace AriasServerUtils { @@ -577,5 +578,15 @@ namespace AriasServerUtils } return TextCommandResult.Success(sReturn); } + + internal static TextCommandResult HandleSleepyDebug(TextCommandCallingArgs args) + { + EntityBehaviorTiredness sleepy = args.Caller.Entity.GetBehavior(); + if (sleepy != null) + { + sleepy.Tiredness = 100; + } + return TextCommandResult.Success(); + } } } \ No newline at end of file diff --git a/AriasServerUtils/ModSystems/ASUClient.cs b/AriasServerUtils/ModSystems/ASUClient.cs index 2f678b3..3374d49 100644 --- a/AriasServerUtils/ModSystems/ASUClient.cs +++ b/AriasServerUtils/ModSystems/ASUClient.cs @@ -24,10 +24,11 @@ public class ASUModClient : ModSystem { // Time acceleration handler accel = packet.Sleeping; + CAPI.Logger.Notification("Time acceleration: " + packet.Sleeping); if (accel) { - CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 500); + CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); } else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); } diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index b00aa66..859f43f 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -238,7 +238,7 @@ namespace AriasServerUtils .HandleWith(Events.HandleASU) .WithDescription("Lists all Aria's Server Utils commands") .EndSubCommand() - /*.BeginSubCommand("test") + .BeginSubCommand("test") .RequiresPlayer() .RequiresPrivilege(Privilege.controlserver) .BeginSubCommand("sleep") @@ -246,12 +246,7 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.controlserver) .HandleWith(TestSleep) .EndSubCommand() - .BeginSubCommand("calendarspeed") - .RequiresPlayer() - .RequiresPrivilege(Privilege.controlserver) - .HandleWith(TestCalendarSpeed) - .EndSubCommand() - .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); @@ -263,12 +258,16 @@ namespace AriasServerUtils 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("debugasu_sleepy").RequiresPlayer().RequiresPrivilege(Privilege.controlserver).WithDescription("Debugging command to test the sleeping system").HandleWith(Events.HandleSleepyDebug); } private TextCommandResult TestSleep(TextCommandCallingArgs args) { // Initiate the sleep process // Basically run all the same commands as we would on a player in bed + Events.HandleSleepyDebug(args); + OriginalSpeed = API.World.Calendar.CalendarSpeedMul; if (args.Caller.Player is IServerPlayer isp) { @@ -361,6 +360,8 @@ namespace AriasServerUtils }); API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + + API.Logger.Notification("Stopping PSP Time Acceleration"); } return; } @@ -422,6 +423,9 @@ namespace AriasServerUtils EntityBehaviorTiredness EBT = bed.MountedBy.GetBehavior(); EBT.IsSleeping = true; + + API.Logger.Notification("Starting PSP Time Acceleration"); + bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index bc18a83..be4f659 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-3-2025 @ 12:40 PM MST", - "version": "1.0.10-dev.2", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 12:53 PM MST", + "version": "1.0.10-dev.3", "dependencies": { "game": "" } From 12d10a9a3c231e057e9d45e848a796eff9ed2846 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 13:57:36 -0700 Subject: [PATCH 31/36] Attempt to fix time accel on server Part of #5 --- AriasServerUtils/ModSystems/ASUClient.cs | 16 -------- AriasServerUtils/ModSystems/ASUServer.cs | 39 +++---------------- AriasServerUtils/modinfo.json | 4 +- .../network/ASUTimeAccelPacket.cs | 7 ---- 4 files changed, 8 insertions(+), 58 deletions(-) delete mode 100644 AriasServerUtils/network/ASUTimeAccelPacket.cs diff --git a/AriasServerUtils/ModSystems/ASUClient.cs b/AriasServerUtils/ModSystems/ASUClient.cs index 3374d49..2966dc3 100644 --- a/AriasServerUtils/ModSystems/ASUClient.cs +++ b/AriasServerUtils/ModSystems/ASUClient.cs @@ -15,21 +15,5 @@ public class ASUModClient : ModSystem public override void StartClientSide(ICoreClientAPI api) { CAPI = api; - api.Network.RegisterChannel("asutimeaccel") - .RegisterMessageType() - .SetMessageHandler(onReceiveTimeAccel); - } - - private void onReceiveTimeAccel(ASUTimeAcceleration packet) - { - // Time acceleration handler - accel = packet.Sleeping; - CAPI.Logger.Notification("Time acceleration: " + packet.Sleeping); - - if (accel) - { - CAPI.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); - } - else CAPI.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); } } \ No newline at end of file diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 859f43f..8c3becd 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -96,10 +96,6 @@ namespace AriasServerUtils //api.Event.PlayerLeave += OnPlayerDC; - ServerNetworkChannel = api.Network.RegisterChannel("asutimeaccel") - .RegisterMessageType(); - - api.ChatCommands.Create("setspawn").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleSetSpawn); api.ChatCommands.Create("spawn").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSpawn); @@ -273,18 +269,15 @@ namespace AriasServerUtils { Hours = API.World.Calendar.TotalHours; SleepingPlayers.Add(isp.Entity); + API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); EntityAgent Agent = isp.Entity; - EntityBehaviorTiredness ebt = Agent.GetBehavior("tiredness") as EntityBehaviorTiredness; + + EntityBehaviorTiredness ebt = Agent.GetBehavior(); + ebt.IsSleeping = true; ebt.Tiredness = 100; Sleeping = true; - - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); } @@ -307,11 +300,6 @@ namespace AriasServerUtils OriginalSpeed = 0.5f; ebt.IsSleeping = true; - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); SendMessageTo(isp, "Applied calendar speed multiplier"); @@ -322,11 +310,6 @@ namespace AriasServerUtils OriginalSpeed = 0; ebt.IsSleeping = false; - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = false - }); - API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); SendMessageTo(isp, "Restored default calendar speed"); @@ -341,7 +324,8 @@ namespace AriasServerUtils if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! if (Sleeping) { - if (API.World.Calendar.TotalHours - Hours >= 7) + API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); + if (API.World.Calendar.TotalHours - Hours >= 6) { Sleeping = false; foreach (var player in SleepingPlayers) @@ -353,12 +337,6 @@ namespace AriasServerUtils SleepingPlayers.Clear(); - - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = false - }); - API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); API.Logger.Notification("Stopping PSP Time Acceleration"); @@ -407,11 +385,6 @@ namespace AriasServerUtils if (Percentage >= config.PlayerSleepingPercentage) { - ServerNetworkChannel.BroadcastPacket(new ASUTimeAcceleration - { - Sleeping = true - }); - API.World.Calendar.SetTimeSpeedModifier("asu_psp", 1000); // Call the API to make sleep happen diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index be4f659..60ec0b3 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-3-2025 @ 12:53 PM MST", - "version": "1.0.10-dev.3", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 1:56 PM MST", + "version": "1.0.10-dev.9", "dependencies": { "game": "" } diff --git a/AriasServerUtils/network/ASUTimeAccelPacket.cs b/AriasServerUtils/network/ASUTimeAccelPacket.cs deleted file mode 100644 index bb66753..0000000 --- a/AriasServerUtils/network/ASUTimeAccelPacket.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System; - -[Serializable] -public class ASUTimeAcceleration -{ - public bool Sleeping = false; -} \ No newline at end of file From b00e56fdf74e4a05c87576fe6327231ae69cee8d Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 14:02:17 -0700 Subject: [PATCH 32/36] Ensure time accel is disabled when world is fully loaded. Part of #5 --- AriasServerUtils/ModSystems/ASUServer.cs | 7 +++++++ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 8c3becd..07b5e45 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -29,6 +29,7 @@ namespace AriasServerUtils internal static Warps serverWarps = new Warps(); internal static Random rng = new Random((int)TimeUtil.GetUnixEpochTimestamp()); + internal bool isFirstStart = true; internal static string[] saveInvTypes = new string[] { @@ -322,6 +323,12 @@ namespace AriasServerUtils private void OnCheckSleepingPlayers() { if (API.Side == EnumAppSide.Client) return; // This must only ever be called on the server! + if (isFirstStart) + { + API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); + isFirstStart = false; + } + if (Sleeping) { API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 60ec0b3..6d99817 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-3-2025 @ 1:56 PM MST", - "version": "1.0.10-dev.9", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:01 PM MST", + "version": "1.0.10-dev.10", "dependencies": { "game": "" } From 7fb2d38c3d2ebb6ccfcbf0f09a37b5b968eca76e Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 14:21:28 -0700 Subject: [PATCH 33/36] Fix: #5 --- AriasServerUtils/ModSystems/ASUServer.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 07b5e45..df4957e 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -357,8 +357,6 @@ namespace AriasServerUtils if (TotalOnline == 0) return; // No one on, just abort the checks. int TotalInBed = 0; - bool isAlreadySleeping = false; - List BEBs = new(); foreach (var player in API.World.AllOnlinePlayers) @@ -368,9 +366,12 @@ namespace AriasServerUtils { BEBs.Add(beb); TotalInBed++; + //API.Logger.Notification($"Bed found for player {player.PlayerName}"); } if (ePlay.MountedOn == null) { + //API.Logger.Notification($"No bed found for player {player.PlayerName}"); + if (SleepingPlayers.Contains(ePlay)) { EntityBehaviorTiredness ebt = ePlay.GetBehavior(); @@ -378,17 +379,16 @@ namespace AriasServerUtils ebt.IsSleeping = false; } } - - EntityBehaviorTiredness EBT = ePlay.GetBehavior(); - if (EBT == null) continue; - if (EBT.IsSleeping) isAlreadySleeping = true; } - if (isAlreadySleeping) return; // Abort + if (Sleeping) return; // Abort SleepingPlayers.Clear(); int Percentage = TotalInBed * 100 / TotalOnline; + + API.Logger.Notification($"Percentage of players in bed: ${Percentage}, Required percentage: ${config.PlayerSleepingPercentage}"); + if (Percentage >= config.PlayerSleepingPercentage) { From 9715975a48522a3a502201cbbc4527d1f17e3988 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sat, 3 May 2025 14:23:18 -0700 Subject: [PATCH 34/36] Release 1.0.10 --- AriasServerUtils/ModSystems/ASUServer.cs | 15 +++++++++------ AriasServerUtils/modinfo.json | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index df4957e..680db83 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -243,6 +243,11 @@ namespace AriasServerUtils .RequiresPrivilege(Privilege.controlserver) .HandleWith(TestSleep) .EndSubCommand() + .BeginSubCommand("sleepy") + .RequiresPlayer() + .RequiresPrivilege(Privilege.controlserver) + .HandleWith(Events.HandleSleepyDebug) + .EndSubCommand() .EndSubCommand(); api.ChatCommands.Create("setwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Creates a new server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpUpdate); @@ -255,8 +260,6 @@ namespace AriasServerUtils 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("debugasu_sleepy").RequiresPlayer().RequiresPrivilege(Privilege.controlserver).WithDescription("Debugging command to test the sleeping system").HandleWith(Events.HandleSleepyDebug); } private TextCommandResult TestSleep(TextCommandCallingArgs args) @@ -331,7 +334,7 @@ namespace AriasServerUtils if (Sleeping) { - API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); + //API.Logger.Notification($"Game Hours: {API.World.Calendar.TotalHours}, Difference: {API.World.Calendar.TotalHours - Hours}"); if (API.World.Calendar.TotalHours - Hours >= 6) { Sleeping = false; @@ -346,7 +349,7 @@ namespace AriasServerUtils API.World.Calendar.RemoveTimeSpeedModifier("asu_psp"); - API.Logger.Notification("Stopping PSP Time Acceleration"); + //API.Logger.Notification("Stopping PSP Time Acceleration"); } return; } @@ -387,7 +390,7 @@ namespace AriasServerUtils int Percentage = TotalInBed * 100 / TotalOnline; - API.Logger.Notification($"Percentage of players in bed: ${Percentage}, Required percentage: ${config.PlayerSleepingPercentage}"); + //API.Logger.Notification($"Percentage of players in bed: {Percentage}, Required percentage: {config.PlayerSleepingPercentage}"); if (Percentage >= config.PlayerSleepingPercentage) { @@ -404,7 +407,7 @@ namespace AriasServerUtils EBT.IsSleeping = true; - API.Logger.Notification("Starting PSP Time Acceleration"); + //API.Logger.Notification("Starting PSP Time Acceleration"); bed.MountedBy.TryUnmount(); // Stand up. We cant trigger the real sleep phase, but all code for starting time accel has been executed. } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 6d99817..594c49e 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-3-2025 @ 2:01 PM MST", - "version": "1.0.10-dev.10", + "description": "A collection of server utilities\n\nBuild Date: 05-3-2025 @ 2:23 PM MST", + "version": "1.0.10", "dependencies": { "game": "" } From 419c05dbacd32bebb246c5a50f71115caa0ce35a Mon Sep 17 00:00:00 2001 From: zontreck Date: Wed, 7 May 2025 12:15:23 -0700 Subject: [PATCH 35/36] Add farmland drop --- AriasServerUtils/EventHandler.cs | 80 +++++++++++++++++++ AriasServerUtils/Globals.cs | 16 +++- AriasServerUtils/ModSystems/ASUServer.cs | 13 +++ .../assets/ariasserverutils/lang/en.json | 3 + AriasServerUtils/modinfo.json | 4 +- 5 files changed, 113 insertions(+), 3 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index b4af602..c7fa6c4 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -559,6 +559,38 @@ namespace AriasServerUtils else return TextCommandResult.Success(); } + + internal static TextCommandResult HandleUpdateASUFarmlandDowngrade(TextCommandCallingArgs args) + { + if (args[0] is bool downgrade) + { + // Update the flag + ServerUtilities.config.EnableFarmlandDowngrade = downgrade; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:farmland-downgrade", ServerUtilities.config.EnableFarmlandDowngrade)); + } + } + + + internal static TextCommandResult HandleUpdateASUFarmlandDrop(TextCommandCallingArgs args) + { + if (args[0] is bool drop) + { + // Update the flag + ServerUtilities.config.EnableFarmlandDrop = drop; + ServerUtilities.MarkDirty(); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + } + else + { + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:farmland-drop", ServerUtilities.config.EnableFarmlandDrop)); + } + } + internal static TextCommandResult HandleListCooldowns(TextCommandCallingArgs args) { string sReturn = "SERVER COOLDOWN SETTINGS\n"; @@ -588,5 +620,53 @@ namespace AriasServerUtils } return TextCommandResult.Success(); } + + internal static void CheckBreakFarmland(IServerPlayer byPlayer, BlockSelection blockSel, ref float dropQuantityMultiplier, ref EnumHandling handling) + { + if (!ServerUtilities.config.EnableFarmlandDrop) + { + return; // Default behavior + } + + if (blockSel.Block is BlockFarmland farmland) + { + BlockEntityFarmland beFarmland = farmland.GetBlockEntity(blockSel.Position); + string farmlandType = blockSel.Block.LastCodePart(); + + if (ServerUtilities.config.EnableFarmlandDowngrade) + { + + switch (farmlandType) + { + case "verylow": + { // barren + break; // Can't downgrade further + } + case "low": + { + farmlandType = "verylow"; + break; + } + case "medium": + { + farmlandType = "low"; + break; + } + case "compost": + { // high + farmlandType = "medium"; + break; + } + case "high": + { // Terra preta + farmlandType = "compost"; + break; + } + } + } + + byPlayer.Entity.World.SpawnItemEntity(new ItemStack(byPlayer.Entity.World.GetBlock(new AssetLocation($"soil-{farmlandType}-none"))), blockSel.Position.ToVec3d().Add(0.5, 0.5, 0.5)); + } + } } } \ No newline at end of file diff --git a/AriasServerUtils/Globals.cs b/AriasServerUtils/Globals.cs index a98b5cc..3436bbf 100644 --- a/AriasServerUtils/Globals.cs +++ b/AriasServerUtils/Globals.cs @@ -22,7 +22,7 @@ namespace AriasServerUtils { CooldownType.RTP, "30s" }, { CooldownType.Back, "5s" } }; - private static readonly int CURRENT_VERSION = 5; + private static readonly int CURRENT_VERSION = 6; public int Version { get; set; } = 0; @@ -36,11 +36,25 @@ namespace AriasServerUtils public int MaxRTPBlockDistance { get; set; } = 50000; public Dictionary Cooldowns { get; set; } = new Dictionary(); + + /// + /// If true, attempts to downgrade the soil quality when breaking farmland. + /// + public bool EnableFarmlandDowngrade { get; set; } = false; + + /// + /// If true, farmland will drop as soil when broken. + /// + public bool EnableFarmlandDrop { get; set; } = true; + public Dictionary GetDefaultCooldowns() { return m_defaultCD; } + /// + /// Performs some checks against known possible invalid values and sets them to sane values. + /// public void SanityCheck() { foreach (var cd in GetDefaultCooldowns()) diff --git a/AriasServerUtils/ModSystems/ASUServer.cs b/AriasServerUtils/ModSystems/ASUServer.cs index 680db83..36a590d 100644 --- a/AriasServerUtils/ModSystems/ASUServer.cs +++ b/AriasServerUtils/ModSystems/ASUServer.cs @@ -94,6 +94,7 @@ namespace AriasServerUtils api.Event.PlayerJoin += OnPlayerJoin; api.Event.PlayerDisconnect += OnPlayerDC; api.Event.ChunkColumnLoaded += RTPFactory.ChunkLoaded; + api.Event.BreakBlock += Events.CheckBreakFarmland; //api.Event.PlayerLeave += OnPlayerDC; @@ -181,6 +182,18 @@ namespace AriasServerUtils .WithDescription("Update RTP Max block distance. Plus and/or minus this distance from player current position (Default is 50000)") .HandleWith(Events.HandleUpdateASURTPMax) .EndSubCommand() + .BeginSubCommand("farmlandDowngrade") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs(parsers.OptionalBool("downgrade")) + .WithDescription("Enables or disables farmland downgrade when breaking farmland") + .HandleWith(Events.HandleUpdateASUFarmlandDowngrade) + .EndSubCommand() + .BeginSubCommand("farmlandDrop") + .RequiresPrivilege(Privilege.controlserver) + .WithArgs(parsers.OptionalBool("drop")) + .WithDescription("Enables or disables dropping soil when breaking farmland") + .HandleWith(Events.HandleUpdateASUFarmlandDrop) + .EndSubCommand() .BeginSubCommand("cooldowns") .WithDescription("Commands related to all the various cooldowns") .BeginSubCommand("back") diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 162d5a9..a53ecdf 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -23,6 +23,9 @@ "updatedconfig": "[ASU] server config updated", "config-value-reset": "[ASU] server config value reset to default", + "farmland-downgrade": "The current farmland downgrade setting is {0}", + "farmland-drop": "The current farmland drop setting is {0}", + "warp-tp": "Teleported to warp [{0}]", "warp-set": "Warp [{0}] created!", "warp-no": "You lack permissions to manage a warp", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 594c49e..f920863 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-3-2025 @ 2:23 PM MST", - "version": "1.0.10", + "description": "A collection of server utilities\n\nBuild Date: 05-7-2025 @ 12:15 AM MST", + "version": "1.0.11-dev.1", "dependencies": { "game": "" } From 45b024654a4f5b6f7a7309ffbcdc0c64eead10c6 Mon Sep 17 00:00:00 2001 From: zontreck Date: Wed, 7 May 2025 12:21:23 -0700 Subject: [PATCH 36/36] Ship 1.0.11 with the farmland feature --- AriasServerUtils/EventHandler.cs | 47 ++++++++++++------- .../assets/ariasserverutils/lang/en.json | 2 +- AriasServerUtils/modinfo.json | 4 +- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index c7fa6c4..6869045 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -275,7 +275,7 @@ namespace AriasServerUtils { ServerUtilities.config.AdminsBypassMaxHomes = bypass; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", bypass)); } return TextCommandResult.Success(); @@ -289,7 +289,7 @@ namespace AriasServerUtils ServerUtilities.config.MaxBackCache = max; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", max)); } return TextCommandResult.Success(); @@ -302,7 +302,7 @@ namespace AriasServerUtils ServerUtilities.config.MaxHomes = maxHomes; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", maxHomes)); } return TextCommandResult.Success(); @@ -311,19 +311,32 @@ namespace AriasServerUtils internal static TextCommandResult HandleUpdateASUMgrWarps(TextCommandCallingArgs args) { if (args[0] is bool mgr) + { ServerUtilities.config.onlyAdminsCreateWarps = mgr; + + ServerUtilities.MarkDirty(); + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", mgr)); + } else ServerUtilities.config.onlyAdminsCreateWarps = true; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + + + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", true)); } internal static TextCommandResult HandleUpdateASUPSP(TextCommandCallingArgs args) { - if (args[0] is int psp) ServerUtilities.config.PlayerSleepingPercentage = psp; - ServerUtilities.MarkDirty(); + if (args[0] is int psp) + { + ServerUtilities.config.PlayerSleepingPercentage = psp; + ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", psp)); + } + + return TextCommandResult.Success(); } internal static TextCommandResult HandleWarp(TextCommandCallingArgs args) @@ -431,7 +444,7 @@ namespace AriasServerUtils ServerUtilities.config.MaxRTPBlockDistance = maxDist; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", maxDist)); } return TextCommandResult.Success(); @@ -444,7 +457,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Back] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -462,7 +475,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Warp] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -480,7 +493,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Home] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -498,7 +511,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.Spawn] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -516,7 +529,7 @@ namespace AriasServerUtils ServerUtilities.config.Cooldowns[CooldownType.RTP] = CD; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", CD)); } else { @@ -542,7 +555,7 @@ namespace AriasServerUtils // Update the bypass ServerUtilities.config.AdminsBypassCooldowns = bypass; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", bypass)); } else return TextCommandResult.Success(); } @@ -554,7 +567,7 @@ namespace AriasServerUtils // Update the flag ServerUtilities.config.AdminsBypassRTPMaxDistance = bypass; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", bypass)); } else return TextCommandResult.Success(); } @@ -567,7 +580,7 @@ namespace AriasServerUtils // Update the flag ServerUtilities.config.EnableFarmlandDowngrade = downgrade; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", downgrade)); } else { @@ -583,7 +596,7 @@ namespace AriasServerUtils // Update the flag ServerUtilities.config.EnableFarmlandDrop = drop; ServerUtilities.MarkDirty(); - return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig")); + return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig", drop)); } else { diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index a53ecdf..7f983a4 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -20,7 +20,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", + "updatedconfig": "[ASU] server config updated with the new value: {0}", "config-value-reset": "[ASU] server config value reset to default", "farmland-downgrade": "The current farmland downgrade setting is {0}", diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index f920863..cc1577f 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:15 AM MST", - "version": "1.0.11-dev.1", + "description": "A collection of server utilities\n\nBuild Date: 05-7-2025 @ 12:21 PM MST", + "version": "1.0.11", "dependencies": { "game": "" }