From 464d66443f93045483eac496c6eb7e79a7def2d5 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Mar 2016 11:59:02 +1100 Subject: [PATCH] Update more commands to use PlayerInfo.FindOrShowMatches, cleanup some commands. --- Commands/CPE/CmdModel.cs | 4 +- Commands/Chat/CmdHigh5.cs | 2 +- Commands/Chat/CmdHug.cs | 2 +- Commands/CmdOverseer.cs | 14 +--- Commands/Economy/CmdFakePay.cs | 98 ++++++++++-------------- Commands/Fun/CmdCountdown.cs | 7 +- Commands/Fun/CmdDisinfect.cs | 6 +- Commands/Fun/CmdInfect.cs | 6 +- Commands/Fun/CmdQueue.cs | 24 ++---- Commands/Fun/CmdTntWars.cs | 9 +-- Commands/Information/CmdFaq.cs | 79 ++++++++----------- Commands/Information/CmdLastCmd.cs | 2 +- Commands/Information/CmdNews.cs | 95 +++++++++++------------ Commands/Information/CmdOpRules.cs | 2 +- Commands/Moderation/CmdP2P.cs | 10 +-- Commands/Moderation/CmdReveal.cs | 4 +- Commands/Moderation/CmdVoice.cs | 74 ++++++++---------- Commands/Moderation/CmdVoteKick.cs | 8 +- Commands/Moderation/CmdWarn.cs | 117 ++++++++++------------------- Commands/other/CmdColor.cs | 4 +- Commands/other/CmdInvincible.cs | 12 +-- Commands/other/CmdSummon.cs | 11 ++- Commands/other/CmdTColor.cs | 4 +- Commands/other/CmdTitle.cs | 4 +- Player/PlayerInfo.cs | 7 +- 25 files changed, 238 insertions(+), 367 deletions(-) diff --git a/Commands/CPE/CmdModel.cs b/Commands/CPE/CmdModel.cs index b54819267..9a0ae426c 100644 --- a/Commands/CPE/CmdModel.cs +++ b/Commands/CPE/CmdModel.cs @@ -34,8 +34,8 @@ namespace MCGalaxy.Commands { string[] args = message.Split(trimChars, 2); if (args.Length > 1) { - who = PlayerInfo.Find(args[0]); - if (who == null) { Player.SendMessage(p, "Player \"" + args[0] + "\" does not exist"); return; } + who = PlayerInfo.FindOrShowMatches(p, args[0]); + if (who == null) return; } else { if (p == null) { Player.SendMessage(p, "Console can't use this command on itself."); return; } } diff --git a/Commands/Chat/CmdHigh5.cs b/Commands/Chat/CmdHigh5.cs index fa70927ff..a63fd0fe0 100644 --- a/Commands/Chat/CmdHigh5.cs +++ b/Commands/Chat/CmdHigh5.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - Player who = PlayerInfo.FindOrShowMatches(message); + Player who = PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; string giver = (p == null) ? "(console)" : p.color + p.DisplayName; diff --git a/Commands/Chat/CmdHug.cs b/Commands/Chat/CmdHug.cs index c8ec45cb8..d77aaeae6 100644 --- a/Commands/Chat/CmdHug.cs +++ b/Commands/Chat/CmdHug.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - Player who = PlayerInfo.FindOrShowMatches(message); + Player who = PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; if (p != null && p.muted) { Player.SendMessage(p, "Cannot use /hug while muted."); return; } diff --git a/Commands/CmdOverseer.cs b/Commands/CmdOverseer.cs index 79a16f614..26dd6cb3d 100644 --- a/Commands/CmdOverseer.cs +++ b/Commands/CmdOverseer.cs @@ -92,15 +92,10 @@ namespace MCGalaxy.Commands Command.all.Find("goto").Use(pl, Server.mainLevel.name); } } else if (cmd == "KICK") { - if (arg == "") { - p.SendMessage("You must specify a player to kick."); - return; - } + if (arg == "") { p.SendMessage("You must specify a player to kick."); return; } - Player kicked = PlayerInfo.Find(arg); - if (kicked == null) { - p.SendMessage("Error: Player not found."); - } else { + Player kicked = PlayerInfo.FindOrShowMatches(p, arg); + if (kicked != null) { if (kicked.level.name == p.level.name) Command.all.Find("goto").Use(kicked, Server.mainLevel.name); else @@ -320,11 +315,10 @@ namespace MCGalaxy.Commands string path = "levels/blacklists/" + p.level.name + ".txt"; EnsureFileExists(path); - value = value.Replace("+", ""); + if (!value.EndsWith("+")) value += "+"; if (!File.ReadAllText(path).Contains(value)) { Player.SendMessage(p, value + " is not blacklisted."); return; } - value = value + "+"; try { var oldLines = File.ReadAllLines(path); diff --git a/Commands/Economy/CmdFakePay.cs b/Commands/Economy/CmdFakePay.cs index c3710dd34..9649930ee 100644 --- a/Commands/Economy/CmdFakePay.cs +++ b/Commands/Economy/CmdFakePay.cs @@ -1,71 +1,49 @@ /* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. */ -namespace MCGalaxy.Commands -{ - public sealed class CmdFakePay : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdFakePay : Command { + public override string name { get { return "fakepay"; } } public override string shortcut { get { return "fpay"; } } public override string type { get { return CommandTypes.Economy; } } - public override bool museumUsable { get { return true; } } - public override void Help(Player p) - { - Player.SendMessage(p, "/fakepay - Sends a fake give change message."); - } + public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override void Use(Player p, string message) - { + + public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - - var split = message.Split(' '); - - Player who = PlayerInfo.Find(split[0]); - if (who == null) - { - Player.SendMessage(p, Server.DefaultColor + "Player not found!"); - return; - } - - int amount = 0; - try - { - amount = int.Parse(split[1]); - } - catch/* (Exception ex)*/ - { - Player.SendMessage(p, "How much do you want to fakepay them?"); - return; - } - - if (amount < 0) - { - Player.SendMessage(p, Server.DefaultColor + "You can't fakepay a negative amount."); - return; - } - - if (amount >= 16777215) - { - Player.SendMessage(p, "Whoa, that's too much money. Try less than 16777215."); - return; - } - - Player.GlobalMessage(who.color + who.prefix + who.DisplayName + Server.DefaultColor + " was given " + amount + " " + Server.moneys); + + string[] args = message.Split(' '); + Player who = PlayerInfo.FindOrShowMatches(p, args[0]); + if (who == null) return; + + int amount = 0; + if (args.Length == 1 || !int.TryParse(args[1], out amount)) { + Player.SendMessage(p, "You must specify an integer amount to fakepay."); return; + } + if (amount < 0) { Player.SendMessage(p, "You can't fakepay a negative amount."); return; } + if (amount >= 16777215) { Player.SendMessage(p, "You can only fakepay up to 16777215."); return; } + Player.GlobalMessage(who.color + who.prefix + who.DisplayName + " %Swas given " + amount + " " + Server.moneys); + } + + public override void Help(Player p) { + Player.SendMessage(p, "/fakepay - Sends a fake give change message."); } } } diff --git a/Commands/Fun/CmdCountdown.cs b/Commands/Fun/CmdCountdown.cs index 7715c21d7..35161e919 100644 --- a/Commands/Fun/CmdCountdown.cs +++ b/Commands/Fun/CmdCountdown.cs @@ -200,10 +200,9 @@ namespace MCGalaxy.Commands { return; } - Player who = PlayerInfo.Find(target); - if (who == null) { - Player.SendMessage(p, "That wasn't an online player."); return; - } else if (p.group.Permission < who.group.Permission) { + Player who = PlayerInfo.FindOrShowMatches(p, target); + if (who == null) return; + if (p.group.Permission < who.group.Permission) { Player.SendMessage(p, "You can't send rules to someone of a higher rank than yourself!!"); return; } else { Player.SendMessage(who, "Countdown rules sent to you by " + p.color + p.name); diff --git a/Commands/Fun/CmdDisinfect.cs b/Commands/Fun/CmdDisinfect.cs index cbab56053..a0e93529f 100644 --- a/Commands/Fun/CmdDisinfect.cs +++ b/Commands/Fun/CmdDisinfect.cs @@ -27,10 +27,8 @@ namespace MCGalaxy.Commands { public CmdDisInfect() { } public override void Use(Player p, string message) { - Player who = message == "" ? p : PlayerInfo.Find(message); - if (who == null) { - Player.SendMessage(p, "There is no player \"" + message + "\"!"); return; - } + Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; if (!who.infected || !Server.zombie.GameInProgess()) { Player.SendMessage(p, "Cannot disinfect player"); diff --git a/Commands/Fun/CmdInfect.cs b/Commands/Fun/CmdInfect.cs index 1469cf292..f41b4d1d2 100644 --- a/Commands/Fun/CmdInfect.cs +++ b/Commands/Fun/CmdInfect.cs @@ -27,10 +27,8 @@ namespace MCGalaxy.Commands { public CmdInfect() { } public override void Use(Player p, string message) { - Player who = message == "" ? p : PlayerInfo.Find(message); - if (who == null) { - Player.SendMessage(p, "There is no player \"" + message + "\"!"); return; - } + Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; if (who.infected || !Server.zombie.GameInProgess()) { Player.SendMessage(p, "Cannot infect player"); diff --git a/Commands/Fun/CmdQueue.cs b/Commands/Fun/CmdQueue.cs index 8b8d3295b..515bc200e 100644 --- a/Commands/Fun/CmdQueue.cs +++ b/Commands/Fun/CmdQueue.cs @@ -33,24 +33,14 @@ namespace MCGalaxy.Commands string value = args[1]; if (args[0] == "zombie") { - Player who = PlayerInfo.Find(value); - if (who == null) { - p.SendMessage(value + " is not online."); - } else { - p.SendMessage(value + " was queued."); - Server.zombie.queZombie = true; - Server.zombie.nextZombie = value; - } - } else if (args[0] == "level") { - bool match = false; - DirectoryInfo di = new DirectoryInfo("levels/"); - FileInfo[] fi = di.GetFiles("*.lvl"); - foreach (FileInfo file in fi) { - if (file.Name.Replace(".lvl", "").ToLower() == value.ToLower()) - match = true; - } + Player who = PlayerInfo.FindOrShowMatches(p, value); + if (who == null) return; - if (match) { + p.SendMessage(value + " was queued."); + Server.zombie.queZombie = true; + Server.zombie.nextZombie = value; + } else if (args[0] == "level") { + if (LevelInfo.ExistsOffline(value)) { p.SendMessage(value + " was queued."); Server.zombie.queLevel = true; Server.zombie.nextLevel = value.ToLower(); diff --git a/Commands/Fun/CmdTntWars.cs b/Commands/Fun/CmdTntWars.cs index ab4b855b9..7c6d9b922 100644 --- a/Commands/Fun/CmdTntWars.cs +++ b/Commands/Fun/CmdTntWars.cs @@ -315,7 +315,7 @@ namespace MCGalaxy.Commands default: if (text[1] != null && (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) { - Player who = PlayerInfo.Find(text[1]); + Player who = PlayerInfo.FindOrShowMatches(p, text[1]); if (who != null) { Player.SendMessage(who, "TNT Wars Rules: (sent to you by " + p.color + p.name + Server.DefaultColor + " )"); @@ -324,13 +324,8 @@ namespace MCGalaxy.Commands Player.SendMessage(who, "During the game the amount of TNT placable at one time may be limited!"); Player.SendMessage(who, "You are not allowed to use hacks of any sort during the game!"); Player.SendMessage(p, "TNT Wars: Sent rules to " + who.color + who.name); - return; - } - else - { - Player.SendMessage(p, "TNT Wars Error: Couldn't find player '" + text[1] + "' to send rules to!"); - return; } + return; } else { diff --git a/Commands/Information/CmdFaq.cs b/Commands/Information/CmdFaq.cs index b97a2aef1..4f3678b16 100644 --- a/Commands/Information/CmdFaq.cs +++ b/Commands/Information/CmdFaq.cs @@ -1,26 +1,26 @@ /* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ using System.Collections.Generic; using System.IO; -namespace MCGalaxy.Commands -{ - public sealed class CmdFaq : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdFaq : Command { + public override string name { get { return "faq"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Information; } } @@ -30,39 +30,26 @@ namespace MCGalaxy.Commands get { return new[] { new CommandPerm(LevelPermission.Builder, "The lowest rank that can send the faq to other players") }; } } - public override void Use(Player p, string message) - { + public override void Use(Player p, string message) { if (!File.Exists("text/faq.txt")) { CP437Writer.WriteAllText("text/faq.txt", "Example: What does this server run on? This server runs on &bMCGalaxy"); } - List faq = CP437Reader.ReadAllLines("text/faq.txt"); + List faq = CP437Reader.ReadAllLines("text/faq.txt"); - Player who = null; - if (message != "") - { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) - { Player.SendMessage(p, "You can't send the FAQ to another player!"); return; } - who = PlayerInfo.Find(message); - } - else - { - who = p; - } - - if (who != null) - { - who.SendMessage("&cFAQ&f:"); - foreach (string s in faq) - who.SendMessage("&f" + s); - } - else - { - Player.SendMessage(p, "There is no player \"" + message + "\"!"); + Player who = p; + if (message != "") { + if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { + Player.SendMessage(p, "Your rank cannot send the FAQ to other players."); return; } + who = PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; } + + Player.SendMessage(who, "&cFAQ&f:"); + foreach (string line in faq) + Player.SendMessage(who, "&f" + line); } - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "/faq [player]- Displays frequently asked questions"); } } diff --git a/Commands/Information/CmdLastCmd.cs b/Commands/Information/CmdLastCmd.cs index 6c13fa4d1..45535d4ca 100644 --- a/Commands/Information/CmdLastCmd.cs +++ b/Commands/Information/CmdLastCmd.cs @@ -45,7 +45,7 @@ namespace MCGalaxy.Commands } else { - Player who = PlayerInfo.FindOrShowMatches(message); + Player who = PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; if (who.lastCMD.Contains("setpass") || who.lastCMD.Contains("pass")) { diff --git a/Commands/Information/CmdNews.cs b/Commands/Information/CmdNews.cs index 9dbd0cdce..613e4c8bd 100644 --- a/Commands/Information/CmdNews.cs +++ b/Commands/Information/CmdNews.cs @@ -1,20 +1,20 @@ /* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ using System.Collections.Generic; using System.IO; @@ -31,52 +31,41 @@ namespace MCGalaxy.Commands get { return new[] { new CommandPerm(LevelPermission.Operator, "The lowest rank that can send the news to everyone") }; } } - public override void Use(Player p, string message) - { - string newsFile = "text/news.txt"; - if (!File.Exists(newsFile)) - { - CP437Writer.WriteAllText(newsFile, "News have not been created. Put News in '" + newsFile + "'."); - return; + const string newsFile = "text/news.txt"; + public override void Use(Player p, string message) { + if (!File.Exists(newsFile)) { + CP437Writer.WriteAllText(newsFile, "News have not been created. Put News in '" + newsFile + "'."); return; } List lines = CP437Reader.ReadAllLines(newsFile); - if (message == "") - { - foreach (string t in lines) - { - Player.SendMessage(p, t); - } + if (message == "") { + foreach (string line in lines) + Player.SendMessage(p, line); + return; } - else - { - string[] split = message.Split(' '); - if (split[0] == "all") { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "You must be at least " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " to send this to all players."); - return; - } - for (int k = 0; k < lines.Count; k++) { - Player.GlobalMessage(lines[k]); - } - return; + + string[] args = message.Split(' '); + if (args[0] == "all") { + if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { + Player.SendMessage(p, "You must be at least " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " to send this to all players."); + return; } - - Player player = PlayerInfo.Find(split[0]); - if (player == null) { Player.SendMessage(p, "Could not find player \"" + split[0] + "\"!"); return; } - foreach (string t in lines) - { - Player.SendMessage(player, t); - } - Player.SendMessage(p, "The News were successfully sent to " + player.name + "."); - + foreach (string line in lines) + Player.GlobalMessage(line); + return; } + + Player who = PlayerInfo.FindOrShowMatches(p, args[0]); + if (who == null) return; + foreach (string line in lines) + Player.SendMessage(who, line); + Player.SendMessage(p, "The News were successfully sent to " + who.name + "."); } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "/news - Shows server news."); Player.SendMessage(p, "/news - Sends the News to ."); Player.SendMessage(p, "/news all - Sends the News to everyone."); } } -} +} \ No newline at end of file diff --git a/Commands/Information/CmdOpRules.cs b/Commands/Information/CmdOpRules.cs index 998b07931..09c89ba32 100644 --- a/Commands/Information/CmdOpRules.cs +++ b/Commands/Information/CmdOpRules.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands Player who = p; if (message != "") { - who = PlayerInfo.FindOrShowMatches(message); + who = PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; if (p != null && p.group.Permission < who.group.Permission) { Player.SendMessage(p, "You cannot send /oprules to a higher or same ranked player."); return; diff --git a/Commands/Moderation/CmdP2P.cs b/Commands/Moderation/CmdP2P.cs index 0b7206422..8af2dd2af 100644 --- a/Commands/Moderation/CmdP2P.cs +++ b/Commands/Moderation/CmdP2P.cs @@ -32,14 +32,10 @@ namespace MCGalaxy.Commands { string[] args = message.Split(' '); if (args.Length > 2) { Help(p); return; } if (args.Length == 1) { Player.SendMessage(p, "You did not specify the target player."); return; } - Player source = PlayerInfo.Find(args[0]), target = PlayerInfo.Find(args[1]); - - if ((source == null || !Player.CanSee(p, source)) && (target == null || !Player.CanSee(p, target))) { - Player.SendMessage(p, "Neither of the players specified are online."); return; - } - if (source == null || !Player.CanSee(p, source)) { Player.SendMessage(p, "The source player is not online."); return; } - if (target == null || !Player.CanSee(p, target)) { Player.SendMessage(p, "The target player is not online."); return; } + Player source = PlayerInfo.FindOrShowMatches(p, args[0]); + Player target = PlayerInfo.FindOrShowMatches(p, args[1]); + if (source == null || target == null) return; if (p.group.Permission < source.group.Permission) { Player.SendMessage(p, "You cannot force a player of higher rank to tp to another player."); return; } diff --git a/Commands/Moderation/CmdReveal.cs b/Commands/Moderation/CmdReveal.cs index d3bbf6ad3..f1830cc83 100644 --- a/Commands/Moderation/CmdReveal.cs +++ b/Commands/Moderation/CmdReveal.cs @@ -56,9 +56,9 @@ namespace MCGalaxy.Commands { ReloadMap(p, who, true); } } else { - Player who = PlayerInfo.Find(parts[0]); + Player who = PlayerInfo.FindOrShowMatches(p, parts[0]); if (who == null) { - Player.SendMessage(p, "Could not find player."); return; + return; } else if (who.group.Permission > p.group.Permission && p != who) { Player.SendMessage(p, "Cannot reload the map of someone higher than you."); return; } diff --git a/Commands/Moderation/CmdVoice.cs b/Commands/Moderation/CmdVoice.cs index 286df0a00..3b6b590b9 100644 --- a/Commands/Moderation/CmdVoice.cs +++ b/Commands/Moderation/CmdVoice.cs @@ -1,59 +1,49 @@ /* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ namespace MCGalaxy.Commands { public sealed class CmdVoice : Command { public override string name { get { return "voice"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Moderation; } } + public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdVoice() { } - public override void Use(Player p, string message) - { + public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - Player who = PlayerInfo.Find(message); - if (who != null) - { - if (who.voice) - { - who.voice = false; - Player.SendMessage(p, "Removing voice status from " + who.color + who.DisplayName); - who.SendMessage("Your voice status has been revoked."); - who.voicestring = ""; - } - else - { - who.voice = true; - Player.SendMessage(p, "Giving voice status to " + who.color + who.DisplayName); - who.SendMessage("You have received voice status."); - who.voicestring = "&f+"; - } - } - else - { - Player.SendMessage(p, "There is no player online named \"" + message + "\""); + Player who = PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; + + if (who.voice) { + Player.SendMessage(p, "Removing voice status from " + who.color + who.DisplayName); + who.SendMessage("Your voice status has been revoked."); + who.voicestring = ""; + } else { + Player.SendMessage(p, "Giving voice status to " + who.color + who.DisplayName); + who.SendMessage("You have received voice status."); + who.voicestring = "&f+"; } + who.voice = !who.voice; } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "/voice - Toggles voice status on or off for specified player."); } } diff --git a/Commands/Moderation/CmdVoteKick.cs b/Commands/Moderation/CmdVoteKick.cs index 39f2340e5..2d05f44d3 100644 --- a/Commands/Moderation/CmdVoteKick.cs +++ b/Commands/Moderation/CmdVoteKick.cs @@ -33,12 +33,8 @@ namespace MCGalaxy.Commands if (Server.voteKickInProgress) { Player.SendMessage(p, "Please wait for the current vote to finish!"); return; } - Player who = PlayerInfo.Find(message); - if (who == null) - { - Player.SendMessage(p, "Could not find player specified!"); - return; - } + Player who = PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; if (who.group.Permission >= p.group.Permission) { diff --git a/Commands/Moderation/CmdWarn.cs b/Commands/Moderation/CmdWarn.cs index 06569f84d..0d2b528a4 100644 --- a/Commands/Moderation/CmdWarn.cs +++ b/Commands/Moderation/CmdWarn.cs @@ -1,101 +1,62 @@ /* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. */ -namespace MCGalaxy.Commands -{ - public sealed class CmdWarn : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdWarn : Command { + public override string name { get { return "warn"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Moderation; } } + public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } - string reason; - - public override void Use(Player p, string message) - { - string warnedby; + static char[] trimChars = { ' ' }; + public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - - Player who = PlayerInfo.Find(message.Split(' ')[0]); - - // Make sure we have a valid player - if (who == null) - { - Player.SendMessage(p, "Player not found!"); - return; - } - - // Don't warn yourself... derp - if (who == p) - { - Player.SendMessage(p, "you can't warn yourself"); - return; - } - - // Check the caller's rank - if (p != null && p.group.Permission <= who.group.Permission) - { - Player.SendMessage(p, "Cannot warn a player of equal or higher rank."); - return; + string[] args = message.Split(trimChars, 2); + Player who = PlayerInfo.FindOrShowMatches(p, args[0]); + + if (who == null) return; + if (who == p) { Player.SendMessage(p, "you can't warn yourself"); return; } + if (p != null && p.group.Permission <= who.group.Permission) { + Player.SendMessage(p, "Cannot warn a player of equal or higher rank."); return; } - // We need a reason - if (message.Split(' ').Length == 1) - { - // No reason was given - reason = "you know why."; - } - else - { - reason = message.Substring(message.IndexOf(' ') + 1).Trim(); - } - - warnedby = (p == null) ? "" : p.color + p.DisplayName; + string reason = args.Length == 1 ? "you know why." : args[1]; + string warnedby = (p == null) ? "" : p.color + p.DisplayName; Player.GlobalMessage(warnedby + " %ewarned " + who.color + who.DisplayName + " %ebecause:"); Player.GlobalMessage("&c" + reason); Server.IRC.Say(warnedby + " %ewarned " + who.color + who.DisplayName + " %efor: %c" + reason); Server.s.Log(warnedby + " warned " + who.name); - //Player.SendMessage(who, "Do it again "); - if (who.warn == 0) - { + if (who.warn == 0) { Player.SendMessage(who, "Do it again twice and you will get kicked!"); - who.warn = 1; - return; - } - if (who.warn == 1) - { + } else if (who.warn == 1) { Player.SendMessage(who, "Do it one more time and you will get kicked!"); - who.warn = 2; - return; - } - if (who.warn == 2) - { - Player.GlobalMessage(who.color + who.DisplayName + " " + Server.DefaultColor + "was warn-kicked by " + warnedby); - who.warn = 0; + } else if (who.warn == 2) { + Player.GlobalMessage(who.color + who.DisplayName + " " + "%Swas warn-kicked by " + warnedby); who.Kick("KICKED BECAUSE " + reason + ""); - return; } + who.warn++; } - public override void Help(Player p) - { - Player.SendMessage(p, "/warn - Warns a player."); + + public override void Help(Player p) { + Player.SendMessage(p, "/warn - Warns a player."); Player.SendMessage(p, "Player will get kicked after 3 warnings."); } } diff --git a/Commands/other/CmdColor.cs b/Commands/other/CmdColor.cs index 1e37afb7f..675e2bd43 100644 --- a/Commands/other/CmdColor.cs +++ b/Commands/other/CmdColor.cs @@ -31,8 +31,8 @@ namespace MCGalaxy.Commands { if (message == "") { Help(p); return; } string[] args = message.Split(' '); - Player who = PlayerInfo.Find(args[0]); - if (who == null) { Player.SendMessage(p, "Could not find player."); return; } + Player who = PlayerInfo.FindOrShowMatches(p, args[0]); + if (who == null) return; if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot change the color of someone of greater rank"); return; } diff --git a/Commands/other/CmdInvincible.cs b/Commands/other/CmdInvincible.cs index fe1cb6246..ecb9e3157 100644 --- a/Commands/other/CmdInvincible.cs +++ b/Commands/other/CmdInvincible.cs @@ -29,15 +29,11 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { - Player who = message == "" ? p : PlayerInfo.Find(message); - if (who == null || !Player.CanSee(p, who)) { - Player.SendMessage(p, "Cannot find player."); return; - } + Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; - if (p != null && who.group.Permission > p.group.Permission) - { - Player.SendMessage(p, "Cannot toggle invincibility for someone of higher rank"); - return; + if (p != null && who.group.Permission > p.group.Permission) { + Player.SendMessage(p, "Cannot toggle invincibility for someone of higher rank");return; } if (who.invincible) diff --git a/Commands/other/CmdSummon.cs b/Commands/other/CmdSummon.cs index c8258a526..e866e03a1 100644 --- a/Commands/other/CmdSummon.cs +++ b/Commands/other/CmdSummon.cs @@ -45,13 +45,12 @@ namespace MCGalaxy.Commands return; } - Player who = PlayerInfo.Find(message); - if (who == null || !Player.CanSee(p, who)) { Player.SendMessage(p, "There is no player \"" + message + "\"!"); return; } - if (p.group.Permission < who.group.Permission) - { - Player.SendMessage(p, "You cannot summon someone ranked higher than you!"); - return; + Player who = PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; + if (p.group.Permission < who.group.Permission) { + Player.SendMessage(p, "You cannot summon someone ranked higher than you!"); return; } + if (p.level != who.level) { Player.SendMessage(p, who.DisplayName + " is in a different Level. Forcefetching has started!"); diff --git a/Commands/other/CmdTColor.cs b/Commands/other/CmdTColor.cs index d9cd44040..042105f44 100644 --- a/Commands/other/CmdTColor.cs +++ b/Commands/other/CmdTColor.cs @@ -31,8 +31,8 @@ namespace MCGalaxy.Commands { if (message == "") { Help(p); return; } string[] args = message.Split(' '); - Player who = PlayerInfo.Find(args[0]); - if (who == null) { Player.SendMessage(p, "Could not find player."); return; } + Player who = PlayerInfo.FindOrShowMatches(p, args[0]); + if (who == null) return; if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot change the title color of someone of greater rank"); return; } diff --git a/Commands/other/CmdTitle.cs b/Commands/other/CmdTitle.cs index 047255df6..a65557346 100644 --- a/Commands/other/CmdTitle.cs +++ b/Commands/other/CmdTitle.cs @@ -32,8 +32,8 @@ namespace MCGalaxy.Commands { if (message == "") { Help(p); return; } string[] parts = message.Split(trimChars, 2); - Player who = PlayerInfo.Find(parts[0]); - if (who == null) { Player.SendMessage(p, "Could not find player."); return; } + Player who = PlayerInfo.FindOrShowMatches(p, parts[0]); + if (who == null) return; if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot change the title of someone of greater rank"); return; } diff --git a/Player/PlayerInfo.cs b/Player/PlayerInfo.cs index 1d4f8e6a0..9695eb4ee 100644 --- a/Player/PlayerInfo.cs +++ b/Player/PlayerInfo.cs @@ -83,8 +83,13 @@ namespace MCGalaxy { } public static Player FindOrShowMatches(Player pl, string name, bool onlyCanSee = true) { + int matches = 0; + return FindOrShowMatches(pl, name, out matches, onlyCanSee); + } + + public static Player FindOrShowMatches(Player pl, string name, out int matches, bool onlyCanSee = true) { Player[] players = PlayerInfo.Online; - Player match = null; int matches = 0; + Player match = null; matches = 0; name = name.ToLower(); StringBuilder matchNames = new StringBuilder();