From ea577019b8b34f45e56c8ab87dbe5341deb16b22 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 9 Jul 2021 10:11:15 -0400 Subject: [PATCH] Don't force-add a tab list entry if it already exists --- .../connection/backend/BackendPlaySessionHandler.java | 3 +-- .../velocitypowered/proxy/tablist/VelocityTabList.java | 9 +++++---- .../proxy/tablist/VelocityTabListLegacy.java | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index fa8dddafd..240c655f0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -211,8 +211,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(PlayerListItem packet) { - serverConn.getPlayer().getTabList().processBackendPacket(packet); - return false; //Forward packet to player + return !serverConn.getPlayer().getTabList().processBackendPacket(packet); } @Override 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 87830fe0c..fabd00f5a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -129,8 +129,9 @@ public class VelocityTabList implements TabList { * Processes a tab list entry packet from the backend. * * @param packet the packet to process + * @return {@code true} to forward the packet on, {@code false} otherwise */ - public void processBackendPacket(PlayerListItem packet) { + public boolean processBackendPacket(PlayerListItem packet) { // Packets are already forwarded on, so no need to do that here for (PlayerListItem.Item item : packet.getItems()) { UUID uuid = item.getUuid(); @@ -149,14 +150,13 @@ public class VelocityTabList implements TabList { if (name == null || properties == null) { throw new IllegalStateException("Got null game profile for ADD_PLAYER"); } - entries.put(item.getUuid(), (VelocityTabListEntry) TabListEntry.builder() + return entries.putIfAbsent(item.getUuid(), (VelocityTabListEntry) TabListEntry.builder() .tabList(this) .profile(new GameProfile(uuid, name, properties)) .displayName(item.getDisplayName()) .latency(item.getLatency()) .gameMode(item.getGameMode()) - .build()); - break; + .build()) == null; } case PlayerListItem.REMOVE_PLAYER: entries.remove(uuid); @@ -187,6 +187,7 @@ public class VelocityTabList implements TabList { break; } } + return true; } void updateEntry(int action, TabListEntry entry) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java index 7e63e51da..485874682 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java @@ -72,7 +72,7 @@ public class VelocityTabListLegacy extends VelocityTabList { } @Override - public void processBackendPacket(PlayerListItem packet) { + public boolean processBackendPacket(PlayerListItem packet) { Item item = packet.getItems().get(0); // Only one item per packet in 1.7 switch (packet.getAction()) { @@ -103,6 +103,7 @@ public class VelocityTabListLegacy extends VelocityTabList { break; } + return true; } @Override