Class Reflection


  • public class Reflection
    extends java.lang.Object
    A Utilities class to handle reflection
    • Constructor Summary

      Constructors 
      Constructor Description
      Reflection()  
    • Method Summary

      Modifier and Type Method Description
      static java.lang.Object get​(java.lang.Class<?> c, java.lang.String fieldName, java.lang.Object object)
      Assumes field isn't private
      static java.lang.Object get​(java.lang.reflect.Field field, java.lang.Object object)
      Get object.
      static java.lang.Object get​(java.lang.String fieldName, java.lang.Object object)
      Assumes field isn't private
      static java.lang.Class<?> getClass​(java.lang.String name)
      Get a class
      static java.lang.reflect.Constructor getConstructor​(java.lang.Class<?> c, java.lang.Class<?>... types)
      Get Constructor from class
      static java.lang.Class<?> getCraftClass​(java.lang.String name)
      Get a bukkit class (org.bukkit.craftbukkit)
      static java.lang.reflect.Field getField​(java.lang.Class<?> c, java.lang.String fieldName)
      Gets field.
      static java.lang.Object getHandle​(java.lang.Object object)
      Get the handle of the passed object
      static java.lang.reflect.Method getMethod​(java.lang.Class<?> c, java.lang.String methodName)
      Get a method from the class
      static java.lang.reflect.Method getMethod​(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>... parameterTypes)
      Get a method from a class with specific parameter types
      static java.lang.Class<?> getNMSClass​(java.lang.String name)
      Get a craft class (net.minecraft.server)
      static org.bukkit.entity.Player[] getOnlinePlayers()
      Get online players player [ ].
      static java.lang.String getVersion()
      Get the server's version
      static java.lang.Object invokeMethod​(java.lang.Class<?> c, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameter)
      Invoke a method
      static java.lang.Object invokeMethod​(java.lang.Class<?> c, java.lang.String methodName, java.lang.Object object)
      Invoke a method on an object
      static java.lang.Object invokeMethod​(java.lang.Class<?> c, java.lang.String methodName, java.lang.Object object, java.lang.Class<?>[] parameterTypes, java.lang.Object[] parameter)
      Invoke method object.
      static java.lang.Object invokeMethod​(java.lang.reflect.Method method, java.lang.Object object, java.lang.Object... args)
      Invoke method object.
      static java.lang.Object invokeMethod​(java.lang.String methodName, java.lang.Object object)
      Invoke a method on an object
      static java.lang.Object newInstance​(java.lang.reflect.Constructor constructor, java.lang.Object... args)
      New instance object.
      static void setField​(java.lang.Class<?> c, java.lang.String fieldName, java.lang.Object obj, java.lang.Object value)
      Set a Field
      static void setField​(java.lang.reflect.Field field, java.lang.Object obj, java.lang.Object value)
      Set a Field
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Reflection

        public Reflection()
    • Method Detail

      • getVersion

        public static java.lang.String getVersion()
        Get the server's version
        Returns:
        version
      • getNMSClass

        public static java.lang.Class<?> getNMSClass​(java.lang.String name)
        Get a craft class (net.minecraft.server)
        Parameters:
        name - the name
        Returns:
        nms class
      • getCraftClass

        public static java.lang.Class<?> getCraftClass​(java.lang.String name)
        Get a bukkit class (org.bukkit.craftbukkit)
        Parameters:
        name - the name
        Returns:
        craft class
      • getClass

        public static java.lang.Class<?> getClass​(java.lang.String name)
        Get a class
        Parameters:
        name - the name
        Returns:
        craft class
      • getHandle

        public static java.lang.Object getHandle​(java.lang.Object object)
        Get the handle of the passed object
        Parameters:
        object - the object
        Returns:
        handle
      • getConstructor

        public static java.lang.reflect.Constructor getConstructor​(java.lang.Class<?> c,
                                                                   java.lang.Class<?>... types)
        Get Constructor from class
        Parameters:
        c - the c
        types - the types
        Returns:
        constructor
      • getMethod

        public static java.lang.reflect.Method getMethod​(java.lang.Class<?> c,
                                                         java.lang.String methodName)
        Get a method from the class
        Parameters:
        c - the c
        methodName - the method name
        Returns:
        method
      • getMethod

        public static java.lang.reflect.Method getMethod​(java.lang.Class<?> c,
                                                         java.lang.String methodName,
                                                         java.lang.Class<?>... parameterTypes)
        Get a method from a class with specific parameter types
        Parameters:
        c - the c
        methodName - the method name
        parameterTypes - the parameter types
        Returns:
        method
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Class<?> c,
                                                    java.lang.String methodName,
                                                    java.lang.Class<?>[] parameterTypes,
                                                    java.lang.Object[] parameter)
        Invoke a method
        Parameters:
        c - the c
        methodName - the method name
        parameterTypes - the parameter types
        parameter - the parameter
        Returns:
        the object
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Class<?> c,
                                                    java.lang.String methodName,
                                                    java.lang.Object object)
        Invoke a method on an object
        Parameters:
        c - the c
        methodName - the method name
        object - the object
        Returns:
        the object
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.String methodName,
                                                    java.lang.Object object)
        Invoke a method on an object
        Parameters:
        methodName - the method name
        object - the object
        Returns:
        the object
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.Class<?> c,
                                                    java.lang.String methodName,
                                                    java.lang.Object object,
                                                    java.lang.Class<?>[] parameterTypes,
                                                    java.lang.Object[] parameter)
        Invoke method object.
        Parameters:
        c - The Class
        methodName - The MethodName
        object - The Object
        parameterTypes - The ParameterTypess
        parameter - The Parameters
        Returns:
        The Object from the Invoked Method
      • invokeMethod

        public static java.lang.Object invokeMethod​(java.lang.reflect.Method method,
                                                    java.lang.Object object,
                                                    java.lang.Object... args)
        Invoke method object.
        Parameters:
        method - The Method
        object - The Object
        args - The Args
        Returns:
        The object from the Invoked Method
      • newInstance

        public static java.lang.Object newInstance​(java.lang.reflect.Constructor constructor,
                                                   java.lang.Object... args)
        New instance object.
        Parameters:
        constructor - The Constructor
        args - The args
        Returns:
        Get a new instance from a constructor
      • setField

        public static void setField​(java.lang.Class<?> c,
                                    java.lang.String fieldName,
                                    java.lang.Object obj,
                                    java.lang.Object value)
        Set a Field
        Parameters:
        c - The Class
        fieldName - The FieldName
        obj - The Object
        value - The Value
      • setField

        public static void setField​(java.lang.reflect.Field field,
                                    java.lang.Object obj,
                                    java.lang.Object value)
        Set a Field
        Parameters:
        field - The field
        obj - The Object
        value - The Value
      • getField

        public static java.lang.reflect.Field getField​(java.lang.Class<?> c,
                                                       java.lang.String fieldName)
        Gets field.
        Parameters:
        c - The Class
        fieldName - The FieldName
        Returns:
        Get the field from the class
      • get

        public static java.lang.Object get​(java.lang.reflect.Field field,
                                           java.lang.Object object)
        Get object.
        Parameters:
        field - The field
        object - The Object
        Returns:
        Get the Object from the Field
      • get

        public static java.lang.Object get​(java.lang.String fieldName,
                                           java.lang.Object object)
        Assumes field isn't private
        Parameters:
        fieldName - The field
        object - The Object
        Returns:
        Get the Object from the Field
      • get

        public static java.lang.Object get​(java.lang.Class<?> c,
                                           java.lang.String fieldName,
                                           java.lang.Object object)
        Assumes field isn't private
        Parameters:
        c - The Class
        fieldName - The field
        object - The Object
        Returns:
        Get the Object from the Field
      • getOnlinePlayers

        public static org.bukkit.entity.Player[] getOnlinePlayers()
        Get online players player [ ].
        Returns:
        Get Array of online players regardless of Mc Version