add support for getting protocol using viaversion's api
This commit is contained in:
+17
@@ -1,5 +1,6 @@
|
||||
package us.ajg0702.queue.platforms.bungeecord.players;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
@@ -79,8 +80,11 @@ public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||
|
||||
final ProxiedPlayer handle;
|
||||
|
||||
private final boolean viaAvailable;
|
||||
|
||||
public BungeePlayer(ProxiedPlayer player) {
|
||||
handle = player;
|
||||
viaAvailable = isClassAvailable("com.viaversion.viaversion.api.Via");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,6 +133,9 @@ public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
if(viaAvailable) {
|
||||
return Via.getAPI().getPlayerVersion(handle.getUniqueId());
|
||||
}
|
||||
return handle.getPendingConnection().getVersion();
|
||||
}
|
||||
|
||||
@@ -155,4 +162,14 @@ public class BungeePlayer implements AdaptedPlayer, Audience {
|
||||
private Audience getAudience() {
|
||||
return BungeeQueue.adventure().player(handle);
|
||||
}
|
||||
|
||||
|
||||
private static boolean isClassAvailable(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user