Allow multiple commands in a /mb.

This commit is contained in:
UnknownShadow200 2016-06-26 12:13:32 +10:00
parent 59b0d8efc7
commit cb9df3e60d
2 changed files with 34 additions and 3 deletions

View File

@ -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");
}
}
}

View File

@ -1210,7 +1210,28 @@ return;
}
public void HandleCommands(List<string> cmds) {
// TODO: finish this then do next release
List<string> messages = new List<string>(cmds.Count);
List<Command> commands = new List<Command>(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<Command> commands, List<string> messages) {
for (int i = 0; i < messages.Count; i++) {
if (!UseCommand(commands[i], messages[i])) return false;
}
return true;
}
}
}