Added a way to execute multiple commands with a single command

This commit is contained in:
Milutinke 2022-09-11 17:06:23 +02:00
parent 223c13561c
commit 59cc4cea7c
2 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace MinecraftClient.Commands
{
class ExecMulti : Command
{
public override string CmdName { get { return "execmulti"; } }
public override string CmdUsage { get { return "execmulti <command 1> -> <command2> -> <command 3> -> ..."; } }
public override string CmdDesc { get { return "cmd.execmulti.desc"; } }
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
{
if (hasArg(command))
{
string commandsString = getArg(command);
IEnumerable<string> commands = commandsString.Split("->")
.ToList()
.ConvertAll(command => command.Trim())
.FindAll(command => !string.IsNullOrEmpty(command) || command.StartsWith("execmulti", StringComparison.OrdinalIgnoreCase));
foreach (string cmd in commands)
{
string output = "";
handler.PerformInternalCommand(cmd, ref output);
string log = Translations.TryGet(
"cmd.execmulti.executed", cmd,
string.IsNullOrEmpty(output) ? Translations.TryGet("cmd.execmulti.no_result") : Translations.TryGet("cmd.execmulti.result", output));
if (output.Contains("unknown command", StringComparison.OrdinalIgnoreCase))
handler.Log.Error(log);
else handler.Log.Info(log);
}
return "";
}
return GetCmdDescTranslated();
}
}
}

View file

@ -271,6 +271,12 @@ cmd.entityCmd.distance=Distance
cmd.entityCmd.location=Location
cmd.entityCmd.type=Type
# Exec Multi
cmd.execmulti.desc=Execute multiple commands one after another
cmd.execmulti.executed=Executed the command '{0}' with {1}
cmd.execmulti.result=result '{0}'!
cmd.execmulti.no_result=no result!
# Exit
cmd.exit.desc=disconnect from the server.