Skip to content

Commit

Permalink
Restore nullability for displayName in UpsertPlayerInfo (PaperMC#1172)
Browse files Browse the repository at this point in the history
This makes the UpsertPlayerInfo's displayName truly nullable as before the ComponentHolder was introduced.
  • Loading branch information
Timongcraft authored and skbeh committed Jan 17, 2024
1 parent d11f13d commit 10c8e89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ public void addEntry(TabListEntry entry1) {
if (!Objects.equals(previousEntry.getDisplayNameComponent().orElse(null),
entry.getDisplayNameComponent().orElse(null))) {
actions.add(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME);
playerInfoEntry.setDisplayName(new ComponentHolder(player.getProtocolVersion(),
entry.getDisplayNameComponent().get()));
playerInfoEntry.setDisplayName(entry.getDisplayNameComponent().isEmpty()
?
null :
new ComponentHolder(player.getProtocolVersion(),
entry.getDisplayNameComponent().get())
);
}
if (!Objects.equals(previousEntry.getLatency(), entry.getLatency())) {
actions.add(UpsertPlayerInfo.Action.UPDATE_LATENCY);
Expand Down Expand Up @@ -140,8 +144,12 @@ public void addEntry(TabListEntry entry1) {
playerInfoEntry.setProfile(entry.getProfile());
if (entry.getDisplayNameComponent().isPresent()) {
actions.add(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME);
playerInfoEntry.setDisplayName(new ComponentHolder(player.getProtocolVersion(),
entry.getDisplayNameComponent().get()));
playerInfoEntry.setDisplayName(entry.getDisplayNameComponent().isEmpty()
?
null :
new ComponentHolder(player.getProtocolVersion(),
entry.getDisplayNameComponent().get())
);
}
if (entry.getChatSession() != null) {
actions.add(UpsertPlayerInfo.Action.INITIALIZE_CHAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ public TabListEntry setDisplayName(@Nullable Component displayName) {
this.displayName = displayName;
UpsertPlayerInfo.Entry upsertEntry = this.tabList.createRawEntry(this);
upsertEntry.setDisplayName(
new ComponentHolder(this.tabList.getPlayer().getProtocolVersion(), displayName));
displayName == null
?
null :
new ComponentHolder(this.tabList.getPlayer().getProtocolVersion(), displayName)
);
this.tabList.emitActionRaw(UpsertPlayerInfo.Action.UPDATE_DISPLAY_NAME, upsertEntry);
return this;
}
Expand Down

0 comments on commit 10c8e89

Please sign in to comment.