Skip to content

Commit

Permalink
Lets go
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed Dec 7, 2023
1 parent 2c2c2b8 commit c724d4e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
*/
public class PlayerConnectionListener implements Listener {

// We need a weird workaround here for https://github.com/SpigotMC/BungeeCord/issues/3542
// 1.20.2+ players hava an additional configuration phase that we need to work around. So for the first event
// we need to fire, and for the second we can mock a server switch.
// We'll use a cache for this, with a retention of 20 seconds
// which should be enough to cover resource pack loading but long enough to mitigate memory leaks.
// This also means that the player might not yet be online in a server, in which case we'll have to delay the entire event or
// outright ignore it, hoping for another one soon.

@EventHandler
public void onPostLogin(PostLoginEvent event) {
OpenAudioMc.getService(NetworkingService.class).register(new BungeeUserAdapter(event.getPlayer()), null);
Expand All @@ -32,6 +40,8 @@ public void onLogout(PlayerDisconnectEvent event) {

@EventHandler
public void onSwitch(ServerSwitchEvent event) {
if (!OpenAudioMc.getService(NetworkingService.class).hasClient(event.getPlayer().getUniqueId())) return;

new BungeeProxyNode(event.getPlayer().getServer().getInfo()).sendPacket(new AnnouncePlatformPacket(
OpenAudioMc.getService(AuthenticationService.class).getServerKeySet().getPublicKey().getValue(),
Platform.BUNGEE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.craftmend.openaudiomc.bungee.utils;

import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;

public class BungeeUtils {

public static boolean doesUserHaveConfigPhase(ProxiedPlayer player) {
UserConnection connection = (UserConnection) player;
// check if protocol is 764 or higher
return connection.getPendingConnection().getVersion() >= 764;
}

public static boolean serverSupportsConfigurationPhase() {
// check if the class net.md_5.bungee.protocol.packet.StartConfiguration exists
try {
Class.forName("net.md_5.bungee.protocol.packet.StartConfiguration");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void onEnable() {
public abstract ClientConnection register(User player, @Nullable SerializableClient importData);
public abstract Set<INetworkingEvents> getEvents();
public abstract ClientConnection getClient(UUID uuid);
public abstract boolean hasClient(UUID uuid);
public abstract Collection<ClientConnection> getClients();
public abstract int getThroughputPerSecond();

Expand Down

0 comments on commit c724d4e

Please sign in to comment.