2022-12-06 15:50:17 +08:00
|
|
|
|
using Brigadier.NET;
|
|
|
|
|
|
using Brigadier.NET.Builder;
|
|
|
|
|
|
using MinecraftClient.CommandHandler;
|
|
|
|
|
|
using static MinecraftClient.CommandHandler.CmdResult;
|
2020-03-26 15:01:42 +08:00
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
class ChangeSlot : Command
|
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
|
public override string CmdName { get { return "changeslot"; } }
|
|
|
|
|
|
public override string CmdUsage { get { return "changeslot <1-9>"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public override string CmdDesc { get { return Translations.cmd_changeSlot_desc; } }
|
2020-03-26 15:01:42 +08:00
|
|
|
|
|
2022-12-11 16:30:45 +08:00
|
|
|
|
public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
|
2022-10-26 08:54:54 +08:00
|
|
|
|
{
|
2022-12-06 15:50:17 +08:00
|
|
|
|
dispatcher.Register(l => l.Literal("help")
|
|
|
|
|
|
.Then(l => l.Literal(CmdName)
|
|
|
|
|
|
.Executes(r => GetUsage(r.Source, string.Empty))
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
dispatcher.Register(l => l.Literal(CmdName)
|
2022-12-11 13:00:19 +08:00
|
|
|
|
.Then(l => l.Argument("Slot", MccArguments.HotbarSlot())
|
2022-12-11 16:30:45 +08:00
|
|
|
|
.Executes(r => DoChangeSlot(r.Source, Arguments.GetInteger(r, "Slot"))))
|
2022-12-06 15:50:17 +08:00
|
|
|
|
.Then(l => l.Literal("_help")
|
2022-12-11 17:31:37 +08:00
|
|
|
|
.Executes(r => GetUsage(r.Source, string.Empty))
|
2022-12-06 15:50:17 +08:00
|
|
|
|
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int GetUsage(CmdResult r, string? cmd)
|
|
|
|
|
|
{
|
|
|
|
|
|
return r.SetAndReturn(cmd switch
|
|
|
|
|
|
{
|
|
|
|
|
|
#pragma warning disable format // @formatter:off
|
|
|
|
|
|
_ => GetCmdDescTranslated(),
|
|
|
|
|
|
#pragma warning restore format // @formatter:on
|
|
|
|
|
|
});
|
2022-10-26 08:54:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-11 16:30:45 +08:00
|
|
|
|
private int DoChangeSlot(CmdResult r, int slot)
|
2020-03-26 15:01:42 +08:00
|
|
|
|
{
|
2022-12-11 16:30:45 +08:00
|
|
|
|
McClient handler = CmdResult.currentHandler!;
|
2020-08-17 23:08:50 +08:00
|
|
|
|
if (!handler.GetInventoryEnabled())
|
2022-12-06 15:50:17 +08:00
|
|
|
|
return r.SetAndReturn(Status.FailNeedInventory);
|
2020-06-20 21:30:23 +02:00
|
|
|
|
|
2022-12-06 15:50:17 +08:00
|
|
|
|
if (handler.ChangeSlot((short)(slot - 1)))
|
|
|
|
|
|
return r.SetAndReturn(Status.Done, string.Format(Translations.cmd_changeSlot_changed, slot));
|
|
|
|
|
|
else
|
|
|
|
|
|
return r.SetAndReturn(Status.Fail, Translations.cmd_changeSlot_fail);
|
2020-03-26 15:01:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|