From a022620712d0c307a23f7bb9c30cd93b16ff8c4a Mon Sep 17 00:00:00 2001 From: fren_gor Date: Sat, 28 Oct 2023 05:47:59 +0200 Subject: [PATCH] Fix reflection field search on Spigot 1.20.2 (#3503) --- .../viaversion/bukkit/listeners/JoinListener.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java index b172dcfbc..be4d7ce71 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/JoinListener.java @@ -63,8 +63,8 @@ public class JoinListener implements Listener { } // Loosely search a field with any name, as long as it matches a type name. - private static Field findField(boolean all, Class clazz, String... types) throws NoSuchFieldException { - for (Field field : all ? clazz.getFields() : clazz.getDeclaredFields()) { + private static Field findField(boolean checkSuperClass, Class clazz, String... types) throws NoSuchFieldException { + for (Field field : clazz.getDeclaredFields()) { String fieldTypeName = field.getType().getSimpleName(); for (String type : types) { if (!fieldTypeName.equals(type)) { @@ -77,6 +77,11 @@ public class JoinListener implements Listener { return field; } } + + if (checkSuperClass && clazz != Object.class && clazz.getSuperclass() != null) { + return findField(true, clazz.getSuperclass(), types); + } + throw new NoSuchFieldException(types[0]); }