mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fix command registration for external MCC scripts
- Update Roslyn compiler LanguageVersion from CSharp9 to Latest - Implement ChatBotCommand.RegisterCommand() (was empty) - Add RegisterChatBotCommand() helper to ChatBot base class - Add automatic command cleanup in BotUnLoad via UnregisterChatBotCommands() - Fix external scripts using Handler.dispatcher (CS0176 static via instance) - Fix AutoTree.cs wrong Initialize/OnUnload signatures (CS0115) - EntityCount.cs RegisterChatBotCommand() now works with new helper Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com> Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/27fc44b8-50d8-4194-8057-019a29675d4a
This commit is contained in:
parent
34bc6c5400
commit
687d1746ed
7 changed files with 62 additions and 15 deletions
|
|
@ -75,7 +75,7 @@ public class AutoTree : ChatBot
|
|||
}
|
||||
}
|
||||
|
||||
public override void Initialize(CommandDispatcher<CmdResult> dispatcher)
|
||||
public override void Initialize()
|
||||
{
|
||||
if (!GetTerrainEnabled())
|
||||
{
|
||||
|
|
@ -89,7 +89,7 @@ public class AutoTree : ChatBot
|
|||
}
|
||||
else
|
||||
{
|
||||
dispatcher.Register(l => l.Literal("help")
|
||||
McClient.dispatcher.Register(l => l.Literal("help")
|
||||
.Then(l => l.Literal(CommandName)
|
||||
.Executes(r => OnCommandHelp(r.Source, string.Empty))
|
||||
.Then(l => l.Literal("set")
|
||||
|
|
@ -99,7 +99,7 @@ public class AutoTree : ChatBot
|
|||
)
|
||||
);
|
||||
|
||||
dispatcher.Register(l => l.Literal(CommandName)
|
||||
McClient.dispatcher.Register(l => l.Literal(CommandName)
|
||||
.Then(l => l.Literal("toggle")
|
||||
.Executes(r => { return r.Source.SetAndReturn(CmdResult.Status.Done, Toggle() ? "Now is running" : "Now is stopping"); }))
|
||||
.Then(l => l.Literal("set")
|
||||
|
|
@ -109,17 +109,17 @@ public class AutoTree : ChatBot
|
|||
.Then(l => l.Argument("TreeType", Arguments.String())
|
||||
.Executes(r => OnCommandType(r.Source, Arguments.GetString(r, "TreeType")))))
|
||||
.Then(l => l.Literal("_help")
|
||||
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CommandName)))
|
||||
.Redirect(McClient.dispatcher.GetRoot().GetChild("help").GetChild(CommandName)))
|
||||
);
|
||||
|
||||
LogToConsole("Loaded.");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUnload(CommandDispatcher<CmdResult> dispatcher)
|
||||
public override void OnUnload()
|
||||
{
|
||||
dispatcher.Unregister(CommandName);
|
||||
dispatcher.GetRoot().GetChild("help").RemoveChild(CommandName);
|
||||
McClient.dispatcher.Unregister(CommandName);
|
||||
McClient.dispatcher.GetRoot().GetChild("help").RemoveChild(CommandName);
|
||||
}
|
||||
|
||||
private int OnCommandHelp(CmdResult r, string? cmd)
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ class DiscordWebhook : ChatBot
|
|||
LogToConsole("Made by Daenges.\nSpecial thanks to Crafatar for providing the beautiful avatars!");
|
||||
LogToConsole("Please set a Webhook with '/dw changeurl [URL]'. For further information type '/discordwebhook help'.");
|
||||
|
||||
Handler.dispatcher.Register(l => l.Literal(CommandName)
|
||||
McClient.dispatcher.Register(l => l.Literal(CommandName)
|
||||
.Then(l => l.Argument("Commands", Arguments.GreedyString())
|
||||
.Executes(r => {
|
||||
CommandHandler(Arguments.GetString(r, "Commands").Split(' ', StringSplitOptions.TrimEntries));
|
||||
|
|
@ -317,7 +317,7 @@ class DiscordWebhook : ChatBot
|
|||
|
||||
public override void OnUnload()
|
||||
{
|
||||
Handler.dispatcher.Unregister(CommandName);
|
||||
McClient.dispatcher.Unregister(CommandName);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class MineCube : ChatBot
|
|||
|
||||
LogToConsole("Mining bot created by Daenges.");
|
||||
|
||||
Handler.dispatcher.Register(l => l.Literal(CommandName)
|
||||
McClient.dispatcher.Register(l => l.Literal(CommandName)
|
||||
.Then(l => l.Argument("Commands", Arguments.GreedyString())
|
||||
.Executes(r => {
|
||||
EvaluateMineCommand(CommandName + ' ' + Arguments.GetString(r, "Commands"), Arguments.GetString(r, "Commands").Split(' ', StringSplitOptions.TrimEntries));
|
||||
|
|
@ -57,7 +57,7 @@ class MineCube : ChatBot
|
|||
|
||||
public override void OnUnload()
|
||||
{
|
||||
Handler.dispatcher.Unregister(CommandName);
|
||||
McClient.dispatcher.Unregister(CommandName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class SugarCaneFarmer : SugarCaneFarmerBase
|
|||
{
|
||||
LogToConsole("Sugar Cane farming bot created by Daenges.");
|
||||
|
||||
Handler.dispatcher.Register(l => l.Literal(CommandName)
|
||||
McClient.dispatcher.Register(l => l.Literal(CommandName)
|
||||
.Then(l => l.Argument("Commands", Arguments.GreedyString())
|
||||
.Executes(r => {
|
||||
CommandHandler(Arguments.GetString(r, "Commands").Split(' ', StringSplitOptions.TrimEntries));
|
||||
|
|
@ -162,7 +162,7 @@ class SugarCaneFarmer : SugarCaneFarmerBase
|
|||
|
||||
public override void OnUnload()
|
||||
{
|
||||
Handler.dispatcher.Unregister(CommandName);
|
||||
McClient.dispatcher.Unregister(CommandName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue