From b6a9299f9f78ec4a48d7f675543bc201e5704895 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 30 Sep 2018 18:27:07 -0400 Subject: [PATCH] Do tab list clearing into one packet --- .../client/ClientPlaySessionHandler.java | 7 ++----- .../proxy/tablist/VelocityTabList.java | 16 ++++++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) 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 2495477ec..42c9d226f 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 @@ -240,11 +240,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { 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())); + player.getTabList().clearAll(); - // 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: // // - The join game packet from the backend server @@ -271,7 +268,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } serverBossBars.clear(); - // Tell the server about this client's plugin messages. Velocity will forward them on to the client. + // Tell the server about this client's plugin message channels. Collection toRegister = new HashSet<>(clientPluginMsgChannels); if (player.getProtocolVersion() >= ProtocolConstants.MINECRAFT_1_13) { toRegister.addAll(server.getChannelRegistrar().getModernChannelIds()); 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 4bfefe7ef..2edc3f2a3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -10,12 +10,7 @@ import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import net.kyori.text.Component; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class VelocityTabList implements TabList { @@ -60,6 +55,15 @@ public class VelocityTabList implements TabList { return Optional.ofNullable(entry); } + public void clearAll() { // Note: this method is called upon server switch + List items = new ArrayList<>(); + for (TabListEntry value : entries.values()) { + items.add(PlayerListItem.Item.from(value)); + } + entries.clear(); + connection.delayedWrite(new PlayerListItem(PlayerListItem.Action.REMOVE_PLAYER, items)); + } + @Override public Collection getEntries() { return Collections.unmodifiableCollection(this.entries.values());