From a9150cf3226d6d1323fe194bc35ea64672e5c542 Mon Sep 17 00:00:00 2001 From: zontreck Date: Fri, 7 Mar 2025 01:12:36 -0700 Subject: [PATCH] Add max distance argument to rtp --- AriasServerUtils/ASUModSystem.cs | 2 +- AriasServerUtils/EventHandler.cs | 11 ++++++++++- AriasServerUtils/RTPFactory.cs | 9 ++++++--- AriasServerUtils/assets/ariasserverutils/lang/en.json | 1 + AriasServerUtils/modinfo.json | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/AriasServerUtils/ASUModSystem.cs b/AriasServerUtils/ASUModSystem.cs index 5921fc8..bdefbaf 100644 --- a/AriasServerUtils/ASUModSystem.cs +++ b/AriasServerUtils/ASUModSystem.cs @@ -210,7 +210,7 @@ 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).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); + api.ChatCommands.Create("rtp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithArgs(parsers.Int("maxDist")).WithDescription("Seeks a position possibly thousands of blocks away to teleport to.").HandleWith(Events.HandleRTP); } private void OnCheckPlayerCooldowns() diff --git a/AriasServerUtils/EventHandler.cs b/AriasServerUtils/EventHandler.cs index 9386346..f74b377 100644 --- a/AriasServerUtils/EventHandler.cs +++ b/AriasServerUtils/EventHandler.cs @@ -54,6 +54,15 @@ namespace AriasServerUtils { if (args.Caller.Player is IServerPlayer isp) { + int maxDistance = ServerUtilities.config.MaxRTPBlockDistance; + if (args[0] is int ix) + { + if (ix > maxDistance) + { + ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-capped", ix, maxDistance)); + } + else maxDistance = ix; + } PlayerStorage ps = ServerUtilities.GetPlayerData(isp); if (ps.ActiveCooldowns.ContainsKey(CooldownType.RTP)) @@ -67,7 +76,7 @@ namespace AriasServerUtils ps.ActiveCooldowns.Add(CooldownType.RTP, TimeUtil.DecodeTimeNotation(ServerUtilities.config.Cooldowns.Get(CooldownType.RTP)) + TimeUtil.GetUnixEpochTimestamp()); ServerUtilities.MarkDirty(); - PlayerPosition pPos = RTPFactory.GetRandomPosition(isp); + PlayerPosition pPos = RTPFactory.GetRandomPosition(isp, maxDistance: maxDistance); if (pPos == null) { ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:rtp-fail")); diff --git a/AriasServerUtils/RTPFactory.cs b/AriasServerUtils/RTPFactory.cs index ddc1c35..8e70256 100644 --- a/AriasServerUtils/RTPFactory.cs +++ b/AriasServerUtils/RTPFactory.cs @@ -16,7 +16,7 @@ public class RTPFactory /// /// The player to be teleported /// A random position +/- max distance from current position. - public static PlayerPosition GetRandomPosition(IServerPlayer isp) + public static PlayerPosition GetRandomPosition(IServerPlayer isp, int maxDistance) { Random rng = new Random(); EntityPos vPos = isp.Entity.Pos; @@ -29,10 +29,13 @@ public class RTPFactory while (tries-- > 0) { // Generate random X and Z within max RTP distance - bPos.X = (int)vPos.X + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); - bPos.Z = (int)vPos.Z + rng.Next(-ServerUtilities.config.MaxRTPBlockDistance, ServerUtilities.config.MaxRTPBlockDistance); + bPos.X = (int)vPos.X + rng.Next(0, maxDistance); + bPos.Z = (int)vPos.Z + rng.Next(0, maxDistance); bPos.Y = 255; + if (rng.Next(0, 1) == 1) bPos.X = -bPos.X; + if (rng.Next(0, 1) == 1) bPos.Z = -bPos.Z; + Block lastAboveLast = null; Block lastBlock = null; Block curBlock; diff --git a/AriasServerUtils/assets/ariasserverutils/lang/en.json b/AriasServerUtils/assets/ariasserverutils/lang/en.json index 5f983f0..4498f90 100644 --- a/AriasServerUtils/assets/ariasserverutils/lang/en.json +++ b/AriasServerUtils/assets/ariasserverutils/lang/en.json @@ -36,6 +36,7 @@ "rtp-search": "Searching for a random position...", "rtp": "You have been teleported [{0}] blocks away!", "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}]" } diff --git a/AriasServerUtils/modinfo.json b/AriasServerUtils/modinfo.json index 4259fac..028e657 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-06-2025 @ 6:37 PM MST", - "version": "1.0.4", + "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 00:52 AM MST", + "version": "1.0.5-dev.1", "dependencies": { "game": "" }