mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
44 lines
1.6 KiB
C#
44 lines
1.6 KiB
C#
using Brigadier.NET;
|
|
using Brigadier.NET.Builder;
|
|
using MinecraftClient.CommandHandler;
|
|
|
|
namespace MinecraftClient.Commands
|
|
{
|
|
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; } }
|
|
|
|
public override void RegisterCommand(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 => LogHealth(r.Source))
|
|
.Then(l => l.Literal("_help")
|
|
.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
|
|
});
|
|
}
|
|
|
|
private int LogHealth(CmdResult r)
|
|
{
|
|
McClient handler = CmdResult.currentHandler!;
|
|
return r.SetAndReturn(CmdResult.Status.Done, string.Format(Translations.cmd_health_response, handler.GetHealth(), handler.GetSaturation(), handler.GetLevel(), handler.GetTotalExperience()));
|
|
}
|
|
}
|
|
}
|