From cae89e87a55ee19cb21d79a555424bfce0e00b5d Mon Sep 17 00:00:00 2001 From: oqammx86 <84847714+oq-x@users.noreply.github.com> Date: Thu, 28 Sep 2023 01:55:28 +0300 Subject: [PATCH] Add ConsoleExecutor --- core_commands/gamemode.go | 5 +++-- server/commands/commands.go | 7 ------- server/console.go | 12 ++++++++++++ server/network/handlers/ChatCommand.go | 5 ----- 4 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 server/console.go diff --git a/core_commands/gamemode.go b/core_commands/gamemode.go index 64b51bf..ff127cb 100644 --- a/core_commands/gamemode.go +++ b/core_commands/gamemode.go @@ -37,11 +37,12 @@ var gamemode_cmd = &commands.Command{ } var player *server.PlayerController if len(ctx.Arguments) == 1 { - if ctx.IsConsole { + if p, ok := ctx.Executor.(*server.PlayerController); ok { ctx.Incomplete() return + } else { + player = p } - player = ctx.Executor.(*server.PlayerController) } else { p := ctx.Executor.(*server.PlayerController).Server.FindPlayer(ctx.Arguments[1]) if p == nil { diff --git a/server/commands/commands.go b/server/commands/commands.go index 762bead..3c10e67 100644 --- a/server/commands/commands.go +++ b/server/commands/commands.go @@ -5,21 +5,14 @@ import ( "strings" pk "github.com/aimjel/minecraft/packet" - "github.com/dynamitemc/dynamite/server/player" ) type CommandContext struct { Executor interface { SystemChatMessage(s string) error - OnGround() bool - ClientSettings() player.ClientInformation - Position() (x float64, y float64, z float64) - Rotation() (yaw float32, pitch float32) - HasPermissions(perms []string) bool } `js:"executor"` Arguments []string `js:"arguments"` FullCommand string `js:"fullCommand"` - IsConsole bool `js:"isConsole"` } func (ctx *CommandContext) Reply(content string) { diff --git a/server/console.go b/server/console.go new file mode 100644 index 0000000..2693f03 --- /dev/null +++ b/server/console.go @@ -0,0 +1,12 @@ +package server + +import "fmt" + +type ConsoleExecutor struct { + Server *Server +} + +func (p *ConsoleExecutor) SystemChatMessage(s string) error { + fmt.Println(s) + return nil +} diff --git a/server/network/handlers/ChatCommand.go b/server/network/handlers/ChatCommand.go index dd3ba5a..fafa16c 100644 --- a/server/network/handlers/ChatCommand.go +++ b/server/network/handlers/ChatCommand.go @@ -5,15 +5,10 @@ import ( "strings" "github.com/dynamitemc/dynamite/server/commands" - "github.com/dynamitemc/dynamite/server/player" ) type controller interface { SystemChatMessage(s string) error - OnGround() bool - ClientSettings() player.ClientInformation - Position() (x float64, y float64, z float64) - Rotation() (yaw float32, pitch float32) HasPermissions(perms []string) bool }