mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implement command completion suggestions.
This commit is contained in:
parent
5d2589b10f
commit
84cf749344
115 changed files with 4684 additions and 2695 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Brigadier.NET;
|
||||
using Brigadier.NET;
|
||||
using Brigadier.NET.Builder;
|
||||
using MinecraftClient.CommandHandler;
|
||||
using static MinecraftClient.CommandHandler.CmdResult;
|
||||
|
||||
namespace MinecraftClient.Commands
|
||||
{
|
||||
|
|
@ -9,18 +11,38 @@ namespace MinecraftClient.Commands
|
|||
public override string CmdUsage { get { return "useitem"; } }
|
||||
public override string CmdDesc { get { return Translations.cmd_useitem_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)
|
||||
.Executes(r => DoUseItem(r.Source, handler))
|
||||
.Then(l => l.Literal("_help")
|
||||
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
|
||||
);
|
||||
}
|
||||
|
||||
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
||||
private int GetUsage(CmdResult r, string? cmd)
|
||||
{
|
||||
if (handler.GetInventoryEnabled())
|
||||
return r.SetAndReturn(cmd switch
|
||||
{
|
||||
handler.UseItemOnHand();
|
||||
return Translations.cmd_useitem_use;
|
||||
}
|
||||
else return Translations.extra_inventory_required;
|
||||
#pragma warning disable format // @formatter:off
|
||||
_ => GetCmdDescTranslated(),
|
||||
#pragma warning restore format // @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
private int DoUseItem(CmdResult r, McClient handler)
|
||||
{
|
||||
if (!handler.GetInventoryEnabled())
|
||||
return r.SetAndReturn(Status.FailNeedInventory);
|
||||
|
||||
handler.UseItemOnHand();
|
||||
return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue