Class ReflectUtils

java.lang.Object
valorless.rarespawns.utils.ReflectUtils

public class ReflectUtils extends Object
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.
  • Constructor Details

    • ReflectUtils

      public ReflectUtils()
  • Method Details

    • nmsPackageFor

      public 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

      public 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

      public 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

      public 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.