add support for getting protocol using viaversion's api

This commit is contained in:
ajgeiss0702
2022-01-14 00:11:26 -07:00
parent 59da488eaa
commit 5cb5370914
4 changed files with 40 additions and 0 deletions
+3
View File
@@ -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"))
@@ -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;
}
}