Fix reflection field search on Spigot 1.20.2 (#3503)

This commit is contained in:
fren_gor 2023-10-28 05:47:59 +02:00 committed by GitHub
parent f618cdec99
commit a022620712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -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]);
}