add support for getting protocol using viaversion's api
This commit is contained in:
@@ -9,6 +9,7 @@ repositories {
|
||||
//mavenLocal()
|
||||
maven { url = uri("https://repo.ajg0702.us") }
|
||||
maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/") }
|
||||
maven { url = uri("https://repo.viaversion.com/") }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@@ -24,6 +25,8 @@ dependencies {
|
||||
implementation("net.kyori:adventure-platform-bungeecord:4.0.0")
|
||||
compileOnly("net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT")
|
||||
|
||||
compileOnly("com.viaversion:viaversion-api:4.2.0-SNAPSHOT")
|
||||
|
||||
implementation("org.bstats:bstats-bungeecord:2.2.1")
|
||||
|
||||
implementation(project(":common"))
|
||||
|
||||
+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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ repositories {
|
||||
//mavenLocal()
|
||||
maven { url = uri("https://repo.ajg0702.us") }
|
||||
maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/") }
|
||||
maven { url = uri("https://repo.viaversion.com/") }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@@ -21,6 +22,8 @@ dependencies {
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.0.0-SNAPSHOT")
|
||||
|
||||
compileOnly("com.viaversion:viaversion-api:4.2.0-SNAPSHOT")
|
||||
|
||||
implementation("org.bstats:bstats-velocity:2.2.1")
|
||||
|
||||
implementation(project(":common"))
|
||||
|
||||
+17
@@ -3,6 +3,7 @@ package us.ajg0702.queue.platforms.velocity.players;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
@@ -73,8 +74,11 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
||||
|
||||
final Player handle;
|
||||
|
||||
private final boolean viaAvailable;
|
||||
|
||||
public VelocityPlayer(Player player) {
|
||||
handle = player;
|
||||
viaAvailable = isClassAvailable("com.viaversion.viaversion.api.Via");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,6 +170,9 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
||||
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
if(viaAvailable) {
|
||||
return Via.getAPI().getPlayerVersion(handle.getUniqueId());
|
||||
}
|
||||
return handle.getProtocolVersion().getProtocol();
|
||||
}
|
||||
|
||||
@@ -188,4 +195,14 @@ public class VelocityPlayer implements AdaptedPlayer, Audience {
|
||||
public Player getHandle() {
|
||||
return 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