From 2b68b93aba66b741f20ad9ee4651655dfd37f316 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 29 Mar 2016 17:17:45 +1100 Subject: [PATCH] First batch of command code cleanups. --- Commands/Economy/CmdBalance.cs | 19 +- Commands/Fun/CmdSlap.cs | 49 +++-- .../{Moderation => Information}/CmdSeen.cs | 15 +- Commands/Information/CmdWhowas.cs | 11 +- Commands/Moderation/CmdJail.cs | 103 +++++------ Commands/other/CmdMove.cs | 8 +- Commands/other/CmdNick.cs | 4 +- Commands/other/CmdSendCmd.cs | 7 +- Commands/other/CmdTpA.cs | 4 +- Commands/other/CmdXJail.cs | 170 ++++++++---------- Commands/other/CmdXspawn.cs | 42 ++--- Games/ZombieSurvival/ZombieGame.Core.cs | 2 +- MCGalaxy_.csproj | 2 +- 13 files changed, 189 insertions(+), 247 deletions(-) rename Commands/{Moderation => Information}/CmdSeen.cs (82%) diff --git a/Commands/Economy/CmdBalance.cs b/Commands/Economy/CmdBalance.cs index f31a057c6..91f2b40c8 100644 --- a/Commands/Economy/CmdBalance.cs +++ b/Commands/Economy/CmdBalance.cs @@ -33,18 +33,15 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, "You must provide a name when using the command from console."); return; } - if (message != "") { - Player who = PlayerInfo.Find(message); - if (who == null) { - ecos = Economy.RetrieveEcoStats(message); - Player.SendMessage(p, "%3===Economy stats for: %f" + ecos.playerName + "%7(offline)%3==="); - } else { - ecos = Economy.RetrieveEcoStats(who.name); - Player.SendMessage(p, "%3===Economy stats for: " + who.color + who.name + "%3==="); - } + int matches = 1; + Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message, out matches); + if (matches > 1) return; + if (matches == 0) { + ecos = Economy.RetrieveEcoStats(message); + Player.SendMessage(p, "%3===Economy stats for: %f" + ecos.playerName + "%7(offline)%3==="); } else { - ecos = Economy.RetrieveEcoStats(p.name); - Player.SendMessage(p, "%3===Economy stats for: " + p.color + p.name + "%3==="); + ecos = Economy.RetrieveEcoStats(who.name); + Player.SendMessage(p, "%3===Economy stats for: " + who.color + who.name + "%3==="); } Player.SendMessage(p, "Current balance: %f" + ecos.money + " %3" + Server.moneys); diff --git a/Commands/Fun/CmdSlap.cs b/Commands/Fun/CmdSlap.cs index 9343ba0d7..3f3f11664 100644 --- a/Commands/Fun/CmdSlap.cs +++ b/Commands/Fun/CmdSlap.cs @@ -14,11 +14,10 @@ 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 CmdSlap : Command - { + */ +namespace MCGalaxy.Commands { + + public sealed class CmdSlap : Command { public override string name { get { return "slap"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } @@ -26,32 +25,24 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public CmdSlap() { } - 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) - { - Level which = LevelInfo.Find(message); - - if (which == null) - { - Player.SendMessage(p, "Could not find player or map specified"); - return; + int matches; + Player who = PlayerInfo.FindOrShowMatches(p, message, out matches); + if (matches > 1) return; + + if (who == null) { + Level lvl = LevelInfo.Find(message); + if (lvl == null) { + Player.SendMessage(p, "Could not find player or map specified"); return; } - else - { - Player[] players = PlayerInfo.Online.Items; - foreach (Player pl in players) { - if (pl.level == which && pl.group.Permission < p.group.Permission) - Command.all.Find("slap").Use(p, pl.name); - } - return; + + Player[] players = PlayerInfo.Online.Items; + foreach (Player pl in players) { + if (pl.level == lvl && pl.group.Permission < p.group.Permission) + Command.all.Find("slap").Use(p, pl.name); } - } - if (!Player.CanSee(p, who)) { - Player.SendMessage(p, "Could not find player or map specified"); return; + return; } if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "You cannot slap someone ranked higher than you!"); return; @@ -72,7 +63,7 @@ namespace MCGalaxy.Commands if (foundHeight == ushort.MaxValue) { who.level.ChatLevel(who.color + who.DisplayName + " %Swas slapped sky high by " + src); foundHeight = 1000; - } + } who.SendPos(0xFF, who.pos[0], (ushort)(foundHeight * 32), who.pos[2], who.rot[0], who.rot[1]); } diff --git a/Commands/Moderation/CmdSeen.cs b/Commands/Information/CmdSeen.cs similarity index 82% rename from Commands/Moderation/CmdSeen.cs rename to Commands/Information/CmdSeen.cs index fc8204f89..41e3f1c2e 100644 --- a/Commands/Moderation/CmdSeen.cs +++ b/Commands/Information/CmdSeen.cs @@ -25,21 +25,20 @@ namespace MCGalaxy.Commands public override string shortcut { get { return ""; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } - public override string type { get { return CommandTypes.Moderation; } } + public override string type { get { return CommandTypes.Information; } } public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - Player pl = PlayerInfo.Find(message); - if (pl != null && Player.CanSee(p, pl)) { - Player.SendMessage(p, pl.color + pl.name + " %Sis currently online."); - return; + int matches; + Player pl = PlayerInfo.FindOrShowMatches(p, message, out matches); + if (matches > 1) return; + if (matches == 1) { + Player.SendMessage(p, pl.color + pl.name + " %Sis currently online."); return; } OfflinePlayer target = PlayerInfo.FindOffline(message); - if (target == null) { - Player.SendMessage(p, "Unable to find player"); return; - } + if (target == null) { Player.SendMessage(p, "Unable to find player"); return; } Player.SendMessage(p, message + " was last seen: " + target.lastLogin); } diff --git a/Commands/Information/CmdWhowas.cs b/Commands/Information/CmdWhowas.cs index 8e1ffd468..883997287 100644 --- a/Commands/Information/CmdWhowas.cs +++ b/Commands/Information/CmdWhowas.cs @@ -33,14 +33,15 @@ namespace MCGalaxy.Commands public override void Use(Player p, string message) { if (message == "") { Help(p); return; } - Player pl = PlayerInfo.Find(message); - if (pl != null && Player.CanSee(p, pl)) { + int matches; + Player pl = PlayerInfo.FindOrShowMatches(p, message, out matches); + if (matches > 1) return; + if (matches == 1) { Player.SendMessage(p, pl.color + pl.name + " %Sis online, using /whois instead."); - Command.all.Find("whois").Use(p, message); - return; + Command.all.Find("whois").Use(p, message); return; } - if (message.IndexOf("'") != -1) { Player.SendMessage(p, "Cannot parse request."); return; } + if (!Player.ValidName(message)) { Player.SendMessage(p, "\"" + message + "\" is not a valid player name."); return; } OfflinePlayer target = PlayerInfo.FindOffline(message, true); string plGroup = Group.findPlayer(message.ToLower()); diff --git a/Commands/Moderation/CmdJail.cs b/Commands/Moderation/CmdJail.cs index a1fad5c12..67300ed59 100644 --- a/Commands/Moderation/CmdJail.cs +++ b/Commands/Moderation/CmdJail.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.IO; namespace MCGalaxy.Commands @@ -23,61 +23,46 @@ namespace MCGalaxy.Commands { public override string name { get { return "jail"; } } 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 CmdJail() { } - public override void Use(Player p, string message) - { - if ((message.ToLower() == "set") && p != null) - { + public override void Use(Player p, string message) { + if (message.ToLower() == "set" && p != null) { p.level.jailx = p.pos[0]; p.level.jaily = p.pos[1]; p.level.jailz = p.pos[2]; p.level.jailrotx = p.rot[0]; p.level.jailroty = p.rot[1]; Player.SendMessage(p, "Set Jail point."); + return; } - else - { - Player who = PlayerInfo.Find(message); - if (who != null) - { - if (!who.jailed) - { - if (p != null) - { - if (who.group.Permission >= p.group.Permission) { Player.SendMessage(p, "Cannot jail someone of equal or greater rank."); return; } - Player.SendMessage(p, "You jailed " + who.DisplayName); - } - Player.GlobalDespawn(who, false); - who.jailed = true; - Player.GlobalSpawn(who, who.level.jailx, who.level.jaily, who.level.jailz, who.level.jailrotx, who.level.jailroty, true); - if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close(); - Extensions.DeleteLineWord("ranks/jailed.txt", who.name); - using (StreamWriter writer = new StreamWriter("ranks/jailed.txt", true)) - { - writer.WriteLine(who.name.ToLower() + " " + who.level.name); - } - Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " was &8jailed", false); - } - else - { - if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close(); - Extensions.DeleteLineWord("ranks/jailed.txt", who.name.ToLower()); - who.jailed = false; - Command.all.Find("spawn").Use(who, ""); - Player.SendMessage(p, "You freed " + who.name + " from jail"); - Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " was &afreed" + Server.DefaultColor + " from jail", false); - } - } - else - { - Player.SendMessage(p, "Could not find specified player."); + Player who = PlayerInfo.FindOrShowMatches(p, message); + if (who == null) return; + + if (!who.jailed) { + if (p != null &&who.group.Permission >= p.group.Permission) { + Player.SendMessage(p, "Cannot jail someone of equal or greater rank."); return; } + Player.SendMessage(p, "You jailed " + who.DisplayName); + Player.GlobalDespawn(who, false); + who.jailed = true; + Player.GlobalSpawn(who, who.level.jailx, who.level.jaily, who.level.jailz, who.level.jailrotx, who.level.jailroty, true); + + if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close(); + Extensions.DeleteLineWord("ranks/jailed.txt", who.name); + using (StreamWriter writer = new StreamWriter("ranks/jailed.txt", true)) + writer.WriteLine(who.name.ToLower() + " " + who.level.name); + Player.SendChatFrom(who, who.color + who.DisplayName + " %Swas &8jailed", false); + } else { + if (!File.Exists("ranks/jailed.txt")) File.Create("ranks/jailed.txt").Close(); + Extensions.DeleteLineWord("ranks/jailed.txt", who.name.ToLower()); + who.jailed = false; + Command.all.Find("spawn").Use(who, ""); + Player.SendMessage(p, "You freed " + who.name + " from jail"); + Player.SendChatFrom(who, who.color + who.DisplayName + " %Swas &afreed %Sfrom jail", false); } } - public override void Help(Player p) - { + public override void Help(Player p) { Player.SendMessage(p, "/jail [user] - Places [user] in jail unable to use commands."); Player.SendMessage(p, "/jail [set] - Creates the jail point for the map."); Player.SendMessage(p, "This command has been deprecated in favor of /xjail."); diff --git a/Commands/other/CmdMove.cs b/Commands/other/CmdMove.cs index 21b0d31eb..fada81097 100644 --- a/Commands/other/CmdMove.cs +++ b/Commands/other/CmdMove.cs @@ -47,9 +47,9 @@ namespace MCGalaxy.Commands if (param.Length == 2) // /move name map { - Player who = PlayerInfo.Find(param[0]); + Player who = PlayerInfo.FindOrShowMatches(p, param[0]); Level where = LevelInfo.Find(param[1]); - if (who == null) { Player.SendMessage(p, "Could not find player specified"); return; } + if (who == null) return; if (where == null) { Player.SendMessage(p, "Could not find level specified"); return; } if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot move someone of greater rank"); return; } @@ -68,8 +68,8 @@ namespace MCGalaxy.Commands if (param.Length == 4) { - who = PlayerInfo.Find(param[0]); - if (who == null) { Player.SendMessage(p, "Could not find player specified"); return; } + who = PlayerInfo.FindOrShowMatches(p, param[0]); + if (who == null) return; if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot move someone of greater rank"); return; } message = message.Substring(message.IndexOf(' ') + 1); } diff --git a/Commands/other/CmdNick.cs b/Commands/other/CmdNick.cs index 94f6e9aed..30a5b7e1c 100644 --- a/Commands/other/CmdNick.cs +++ b/Commands/other/CmdNick.cs @@ -34,8 +34,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 nick of someone of greater rank"); return; } diff --git a/Commands/other/CmdSendCmd.cs b/Commands/other/CmdSendCmd.cs index e72f85934..e426b2068 100644 --- a/Commands/other/CmdSendCmd.cs +++ b/Commands/other/CmdSendCmd.cs @@ -30,11 +30,8 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { string[] parts = message.Split(trimChars, 3); - Player target = PlayerInfo.Find(parts[0]); - - if (target == null) { - Player.SendMessage(p, "No online player found matching: " + parts[0]); return; - } + Player target = PlayerInfo.FindOrShowMatches(p, parts[0]); + if (target == null) return; if (p != null && p.group.Permission < target.group.Permission) { Player.SendMessage(p, "Cannot use this on someone of equal or greater rank."); return; } diff --git a/Commands/other/CmdTpA.cs b/Commands/other/CmdTpA.cs index 578479924..d6a395795 100644 --- a/Commands/other/CmdTpA.cs +++ b/Commands/other/CmdTpA.cs @@ -86,7 +86,7 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, "&cError:" + Server.DefaultColor + " You do not have any pending teleport requests!"); return; } - Player who = PlayerInfo.Find(p.senderName); + Player who = PlayerInfo.FindExact(p.senderName); p.Request = false; p.senderName = ""; if (who == null) { @@ -127,7 +127,7 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, "&cError:" + Server.DefaultColor + " You do not have any pending teleport requests!"); return; } - Player who = PlayerInfo.Find(p.senderName); + Player who = PlayerInfo.FindExact(p.senderName); p.Request = false; p.senderName = ""; if (who == null) { diff --git a/Commands/other/CmdXJail.cs b/Commands/other/CmdXJail.cs index 1941acbad..223ec6bbc 100644 --- a/Commands/other/CmdXJail.cs +++ b/Commands/other/CmdXJail.cs @@ -1,117 +1,97 @@ /* - 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.IO; -namespace MCGalaxy.Commands -{ - public sealed class CmdXJail : Command - { +namespace MCGalaxy.Commands { + + public sealed class CmdXJail : Command { public override string name { get { return "xjail"; } } public override string shortcut { get { return "xj"; } } public override string type { get { return CommandTypes.Other; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override bool museumUsable { get { return true; } } - public override void Help(Player p) - { - Player.SendMessage(p, "/xjail - Mutes , freezes and sends to the XJail map (shortcut = /xj)"); - Player.SendMessage(p, "If is already jailed, will be spawned, unfrozen and unmuted"); - Player.SendMessage(p, "/xjail set - Sets the map to be used for xjail to your current map and sets jail to current location"); - } - public override void Use(Player p, string message) - { + + public override void Use(Player p, string message) { string dir = "extra/jail/"; string jailMapFile = dir + "xjail.map.xjail"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } - if (!File.Exists(jailMapFile)) - { + if (!File.Exists(jailMapFile)) { using (StreamWriter SW = new StreamWriter(jailMapFile)) - { SW.WriteLine(Server.mainLevel.name); - } } + if (message == "") { Help(p); return; } - else - { - using (StreamReader SR = new StreamReader(jailMapFile)) - { - string xjailMap = SR.ReadLine(); - SR.Close(); - Command jail = Command.all.Find("jail"); - if (message == "set") - { - if (!p.level.IsMuseum) - { - jail.Use(p, "create"); - using (StreamWriter SW = new StreamWriter(jailMapFile)) - { - SW.WriteLine(p.level.name); - } - Player.SendMessage(p, "The xjail map was set from '" + xjailMap + "' to '" + p.level.name + "'"); - return; - } - else { Player.SendMessage(p, "You are in a museum!"); return; } + using (StreamReader SR = new StreamReader(jailMapFile)) { + string xjailMap = SR.ReadLine(); + SR.Close(); + Command jail = Command.all.Find("jail"); + if (message == "set") { + if (!p.level.IsMuseum) { + jail.Use(p, "create"); + using (StreamWriter SW = new StreamWriter(jailMapFile)) + SW.WriteLine(p.level.name); + Player.SendMessage(p, "The xjail map was set from '" + xjailMap + "' to '" + p.level.name + "'"); + } else { + Player.SendMessage(p, "You are in a museum!"); } - else - { - Player player = PlayerInfo.Find(message); + return; + } + + Player pl = PlayerInfo.FindOrShowMatches(p, message); + if (pl == null) return; - if (player != null) - { - Command move = Command.all.Find("move"); - Command spawn = Command.all.Find("spawn"); - Command freeze = Command.all.Find("freeze"); - Command mute = Command.all.Find("mute"); - string playerFile = dir + player.name + "_temp.xjail"; - if (!File.Exists(playerFile)) - { - using (StreamWriter writeFile = new StreamWriter(playerFile)) - { - writeFile.WriteLine(player.level.name); - } - if (!player.muted) { mute.Use(p, message); } - if (!player.frozen) { freeze.Use(p, message); } - move.Use(p, message + " " + xjailMap); - player.BlockUntilLoad(10); - if (!player.jailed) { jail.Use(p, message); } - Player.GlobalMessage(player.color + player.DisplayName + Server.DefaultColor + " was XJailed!"); - return; - } - else - { - using (StreamReader readFile = new StreamReader(playerFile)) - { - string playerMap = readFile.ReadLine(); - readFile.Close(); - File.Delete(playerFile); - move.Use(p, message + " " + playerMap); - player.BlockUntilLoad(10); - mute.Use(p, message); - jail.Use(p, message); - freeze.Use(p, message); - spawn.Use(player, ""); - Player.GlobalMessage(player.color + player.DisplayName + Server.DefaultColor + " was released from XJail!"); - } - return; - } - } - else { Player.SendMessage(p, "Player not found"); return; } + Command move = Command.all.Find("move"); + Command spawn = Command.all.Find("spawn"); + Command freeze = Command.all.Find("freeze"); + Command mute = Command.all.Find("mute"); + string playerFile = dir + pl.name + "_temp.xjail"; + + if (!File.Exists(playerFile)) { + using (StreamWriter writeFile = new StreamWriter(playerFile)) + writeFile.WriteLine(pl.level.name); + if (!pl.muted) { mute.Use(p, message); } + if (!pl.frozen) { freeze.Use(p, message); } + move.Use(p, message + " " + xjailMap); + + pl.BlockUntilLoad(10); + if (!pl.jailed) { jail.Use(p, message); } + Player.GlobalMessage(pl.color + pl.DisplayName + Server.DefaultColor + " was XJailed!"); + } else { + using (StreamReader readFile = new StreamReader(playerFile)) { + string playerMap = readFile.ReadLine(); + readFile.Close(); + File.Delete(playerFile); + move.Use(p, message + " " + playerMap); + + pl.BlockUntilLoad(10); + mute.Use(p, message); + jail.Use(p, message); + freeze.Use(p, message); + spawn.Use(pl, ""); + Player.GlobalMessage(pl.color + pl.DisplayName + Server.DefaultColor + " was released from XJail!"); } } } } + + public override void Help(Player p) { + Player.SendMessage(p, "/xjail - Mutes , freezes and sends to the XJail map (shortcut = /xj)"); + Player.SendMessage(p, "If is already jailed, will be spawned, unfrozen and unmuted"); + Player.SendMessage(p, "/xjail set - Sets the map to be used for xjail to your current map and sets jail to current location"); + } } } diff --git a/Commands/other/CmdXspawn.cs b/Commands/other/CmdXspawn.cs index 8e8b1c1a4..910e29a24 100644 --- a/Commands/other/CmdXspawn.cs +++ b/Commands/other/CmdXspawn.cs @@ -19,39 +19,31 @@ */ using System; -namespace MCGalaxy.Commands -{ - public class CmdXspawn : Command - { +namespace MCGalaxy.Commands { + public class CmdXspawn : Command { public override string name { get { return "xspawn"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override void Use(Player p, string message) - { - Player player = PlayerInfo.Find(message.Split(' ')[0]); - if (player == null) - { - Player.SendMessage(p, "Error: " + player.color + player.name + Server.DefaultColor + " was not found"); - return; + + public override void Use(Player p, string message) { + Player pl = PlayerInfo.FindOrShowMatches(p, message); + if (pl == null) return; + if (pl == p) { + Player.SendMessage(p, "Use /spawn to respawn yourself."); return; } - if (player == p) - { - Player.SendMessage(p, "Error: Seriously? Just use /spawn!"); - return; + if (p != null && pl.group.Permission >= p.group.Permission) { + Player.SendMessage(p, "Cannot respawn someone of greater or same rank"); return; } - if (player.group.Permission > p.group.Permission) - { - Player.SendMessage(p, "Cannot move someone of greater rank"); - return; - } - Command.all.Find("spawn").Use(player, ""); - Player.SendMessage(p, "Succesfully spawned " + player.color + player.DisplayName + Server.DefaultColor + "."); - Player.GlobalMessage(player.color + player.name + Server.DefaultColor + " was respawned by " + p.color + p.DisplayName + Server.DefaultColor + "."); + + Command.all.Find("spawn").Use(pl, ""); + Player.SendMessage(p, "Succesfully spawned " + pl.color + pl.DisplayName + "%S."); + string src = p == null ? "(console)" : p.color + p.DisplayName; + Player.GlobalMessage(pl.color + pl.name + " %Swas respawned by " + src + "%S."); } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "/xspawn [player] - Spawn another player."); Player.SendMessage(p, "WARNING: It says who used it!"); } diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index 8312f5172..9468c90e5 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -103,7 +103,7 @@ namespace MCGalaxy.Games { Player first = null; do { first = QueuedZombie != null ? - PlayerInfo.Find(QueuedZombie) : players[random.Next(players.Count)]; + PlayerInfo.FindExact(QueuedZombie) : players[random.Next(players.Count)]; QueuedZombie = null; } while (first == null || !first.level.name.CaselessEq(CurLevelName)); return first; diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index aff7ffaa3..22c7866a3 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -227,6 +227,7 @@ + @@ -289,7 +290,6 @@ -