Skip to content

Commit

Permalink
Add server.FindPlayer function
Browse files Browse the repository at this point in the history
  • Loading branch information
oq-x committed Sep 27, 2023
1 parent ad85a2a commit c754bfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core_commands/gamemode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 9 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c754bfb

Please sign in to comment.