diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 748481cb..5afa1f99 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -40,6 +40,7 @@ namespace MinecraftClient private McClient _handler = null; private ChatBot master = null; private List registeredPluginChannels = new List(); + private List registeredCommands = new List(); private McClient Handler { get @@ -781,6 +782,10 @@ namespace MinecraftClient /// protected void UnloadBot() { + foreach (string cmdName in registeredCommands) + { + Handler.UnregisterCommand(cmdName); + } Handler.BotUnLoad(this); } @@ -1261,7 +1266,7 @@ namespace MinecraftClient } /// - /// Register a command in command prompt + /// Register a command in command prompt. Command will be automatically unregistered when unloading ChatBot /// /// Name of the command /// Description/usage of the command @@ -1269,7 +1274,10 @@ namespace MinecraftClient /// True if successfully registered protected bool RegisterChatBotCommand(string cmdName, string cmdDesc, string cmdUsage, CommandRunner callback) { - return Handler.RegisterCommand(cmdName, cmdDesc, cmdUsage, callback); + bool result = Handler.RegisterCommand(cmdName, cmdDesc, cmdUsage, callback); + if (result) + registeredCommands.Add(cmdName.ToLower()); + return result; } /// diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 49e48619..e6f66ca8 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -629,6 +629,26 @@ namespace MinecraftClient } } + /// + /// Unregister a console command + /// + /// + /// There is no check for the command is registered by above method or is embedded command. + /// Which mean this can unload any command + /// + /// The name of command to be unregistered + /// + public bool UnregisterCommand(string cmdName) + { + if (cmds.ContainsKey(cmdName.ToLower())) + { + cmds.Remove(cmdName.ToLower()); + cmd_names.Remove(cmdName.ToLower()); + return true; + } + else return false; + } + #region Management: Load/Unload ChatBots and Enable/Disable settings ///