Minecraft-Console-Client/MinecraftClient/Commands/Animation.cs

54 lines
2.2 KiB
C#
Raw Normal View History

using Brigadier.NET;
2022-10-26 08:54:54 +08:00
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
2020-05-26 14:02:09 +05:00
namespace MinecraftClient.Commands
{
public class Animation : Command
{
public override string CmdName { get { return "animation"; } }
public override string CmdUsage { get { return "animation <mainhand|offhand>"; } }
public override string CmdDesc { get { return Translations.cmd_animation_desc; } }
2020-05-26 14:02:09 +05:00
public override void RegisterCommand(McClient handler, CommandDispatcher<CmdResult> dispatcher)
2022-10-26 08:54:54 +08:00
{
dispatcher.Register(l => l.Literal("help")
.Then(l => l.Literal(CmdName)
.Executes(r => GetUsage(r.Source, string.Empty))
.Then(l => l.Literal("mainhand")
.Executes(r => GetUsage(r.Source, "mainhand")))
.Then(l => l.Literal("offhand")
.Executes(r => GetUsage(r.Source, "offhand")))
2022-10-26 08:54:54 +08:00
)
);
dispatcher.Register(l => l.Literal(CmdName)
.Executes(r => DoAnimation(r.Source, handler, mainhand: true))
.Then(l => l.Literal("mainhand")
.Executes(r => DoAnimation(r.Source, handler, mainhand: true)))
.Then(l => l.Literal("offhand")
.Executes(r => DoAnimation(r.Source, handler, mainhand: false)))
.Then(l => l.Literal("_help")
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
2022-10-26 08:54:54 +08:00
);
}
private int GetUsage(CmdResult r, string? cmd)
2020-05-26 14:02:09 +05:00
{
return r.SetAndReturn(cmd switch
2020-05-26 14:02:09 +05:00
{
#pragma warning disable format // @formatter:off
"mainhand" => GetCmdDescTranslated(),
"offhand" => GetCmdDescTranslated(),
_ => GetCmdDescTranslated(),
#pragma warning restore format // @formatter:on
});
}
private static int DoAnimation(CmdResult r, McClient handler, bool mainhand)
{
return r.SetAndReturn(handler.DoAnimation(mainhand ? 1 : 0));
2020-05-26 14:02:09 +05:00
}
}
}