Fix /cmdbind num.

This commit is contained in:
UnknownShadow200 2016-02-10 23:20:28 +11:00
parent 461d41ad0e
commit fddbd360d9

View File

@ -1,89 +1,74 @@
/* /*
Copyright 2011 MCGalaxy Copyright 2011 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
namespace MCGalaxy.Commands
{ namespace MCGalaxy.Commands {
public sealed class CmdCmdBind : Command
{ public sealed class CmdCmdBind : Command {
public override string name { get { return "cmdbind"; } } public override string name { get { return "cmdbind"; } }
public override string shortcut { get { return "cb"; } } public override string shortcut { get { return "cb"; } }
public override string type { get { return CommandTypes.Building; } } public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
public CmdCmdBind() { } public CmdCmdBind() { }
static char[] trimChars = { ' ' };
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ if (p == null) { MessageInGameOnly(p); return; }
if (p == null) { MessageInGameOnly(p); return; }
string foundcmd, foundmessage = ""; int foundnum = 0;
if (message.IndexOf(' ') == -1) if (message == "") {
{ bool foundBind = false;
bool OneFound = false; for (int i = 0; i < 10; i++) {
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]);
if (p.cmdBind[i] != null) foundBind = true;
{
Player.SendMessage(p, "&c/" + i + Server.DefaultColor + " bound to &b" + p.cmdBind[i] + " " + p.messageBind[i]);
OneFound = true;
} }
} }
if (!OneFound) Player.SendMessage(p, "You have no commands binded"); if (!foundBind) Player.SendMessage(p, "You currently have no commands bound.");
return; return;
} }
if (message.Split(' ').Length == 1) string[] parts = message.Split(trimChars, 3);
{ byte index;
try if (!byte.TryParse(parts[0], out index) || index >= 10) {
{ Player.SendMessage(p, "Bind number must be between 0 and 9."); return;
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); }
} }
else if (message.Split(' ').Length > 1)
{ if (parts.Length == 1) {
try if (p.cmdBind[index] == null)
{ Player.SendMessage(p, "No command bound for &c/" + index);
foundnum = Convert.ToInt16(message.Split(' ')[message.Split(' ').Length - 1]); else
foundcmd = message.Split(' ')[0]; Player.SendMessage(p, "&c/" + index + " %Sbound to &b" + p.cmdBind[index] + " " + p.messageBind[index]);
if (message.Split(' ').Length > 2) } else {
{ p.cmdBind[index] = parts[1];
foundmessage = message.Substring(message.IndexOf(' ') + 1); p.messageBind[index] = parts.Length > 2 ? parts[2] : "";
foundmessage = foundmessage.Remove(foundmessage.LastIndexOf(' '));
}
p.cmdBind[foundnum] = foundcmd; Player.SendMessage(p, "Bound &b/" + p.cmdBind[index] + " " + p.messageBind[index] + " to &c/" + index);
p.messageBind[foundnum] = foundmessage;
Player.SendMessage(p, "Binded &b/" + foundcmd + " " + foundmessage + " to &c/" + foundnum);
}
catch { Help(p); }
} }
} }
public override void Help(Player p)
{ public override void Help(Player p) {
Player.SendMessage(p, "/cmdbind [command] [num] - Binds [command] to [num]"); Player.SendMessage(p, "/cmdbind [num] [command] - Binds [num] to [command]");
Player.SendMessage(p, "[num] must be between 0 and 9"); Player.SendMessage(p, "[num] must be between 0 and 9");
Player.SendMessage(p, "Use with \"/[num]\" &b(example: /2)"); 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.");
} }
} }
} }