Class ReflectionUtility

java.lang.Object
xyz.srnyx.annoyingapi.utility.ReflectionUtility

public class ReflectionUtility extends Object
Utility class for managing reflected objects
  • Method Details

    • getClass

      @Nullable public static @Nullable Class<?> getClass(int major, int minor, int patch, @NotNull @NotNull String className)
      Returns a Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      className - the class name
      Returns:
      the class if the version is greater than or equal to the minimum version, otherwise null
    • getClass

      @Nullable public static @Nullable Class<?> getClass(int major, int minor, int patch, @NotNull @NotNull Class<?> reflectionClass)
      Returns a Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      reflectionClass - the reflection class
      Returns:
      the class if the version is greater than or equal to the minimum version, otherwise null
    • getEnum

      @Nullable public static @Nullable Class<? extends Enum> getEnum(int major, int minor, int patch, @NotNull @NotNull String enumClassName)
      Returns an Enum Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      enumClassName - the enum class name
      Returns:
      the enum if the version is greater than or equal to the minimum version, otherwise null
    • getEnum

      @Nullable public static @Nullable Class<? extends Enum> getEnum(int major, int minor, int patch, @NotNull @NotNull Class<?> reflectionClass)
      Returns an Enum Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      reflectionClass - the reflection class
      Returns:
      the enum if the version is greater than or equal to the minimum version, otherwise null
    • getClassArray

      @Nullable public static @Nullable Class<?> getClassArray(int major, int minor, int patch, @NotNull @NotNull String className)
      Returns an array Class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      className - the class name
      Returns:
      the array class if the version is greater than or equal to the minimum version, otherwise null
    • getClassArray

      @Nullable public static @Nullable Class<?> getClassArray(int major, int minor, int patch, @NotNull @NotNull Class<?> reflectionClass)
      Returns an array Class from a reflection class if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      reflectionClass - the reflection class
      Returns:
      the array class if the version is greater than or equal to the minimum version, otherwise null
    • getConstructor

      @Nullable public static <T> @Nullable Constructor<T> getConstructor(int major, int minor, int patch, @Nullable @Nullable Class<T> clazz, @Nullable @Nullable Class<?>... parameterTypes)
      Returns a Constructor if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null
      Type Parameters:
      T - the type of the class
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      clazz - the class to get the constructor from
      parameterTypes - the parameter types of the constructor
      Returns:
      the constructor if the version is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null, otherwise null
    • getMethod

      @Nullable public static <T> @Nullable Method getMethod(int major, int minor, int patch, @Nullable @Nullable Class<T> clazz, @NotNull @NotNull String methodName, @Nullable @Nullable Class<?>... parameterTypes)
      Returns a Method if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null
      Type Parameters:
      T - the type of the class
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      clazz - the class to get the method from
      methodName - the name of the method
      parameterTypes - the parameter types of the method
      Returns:
      the method if the version is greater than or equal to the minimum version, the class is not null, and none of the parameter types are null, otherwise null
    • getField

      @Nullable public static @Nullable Field getField(int major, int minor, int patch, @Nullable @Nullable Class<?> clazz, @NotNull @NotNull String fieldName)
      Returns a Field if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      clazz - the class to get the field from
      fieldName - the name of the field
      Returns:
      the field if the version is greater than or equal to the minimum version, otherwise null
      See Also:
    • getDeclaredField

      @Nullable public static @Nullable Field getDeclaredField(int major, int minor, int patch, @Nullable @Nullable Class<?> clazz, @NotNull @NotNull String fieldName)
      Returns a declared Field if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      clazz - the class to get the field from
      fieldName - the name of the field
      Returns:
      the field if the version is greater than or equal to the minimum version, otherwise null
      See Also:
    • getStaticFieldValue

      @Nullable public static @Nullable Object getStaticFieldValue(int major, int minor, int patch, @Nullable @Nullable Class<?> clazz, @NotNull @NotNull String fieldName)
      Returns the value of a static Field if the result of getField(int, int, int, Class, String) is not null
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      clazz - the class to get the field from
      fieldName - the name of the field
      Returns:
      the value of the field if the result of getField(int, int, int, Class, String) is not null, otherwise null
    • getEnumValue

      @Nullable public static <T extends Enum> T getEnumValue(int major, int minor, int patch, @Nullable @Nullable Class<T> enumClass, @NotNull @NotNull String enumName) throws IllegalArgumentException
      Returns an Enum value if AnnoyingPlugin.MINECRAFT_VERSION is greater than or equal to the minimum version
      Type Parameters:
      T - the type of the enum
      Parameters:
      major - the major version of the minimum version
      minor - the minor version of the minimum version
      patch - the patch version of the minimum version
      enumClass - the enum class
      enumName - the name of the enum
      Returns:
      the enum value if the version is greater than or equal to the minimum version, otherwise null
      Throws:
      IllegalArgumentException - if no enum constant is found with the specified name
    • createArray

      @Nullable @Contract("null, _ -> null") public static @Nullable Object createArray(@Nullable @Nullable Class<?> clazz, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int length)
      Returns a new array of the specified class with the specified length
      Parameters:
      clazz - the class of the array
      length - the length of the array
      Returns:
      the new array or null if the class is null/Void