3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

More minor refactoring

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-11-10 13:32:25 +01:00
Ursprung 85f9414b95
Commit a3080800b0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 22 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -43,14 +43,17 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
@Override @Override
public int getPlayerVersion(UUID uuid) { public int getPlayerVersion(UUID uuid) {
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(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); Player player = Bukkit.getPlayer(uuid);
if (player != null && isProtocolSupport()) { if (player != null) {
return ProtocolSupportUtil.getProtocolVersion(player); return ProtocolSupportUtil.getProtocolVersion(player);
} }
return -1;
} }
return connection.getProtocolInfo().getProtocolVersion(); return -1;
} }
@Override @Override
@ -66,5 +69,4 @@ public class BukkitViaAPI extends ViaAPIBase<Player> {
public boolean isProtocolSupport() { public boolean isProtocolSupport() {
return plugin.isProtocolSupport(); return plugin.isProtocolSupport();
} }
} }

Datei anzeigen

@ -19,7 +19,7 @@ package com.viaversion.viaversion.bukkit.util;
import org.bukkit.Bukkit; 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 BASE = Bukkit.getServer().getClass().getPackage().getName();
private static final String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server"); private static final String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server");
private static final boolean DEBUG_PROPERTY = loadDebugProperty(); private static final boolean DEBUG_PROPERTY = loadDebugProperty();

Datei anzeigen

@ -22,27 +22,31 @@ import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class ProtocolSupportUtil { public final class ProtocolSupportUtil {
private static Method protocolVersionMethod = null; private static final Method PROTOCOL_VERSION_METHOD;
private static Method getIdMethod = null; private static final Method GET_ID_METHOD;
static { static {
Method protocolVersionMethod = null;
Method getIdMethod = null;
try { try {
protocolVersionMethod = Class.forName("protocolsupport.api.ProtocolSupportAPI").getMethod("getProtocolVersion", Player.class); protocolVersionMethod = Class.forName("protocolsupport.api.ProtocolSupportAPI").getMethod("getProtocolVersion", Player.class);
getIdMethod = Class.forName("protocolsupport.api.ProtocolVersion").getMethod("getId"); getIdMethod = Class.forName("protocolsupport.api.ProtocolVersion").getMethod("getId");
} catch (Exception e) { } catch (ReflectiveOperationException e) {
// ProtocolSupport not installed. // ProtocolSupport not installed.
} }
PROTOCOL_VERSION_METHOD = protocolVersionMethod;
GET_ID_METHOD = getIdMethod;
} }
public static int getProtocolVersion(Player player) { public static int getProtocolVersion(Player player) {
if (protocolVersionMethod == null) return -1; if (PROTOCOL_VERSION_METHOD == null) {
return -1;
}
try { try {
Object version = protocolVersionMethod.invoke(null, player); Object version = PROTOCOL_VERSION_METHOD.invoke(null, player);
return (int) getIdMethod.invoke(version); return (int) GET_ID_METHOD.invoke(version);
} catch (IllegalAccessException e) { } catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
return -1; return -1;