From 3e65000ab3fd502a853308c2a127dd5428645c5f Mon Sep 17 00:00:00 2001 From: Desetude Date: Sun, 30 Sep 2018 21:40:22 +0100 Subject: [PATCH] Clear tab list on server connect --- .../proxy/connection/client/ClientPlaySessionHandler.java | 5 +++++ .../com/velocitypowered/proxy/tablist/VelocityTabList.java | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 5fd667463..2495477ec 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -4,6 +4,7 @@ import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.VelocityConstants; @@ -238,6 +239,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // The call will handle if the player is not a Forge player appropriately. player.getConnection().setCanSendLegacyFMLResetPacket(true); } else { + // Clear tab list to avoid duplicate entries + TabList tabList = player.getTabList(); + tabList.getEntries().forEach(entry -> tabList.removeEntry(entry.getProfile().idAsUuid())); + // Ah, this is the meat and potatoes of the whole venture! // // In order to handle switching to another server, you will need to send three packets: 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 dffbaaba4..4bfefe7ef 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -16,10 +16,11 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class VelocityTabList implements TabList { private final MinecraftConnection connection; - private final Map entries = new HashMap<>(); + private final Map entries = new ConcurrentHashMap<>(); public VelocityTabList(MinecraftConnection connection) { this.connection = connection;