Tab list api rough around the edges.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 959
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 2
Description
Expected Behavior
The current tab list API allows the following to occur:
// Two players
Player player1 = p1.get();
Player player2 = p2.get();
// Game profile to send tablist entry for
GameProfile tabListPlayer = GameProfile.forOfflinePlayer("Johny");
// A TabListEntry which will internally reference Player1's TabList
TabListEntry tabListEntry = TabListEntry.builder()
.profile(tabListPlayer)
.displayName(Component.text("DisplayName").color(NamedTextColor.GOLD))
.latency(1000)
.gameMode(1)
.tabList(player1.getTabList())
.build();
// Add this entry both the player's TabLists.
player1.getTabList().addEntry(tabListEntry);
player2.getTabList().addEntry(tabListEntry);
// If we try to change a value of the previously added TabListEntry for Player2,
// it changes the entry for Player1 because the entry still references that TabList.
Optional<TabListEntry> entry = player2.getTabList().getEntry(tabListPlayer.getId());
entry.ifPresent(listEntry -> listEntry.setDisplayName(Component.text("Changed DisplayName").color(NamedTextColor.DARK_PURPLE)));
Someone editing a tab list entry in player2's tab list would expect player2's tab list to change.
Actual Behavior
player1's tab list changes.
Steps to Reproduce
See code above.
Plugin List
Velocity Version
Velocity 3.4.0-SNAPSHOT (git-08a42b37-b449)
Additional Information
A simple solution is throwing an exception on the second AddEntry because player.getTabList() != tabListEntry.getTabList().
Another option is modifying the internal TabList when an TabListEntryis added to a TabList. But then why bother specifying a TabList when creating a TabListEntry? I think this area of the API is a little clunky in this respect and could use some work.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TabListEntry builder, TabList.addEntry, and TabList.getEntry behavior shown in the reproduction. Determine and document a consistent ownership rule for entries added to multiple tab lists; done means editing an entry in one player's tab list no longer unexpectedly changes another player's list, with the chosen behavior reflected in the API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100