From a282afb5dba32a3cfbed1b23533a9b366cf7d1bb Mon Sep 17 00:00:00 2001 From: xDark <19853368+xxDark@users.noreply.github.com> Date: Fri, 31 Jul 2020 19:19:26 +0300 Subject: [PATCH] Return earlier, predict list's size for tab clearing --- .../proxy/tablist/VelocityTabList.java | 12 +++++++----- 1 file changed, 7 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 58103eb07..c60ebe6fa 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -89,14 +89,16 @@ public class VelocityTabList implements TabList { * MinecraftConnection#flush()}. */ public void clearAll() { - List items = new ArrayList<>(); - for (TabListEntry value : entries.values()) { + Collection listEntries = entries.values(); + if (listEntries.isEmpty()) { + return; + } + List items = new ArrayList<>(listEntries.size()); + for (TabListEntry value : listEntries) { items.add(PlayerListItem.Item.from(value)); } entries.clear(); - if (!items.isEmpty()) { - connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, items)); - } + connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, items)); } @Override