mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Implement command completion suggestions.
This commit is contained in:
parent
5d2589b10f
commit
84cf749344
115 changed files with 4684 additions and 2695 deletions
|
|
@ -2,6 +2,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Brigadier.NET;
|
||||
using Brigadier.NET.Builder;
|
||||
using MinecraftClient.CommandHandler;
|
||||
|
||||
namespace MinecraftClient.Commands
|
||||
{
|
||||
|
|
@ -11,42 +13,47 @@ namespace MinecraftClient.Commands
|
|||
public override string CmdUsage { get { return "execmulti <command 1> -> <command2> -> <command 3> -> ..."; } }
|
||||
public override string CmdDesc { get { return Translations.cmd_execmulti_desc; } }
|
||||
|
||||
public override void RegisterCommand(McClient handler, CommandDispatcher<CommandSource> dispatcher)
|
||||
public override void RegisterCommand(McClient handler, CommandDispatcher<CmdResult> dispatcher)
|
||||
{
|
||||
dispatcher.Register(l => l.Literal("help")
|
||||
.Then(l => l.Literal(CmdName)
|
||||
.Executes(r => GetUsage(r.Source, string.Empty))
|
||||
)
|
||||
);
|
||||
|
||||
dispatcher.Register(l => l.Literal(CmdName)
|
||||
.Then(l => l.Argument("Commands", Arguments.GreedyString())
|
||||
.Executes(r => HandleCommand(r.Source, handler, Arguments.GetString(r, "Commands"))))
|
||||
);
|
||||
}
|
||||
|
||||
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
||||
private int GetUsage(CmdResult r, string? cmd)
|
||||
{
|
||||
if (HasArg(command))
|
||||
return r.SetAndReturn(cmd switch
|
||||
{
|
||||
string commandsString = GetArg(command);
|
||||
#pragma warning disable format // @formatter:off
|
||||
_ => GetCmdDescTranslated(),
|
||||
#pragma warning restore format // @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
if (commandsString.Contains("execmulti", StringComparison.OrdinalIgnoreCase) || commandsString.Contains("execif", StringComparison.OrdinalIgnoreCase))
|
||||
return Translations.cmd_execmulti_prevent;
|
||||
private int HandleCommand(CmdResult r, McClient handler, string commandsString)
|
||||
{
|
||||
if (commandsString.Contains("execmulti", StringComparison.OrdinalIgnoreCase) || commandsString.Contains("execif", StringComparison.OrdinalIgnoreCase))
|
||||
return r.SetAndReturn(CmdResult.Status.Fail, Translations.cmd_execmulti_prevent);
|
||||
|
||||
IEnumerable<string> commands = commandsString.Split("->", StringSplitOptions.TrimEntries)
|
||||
.ToList()
|
||||
.FindAll(command => !string.IsNullOrEmpty(command));
|
||||
IEnumerable<string> commands = commandsString.Split("->", StringSplitOptions.TrimEntries)
|
||||
.ToList()
|
||||
.FindAll(command => !string.IsNullOrEmpty(command));
|
||||
|
||||
foreach (string cmd in commands)
|
||||
{
|
||||
string? output = "";
|
||||
handler.PerformInternalCommand(cmd, ref output);
|
||||
|
||||
string log = string.Format(
|
||||
Translations.cmd_execmulti_executed, cmd,
|
||||
string.IsNullOrEmpty(output) ? Translations.cmd_execmulti_no_result : string.Format(Translations.cmd_execmulti_result, output));
|
||||
|
||||
if (output != null && output.Contains("unknown command", StringComparison.OrdinalIgnoreCase))
|
||||
handler.Log.Error(log);
|
||||
else
|
||||
handler.Log.Info(log);
|
||||
}
|
||||
|
||||
return "";
|
||||
foreach (string cmd in commands)
|
||||
{
|
||||
CmdResult output = new();
|
||||
handler.PerformInternalCommand(cmd, ref output);
|
||||
handler.Log.Info(string.Format(Translations.cmd_execmulti_executed, cmd, string.Format(Translations.cmd_execmulti_result, output)));
|
||||
}
|
||||
|
||||
return GetCmdDescTranslated();
|
||||
return r.SetAndReturn(CmdResult.Status.Done);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue