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.
  • 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

      boolean hasClass(String... classParts)
      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

      boolean hasClass(String className)
      Whether a class is present.
      Parameters:
      className - the fully qualified class name
      Returns:
      true if the class is on the classpath
    • hasClassOrElse

      void hasClassOrElse(String className, Consumer<LibraryResolver> libraryConsumer)
      Downloads a library only when the platform does not already provide the given class.
      Parameters:
      className - the class that decides whether the download is needed
      libraryConsumer - 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 needed
      needChecking - whether to check at all; false always fetches
      libraryConsumer - registers the libraries to fetch
    • resolveClass

      @Nullable Class<?> resolveClass(String... classParts)
      Loads a class, with its name given in pieces so the literal survives relocation.
      Parameters:
      classParts - the pieces of the class name, joined without a separator
      Returns:
      the class, or null if it is not on the classpath
    • resolveClass

      @Nullable Class<?> resolveClass(String className)
      Loads a class.
      Parameters:
      className - the fully qualified class name
      Returns:
      the class, or null if it is not on the classpath
    • hasMethod

      boolean hasMethod(@NonNull Class<?> clazz, String methodName, Class<?>... parameterTypes)
      Whether a method exists, searching the class and its superclasses.
      Parameters:
      clazz - the class to search
      methodName - the method name
      parameterTypes - the parameter types
      Returns:
      true if the method exists
    • 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 search
      methodName - the method name
      parameterTypes - 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 search
      methodName - the method name
      parameterTypes - the parameter types
      Returns:
      the handle, or null if the method is missing or inaccessible
    • unreflectMethod

      @Nullable MethodHandle unreflectMethod(@Nullable Method method)
      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

      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