mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
65 lines
No EOL
2.3 KiB
C#
65 lines
No EOL
2.3 KiB
C#
using Brigadier.NET;
|
|
using Brigadier.NET.Builder;
|
|
using MinecraftClient.CommandHandler;
|
|
|
|
namespace MinecraftClient.Commands
|
|
{
|
|
public class Sneak : Command
|
|
{
|
|
private bool sneaking = false;
|
|
public override string CmdName { get { return "sneak"; } }
|
|
public override string CmdUsage { get { return "sneak"; } }
|
|
public override string CmdDesc { get { return Translations.cmd_sneak_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 => DoSneak(r.Source))
|
|
.Then(l => l.Literal("_help")
|
|
.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
|
|
});
|
|
}
|
|
|
|
private int DoSneak(CmdResult r)
|
|
{
|
|
McClient handler = CmdResult.currentHandler!;
|
|
if (sneaking)
|
|
{
|
|
var result = handler.SendEntityAction(Protocol.EntityActionType.StopSneaking);
|
|
if (result)
|
|
sneaking = false;
|
|
if (result)
|
|
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_sneak_off);
|
|
else
|
|
return r.SetAndReturn(CmdResult.Status.Fail);
|
|
}
|
|
else
|
|
{
|
|
var result = handler.SendEntityAction(Protocol.EntityActionType.StartSneaking);
|
|
if (result)
|
|
sneaking = true;
|
|
if (result)
|
|
return r.SetAndReturn(CmdResult.Status.Done, Translations.cmd_sneak_on);
|
|
else
|
|
return r.SetAndReturn(CmdResult.Status.Fail);
|
|
}
|
|
}
|
|
}
|
|
} |