Commands as separate classes

Each command is now in its own class in the 'Commands' namespace, and
loaded through reflection.
This commit is contained in:
ORelio 2014-06-18 13:32:17 +02:00
parent 715bc09872
commit 36690b8b34
12 changed files with 322 additions and 78 deletions

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Connect : Command
{
public override string CMDName { get { return "connect"; } }
public override string CMDDesc { get { return "connect <serverip>: connect to the specified server."; } }
public override string Run(McTcpClient handler, string command)
{
if (hasArg(command))
{
Settings.setServerIP(getArgs(command)[0]);
Program.Restart();
return "";
}
else return CMDDesc;
}
}
}

View file

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Exit : Command
{
public override string CMDName { get { return "exit"; } }
public override string CMDDesc { get { return "exit: disconnect from the server."; } }
public override string Run(McTcpClient handler, string command)
{
Program.Exit();
return "";
}
public override IEnumerable<string> getCMDAliases()
{
return new string[] { "quit" };
}
}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Reco : Command
{
public override string CMDName { get { return "reco"; } }
public override string CMDDesc { get { return "reco: restart and reconnect to the server."; } }
public override string Run(McTcpClient handler, string command)
{
Program.Restart();
return "";
}
}
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Respawn : Command
{
public override string CMDName { get { return "respawn"; } }
public override string CMDDesc { get { return "respawn: respawn after death."; } }
public override string Run(McTcpClient handler, string command)
{
handler.SendRespawnPacket();
return "You have respawned.";
}
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Script : Command
{
public override string CMDName { get { return "script"; } }
public override string CMDDesc { get { return "script <scriptname>: run a script file."; } }
public override string Run(McTcpClient handler, string command)
{
if (hasArg(command))
{
handler.BotLoad(new ChatBots.Script(getArg(command)));
return "";
}
else return CMDDesc;
}
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Send : Command
{
public override string CMDName { get { return "send"; } }
public override string CMDDesc { get { return "send <text>: send a chat message or command."; } }
public override string Run(McTcpClient handler, string command)
{
if (hasArg(command))
{
handler.SendChatMessage(getArg(command));
return "";
}
else return CMDDesc;
}
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Commands
{
public class Set : Command
{
public override string CMDName { get { return "set"; } }
public override string CMDDesc { get { return "set varname=value: set a custom %variable%."; } }
public override string Run(McTcpClient handler, string command)
{
if (hasArg(command))
{
string[] temp = getArg(command).Split('=');
if (temp.Length > 1)
{
if (Settings.setVar(temp[0], getArg(command).Substring(temp[0].Length + 1)))
{
return ""; //Success
}
else return "variable name must be A-Za-z0-9.";
}
else return CMDDesc;
}
else return CMDDesc;
}
}
}