diff --git a/core_commands/gamemode.go b/core_commands/gamemode.go index 22c3c4a..4aa2a3f 100644 --- a/core_commands/gamemode.go +++ b/core_commands/gamemode.go @@ -52,8 +52,8 @@ var gamemode_cmd = &commands.Command{ } player = ctx.Executor.(*server.PlayerController) } else { - p, ok := ctx.Executor.(*server.PlayerController).Server.Players[ctx.Arguments[1]] - if !ok { + p := ctx.Executor.(*server.PlayerController).Server.FindPlayer(ctx.Arguments[1]) + if p == nil { ctx.Error("No player was found") return } diff --git a/server/server.go b/server/server.go index 17c06fa..33d3989 100644 --- a/server/server.go +++ b/server/server.go @@ -115,10 +115,17 @@ func (srv *Server) Reload() error { *addresses[i] = u } - srv.mu.RLock() - defer srv.mu.RUnlock() for _, p := range srv.Players { p.SendCommands(srv.CommandGraph) } return nil } + +func (srv *Server) FindPlayer(username string) *PlayerController { + for _, p := range srv.Players { + if p.Name() == username { + return p + } + } + return nil +}