From fddbd360d97bed8201e28e0c98a419032e79f8b7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 10 Feb 2016 23:20:28 +1100 Subject: [PATCH] Fix /cmdbind num. --- Commands/building/CmdCmdBind.cs | 117 ++++++++++++++------------------ 1 file changed, 51 insertions(+), 66 deletions(-) diff --git a/Commands/building/CmdCmdBind.cs b/Commands/building/CmdCmdBind.cs index bd6039886..3803883e1 100644 --- a/Commands/building/CmdCmdBind.cs +++ b/Commands/building/CmdCmdBind.cs @@ -1,89 +1,74 @@ /* - Copyright 2011 MCGalaxy - - 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 MCGalaxy + + 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; -namespace MCGalaxy.Commands -{ - public sealed class CmdCmdBind : Command - { + +namespace MCGalaxy.Commands { + + public sealed class CmdCmdBind : Command { + public override string name { get { return "cmdbind"; } } public override string shortcut { get { return "cb"; } } public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public CmdCmdBind() { } + static char[] trimChars = { ' ' }; - public override void Use(Player p, string message) - { - if (p == null) { MessageInGameOnly(p); return; } - string foundcmd, foundmessage = ""; int foundnum = 0; + public override void Use(Player p, string message) { + if (p == null) { MessageInGameOnly(p); return; } - if (message.IndexOf(' ') == -1) - { - bool OneFound = false; - for (int i = 0; i < 10; i++) - { - if (p.cmdBind[i] != null) - { - Player.SendMessage(p, "&c/" + i + Server.DefaultColor + " bound to &b" + p.cmdBind[i] + " " + p.messageBind[i]); - OneFound = true; + if (message == "") { + bool foundBind = false; + for (int i = 0; i < 10; i++) { + if (p.cmdBind[i] != null) { + Player.SendMessage(p, "&c/" + i + " %Sbound to &b" + p.cmdBind[i] + " " + p.messageBind[i]); + foundBind = true; } } - if (!OneFound) Player.SendMessage(p, "You have no commands binded"); + if (!foundBind) Player.SendMessage(p, "You currently have no commands bound."); return; } - - if (message.Split(' ').Length == 1) - { - try - { - foundnum = Convert.ToInt16(message); - if (p.cmdBind[foundnum] == null) { Player.SendMessage(p, "No command stored here yet."); return; } - foundcmd = "/" + p.cmdBind[foundnum] + " " + p.messageBind[foundnum]; - Player.SendMessage(p, "Stored command: &b" + foundcmd); - } - catch { Help(p); } + + string[] parts = message.Split(trimChars, 3); + byte index; + if (!byte.TryParse(parts[0], out index) || index >= 10) { + Player.SendMessage(p, "Bind number must be between 0 and 9."); return; } - else if (message.Split(' ').Length > 1) - { - try - { - foundnum = Convert.ToInt16(message.Split(' ')[message.Split(' ').Length - 1]); - foundcmd = message.Split(' ')[0]; - if (message.Split(' ').Length > 2) - { - foundmessage = message.Substring(message.IndexOf(' ') + 1); - foundmessage = foundmessage.Remove(foundmessage.LastIndexOf(' ')); - } + + if (parts.Length == 1) { + if (p.cmdBind[index] == null) + Player.SendMessage(p, "No command bound for &c/" + index); + else + Player.SendMessage(p, "&c/" + index + " %Sbound to &b" + p.cmdBind[index] + " " + p.messageBind[index]); + } else { + p.cmdBind[index] = parts[1]; + p.messageBind[index] = parts.Length > 2 ? parts[2] : ""; - p.cmdBind[foundnum] = foundcmd; - p.messageBind[foundnum] = foundmessage; - - Player.SendMessage(p, "Binded &b/" + foundcmd + " " + foundmessage + " to &c/" + foundnum); - } - catch { Help(p); } + Player.SendMessage(p, "Bound &b/" + p.cmdBind[index] + " " + p.messageBind[index] + " to &c/" + index); } } - public override void Help(Player p) - { - Player.SendMessage(p, "/cmdbind [command] [num] - Binds [command] to [num]"); + + public override void Help(Player p) { + Player.SendMessage(p, "/cmdbind [num] [command] - Binds [num] to [command]"); Player.SendMessage(p, "[num] must be between 0 and 9"); Player.SendMessage(p, "Use with \"/[num]\" &b(example: /2)"); - Player.SendMessage(p, "Use /cmdbind [num] to see stored commands."); + Player.SendMessage(p, "Use /cmdbind [num] to see the currently bound command."); + Player.SendMessage(p, "Use /cmdbind to see all bound commands."); } } }