Fix /cmdbind num.

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

View File

@ -16,74 +16,59 @@
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)
{
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
string foundcmd, foundmessage = ""; int foundnum = 0;
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); }
}
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(' '));
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;
}
p.cmdBind[foundnum] = foundcmd;
p.messageBind[foundnum] = foundmessage;
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] : "";
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.");
}
}
}