From 01fc41968d730ad0d62afbd9b14442e3fc8db8a5 Mon Sep 17 00:00:00 2001 From: Chris <2648373+QuiCM@users.noreply.github.com> Date: Mon, 19 Apr 2021 22:04:41 +0930 Subject: [PATCH] Refactor `wallow` command & update changelog --- CHANGELOG.md | 2 ++ TShockAPI/Commands.cs | 27 ++++++++++++--------------- TShockAPI/TSPlayer.cs | 5 +++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86dc96b9..7d10dc45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Changed the spawnboss command to support silent command specifiers. (@QuiCM, suggested by @nojomyth-dev) * Updated /godmode to use Journey Mode's Godmode power instead of healing on damage. (requested by @tlworks, backported by @bartico6, implemented preemptive bugfix for creative powers mentioned by @Stealownz) * Fixed /r attempting to send messages to players that have since disconnected. (@bartico6, reported by @Arthri) +* Added ban ticket ID to ban messages (@QuiCM, suggested by @Bippity) +* Refactored /wallow command. /reply no longer bypasses /wallow (@QuiCM) ## TShock 4.5.0.1 * Fixed conversion from old to new ban system for MySQL hosted ban databases. (@DeathCradle, @ATFGK) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index d7a6350d..e71d604c 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -5309,8 +5309,6 @@ namespace TShockAPI args.Player.SendFileTextAsMessage(FileTools.RulesPath); } - public static bool[] WDisabled { get; set; } = new bool[256]; - public static void Whisper(CommandArgs args) { if (args.Parameters.Count < 2) @@ -5334,12 +5332,12 @@ namespace TShockAPI else { var plr = players[0]; - var msg = string.Join(" ", args.Parameters.ToArray(), 1, args.Parameters.Count - 1); - if (WDisabled[players[0].Index]) + if (!plr.AcceptingWhispers) { - args.Player.SendErrorMessage("This player has disabled people from sending whispers!"); + args.Player.SendErrorMessage("This player is not accepting whispers."); return; } + var msg = string.Join(" ", args.Parameters.ToArray(), 1, args.Parameters.Count - 1); plr.SendMessage(String.Format(" {1}", args.Player.Name, msg), Color.MediumPurple); args.Player.SendMessage(String.Format(" {1}", plr.Name, msg), Color.MediumPurple); plr.LastWhisper = args.Player; @@ -5347,17 +5345,11 @@ namespace TShockAPI } } - public static void Wallow(CommandArgs args) + private static void Wallow(CommandArgs args) { - int index = args.Player.Index; - if (WDisabled[index]) - { - args.Player.SendSuccessMessage("You will now recieve whispers from other players!"); - WDisabled[index] = !WDisabled[index]; - return; - } - WDisabled[index] = !WDisabled[index]; - args.Player.SendSuccessMessage("You will now not recieve whispers from other players, type '/wallow' to recieve them again!"); + args.Player.AcceptingWhispers = !args.Player.AcceptingWhispers; + args.Player.SendSuccessMessage($"You {(args.Player.AcceptingWhispers ? "may now" : "will no longer")} receive whispers from other players."); + args.Player.SendSuccessMessage($"You can toggle this with the '{Specifier}wallow' command."); } private static void Reply(CommandArgs args) @@ -5368,6 +5360,11 @@ namespace TShockAPI } else if (args.Player.LastWhisper != null && args.Player.LastWhisper.Active) { + if (!args.Player.LastWhisper.AcceptingWhispers) + { + args.Player.SendErrorMessage("This player is not accepting whispers."); + return; + } var msg = string.Join(" ", args.Parameters); args.Player.LastWhisper.SendMessage(String.Format(" {1}", args.Player.Name, msg), Color.MediumPurple); args.Player.SendMessage(String.Format(" {1}", args.Player.LastWhisper.Name, msg), Color.MediumPurple); diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 4c24468b..68d8e306 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -599,6 +599,11 @@ namespace TShockAPI public bool SilentJoinInProgress; + /// + /// Whether the player is accepting whispers from other users + /// + public bool AcceptingWhispers = true; + /// Checks if a player is in range of a given tile if range checks are enabled. /// The x coordinate of the tile. /// The y coordinate of the tile.