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

Spigot 1.17 compatibility

Dieser Commit ist enthalten in:
Myles 2021-06-11 20:19:06 +01:00
Ursprung 317af7ebc5
Commit 68ccc6634d
5 geänderte Dateien mit 44 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -109,7 +109,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform<Player>
// Check if it's a spigot build with a protocol mod
try {
NMSUtil.nms("PacketEncoder").getDeclaredField("version");
NMSUtil.nms(
"PacketEncoder",
"net.minecraft.network.PacketEncoder"
).getDeclaredField("version");
compatSpigotBuild = true;
} catch (Exception e) {
compatSpigotBuild = false;

Datei anzeigen

@ -65,8 +65,8 @@ public class ClassGenerator {
}
if (ViaVersionPlugin.getInstance().isCompatSpigotBuild()) {
Class decodeSuper = NMSUtil.nms("PacketDecoder");
Class encodeSuper = NMSUtil.nms("PacketEncoder");
Class decodeSuper = NMSUtil.nms("PacketDecoder", "net.minecraft.network.PacketDecoder");
Class encodeSuper = NMSUtil.nms("PacketEncoder", "net.minecraft.network.PacketEncoder");
// Generate the classes
addSpigotCompatibility(pool, BukkitDecodeHandler.class, decodeSuper);
addSpigotCompatibility(pool, BukkitEncodeHandler.class, encodeSuper);
@ -209,7 +209,10 @@ public class ClassGenerator {
pool.importPackage("protocolsupport.api.Connection.PacketListener");
pool.importPackage("protocolsupport.api.Connection.PacketListener.PacketEvent");
pool.importPackage("protocolsupport.protocol.ConnectionImpl");
pool.importPackage(NMSUtil.nms("PacketHandshakingInSetProtocol").getName());
pool.importPackage(NMSUtil.nms(
"PacketHandshakingInSetProtocol",
"net.minecraft.network.protocol.handshake.PacketHandshakingInSetProtocol"
).getName());
// Add connection reference field
connectListenerClazz.addField(CtField.make("private ConnectionImpl connection;", connectListenerClazz));
// Bake constructor
@ -303,7 +306,10 @@ public class ClassGenerator {
public static boolean shouldUseNewHandshakeVersionMethod() {
try {
NMSUtil.nms("PacketHandshakingInSetProtocol").getMethod("getProtocolVersion");
NMSUtil.nms(
"PacketHandshakingInSetProtocol",
"net.minecraft.network.protocol.handshake.PacketHandshakingInSetProtocol"
).getMethod("getProtocolVersion");
return true;
} catch (Exception e) {
return false;

Datei anzeigen

@ -39,7 +39,12 @@ public class BukkitEncodeHandler extends MessageToByteEncoder implements ViaCode
static {
try {
versionField = NMSUtil.nms("PacketEncoder").getDeclaredField("version");
// Attempt to get any version info from the handler
versionField = NMSUtil.nms(
"PacketEncoder",
"net.minecraft.network.PacketEncoder"
).getDeclaredField("version");
versionField.setAccessible(true);
} catch (Exception e) {
// Not compat version

Datei anzeigen

@ -204,9 +204,15 @@ public class BukkitViaInjector implements ViaInjector {
}
try {
Class<?> serverClazz = NMSUtil.nms("MinecraftServer");
// Grab a static instance of the server
Class<?> serverClazz = NMSUtil.nms("MinecraftServer", "net.minecraft.server.MinecraftServer");
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
Class<?> pingClazz = NMSUtil.nms("ServerPing");
// Grab the ping class and find the field to access it
Class<?> pingClazz = NMSUtil.nms(
"ServerPing",
"net.minecraft.network.protocol.status.ServerPing"
);
Object ping = null;
// Search for ping method
for (Field f : serverClazz.getDeclaredFields()) {
@ -259,7 +265,10 @@ public class BukkitViaInjector implements ViaInjector {
}
public static Object getServerConnection() throws Exception {
Class<?> serverClazz = NMSUtil.nms("MinecraftServer");
Class<?> serverClazz = NMSUtil.nms(
"MinecraftServer",
"net.minecraft.server.MinecraftServer"
);
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
Object connection = null;
for (Method m : serverClazz.getDeclaredMethods()) {

Datei anzeigen

@ -26,7 +26,10 @@ public class NMSUtil {
private static boolean loadDebugProperty() {
try {
Class<?> serverClass = nms("MinecraftServer");
Class<?> serverClass = nms(
"MinecraftServer",
"net.minecraft.server.MinecraftServer"
);
Object server = serverClass.getDeclaredMethod("getServer").invoke(null);
return (boolean) serverClass.getMethod("isDebugging").invoke(server);
} catch (ReflectiveOperationException e) {
@ -38,6 +41,14 @@ public class NMSUtil {
return Class.forName(NMS + "." + className);
}
public static Class<?> nms(String className, String fallbackFullClassName) throws ClassNotFoundException {
try {
return Class.forName(NMS + "." + className);
} catch (ClassNotFoundException ignored) {
return Class.forName(fallbackFullClassName);
}
}
public static Class<?> obc(String className) throws ClassNotFoundException {
return Class.forName(BASE + "." + className);
}