From cb9df3e60d82bfb0feb5241b6c486c5b3dcc50fc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 26 Jun 2016 12:13:32 +1000 Subject: [PATCH] Allow multiple commands in a /mb. --- Commands/building/CmdMessageBlock.cs | 3 ++- Player/Player.Handlers.cs | 34 ++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Commands/building/CmdMessageBlock.cs b/Commands/building/CmdMessageBlock.cs index becfea72e..39d6f8806 100644 --- a/Commands/building/CmdMessageBlock.cs +++ b/Commands/building/CmdMessageBlock.cs @@ -144,8 +144,9 @@ namespace MCGalaxy.Commands.Building { Player.Message(p, "%T/mb [block] [message]"); Player.Message(p, "%HPlaces a message in your next block."); Player.Message(p, "%H Valid blocks: white, black, air, water, lava"); + Player.Message(p, "%H Use | to separate commands, e.g. /say 1 |/say 2"); Player.Message(p, "%T/mb show"); - Player.Message(p, "%Hshows or hides MBs"); + Player.Message(p, "%HShows or hides MBs"); } } } diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 253c2fb03..bc160c66c 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -1210,7 +1210,28 @@ return; } public void HandleCommands(List cmds) { - // TODO: finish this then do next release + List messages = new List(cmds.Count); + List commands = new List(cmds.Count); + try { + foreach (string raw in cmds) { + string[] parts = raw.SplitSpaces(2); + string cmd = parts[0].ToLower(); + string message = parts.Length > 1 ? parts[1] : ""; + + if (!CheckCommand(cmd)) return; + Command command = GetCommand(ref cmd, ref message); + if (command == null) return; + + messages.Add(message); commands.Add(command); + } + + Thread thread = new Thread(() => UseCommands(commands, messages)); + thread.Name = "MCG_Command"; + thread.IsBackground = true; + thread.Start(); + } catch (Exception e) { + Server.ErrorLog(e); SendMessage("Command failed."); + } } bool CheckCommand(string cmd) { @@ -1293,7 +1314,7 @@ return; return command; } - void UseCommand(Command command, string message) { + bool UseCommand(Command command, string message) { string cmd = command.name; if (!(cmd == "repeat" || cmd == "pass" || cmd == "setpass")) { lastCMD = cmd + " " + message; @@ -1321,7 +1342,16 @@ return; Server.ErrorLog(e); Player.Message(this, "An error occured when using the command!"); Player.Message(this, e.GetType() + ": " + e.Message); + return false; } + return true; + } + + bool UseCommands(List commands, List messages) { + for (int i = 0; i < messages.Count; i++) { + if (!UseCommand(commands[i], messages[i])) return false; + } + return true; } } }