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

46 lines
1.6 KiB
C#
Raw Normal View History

2022-12-06 20:32:46 +08:00
using Brigadier.NET;
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
namespace MinecraftClient.Commands
{
2020-04-04 19:18:18 +08:00
class Health : Command
{
public override string CmdName { get { return "health"; } }
public override string CmdUsage { get { return "health"; } }
public override string CmdDesc { get { return Translations.cmd_health_desc; } }
2022-12-11 16:30:45 +08:00
public override void RegisterCommand(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))
)
);
dispatcher.Register(l => l.Literal(CmdName)
2022-12-11 16:30:45 +08:00
.Executes(r => LogHealth(r.Source))
.Then(l => l.Literal("_help")
2022-12-11 17:31:37 +08:00
.Executes(r => GetUsage(r.Source, string.Empty))
.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 LogHealth(CmdResult r)
{
2022-12-11 16:30:45 +08:00
McClient handler = CmdResult.currentHandler!;
return r.SetAndReturn(CmdResult.Status.Done, string.Format(Translations.cmd_health_response, handler.GetHealth(), handler.GetSaturation(), handler.GetLevel(), handler.GetTotalExperience()));
}
}
}