mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
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:
parent
715bc09872
commit
36690b8b34
12 changed files with 322 additions and 78 deletions
24
MinecraftClient/Commands/Connect.cs
Normal file
24
MinecraftClient/Commands/Connect.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
MinecraftClient/Commands/Exit.cs
Normal file
24
MinecraftClient/Commands/Exit.cs
Normal 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" };
|
||||
}
|
||||
}
|
||||
}
|
||||
19
MinecraftClient/Commands/Reco.cs
Normal file
19
MinecraftClient/Commands/Reco.cs
Normal 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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
19
MinecraftClient/Commands/Respawn.cs
Normal file
19
MinecraftClient/Commands/Respawn.cs
Normal 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.";
|
||||
}
|
||||
}
|
||||
}
|
||||
23
MinecraftClient/Commands/Script.cs
Normal file
23
MinecraftClient/Commands/Script.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
MinecraftClient/Commands/Send.cs
Normal file
23
MinecraftClient/Commands/Send.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
MinecraftClient/Commands/Set.cs
Normal file
31
MinecraftClient/Commands/Set.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue