using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MinecraftClient { /// /// Represents an internal MCC command: Command name, source code and usage message /// To add a new command, inherit from this class while adding the command class to the folder "Commands". /// If inheriting from the 'Command' class and placed in the 'Commands' namespace, the command will be /// automatically loaded and available in main chat prompt, scripts, remote control and command help. /// public abstract class Command { /// /// The command name /// public abstract string CMDName { get; } /// /// Usage message, eg: 'name [args]: do something' /// public abstract string CMDDesc { get; } /// /// Perform the command /// /// The full command, eg: 'mycommand arg1 arg2' /// Local variables passed along with the command (may be null) /// A confirmation/error message, or "" if no message public abstract string Run(McTcpClient handler, string command, Dictionary localVars); /// /// Return a list of aliases for this command. /// Override this method if you wish to put aliases to the command /// public virtual IEnumerable getCMDAliases() { return new string[0]; } /// /// Check if at least one argument has been passed to the command /// public static bool hasArg(string command) { int first_space = command.IndexOf(' '); return (first_space > 0 && first_space < command.Length - 1); } /// /// Extract the argument string from the command /// /// Argument or "" if no argument public static string getArg(string command) { if (hasArg(command)) { return command.Substring(command.IndexOf(' ') + 1); } else return ""; } /// /// Extract the arguments as a string array from the command /// /// Argument array or empty array if no arguments public static string[] getArgs(string command) { string[] args = getArg(command).Split(' '); if (args.Length == 1 && args[0] == "") { return new string[] { }; } else { return args; } } } }