Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
More minor refactoring
Dieser Commit ist enthalten in:
Ursprung
85f9414b95
Commit
a3080800b0
@ -43,14 +43,17 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
|
||||
if (connection == null) {
|
||||
if (connection != null) {
|
||||
return connection.getProtocolInfo().getProtocolVersion();
|
||||
}
|
||||
|
||||
if (isProtocolSupport()) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null && isProtocolSupport()) {
|
||||
if (player != null) {
|
||||
return ProtocolSupportUtil.getProtocolVersion(player);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return connection.getProtocolInfo().getProtocolVersion();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,5 +69,4 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
|
||||
public boolean isProtocolSupport() {
|
||||
return plugin.isProtocolSupport();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package com.viaversion.viaversion.bukkit.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class NMSUtil {
|
||||
public final class NMSUtil {
|
||||
private static final String BASE = Bukkit.getServer().getClass().getPackage().getName();
|
||||
private static final String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
private static final boolean DEBUG_PROPERTY = loadDebugProperty();
|
||||
|
@ -22,27 +22,31 @@ import org.bukkit.entity.Player;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ProtocolSupportUtil {
|
||||
private static Method protocolVersionMethod = null;
|
||||
private static Method getIdMethod = null;
|
||||
public final class ProtocolSupportUtil {
|
||||
private static final Method PROTOCOL_VERSION_METHOD;
|
||||
private static final Method GET_ID_METHOD;
|
||||
|
||||
static {
|
||||
Method protocolVersionMethod = null;
|
||||
Method getIdMethod = null;
|
||||
try {
|
||||
protocolVersionMethod = Class.forName("protocolsupport.api.ProtocolSupportAPI").getMethod("getProtocolVersion", Player.class);
|
||||
getIdMethod = Class.forName("protocolsupport.api.ProtocolVersion").getMethod("getId");
|
||||
} catch (Exception e) {
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// ProtocolSupport not installed.
|
||||
}
|
||||
PROTOCOL_VERSION_METHOD = protocolVersionMethod;
|
||||
GET_ID_METHOD = getIdMethod;
|
||||
}
|
||||
|
||||
public static int getProtocolVersion(Player player) {
|
||||
if (protocolVersionMethod == null) return -1;
|
||||
if (PROTOCOL_VERSION_METHOD == null) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
Object version = protocolVersionMethod.invoke(null, player);
|
||||
return (int) getIdMethod.invoke(version);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
Object version = PROTOCOL_VERSION_METHOD.invoke(null, player);
|
||||
return (int) GET_ID_METHOD.invoke(version);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren