From b9099757fbc5b711cef401236251aa38328a6c0f Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Mon, 1 Oct 2012 01:55:48 -0400 Subject: [PATCH] Added support for multiple chat commands being executed off one /command. This is due to a request that we allow people to register the same command as someone else. Also, this will fix any issues where two plugins register the same command and one breaks. Ofc, any better suggestions are extremely welcome. --- TShockAPI/Commands.cs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 1dae17fd..fbf800ae 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -223,9 +223,9 @@ namespace TShockAPI string cmdName = args[0].ToLower(); args.RemoveAt(0); - Command cmd = ChatCommands.FirstOrDefault(c => c.HasAlias(cmdName)); + IEnumerable cmds = ChatCommands.Where(c => c.HasAlias(cmdName)); - if (cmd == null) + if (cmds.Count() == 0) { if (player.AwaitingResponse.ContainsKey(cmdName)) { @@ -237,23 +237,25 @@ namespace TShockAPI player.SendErrorMessage("Invalid command entered. Type /help for a list of valid commands."); return true; } - - if (!cmd.CanRun(player)) - { - TShock.Utils.SendLogs(string.Format("{0} tried to execute /{1}.", player.Name, cmdText), Color.Red); - player.SendErrorMessage("You do not have access to that command."); - } - else if (!cmd.AllowServer && !player.RealPlayer) - { - player.SendErrorMessage("You must use this command in-game."); - } - else - { - if (cmd.DoLog) - TShock.Utils.SendLogs(string.Format("{0} executed: /{1}.", player.Name, cmdText), Color.Red); - cmd.Run(cmdText, player, args); - } - return true; + foreach (Command cmd in cmds) + { + if (!cmd.CanRun(player)) + { + TShock.Utils.SendLogs(string.Format("{0} tried to execute /{1}.", player.Name, cmdText), Color.Red); + player.SendErrorMessage("You do not have access to that command."); + } + else if (!cmd.AllowServer && !player.RealPlayer) + { + player.SendErrorMessage("You must use this command in-game."); + } + else + { + if (cmd.DoLog) + TShock.Utils.SendLogs(string.Format("{0} executed: /{1}.", player.Name, cmdText), Color.Red); + cmd.Run(cmdText, player, args); + } + } + return true; } ///