From e298a7efac794daec6afa7780a47991d3ffb3cad Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 17 Mar 2023 18:36:48 +0100 Subject: [PATCH] Fix protocol detection on some versions of Spigot Fixes #3263 --- .../java/com/viaversion/viaversion/api/type/Type.java | 2 +- .../viaversion/bukkit/platform/BukkitViaInjector.java | 8 +++++--- .../viaversion/protocol/packet/PacketWrapperImpl.java | 11 ++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index e6ba48d5a..2cbfdbcc3 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -237,6 +237,6 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { @Override public String toString() { - return "Type|" + typeName; + return typeName; } } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java index 955433748..d62fe1423 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaInjector.java @@ -36,7 +36,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; public class BukkitViaInjector extends LegacyViaInjector { - private static final boolean HAS_SHARED_CONSTANTS = PaperViaInjector.hasClass("net.minecraft.SharedConstants") && PaperViaInjector.hasClass("net.minecraft.WorldVersion"); + private static final boolean HAS_WORLD_VERSION_PROTOCOL_VERSION = PaperViaInjector.hasClass("net.minecraft.SharedConstants") + && PaperViaInjector.hasClass("net.minecraft.WorldVersion") + && !PaperViaInjector.hasClass("com.mojang.bridge.game.GameVersion"); @Override public void inject() throws ReflectiveOperationException { @@ -65,7 +67,7 @@ public class BukkitViaInjector extends LegacyViaInjector { return Bukkit.getUnsafe().getProtocolVersion(); } - return HAS_SHARED_CONSTANTS ? cursedProtocolDetection() : veryCursedProtocolDetection(); + return HAS_WORLD_VERSION_PROTOCOL_VERSION ? cursedProtocolDetection() : veryCursedProtocolDetection(); } private int cursedProtocolDetection() throws ReflectiveOperationException { @@ -187,7 +189,7 @@ public class BukkitViaInjector extends LegacyViaInjector { @Override public boolean lateProtocolVersionSetting() { - return !(PaperViaInjector.PAPER_PROTOCOL_METHOD || HAS_SHARED_CONSTANTS); + return !(PaperViaInjector.PAPER_PROTOCOL_METHOD || HAS_WORLD_VERSION_PROTOCOL_VERSION); } public boolean isBinded() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java b/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java index c41a6a610..38491f3e1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java @@ -509,10 +509,10 @@ public class PacketWrapperImpl implements PacketWrapper { @Override public String toString() { return "PacketWrapper{" + - "packetType=" + packetType + + "type=" + packetType + ", id=" + id + - ", packetValues=" + packetValues + - ", readableObjects=" + readableObjects + + ", values=" + packetValues + + ", readable=" + readableObjects + '}'; } @@ -555,10 +555,7 @@ public class PacketWrapperImpl implements PacketWrapper { @Override public String toString() { - return "{" - + type + - ", " + value + - '}'; + return "{" + type + ": " + value + "}"; } } }