Skip to content

Commit

Permalink
Allow adding multiple /pronouns to be displayed in /whois
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodlyay committed May 15, 2024
1 parent e2fd9a5 commit a40648a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 28 deletions.
33 changes: 26 additions & 7 deletions MCGalaxy/Commands/Chat/CmdPronouns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,43 @@ 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"; } }
public override string type { get { return CommandTypes.Chat; } }
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<string, Pronouns> pros = new Dictionary<string, Pronouns>();

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<Pronouns> final = new List<Pronouns>();
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] <pronouns2> <etc>");
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);
}
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Chat/CmdSend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/Moderation/CmdReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/CorePlugin/ConnectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/CorePlugin/ModActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Database/Stats/OnlineStat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pronouns> 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) {
Expand Down
2 changes: 1 addition & 1 deletion MCGalaxy/Modules/Awards/CmdAward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/Player/Player.Fields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public partial class Player : IDisposable {
/// <remarks> Use 'truename' for displaying/logging, use 'name' for storing data </remarks>
public string name;
public string DisplayName;
public Pronouns pronouns = Pronouns.Default;
public Pronouns pronouns { get { return pronounsList[0]; } }
internal List<Pronouns> pronounsList = new List<Pronouns> { Pronouns.Default };

public int warn;
public byte id;
public IPAddress IP;
Expand Down
35 changes: 23 additions & 12 deletions MCGalaxy/Player/Pronouns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -113,25 +113,32 @@ static void LoadFrom(string line) {
/// <summary>
/// Find the pronouns associated with the playerName. Returns Default pronouns if none were specified.
/// </summary>
public static Pronouns GetFor(string playerName) {
public static List<Pronouns> 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<Pronouns> { 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<Pronouns> { Default };

List<Pronouns> pros = new List<Pronouns>();
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<Pronouns> { Default };

} catch (Exception e) {
Logger.LogError(e);
return Default;
return new List<Pronouns> { Default };
}
}

Expand Down Expand Up @@ -168,6 +175,9 @@ public static List<string> GetNames() {
}
return names;
}
public static string ListFor(Player p, string separator) {
return p.pronounsList.Join((pro) => pro.Name, separator);
}


public readonly string Name;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a40648a

Please sign in to comment.