Interface ReflectionResolver
public interface ReflectionResolver
Reflection helpers used to work with server internals that differ between versions and forks,
and to detect which of them are present.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA lookup that is allowed to fail withIllegalAccessException. -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether a class is present.booleanWhether a class is present, with its name given in pieces so the literal survives relocation.voidhasClassOrElse(String className, boolean needChecking, Consumer<LibraryResolver> libraryConsumer) Downloads a library, optionally skipping the class check and always fetching.voidhasClassOrElse(String className, Consumer<LibraryResolver> libraryConsumer) Downloads a library only when the platform does not already provide the given class.booleanWhether a method exists, searching the class and its superclasses.booleanisFolia()Whether the server is Folia, which schedules per region rather than on one main thread.booleanisPaper()Whether the server is Paper or a Paper fork.@Nullable Class<?> resolveClass(String className) Loads a class.@Nullable Class<?> resolveClass(String... classParts) Loads a class, with its name given in pieces so the literal survives relocation.@Nullable MethodresolveMethod(@NonNull Class<?> clazz, @NonNull String methodName, Class<?>... parameterTypes) Finds a method, searching the class and its superclasses, including non-public ones.@Nullable MethodHandleunreflect(ReflectionResolver.HandleFunction<MethodHandles.Lookup, MethodHandle> handleFunction) Runs a lookup that may fail on access, swallowing the failure.@Nullable MethodHandleunreflectMethod(@NonNull Class<?> clazz, @NonNull String methodName, Class<?>... parameterTypes) Finds a method and turns it into a handle, which is far cheaper to call repeatedly.@Nullable MethodHandleunreflectMethod(@Nullable Method method) Turns a method into a handle.
-
Method Details
-
isPaper
boolean isPaper()Whether the server is Paper or a Paper fork.- Returns:
- true on Paper
-
isFolia
boolean isFolia()Whether the server is Folia, which schedules per region rather than on one main thread.- Returns:
- true on Folia
-
hasClass
Whether a class is present, with its name given in pieces so the literal survives relocation.- Parameters:
classParts- the pieces of the class name, joined without a separator- Returns:
- true if the class is on the classpath
-
hasClass
Whether a class is present.- Parameters:
className- the fully qualified class name- Returns:
- true if the class is on the classpath
-
hasClassOrElse
Downloads a library only when the platform does not already provide the given class.- Parameters:
className- the class that decides whether the download is neededlibraryConsumer- registers the libraries to fetch
-
hasClassOrElse
void hasClassOrElse(String className, boolean needChecking, Consumer<LibraryResolver> libraryConsumer) Downloads a library, optionally skipping the class check and always fetching.- Parameters:
className- the class that decides whether the download is neededneedChecking- whether to check at all; false always fetcheslibraryConsumer- registers the libraries to fetch
-
resolveClass
-
resolveClass
-
hasMethod
-
resolveMethod
@Nullable Method resolveMethod(@NonNull Class<?> clazz, @NonNull String methodName, Class<?>... parameterTypes) Finds a method, searching the class and its superclasses, including non-public ones.- Parameters:
clazz- the class to searchmethodName- the method nameparameterTypes- the parameter types- Returns:
- the method, or null if it does not exist
-
unreflectMethod
@Nullable MethodHandle unreflectMethod(@NonNull Class<?> clazz, @NonNull String methodName, Class<?>... parameterTypes) Finds a method and turns it into a handle, which is far cheaper to call repeatedly.- Parameters:
clazz- the class to searchmethodName- the method nameparameterTypes- the parameter types- Returns:
- the handle, or null if the method is missing or inaccessible
-
unreflectMethod
Turns a method into a handle.- Parameters:
method- the method, may be null- Returns:
- the handle, or null if the method was null or inaccessible
-
unreflect
@Nullable MethodHandle unreflect(ReflectionResolver.HandleFunction<MethodHandles.Lookup, MethodHandle> handleFunction) Runs a lookup that may fail on access, swallowing the failure.- Parameters:
handleFunction- performs the lookup- Returns:
- the handle, or null if access was denied
-