From a6407d6bb04dd9c2df69c6ffa379ea15be9eaaba Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Aug 2022 18:10:52 +0200 Subject: [PATCH] Fix tablist failure on softreload Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/tablist/Tablist.java | 9 +++++++-- src/de/steamwar/bungeecore/tablist/TablistManager.java | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index b9acc96..ad400cb 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -62,7 +62,7 @@ public class Tablist extends MessageToMessageDecoder { this.player = player; this.viewer = ChatSender.of(player); this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>()); - onServerSwitch(); + injection(); } public void update(TablistPart global, int seconds) { @@ -145,12 +145,17 @@ public class Tablist extends MessageToMessageDecoder { } public void onServerSwitch() { - connection = (ServerConnection) player.getServer(); + injection(); + synchronized (directTabItems) { sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true); directTabItems.clear(); npcs.clear(); } + } + + private void injection() { + connection = (ServerConnection) player.getServer(); if(connection != null) { ChannelPipeline pipeline = connection.getCh().getHandle().pipeline(); diff --git a/src/de/steamwar/bungeecore/tablist/TablistManager.java b/src/de/steamwar/bungeecore/tablist/TablistManager.java index 0f02f55..b6e7875 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistManager.java +++ b/src/de/steamwar/bungeecore/tablist/TablistManager.java @@ -51,7 +51,9 @@ public class TablistManager extends BasicListener { public TablistManager() { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::updateTablist, 1, 1, TimeUnit.SECONDS); - ProxyServer.getInstance().getPlayers().forEach(player -> tablists.put(player, new Tablist(player))); + synchronized (tablists) { + ProxyServer.getInstance().getPlayers().forEach(player -> tablists.put(player, new Tablist(player))); + } } @EventHandler -- 2.39.2