From 960de6c3c3746f1f2fd38b5089f0f3eb8c5c7e2d Mon Sep 17 00:00:00 2001 From: Florian Stober Date: Sun, 8 Oct 2023 11:08:06 +0200 Subject: [PATCH 1/2] send create team packets after server switch; see #731 --- .../handler/NewTabOverlayHandler.java | 67 +++++++++---------- .../managers/TabViewManager.java | 28 +++++++- 2 files changed, 57 insertions(+), 38 deletions(-) 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); } From 3b101e740127704a66a68a705bf178c392c953a9 Mon Sep 17 00:00:00 2001 From: Florian Stober Date: Sun, 8 Oct 2023 11:08:39 +0200 Subject: [PATCH 2/2] silence exception on disconnect; see #730 --- .../bungeetablistplus/handler/NewTabOverlayHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java index 18ea81a8..50fea221 100644 --- a/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java +++ b/bungee/src/main/java/codecrafter47/bungeetablistplus/handler/NewTabOverlayHandler.java @@ -188,7 +188,11 @@ private void sendPacket(DefinedPacket packet) { // Ensure that unsafe packets are not sent in the config phase // Why bungee doesn't expose this via api beyond me... // https://github.com/SpigotMC/BungeeCord/blob/1ef4d27dbea48a1d47501ad2be0d75e42cc2cc12/proxy/src/main/java/net/md_5/bungee/UserConnection.java#L182-L192 - ((UserConnection) player).sendPacketQueued(packet); + try { + ((UserConnection) player).sendPacketQueued(packet); + } catch (Exception ignored) { + + } } else { player.unsafe().sendPacket(packet); }