From a40648afcea71bbec34f0435ba07a94346a13d66 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Tue, 14 May 2024 19:18:37 -0700 Subject: [PATCH] Allow adding multiple /pronouns to be displayed in /whois --- MCGalaxy/Commands/Chat/CmdPronouns.cs | 33 ++++++++++++++++----- MCGalaxy/Commands/Chat/CmdSend.cs | 2 +- MCGalaxy/Commands/Moderation/CmdReport.cs | 2 +- MCGalaxy/CorePlugin/ConnectHandler.cs | 2 +- MCGalaxy/CorePlugin/ModActionHandler.cs | 2 +- MCGalaxy/Database/Stats/OnlineStat.cs | 6 ++-- MCGalaxy/Modules/Awards/CmdAward.cs | 2 +- MCGalaxy/Player/Player.Fields.cs | 4 ++- MCGalaxy/Player/Pronouns.cs | 35 +++++++++++++++-------- 9 files changed, 60 insertions(+), 28 deletions(-) diff --git a/MCGalaxy/Commands/Chat/CmdPronouns.cs b/MCGalaxy/Commands/Chat/CmdPronouns.cs index f739526b9..1d79299ac 100644 --- a/MCGalaxy/Commands/Chat/CmdPronouns.cs +++ b/MCGalaxy/Commands/Chat/CmdPronouns.cs @@ -16,6 +16,8 @@ software distributed under the Licenses are distributed on an "AS IS" permissions and limitations under the Licenses. */ +using System.Collections.Generic; + namespace MCGalaxy.Commands.Chatting { public class CmdPronouns : Command2 { public override string name { get { return "Pronouns"; } } @@ -23,17 +25,34 @@ public class CmdPronouns : Command2 { public override void Use(Player p, string message, CommandData data) { if (message.Length == 0) { Help(p); return; } - Pronouns pro = Pronouns.FindMatch(p, message); - if (pro == null) { HelpList(p); return; } + string[] names = message.SplitSpaces(); + Dictionary pros = new Dictionary(); + + foreach (string name in names) { + Pronouns pro = Pronouns.FindMatch(p, name); + if (pro == null) { HelpList(p); return; } + pros[pro.Name] = pro; + } + + // Disallow using default pronouns along with other pronouns (it's weird..?) + if (pros.Count > 1 && pros.ContainsKey(Pronouns.Default.Name)) { + pros.Remove(Pronouns.Default.Name); + } + + List final = new List(); + foreach (var pair in pros) { + final.Add(pair.Value); + } - p.pronouns = pro; - p.Message("Your pronouns were changed to: &T{0}", pro.Name); - pro.SaveFor(p); + p.pronounsList = final; + p.Message("Your pronouns were changed to: &T{0}", Pronouns.ListFor(p, ", ")); + Pronouns.SaveFor(p); } public override void Help(Player p) { - p.Message("&T/Pronouns [pronouns]"); - p.Message("&HChanges the pronouns used to refer to you in server messages."); + p.Message("&T/Pronouns [pronouns1] "); + p.Message("&H[pronouns1] will be used to refer to you in server messages."); + p.Message("&HThe list of pronouns you select will appear in &T/whois"); HelpList(p); p.Message("&HYour pronouns are currently: &T{0}", p.pronouns.Name); } diff --git a/MCGalaxy/Commands/Chat/CmdSend.cs b/MCGalaxy/Commands/Chat/CmdSend.cs index 3888f6bc0..4449a9d45 100644 --- a/MCGalaxy/Commands/Chat/CmdSend.cs +++ b/MCGalaxy/Commands/Chat/CmdSend.cs @@ -47,7 +47,7 @@ public override void Use(Player p, string message, CommandData data) { int pending = Database.CountRows("Inbox" + name, "WHERE PlayerFrom=@0", p.name); if (pending >= 200) { - Pronouns pronouns = Pronouns.GetFor(name); + Pronouns pronouns = Pronouns.GetFor(name)[0]; p.Message("{0} &calready has 200+ messages from you currently in {1} inbox. " + "Try again later after {2} {3} deleted some of {4} inbox messages", p.FormatNick(name), pronouns.Object, pronouns.Subject, pronouns.PresentPerfectVerb, pronouns.Object); diff --git a/MCGalaxy/Commands/Moderation/CmdReport.cs b/MCGalaxy/Commands/Moderation/CmdReport.cs index ad2b5aa0f..28ce227d0 100644 --- a/MCGalaxy/Commands/Moderation/CmdReport.cs +++ b/MCGalaxy/Commands/Moderation/CmdReport.cs @@ -159,7 +159,7 @@ void HandleAdd(Player p, string[] args) { string opsMsg = "λNICK &Sreported " + nick + "&S. Reason: " + reason; Chat.MessageFrom(ChatScope.Perms, p, opsMsg, checkPerms, null, true); - string allMsg = "Use &T/Report check " + target + " &Sto see all of " + Pronouns.GetFor(target).Object + " reports"; + string allMsg = "Use &T/Report check " + target + " &Sto see all of " + Pronouns.GetFor(target)[0].Object + " reports"; Chat.MessageFrom(ChatScope.Perms, p, allMsg, checkPerms, null, true); } diff --git a/MCGalaxy/CorePlugin/ConnectHandler.cs b/MCGalaxy/CorePlugin/ConnectHandler.cs index 6c597b3b0..09e4f1e24 100644 --- a/MCGalaxy/CorePlugin/ConnectHandler.cs +++ b/MCGalaxy/CorePlugin/ConnectHandler.cs @@ -25,7 +25,7 @@ internal static void HandleConnect(Player p) { if (p.CanUse("ReachDistance")) LoadReach(p); p.Ignores.Load(p); - p.pronouns = Pronouns.GetFor(p.name); + p.pronounsList = Pronouns.GetFor(p.name); } static void LoadReach(Player p) { diff --git a/MCGalaxy/CorePlugin/ModActionHandler.cs b/MCGalaxy/CorePlugin/ModActionHandler.cs index cb22f5079..f02a5963e 100644 --- a/MCGalaxy/CorePlugin/ModActionHandler.cs +++ b/MCGalaxy/CorePlugin/ModActionHandler.cs @@ -148,7 +148,7 @@ static void DoUnban(ModAction e) { string ip = PlayerDB.FindIP(e.Target); if (ip != null && Server.bannedIP.Contains(ip)) { - e.Actor.Message("NOTE: {0} IP is still banned.", Pronouns.GetFor(e.Target).Object); + e.Actor.Message("NOTE: {0} IP is still banned.", Pronouns.GetFor(e.Target)[0].Object); } } diff --git a/MCGalaxy/Database/Stats/OnlineStat.cs b/MCGalaxy/Database/Stats/OnlineStat.cs index bd2f13256..23eca2699 100644 --- a/MCGalaxy/Database/Stats/OnlineStat.cs +++ b/MCGalaxy/Database/Stats/OnlineStat.cs @@ -54,9 +54,9 @@ internal static void CommonCoreLine(Player p, string fullName, string name, Grou p.Message("{0} &S({1}) has:", fullName, name); p.Message(" Rank of {0}&S, wrote &a{1} &Smessages", grp.ColoredName, messages); - Pronouns pro = Pronouns.GetFor(name); - if (pro == Pronouns.Default) { return; } - p.Message(" Pronouns: &a{0}", pro.Name); + List pros = Pronouns.GetFor(name); + if (pros[0] == Pronouns.Default) { return; } + p.Message(" Pronouns: &a{0}", pros.Join((pro) => pro.Name, ", ")); } public static void MiscLine(Player p, string name, int deaths, int money) { diff --git a/MCGalaxy/Modules/Awards/CmdAward.cs b/MCGalaxy/Modules/Awards/CmdAward.cs index 8dd276aa1..75058ad74 100644 --- a/MCGalaxy/Modules/Awards/CmdAward.cs +++ b/MCGalaxy/Modules/Awards/CmdAward.cs @@ -54,7 +54,7 @@ public override void Use(Player p, string message, CommandData data) { } } else { if (PlayerAwards.Take(plName, award)) { - Chat.MessageGlobal(string.Format("{0} &Shad {1} &b{2} &Saward removed", displayName, Pronouns.GetFor(plName).Object, award)); + Chat.MessageGlobal(string.Format("{0} &Shad {1} &b{2} &Saward removed", displayName, Pronouns.GetFor(plName)[0].Object, award)); PlayerAwards.Save(); } else if (plName.CaselessEq(p.name)) { p.Message("You did not have that award to begin with."); diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 902ab8bda..dc0b74578 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -63,7 +63,9 @@ public partial class Player : IDisposable { /// Use 'truename' for displaying/logging, use 'name' for storing data public string name; public string DisplayName; - public Pronouns pronouns = Pronouns.Default; + public Pronouns pronouns { get { return pronounsList[0]; } } + internal List pronounsList = new List { Pronouns.Default }; + public int warn; public byte id; public IPAddress IP; diff --git a/MCGalaxy/Player/Pronouns.cs b/MCGalaxy/Player/Pronouns.cs index 86eafad77..704ed7b63 100644 --- a/MCGalaxy/Player/Pronouns.cs +++ b/MCGalaxy/Player/Pronouns.cs @@ -85,7 +85,7 @@ static void OnConfigUpdated() { //In case any were deleted or changed foreach (Player p in PlayerInfo.Online.Items) { - p.pronouns = GetFor(p.name); + p.pronounsList = GetFor(p.name); } } static void LoadFrom(string line) { @@ -113,25 +113,32 @@ static void LoadFrom(string line) { /// /// Find the pronouns associated with the playerName. Returns Default pronouns if none were specified. /// - public static Pronouns GetFor(string playerName) { + public static List GetFor(string playerName) { string myPath = PlayerPath(playerName); try { string data; lock (locker) { - if (!File.Exists(myPath)) { return Default; } + if (!File.Exists(myPath)) { return new List { Default }; } data = File.ReadAllText(myPath); } data = data.Trim(); - - if (data.Length == 0) return Default; - Pronouns p = FindExact(data); - if (p != null) return p; - return Default; + if (data.Length == 0) return new List { Default }; + + List pros = new List(); + string[] names = data.SplitSpaces(); + foreach (string name in names) { + Pronouns p = FindExact(name); + if (p == null) continue; + pros.Add(p); + } + if (pros.Count != 0) return pros; + + return new List { Default }; } catch (Exception e) { Logger.LogError(e); - return Default; + return new List { Default }; } } @@ -168,6 +175,9 @@ public static List GetNames() { } return names; } + public static string ListFor(Player p, string separator) { + return p.pronounsList.Join((pro) => pro.Name, separator); + } public readonly string Name; @@ -217,13 +227,14 @@ void Write(StreamWriter w) { w.WriteLine(string.Format("{0} {1} {2} {3} {4}", Name, Subject, Object, Reflexive, (Plural ? "plural" : "singular") )); w.WriteLine(); } - public void SaveFor(Player p) { + public static void SaveFor(Player p) { string path = PlayerPath(p.name); try { //Reduce clutter by simply erasing the file if it's default - if (this == Default) { File.Delete(path); return; } + if (p.pronounsList.Count == 1 && p.pronounsList[0] == Default) { File.Delete(path); return; } + + File.WriteAllText(path, ListFor(p, " ")); - File.WriteAllText(path, Name); } catch (Exception e) { Logger.LogError(e); p.Message("&WThere was an error when saving your pronouns: &S{0}", e.Message);