Skip to content

Commit

Permalink
fix #43, #42
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Sep 24, 2021
1 parent ef41b11 commit bf19d52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/edition/java/proxy/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Player interface {
// CreateConnectionRequest creates a connection request to begin switching the backend server.
CreateConnectionRequest(target RegisteredServer) ConnectionRequest
GameProfile() profile.GameProfile // Returns the player's game profile.
Settings() player.Settings // The players client settings. Returns player.DefaultSettings if not yet unknown.
Settings() player.Settings // The players client settings. Returns player.DefaultSettings if known.
// Disconnect disconnects the player with a reason.
// Once called, further interface calls to this player become undefined.
Disconnect(reason component.Component)
Expand Down
14 changes: 11 additions & 3 deletions pkg/edition/java/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,21 @@ func (p *Proxy) Players() []Player {
func (p *Proxy) Player(id uuid.UUID) Player {
p.muP.RLock()
defer p.muP.RUnlock()
return p.playerIDs[id]
player, ok := p.playerIDs[id]
if !ok {
return nil // return correct nil
}
return player
}

// Player returns the online player by their Minecraft name (search is case-insensitive).
// PlayerByName returns the online player by their Minecraft name (search is case-insensitive).
// Returns nil if the player was not found.
func (p *Proxy) PlayerByName(username string) Player {
return p.playerByName(username)
player := p.playerByName(username)
if player == (*connectedPlayer)(nil) {
return nil // return correct nil
}
return player
}
func (p *Proxy) playerByName(username string) *connectedPlayer {
p.muP.RLock()
Expand Down

0 comments on commit bf19d52

Please sign in to comment.