public final class ReflectionUtils extends Object
ParticleConstants| Modifier and Type | Field and Description |
|---|---|
static int |
MINECRAFT_VERSION
The current Minecraft version as an int.
|
static PlayerConnectionCache |
PLAYER_CONNECTION_CACHE
A cache for playerconnections.
|
| Constructor and Description |
|---|
ReflectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Object |
createBlockPosition(org.bukkit.Location location)
Creates a new BlockPosition.
|
static Object |
createVector3fa(float x,
float y,
float z)
Creates a new Vector3fa instance.
|
static boolean |
existsClass(String path)
Checks if a class exists
|
static Class<?> |
getClassSafe(String path)
Gets a class but returns null instead of throwing
a
ClassNotFoundException. |
static Constructor |
getConstructorOrNull(Class targetClass,
Class... parameterTypes)
Gets a constructor without throwing exceptions
|
static Class<?> |
getCraftBukkitClass(String path)
Method to directly get the class object over the path
|
static String |
getCraftBukkitPackagePath() |
static String |
getCraftBukkitPath(String path)
Gets the craftbukkit path of a class without depending on versions
|
static Field |
getFieldOrNull(Class targetClass,
String fieldName,
boolean declared)
Method to not get disturbed by the forced try catch block
|
static Method |
getMethodOrNull(Class targetClass,
String methodName,
Class<?>... parameterTypes)
Method to not get disturbed by the forced try catch block
|
static Object |
getMinecraftKey(String key)
Creates a new MinecraftKey with the given data.
|
static String |
getNetMinecraftServerPackagePath() |
static Class<?> |
getNMSClass(String path)
Directly gets the class object over the path
|
static String |
getNMSPath(String path)
Gets the nms path of a class without depending on versions
|
static Object |
getPlayerConnection(org.bukkit.entity.Player target)
Gets the PlayerConnection of a
Player |
static Object |
getPlayerHandle(org.bukkit.entity.Player player)
Gets the EntityPlayer instance of a CraftPlayer
|
static org.bukkit.plugin.Plugin |
getPlugin()
Gets the plugin ParticleLib uses to register
event
Listeners and start
tasks. |
static Object |
readDeclaredField(Class targetClass,
String fieldName,
Object object)
Gets the specified declared Field over the specified fieldName and the given
targetClass.
|
static <T> T |
readDeclaredField(Field field,
Object object)
|
static Object |
readField(Class targetClass,
String fieldName,
Object object)
Gets the specified Field over the specified fieldName and the given targetClass.
|
static <T> T |
readField(Field field,
Object object)
|
static void |
sendPacket(org.bukkit.entity.Player player,
Object packet)
Sends a packet to a defined player.
|
static void |
setPlugin(org.bukkit.plugin.Plugin plugin)
Sets the plugin ParticleLib uses to register
event
Listeners and start
tasks. |
static void |
writeDeclaredField(Class targetClass,
String fieldName,
Object object,
Object value)
Gets the specified declared
Field over the specified fieldName and the given
targetClass. |
static void |
writeDeclaredField(Field field,
Object object,
Object value)
|
static void |
writeField(Class targetClass,
String fieldName,
Object object,
Object value)
Gets the specified
Field over the specified fieldName and the given
targetClass. |
static void |
writeField(Field field,
Object object,
Object value)
|
public static final int MINECRAFT_VERSION
public static final PlayerConnectionCache PLAYER_CONNECTION_CACHE
public static org.bukkit.plugin.Plugin getPlugin()
Listeners and start
tasks.public static void setPlugin(org.bukkit.plugin.Plugin plugin)
Listeners and start
tasks.plugin - the plugin ParticleLib should usepublic static Class<?> getClassSafe(String path)
ClassNotFoundException.path - the path of the classpublic static String getNMSPath(String path)
e.g. getNMSPath("Block") = "net.minecraft.server.v1_14_R1.Block" getNMSPath("Entity") = "net.minecraft.server.v1_12_R1.Entity"
path - the path that should be added
to the nms pathpublic static Class<?> getNMSClass(String path)
path - the path of the classpublic static String getCraftBukkitPath(String path)
e.g. getCraftBukkitPath("CraftChunk") = "org.bukkit.craftbukkit.v1_15_R1.CraftChunk" getCraftBukkitPath("event.CraftEventFactory") = "org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory"
path - the path that should be added to the craftbukkit pathpublic static Class<?> getCraftBukkitClass(String path)
path - the path of the classpublic static Method getMethodOrNull(Class targetClass, String methodName, Class<?>... parameterTypes)
public static Field getFieldOrNull(Class targetClass, String fieldName, boolean declared)
public static Constructor getConstructorOrNull(Class targetClass, Class... parameterTypes)
targetClass - the Class the Constructor is inparameterTypes - the parameterTypes of the ConstructorConstructor. If not found null.public static boolean existsClass(String path)
path - the path of the class that should be checkedpublic static Object readDeclaredField(Class targetClass, String fieldName, Object object)
public static void writeDeclaredField(Class targetClass, String fieldName, Object object, Object value)
public static void writeField(Class targetClass, String fieldName, Object object, Object value)
public static String getNetMinecraftServerPackagePath()
public static String getCraftBukkitPackagePath()
public static Object getMinecraftKey(String key)
key - the data that should be
used in the constructor
of the key.public static Object createVector3fa(float x, float y, float z)
x - x value of the vector.y - y value of the vector.z - z value of the vector.public static Object createBlockPosition(org.bukkit.Location location)
location - the Location of the block.public static Object getPlayerHandle(org.bukkit.entity.Player player)
player - the CraftPlayernull if either the given parameter is invalid or an error occurs.public static Object getPlayerConnection(org.bukkit.entity.Player target)
Playertarget - the target PlayerPlayerpublic static void sendPacket(org.bukkit.entity.Player player,
Object packet)
player - the player that should receive the packetpacket - the packet that should be sentCopyright © 2021. All rights reserved.