From cd5c64734ee96c17260e941ce0b131f9e6962643 Mon Sep 17 00:00:00 2001 From: Pasqual Koschmieder Date: Fri, 22 Sep 2023 20:35:08 +0200 Subject: [PATCH] fix networkmanager field resolving --- .../com/comphenix/protocol/utility/MinecraftFields.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/comphenix/protocol/utility/MinecraftFields.java b/src/main/java/com/comphenix/protocol/utility/MinecraftFields.java index 81f904dc..ec1aabf1 100644 --- a/src/main/java/com/comphenix/protocol/utility/MinecraftFields.java +++ b/src/main/java/com/comphenix/protocol/utility/MinecraftFields.java @@ -1,6 +1,7 @@ package com.comphenix.protocol.utility; import com.comphenix.protocol.injector.BukkitUnwrapper; +import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.reflect.accessors.Accessors; import com.comphenix.protocol.reflect.accessors.FieldAccessor; import org.bukkit.entity.Player; @@ -33,7 +34,13 @@ public final class MinecraftFields { if (NETWORK_ACCESSOR == null) { Class networkClass = MinecraftReflection.getNetworkManagerClass(); Class connectionClass = MinecraftReflection.getPlayerConnectionClass(); - NETWORK_ACCESSOR = Accessors.getFieldAccessor(connectionClass, networkClass, true); + NETWORK_ACCESSOR = FuzzyReflection.fromClass(connectionClass, true) + .getDeclaredFields(Object.class) + .stream() + .filter(field -> field.getType().equals(networkClass)) + .findFirst() + .map(Accessors::getFieldAccessor) + .orElseThrow(() -> new IllegalArgumentException("Unable to find the NetworkManager field in PlayerConnection")); } // Retrieve the network manager