2022-10-02 18:31:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
2022-10-26 08:54:54 +08:00
|
|
|
|
using Brigadier.NET;
|
2022-12-06 15:50:17 +08:00
|
|
|
|
using Brigadier.NET.Builder;
|
|
|
|
|
|
using MinecraftClient.CommandHandler;
|
2014-06-18 13:32:17 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
public class Script : Command
|
|
|
|
|
|
{
|
2020-10-17 19:41:31 +08:00
|
|
|
|
public override string CmdName { get { return "script"; } }
|
|
|
|
|
|
public override string CmdUsage { get { return "script <scriptname>"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
|
public override string CmdDesc { get { return Translations.cmd_script_desc; } }
|
2014-06-18 13:32:17 +02: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)
|
2023-01-15 19:59:57 +08:00
|
|
|
|
.Then(l => l.Argument("Script", MccArguments.ScriptName())
|
2022-12-11 16:30:45 +08:00
|
|
|
|
.Executes(r => DoExecuteScript(r.Source, Arguments.GetString(r, "Script"), null)))
|
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)))
|
|
|
|
|
|
);
|
2022-10-26 08:54:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-06 15:50:17 +08:00
|
|
|
|
private int GetUsage(CmdResult r, string? cmd)
|
2014-06-18 13:32:17 +02:00
|
|
|
|
{
|
2022-12-06 15:50:17 +08:00
|
|
|
|
return r.SetAndReturn(cmd switch
|
2014-06-18 13:32:17 +02:00
|
|
|
|
{
|
2022-12-06 15:50:17 +08:00
|
|
|
|
#pragma warning disable format // @formatter:off
|
|
|
|
|
|
_ => GetCmdDescTranslated(),
|
|
|
|
|
|
#pragma warning restore format // @formatter:on
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-11 16:30:45 +08:00
|
|
|
|
private int DoExecuteScript(CmdResult r, string command, Dictionary<string, object>? localVars)
|
2022-12-06 15:50:17 +08:00
|
|
|
|
{
|
2022-12-11 16:30:45 +08:00
|
|
|
|
McClient handler = CmdResult.currentHandler!;
|
2022-12-06 15:50:17 +08:00
|
|
|
|
handler.BotLoad(new ChatBots.Script(command.Trim(), null, localVars));
|
|
|
|
|
|
return r.SetAndReturn(CmdResult.Status.Done);
|
2014-06-18 13:32:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|