From 6a698dfba970edecb82636e5fd82f119753ddd73 Mon Sep 17 00:00:00 2001 From: oqammx86 <84847714+oq-x@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:36:26 +0300 Subject: [PATCH] command error helpers --- server/commands/commands.go | 13 ++++++++++++- server/network/handlers/ChatCommand.go | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/commands/commands.go b/server/commands/commands.go index fe69333..7e21b9d 100644 --- a/server/commands/commands.go +++ b/server/commands/commands.go @@ -1,6 +1,8 @@ package commands import ( + "fmt" + pk "github.com/aimjel/minecraft/packet" "github.com/dynamitemc/dynamite/server/player" ) @@ -13,13 +15,22 @@ type CommandContext struct { Position() (x float64, y float64, z float64) Rotation() (yaw float32, pitch float32) } `js:"executor"` - Arguments []string `js:"arguments"` + Arguments []string `js:"arguments"` + FullCommand string } func (ctx *CommandContext) Reply(content string) { ctx.Executor.SystemChatMessage(content) } +func (ctx *CommandContext) Incomplete() { + ctx.Reply(fmt.Sprintf("§cUnknown or incomplete command, see below for error\n§7%s§r§c§o<--[HERE]", ctx.FullCommand)) +} + +func (ctx *CommandContext) Error(msg string) { + ctx.Reply(fmt.Sprintf("§c%s\n§7%s§r§c§o<--[HERE]", msg, ctx.FullCommand)) +} + const ( ChatModeEnabled = iota ChatModeCommandsOnly diff --git a/server/network/handlers/ChatCommand.go b/server/network/handlers/ChatCommand.go index abd5707..b0a69ed 100644 --- a/server/network/handlers/ChatCommand.go +++ b/server/network/handlers/ChatCommand.go @@ -32,11 +32,12 @@ func ChatCommandPacket(controller controller, graph *commands.Graph, content str } } if command == nil { - controller.SystemChatMessage(fmt.Sprintf("§cUnknown or incomplete command, see below for error\n%s§o<--[HERE]", content)) + controller.SystemChatMessage(fmt.Sprintf("§cUnknown or incomplete command, see below for error\n§n%s§r§c§o<--[HERE]", content)) return } command.Execute(commands.CommandContext{ - Arguments: args, - Executor: controller, + Arguments: args, + Executor: controller, + FullCommand: content, }) }