Skip to content

Commit

Permalink
command error helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Sep 27, 2023
1 parent 3c3f8b0 commit 6a698df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 12 additions & 1 deletion server/commands/commands.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package commands

import (
"fmt"

pk "github.com/aimjel/minecraft/packet"
"github.com/dynamitemc/dynamite/server/player"
)
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions server/network/handlers/ChatCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

0 comments on commit 6a698df

Please sign in to comment.