Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCrafter47 committed Oct 8, 2023
2 parents ac2eca5 + 3b101e7 commit 8c8c9d8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,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);
}
Expand Down Expand Up @@ -265,41 +271,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;
}
}

Expand Down Expand Up @@ -345,10 +342,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;
Expand Down Expand Up @@ -644,8 +643,7 @@ private String getCustomSlotUsername(int index) {

@Override
void onServerSwitch() {

createTeamsIfNecessary();
// do nothing
}

@Override
Expand Down Expand Up @@ -706,6 +704,9 @@ void onDeactivated() {

@Override
void update() {

createTeamsIfNecessary();

T tabOverlay = getTabOverlay();

if (tabOverlay.dirtyFlagSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 8c8c9d8

Please sign in to comment.