mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-12 03:11:05 +01:00
Add getFirst<Getter|Setter> API
This commit is contained in:
parent
bd19c9e3e4
commit
b1990138d8
@ -164,6 +164,32 @@ public class NMS {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Field getFirstFieldMatchingType(Class<?> clazz, Class<?> type) {
|
||||||
|
Field found = null;
|
||||||
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
|
if (field.getType() == type) {
|
||||||
|
found = field;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found != null) {
|
||||||
|
found.setAccessible(true);
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MethodHandle getFirstGetter(Class<?> clazz, Class<?> type) {
|
||||||
|
try {
|
||||||
|
Field found = getFirstFieldMatchingType(clazz, type);
|
||||||
|
if (found == null)
|
||||||
|
return null;
|
||||||
|
return LOOKUP.unreflectGetter(found);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static MethodHandle getFirstMethodHandle(Class<?> clazz, boolean log, Class<?>... params) {
|
public static MethodHandle getFirstMethodHandle(Class<?> clazz, boolean log, Class<?>... params) {
|
||||||
if (clazz == null)
|
if (clazz == null)
|
||||||
return null;
|
return null;
|
||||||
@ -195,6 +221,18 @@ public class NMS {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MethodHandle getFirstSetter(Class<?> clazz, Class<?> type) {
|
||||||
|
try {
|
||||||
|
Field found = getFirstFieldMatchingType(clazz, type);
|
||||||
|
if (found == null)
|
||||||
|
return null;
|
||||||
|
return LOOKUP.unreflectSetter(found);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Messaging.logTr(Messages.ERROR_GETTING_FIELD, type, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static GameProfileRepository getGameProfileRepository() {
|
public static GameProfileRepository getGameProfileRepository() {
|
||||||
return BRIDGE.getGameProfileRepository();
|
return BRIDGE.getGameProfileRepository();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user