Class ReflectionUtil


  • public class ReflectionUtil
    extends Object
    Useful utility for accessing net.minecraft.server or org.bukkit.craftbukkit classes/methods/fields.
    • Constructor Detail

      • ReflectionUtil

        public ReflectionUtil()
    • Method Detail

      • getVersion

        public static String getVersion()
        Gets the version string for NMS and OBC class paths
        Returns:
        The version string of OBC and NMS packages
      • getNMSClass

        public static Class<?> getNMSClass​(String nmsClassName)
        Get an NMS Class
        Parameters:
        nmsClassName - The name of the class
        Returns:
        The class
      • getOBCClass

        public static Class<?> getOBCClass​(String obcClassName)
        Get a class from the org.bukkit.craftbukkit package
        Parameters:
        obcClassName - the path to the class
        Returns:
        the found class at the specified path
      • getConnection

        public static Object getConnection​(org.bukkit.entity.Player player)
        Get a Bukkit Player players NMS playerConnection object
        Parameters:
        player - The player
        Returns:
        The players connection
      • getConstructor

        public static Constructor<?> getConstructor​(Class<?> clazz,
                                                    Class<?>... params)
        Get a classes constructor
        Parameters:
        clazz - The constructor class
        params - The parameters in the constructor
        Returns:
        The constructor object
      • getMethod

        public static Method getMethod​(Class<?> clazz,
                                       String methodName,
                                       Class<?>... params)
        Get a method from a class that has the specific paramaters
        Parameters:
        clazz - The class we are searching
        methodName - The name of the method
        params - Any parameters that the method has
        Returns:
        The method with appropriate paramaters
      • getField

        public static Field getField​(Class<?> clazz,
                                     String fieldName)
        Get a field with a particular name from a class
        Parameters:
        clazz - The class
        fieldName - The name of the field
        Returns:
        The field object