From 00ef92bc5c82c46ed4770aaaf126c285a6ab705c Mon Sep 17 00:00:00 2001 From: Timon Date: Thu, 28 Dec 2023 16:37:31 +0100 Subject: [PATCH] Restore nullability for displayName in UpsertPlayerInfo (#1172) This makes the UpsertPlayerInfo's displayName truly nullable as before the ComponentHolder was introduced. --- .../proxy/tablist/VelocityTabList.java | 16 ++++++++++++---- .../proxy/tablist/VelocityTabListEntry.java | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index b207ce4bf..9565dc9e5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -110,8 +110,12 @@ public class VelocityTabList implements InternalTabList { 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); @@ -140,8 +144,12 @@ public class VelocityTabList implements InternalTabList { 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); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java index c6adc7d21..c6649070b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java @@ -80,7 +80,11 @@ public class VelocityTabListEntry implements TabListEntry { 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; }