Package xyz.srnyx.annoyingapi.utility
Class ReflectionUtility
java.lang.Object
xyz.srnyx.annoyingapi.utility.ReflectionUtility
Utility class for managing reflected objects
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable ObjectcreateArray(@Nullable Class<?> clazz, @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int length) Returns a new array of the specified class with the specified lengthstatic @Nullable Class<?> Returns aClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable Class<?> Returns aClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable Class<?> getClassArray(int major, int minor, int patch, @NotNull Class<?> reflectionClass) Returns an arrayClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable Class<?> getClassArray(int major, int minor, int patch, @NotNull String className) Returns an arrayClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic <T> @Nullable Constructor<T> getConstructor(int major, int minor, int patch, @Nullable Class<T> clazz, @Nullable Class<?>... parameterTypes) static <T> @Nullable Constructor<T> getConstructor(@Nullable ServerSoftware software, int major, int minor, int patch, @Nullable Class<T> clazz, @Nullable Class<?>... parameterTypes) Returns aConstructorifAnnoyingPlugin.SERVER_SOFTWAREhas the given software,AnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version, the class is not null, and none of the parameter types are nullstatic @Nullable FieldgetDeclaredField(int major, int minor, int patch, @Nullable Class<?> clazz, @NotNull String fieldName) Returns a declaredFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionReturns anEnumClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionReturns anEnumClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic <T extends Enum>
TgetEnumValue(int major, int minor, int patch, @Nullable Class<T> enumClass, @NotNull String enumName) Returns anEnumvalue ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic @Nullable FieldReturns aFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum versionstatic <T> @Nullable MethodgetMethod(int major, int minor, int patch, @Nullable Class<T> clazz, @NotNull String methodName, @Nullable Class<?>... parameterTypes) Returns aMethodifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version, the class is not null, and none of the parameter types are nullstatic @Nullable ObjectgetStaticFieldValue(int major, int minor, int patch, @Nullable Class<?> clazz, @NotNull String fieldName) Returns the value of a staticFieldif the result ofgetField(int, int, int, Class, String)is not null
-
Method Details
-
getClass
@Nullable public static @Nullable Class<?> getClass(int major, int minor, int patch, @NotNull @NotNull String className) Returns aClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclassName- 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 aClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionreflectionClass- 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 anEnumClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionenumClassName- 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 anEnumClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionreflectionClass- 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 arrayClassifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclassName- 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 arrayClassfrom a reflection class ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionreflectionClass- 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(@Nullable @Nullable ServerSoftware software, int major, int minor, int patch, @Nullable @Nullable Class<T> clazz, @Nullable @Nullable Class<?>... parameterTypes) Returns aConstructorifAnnoyingPlugin.SERVER_SOFTWAREhas the given software,AnnoyingPlugin.MINECRAFT_VERSIONis 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:
software- the server software or null to ignore softwaremajor- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the classparameterTypes- the parameter types- Returns:
- the constructor if the server software matches, 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
-
getConstructor
@Nullable public static <T> @Nullable Constructor<T> getConstructor(int major, int minor, int patch, @Nullable @Nullable Class<T> clazz, @Nullable @Nullable Class<?>... parameterTypes) -
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 aMethodifAnnoyingPlugin.MINECRAFT_VERSIONis 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 versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the method frommethodName- the name of the methodparameterTypes- 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 aFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the field fromfieldName- 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 declaredFieldifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the field fromfieldName- 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 staticFieldif the result ofgetField(int, int, int, Class, String)is not null- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionclazz- the class to get the field fromfieldName- 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 anEnumvalue ifAnnoyingPlugin.MINECRAFT_VERSIONis greater than or equal to the minimum version- Type Parameters:
T- the type of the enum- Parameters:
major- the major version of the minimum versionminor- the minor version of the minimum versionpatch- the patch version of the minimum versionenumClass- the enum classenumName- 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 arraylength- the length of the array- Returns:
- the new array or null if the class is null/Void
-