From 48eea6202df7f18f8fb9bb27c002233c1fa53eb1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 4 Jul 2016 14:58:22 +1000 Subject: [PATCH] Add /ignore nicks. (Thanks goodlyay) --- Commands/Chat/CmdIgnore.cs | 7 +++++++ Player/Player.Fields.cs | 2 +- Player/Player.cs | 35 +++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Commands/Chat/CmdIgnore.cs b/Commands/Chat/CmdIgnore.cs index 073a30f16..fdad1e451 100644 --- a/Commands/Chat/CmdIgnore.cs +++ b/Commands/Chat/CmdIgnore.cs @@ -53,6 +53,11 @@ namespace MCGalaxy.Commands { Player.Message(p, "{0} show before names in chat", p.ignoreTitles ? "&cPlayer titles no longer" : "&aPlayer titles now"); CreateIgnoreFile(p); return; + } else if (action == "nicks") { + p.ignoreNicks = !p.ignoreNicks; + Player.Message(p, "{0} show in chat", + p.ignoreNicks ? "&cCustom player nicks no longer" : "&aCustom player nicks"); + CreateIgnoreFile(p); return; } else if (action == "list") { Player.Message(p, "&cCurrently ignoring the following players:"); string names = p.listignored.Concatenate(); @@ -61,6 +66,7 @@ namespace MCGalaxy.Commands { if (p.ignoreIRC) Player.Message(p, "&cIgnoring IRC chat"); if (p.ignoreGlobal) Player.Message(p, "&cIgnoring global chat"); if (p.ignoreTitles) Player.Message(p, "&cPlayer titles do not show before names in chat."); + if (p.ignoreNicks) Player.Message(p, "&cCustom player nicks do not show in chat."); return; } @@ -107,6 +113,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "%H If name is \"global\", MCGalaxy global chat is ignored."); Player.Message(p, "%H If name is \"irc\", IRC chat is ignored."); Player.Message(p, "%H If name is \"titles\", player titles before names are ignored."); + Player.Message(p, "%H If name is \"nicks\", custom player nicks do not show in chat."); Player.Message(p, "%HOtherwise, all chat from the player with [name] is ignored."); } } diff --git a/Player/Player.Fields.cs b/Player/Player.Fields.cs index 1e03ece94..40797d6c9 100644 --- a/Player/Player.Fields.cs +++ b/Player/Player.Fields.cs @@ -135,7 +135,7 @@ namespace MCGalaxy { public bool onWhitelist = false; public bool whisper = false; public string whisperTo = ""; - public bool ignoreAll, ignoreGlobal, ignoreIRC, ignoreTitles; + public bool ignoreAll, ignoreGlobal, ignoreIRC, ignoreTitles, ignoreNicks; public string storedMessage = ""; diff --git a/Player/Player.cs b/Player/Player.cs index 917df7380..786bb525a 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -156,8 +156,7 @@ namespace MCGalaxy { public static void SendChatFrom(Player from, string message) { SendChatFrom(from, message, true); } public static void SendChatFrom(Player from, string message, bool showname) { - if (from == null) return; // So we don't fucking derp the hell out! - + if (from == null) return; if (Last50Chat.Count == 50) Last50Chat.RemoveAt(0); var chatmessage = new ChatMessage(); chatmessage.text = message; @@ -165,22 +164,27 @@ namespace MCGalaxy { chatmessage.time = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); Last50Chat.Add(chatmessage); - string messageLite = message; + string msg_NT = message, msg_NN = message, msg_NNNT = message; if (showname) { - string prefix = from.group.prefix == "" ? "" : "&f" + from.group.prefix; - messageLite = from.voicestring + prefix + from.ColoredName + ": &f" + message; - message = from.voicestring + from.FullName + ": &f" + message; + string msg = ": &f" + message; + string pre = from.voicestring + from.color + from.prefix; + message = pre + from.DisplayName + msg; // Titles + Nickname + msg_NN = pre + from.truename + msg; // Titles + Account name + + pre = from.voicestring + (from.group.prefix == "" ? "" : "&f" + from.group.prefix); + msg_NT = pre + from.color + from.DisplayName + msg; // Nickname + msg_NNNT = pre + from.color + from.truename + msg; // Account name } Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { - if (p.level.worldChat && p.Chatroom == null) { - if (from != null && p.listignored.Contains(from.name)) continue; - - string msg = p.ignoreTitles ? messageLite : message; - if (!p.ignoreAll || (from != null && from == p)) - Player.Message(p, msg); - } + if (p.Chatroom != null || p.listignored.Contains(from.name)) continue; + if (!p.level.worldChat || (p.ignoreAll && p != from)) continue; + + if (p.ignoreNicks && p.ignoreTitles) Player.Message(p, msg_NNNT); + else if (p.ignoreNicks) Player.Message(p, msg_NN); + else if (p.ignoreTitles) Player.Message(p, msg_NT); + else Player.Message(p, message); } } @@ -529,6 +533,7 @@ Next: continue; if (ignoreGlobal) w.WriteLine("&global"); if (ignoreIRC) w.WriteLine("&irc"); if (ignoreTitles) w.WriteLine("&titles"); + if (ignoreNicks) w.WriteLine("&nicks"); foreach (string line in listignored) w.WriteLine(line); @@ -550,6 +555,7 @@ Next: continue; else if (line == "&all") ignoreAll = true; else if (line == "&irc") ignoreIRC = true; else if (line == "&titles") ignoreTitles = true; + else if (line == "&nicks") ignoreNicks = true; else listignored.Add(line); } } catch (Exception ex) { @@ -557,7 +563,8 @@ Next: continue; Server.s.Log("Failed to load ignore list for: " + name); } - if (ignoreAll || ignoreGlobal || ignoreIRC || ignoreTitles || listignored.Count > 0) + if (ignoreAll || ignoreGlobal || ignoreIRC + || ignoreTitles || ignoreNicks || listignored.Count > 0) SendMessage("&cType &a/ignore list &cto see who you are still ignoring"); }