Skip to content

Commit

Permalink
send create team packets after server switch; see #731
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeCrafter47 committed Oct 8, 2023
1 parent a05bead commit 960de6c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 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 @@ -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;
}
}

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

@Override
void onServerSwitch() {

createTeamsIfNecessary();
// do nothing
}

@Override
Expand Down Expand Up @@ -706,6 +700,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 960de6c

Please sign in to comment.