From c390ebbd5e1e87baa5717603fb9380cf3ee850b7 Mon Sep 17 00:00:00 2001 From: Stijn Bannink Date: Wed, 9 Aug 2023 10:48:37 +0200 Subject: [PATCH] Hotfix: Fixed supports() function detecting invalid major/minor version combination for newer versions; closes #22 --- .idea/misc.xml | 1 - pom.xml | 2 +- .../mapreflectionapi/listeners/PacketListener.java | 2 +- .../sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 200af21..4a803e8 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/pom.xml b/pom.xml index 42a77e5..f1bd2ed 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ tech.sbdevelopment MapReflectionAPI - 1.5.1 + 1.5.2 jar MapReflectionAPI diff --git a/src/main/java/tech/sbdevelopment/mapreflectionapi/listeners/PacketListener.java b/src/main/java/tech/sbdevelopment/mapreflectionapi/listeners/PacketListener.java index 3785599..b4f5ed0 100644 --- a/src/main/java/tech/sbdevelopment/mapreflectionapi/listeners/PacketListener.java +++ b/src/main/java/tech/sbdevelopment/mapreflectionapi/listeners/PacketListener.java @@ -143,7 +143,7 @@ public class PacketListener implements Listener { private Channel getChannel(Player player) { Object playerHandle = getHandle(player); Object playerConnection = getDeclaredField(playerHandle, ReflectionUtil.supports(20) ? "c" : ReflectionUtil.supports(17) ? "b" : "playerConnection"); //1.20 = c, 1.17-1.19 = b, 1.16 = playerConnection - Object networkManager = getDeclaredField(playerConnection, ReflectionUtil.supports(19, 3) ? "h" : ReflectionUtil.supports(19) ? "b" : ReflectionUtil.supports(17) ? "a" : "networkManager"); //1.19.4 = h, >= 1.19.3 = b, 1.18 = a, 1.16 = networkManager + Object networkManager = getDeclaredField(playerConnection, ReflectionUtil.supports(19, 3) ? "h" : ReflectionUtil.supports(19) ? "b" : ReflectionUtil.supports(17) ? "a" : "networkManager"); //1.20 & 1.19.4 = h, >= 1.19.3 = b, 1.18 = a, 1.16 = networkManager return (Channel) getDeclaredField(networkManager, ReflectionUtil.supports(18) ? "m" : ReflectionUtil.supports(17) ? "k" : "channel"); //1.19 & 1.18 = m, 1.17 = k, 1.16 = channel } diff --git a/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java b/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java index bcf93d8..d0288c6 100644 --- a/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java +++ b/src/main/java/tech/sbdevelopment/mapreflectionapi/utils/ReflectionUtil.java @@ -197,7 +197,7 @@ public class ReflectionUtil { * @since 4.0.0 */ public static boolean supports(int major, int minor) { - return VER >= major && VER_MINOR >= minor; + return (VER == major && VER_MINOR >= minor) || VER > major; } /**