diff --git a/pkg/edition/java/proxy/player/tab_list.go b/pkg/edition/java/proxy/player/tab_list.go index eeaf836c..a6d00b0d 100644 --- a/pkg/edition/java/proxy/player/tab_list.go +++ b/pkg/edition/java/proxy/player/tab_list.go @@ -24,11 +24,21 @@ type TabListEntry interface { // containing uuid, as well as deciding what is shown as the player head in the tab list. Profile() profile.GameProfile // DisplayName returns the optional text displayed for this entry in the TabList, - // otherwise profile.GameProfile.Names is shown and returns nil. + // otherwise if returns nil Profile().Name is shown (but not returned here). DisplayName() component.Component + // SetDisplayName the text to be displayed for the entry. + // If nil Profile().Name will be shown. + SetDisplayName(component.Component) error // GameMode returns the game mode the entry has been set to. + // 0 - Survival + // 1 - Creative + // 2 - Adventure + // 3 - Spectator GameMode() int - // Latency returns the latency for the entry. + // SetGameMode sets the gamemode for the entry. + // See GameMode() for more details. + SetGameMode(int) error + // Latency returns the latency/ping for the entry. // // The icon shown in the tab list is calculated // by the millisecond latency as follows: @@ -40,7 +50,7 @@ type TabListEntry interface { // 600-1000 will display 2 bars // A latency move than 1 second will display 1 bar Latency() time.Duration - // TODO SetDisplayName - // TODO SetLatency(time.Duration) - // TODO more... + // SetLatency sets the latency/ping for the entry. + // See Latency() for how it is displayed. + SetLatency(time.Duration) error } diff --git a/pkg/edition/java/proxy/tab_list.go b/pkg/edition/java/proxy/tab_list.go index b8f303b7..fd8d374e 100644 --- a/pkg/edition/java/proxy/tab_list.go +++ b/pkg/edition/java/proxy/tab_list.go @@ -184,7 +184,7 @@ func (t *tabList) processBackendPacket(p *packet.PlayerListItem) error { case packet.UpdateGameModePlayerListItemAction: e, ok := t.entries[item.ID] if ok { - return e.setGameMode(item.GameMode) + e.setGameMode(item.GameMode) } default: // Nothing we can do here @@ -214,7 +214,7 @@ type tabListEntry struct { mu sync.RWMutex // protects following fields profile *profile.GameProfile - displayName component.Component + displayName component.Component // nil-able latency time.Duration gameMode int } @@ -260,17 +260,24 @@ func (t *tabListEntry) Latency() time.Duration { return t.latency } +func (t *tabListEntry) SetLatency(latency time.Duration) error { + t.setLatency(latency) + return t.tabList.updateEntry(packet.UpdateLatencyPlayerListItemAction, t) +} func (t *tabListEntry) setLatency(latency time.Duration) { t.mu.Lock() t.latency = latency t.mu.Unlock() } -func (t *tabListEntry) setGameMode(gameMode int) error { +func (t *tabListEntry) SetGameMode(gameMode int) error { + t.setGameMode(gameMode) + return t.tabList.updateEntry(packet.UpdateGameModePlayerListItemAction, t) +} +func (t *tabListEntry) setGameMode(gameMode int) { t.mu.Lock() t.gameMode = gameMode t.mu.Unlock() - return t.tabList.updateEntry(packet.UpdateGameModePlayerListItemAction, t) } func newPlayerListItemEntry(entry player.TabListEntry) *packet.PlayerListItemEntry {