Skip to content

Commit

Permalink
Add ConsoleExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Sep 27, 2023
1 parent 796771d commit cae89e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions core_commands/gamemode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 0 additions & 7 deletions server/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions server/console.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 0 additions & 5 deletions server/network/handlers/ChatCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit cae89e8

Please sign in to comment.