From 9a8b9d154544e77aae2445254dde6f1afd6cf82d Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 10 Mar 2025 17:17:25 -0700 Subject: [PATCH 01/16] 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 02/16] 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 03/16] 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 04/16] 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 05/16] 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 06/16] 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 07/16] 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 08/16] 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 09/16] 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 10/16] #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 11/16] 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 12/16] 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 13/16] 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 14/16] 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 15/16] 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 16/16] 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": "" }