Package valorless.rarespawns.utils
Class ReflectUtils
java.lang.Object
valorless.rarespawns.utils.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldFinds a field by name in the given class using reflection.static MethodFinds a method by name in the given class using reflection.static ObjectgetNmsEntityPlayer(org.bukkit.entity.Player bukkitPlayer) Gets the NMS EntityPlayer object for a Bukkit Player using reflection.static StringnmsPackageFor(valorless.valorlessutils.Server.Version version) Returns the NMS package name for the given Minecraft version.
-
Constructor Details
-
ReflectUtils
public ReflectUtils()
-
-
Method Details
-
nmsPackageFor
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
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
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
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.
-