diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java index d3e271b9..18ea81a8 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java @@ -35,7 +35,9 @@ import lombok.*; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.netty.ChannelWrapper; import net.md_5.bungee.protocol.DefinedPacket; +import net.md_5.bungee.protocol.Protocol; import net.md_5.bungee.protocol.packet.*; import javax.annotation.Nonnull; @@ -265,41 +267,32 @@ public PacketListenerResult onPlayerListHeaderFooterPacket(PlayerListHeaderFoote @Override public void onServerSwitch(boolean is13OrLater) { - if (!active) { - active = true; - update(); - } else { - hasCreatedCustomTeams = false; + hasCreatedCustomTeams = false; - try { - this.activeContentHandler.onServerSwitch(); - } catch (Throwable th) { - logger.log(Level.SEVERE, "Unexpected error", th); - // try recover - enterContentOperationMode(ContentOperationMode.PASS_TROUGH); - } - try { - this.activeHeaderFooterHandler.onServerSwitch(); - } catch (Throwable th) { - logger.log(Level.SEVERE, "Unexpected error", th); - // try recover - enterContentOperationMode(ContentOperationMode.PASS_TROUGH); - } + try { + this.activeContentHandler.onServerSwitch(); + } catch (Throwable th) { + logger.log(Level.SEVERE, "Unexpected error", th); + } + try { + this.activeHeaderFooterHandler.onServerSwitch(); + } catch (Throwable th) { + logger.log(Level.SEVERE, "Unexpected error", th); + } - if (!serverPlayerListListed.isEmpty()) { - PlayerListItemRemove packet = new PlayerListItemRemove(); - packet.setUuids(serverPlayerListListed.keySet().toArray(new UUID[0])); - sendPacket(packet); - } + if (!serverPlayerListListed.isEmpty()) { + PlayerListItemRemove packet = new PlayerListItemRemove(); + packet.setUuids(serverPlayerListListed.keySet().toArray(new UUID[0])); + sendPacket(packet); + } - serverPlayerListListed.clear(); - if (serverHeader != null) { - serverHeader = EMPTY_JSON_TEXT; - } - if (serverFooter != null) { - serverFooter = EMPTY_JSON_TEXT; - } + serverPlayerListListed.clear(); + if (serverHeader != null) { + serverHeader = EMPTY_JSON_TEXT; + } + if (serverFooter != null) { + serverFooter = EMPTY_JSON_TEXT; } } @@ -345,10 +338,12 @@ private void scheduleUpdate() { } private void update() { - if (!active) { + updateScheduledFlag.set(false); + + ChannelWrapper ch = ((UserConnection) player).getCh(); + if (ch.isClosed() || ch.getEncodeProtocol() != Protocol.GAME) { return; } - updateScheduledFlag.set(false); // update content handler AbstractContentOperationModeHandler contentHandler; @@ -644,8 +639,7 @@ private String getCustomSlotUsername(int index) { @Override void onServerSwitch() { - - createTeamsIfNecessary(); + // do nothing } @Override @@ -706,6 +700,9 @@ void onDeactivated() { @Override void update() { + + createTeamsIfNecessary(); + T tabOverlay = getTabOverlay(); if (tabOverlay.dirtyFlagSize) { diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/managers/TabViewManager.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/managers/TabViewManager.java index e11a9cee..50e92de2 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/managers/TabViewManager.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/managers/TabViewManager.java @@ -31,6 +31,7 @@ import net.md_5.bungee.ServerConnection; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; @@ -76,7 +77,30 @@ public TabView onPlayerDisconnect(ProxiedPlayer player) { } @EventHandler - public void onServerConnected(ServerSwitchEvent event) { + public void onServerConnected(ServerConnectedEvent event) { + if (GeyserCompat.isBedrockPlayer(event.getPlayer().getUniqueId())) { + return; + } + try { + ProxiedPlayer player = event.getPlayer(); + + PlayerTabView tabView = playerTabViewMap.get(player); + + if (tabView == null) { + throw new AssertionError("Received ServerSwitchEvent for non-existent player " + player.getName()); + } + + PacketHandler packetHandler = tabView.packetHandler; + + packetHandler.onServerSwitch(protocolVersionProvider.has113OrLater(player)); + + } catch (Exception ex) { + btlp.getLogger().log(Level.SEVERE, "Failed to inject packet listener", ex); + } + } + + @EventHandler + public void onServerSwitch(ServerSwitchEvent event) { if (GeyserCompat.isBedrockPlayer(event.getPlayer().getUniqueId())) { return; } @@ -98,8 +122,6 @@ public void onServerConnected(ServerSwitchEvent event) { wrapper.getHandle().pipeline().addBefore(PipelineUtils.BOSS_HANDLER, "btlp-packet-listener", packetListener); - packetHandler.onServerSwitch(protocolVersionProvider.has113OrLater(player)); - } catch (Exception ex) { btlp.getLogger().log(Level.SEVERE, "Failed to inject packet listener", ex); }