From a2164015ec9c452818f653fcac5c2a22888ce128 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 18 May 2016 19:02:38 +1000 Subject: [PATCH] Allow unignoring offline players. (Thanks goodlyay) --- Commands/Chat/CmdIgnore.cs | 49 ++++++++++++++++++++++++++------------ Player/Chat.cs | 12 +++------- Player/Player.cs | 3 +-- util/Extensions.cs | 2 +- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Commands/Chat/CmdIgnore.cs b/Commands/Chat/CmdIgnore.cs index 40ae8ab30..98e04b14a 100644 --- a/Commands/Chat/CmdIgnore.cs +++ b/Commands/Chat/CmdIgnore.cs @@ -27,6 +27,9 @@ namespace MCGalaxy.Commands { public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } + public override CommandAlias[] Aliases { + get { return new [] { new CommandAlias("deafen", "ignore all") }; } + } public override void Use(Player p, string message) { if (p == null) { MessageInGameOnly(p); return; } @@ -35,37 +38,53 @@ namespace MCGalaxy.Commands { if (action == "all") { p.ignoreAll = !p.ignoreAll; - Player.Message(p, p.ignoreAll ? "&cAll chat is now ignored!" : "&aAll chat is no longer ignored!"); + Player.Message(p, p.ignoreAll ? "&cNow ignoring all chat" : "&aNo longer ignoring all chat"); CreateIgnoreFile(p); return; } else if (action == "irc") { p.ignoreIRC = !p.ignoreIRC; - Player.Message(p, p.ignoreIRC ? "&cIRC chat is now ignored!" : "&aIRC chat is no longer ignored!"); + Player.Message(p, p.ignoreIRC ? "&cNow ignoring IRC chat" : "&aNo longer ignoring IRC chat"); CreateIgnoreFile(p); return; } else if (action == "global") { p.ignoreGlobal = !p.ignoreGlobal; - Player.Message(p, p.ignoreGlobal ? "&cGlobal Chat is now ignored!" : "&aGlobal Chat is no longer ignored!"); + Player.Message(p, p.ignoreGlobal ? "&cNow ignoring Global Chat" : "&aNo longer ignoring Global Chat"); CreateIgnoreFile(p); return; } else if (action == "list") { Player.Message(p, "&cCurrently ignoring the following players:"); string names = string.Join(", ", p.listignored); if (names != "") Player.Message(p, names); - if (p.ignoreAll) Player.Message(p, "&cIgnoring all chat."); - if (p.ignoreIRC) Player.Message(p, "&cIgnoring IRC chat."); - if (p.ignoreGlobal) Player.Message(p, "&cIgnoring global chat."); + if (p.ignoreAll) Player.Message(p, "&cIgnoring all chat"); + if (p.ignoreIRC) Player.Message(p, "&cIgnoring IRC chat"); + if (p.ignoreGlobal) Player.Message(p, "&cIgnoring global chat"); return; } - Player who = PlayerInfo.Find(action); - if (who == null) { Player.Message(p, "Could not find player specified."); return; } - if (who.name == p.name) { Player.Message(p, "You cannot ignore yourself."); return; } CreateIgnoreFile(p); + string unignore = null; + for (int i = 0; i < p.listignored.Count; i++) { + if (!action.CaselessEq(p.listignored[i])) continue; + unignore = p.listignored[i]; break; + } - if (!p.listignored.Contains(who.name)) { - p.listignored.Add(who.name); - Player.Message(p, "Player now ignored: &c" + who.DisplayName + "!"); + if (unignore != null) { + p.listignored.Remove(unignore); + Player.Message(p, "No longer ignoring &a{0}", unignore); } else { - p.listignored.Remove(who.name); - Player.Message(p, "Player is no longer ignored: &a" + who.DisplayName + "!"); + int matches = 0; + Player who = PlayerInfo.FindOrShowMatches(p, action); + if (who == null) { + if (matches == 0) + Player.SendMessage(p, "You must use the full name when unignoring offline players."); + return; + } + if (p.name == who.name) { Player.Message(p, "You cannot ignore yourself."); return; } + + if (p.listignored.Contains(who.name)) { + p.listignored.Remove(who.name); + Player.Message(p, "No longer ignoring &a{0}", who.DisplayName); + } else { + p.listignored.Add(who.name); + Player.Message(p, "Now ignoring &c{0}", who.DisplayName); + } } } @@ -81,7 +100,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "%H If name is \"all\", all chat is ignored."); 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 Otherwise, the online player matching the name is ignored."); + Player.Message(p, "%H Otherwise, the online player matching the name is ignored."); } } } diff --git a/Player/Chat.cs b/Player/Chat.cs index eb5d0b5c1..1afbb7161 100644 --- a/Player/Chat.cs +++ b/Player/Chat.cs @@ -229,17 +229,11 @@ namespace MCGalaxy { if (who == null) return; if (who == p) { Player.Message(p, "Trying to talk to yourself, huh?"); return; } - LevelPermission perm = p == null ? LevelPermission.Nobody : p.group.Permission; - LevelPermission whoPerm = who.group.Permission; - if (who.ignoreAll) { DoFakePM(p, who, message); return; - } - - foreach (string ignored in who.listignored) { - if (p != null && ignored == p.name) { - DoFakePM(p, who, message); return; - } + } + if (p != null && who.listignored.Contains(p.name)) { + DoFakePM(p, who, message); return; } DoPM(p, who, message); } diff --git a/Player/Player.cs b/Player/Player.cs index e240574fa..2177bf1ee 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -840,8 +840,7 @@ Next: continue; Server.s.Log("Failed to load ignore list for: " + name); } if (ignoreAll || ignoreGlobal || ignoreIRC || listignored.Count > 0) { - SendMessage("&cYou are still ignoring some people from your last login."); - SendMessage("&cType &a/ignore list &cto see the list."); + SendMessage("&cType &a/ignore list &cto see who you are still ignoring"); } } diff --git a/util/Extensions.cs b/util/Extensions.cs index ad8b3df7c..b9a5ad4b1 100644 --- a/util/Extensions.cs +++ b/util/Extensions.cs @@ -195,7 +195,7 @@ namespace MCGalaxy { foreach (T item in items) { if (!filter(item)) continue; - string itemName = nameGetter(item); + string itemName = nameGetter(item); if (itemName.Equals(name, comp)) { matches = 1; return item; } if (itemName.IndexOf(name, comp) < 0) continue;