Interface ReflectUtils


public interface ReflectUtils
Utility class for reflection-based operations in RareSpawns. Used for accessing NMS (net.minecraft.server) classes, fields, and methods dynamically. Primarily used for debugging and compatibility across Minecraft versions.
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static Field
    getField(Class<?> clazz, String target)
    Finds a field by name in the given class using reflection.
    static Method
    getMethod(Class<?> clazz, String target)
    Finds a method by name in the given class using reflection.
    static Object
    getNmsEntityPlayer(org.bukkit.entity.Player bukkitPlayer)
    Gets the NMS EntityPlayer object for a Bukkit Player using reflection.
    static String
    nmsPackageFor(valorless.valorlessutils.Server.Version version)
    Returns the NMS package name for the given Minecraft version.
  • Method Details

    • nmsPackageFor

      static String nmsPackageFor(valorless.valorlessutils.Server.Version version)
      Returns the NMS package name for the given Minecraft version. Used to construct fully qualified class names for reflection.
      Parameters:
      version - The Minecraft server version.
      Returns:
      The NMS package name string.
    • getNmsEntityPlayer

      static Object getNmsEntityPlayer(org.bukkit.entity.Player bukkitPlayer) throws Exception
      Gets the NMS EntityPlayer object for a Bukkit Player using reflection.
      Parameters:
      bukkitPlayer - The Bukkit Player instance.
      Returns:
      The NMS EntityPlayer object.
      Throws:
      Exception - If reflection fails or the class is not found.
    • getField

      static Field getField(Class<?> clazz, String target)
      Finds a field by name in the given class using reflection. Searches both public and declared fields (case-insensitive).
      Parameters:
      clazz - The class to search.
      target - The field name to find.
      Returns:
      The Field object if found, or null if not found.
    • getMethod

      static Method getMethod(Class<?> clazz, String target)
      Finds a method by name in the given class using reflection. Searches both public and declared methods (case-insensitive).
      Parameters:
      clazz - The class to search.
      target - The method name to find.
      Returns:
      The Method object if found, or null if not found.