Package xyz.xenondevs.particle.utils
Class ReflectionUtils
java.lang.Object
xyz.xenondevs.particle.utils.ReflectionUtils
- Since:
- 30.08.2018
- Author:
- ByteZ
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
The current Minecraft version as an int.static final PlayerConnectionCache
A cache for playerconnections. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 existsstatic Class<?>
getClassSafe
(String path) Gets a class but returns null instead of throwing aClassNotFoundException
.static Constructor
getConstructorOrNull
(Class targetClass, Class... parameterTypes) Gets a constructor without throwing exceptionsstatic Class<?>
getCraftBukkitClass
(String path) Method to directly get the class object over the pathstatic String
static String
getCraftBukkitPath
(String path) Gets the craftbukkit path of a class without depending on versionsstatic Object
getEntityHandle
(org.bukkit.entity.Entity entity) Gets the Entity instance of a CraftEntitystatic Field
getFieldOrNull
(Class targetClass, String fieldName, boolean declared) Method to not get disturbed by the forced try catch blockstatic Method
getMethodOrNull
(Class targetClass, String methodName, Class<?>... parameterTypes) Method to not get disturbed by the forced try catch blockstatic Object
getMinecraftKey
(String key) Creates a new MinecraftKey with the given data.static String
static Class<?>
getNMSClass
(String path) Directly gets the class object over the pathstatic String
getNMSPath
(String path) Gets the nms path of a class without depending on versionsstatic Object
getPlayerConnection
(org.bukkit.entity.Player target) Gets the PlayerConnection of aPlayer
static Object
getPlayerHandle
(org.bukkit.entity.Player player) Gets the EntityPlayer instance of a CraftPlayerstatic org.bukkit.plugin.Plugin
Gets the plugin ParticleLib uses to register eventListeners
and starttasks
.static InputStream
getResourceStreamSafe
(String resource) Gets theInputStream
of a resource.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
Gets the specified Field over the specified fieldName and the given targetClass.static <T> T
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 eventListeners
and starttasks
.static void
writeDeclaredField
(Class targetClass, String fieldName, Object object, Object value) Gets the specified declaredField
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 specifiedField
over the specified fieldName and the given targetClass.static void
writeField
(Field field, Object object, Object value)
-
Field Details
-
MINECRAFT_VERSION
public static final double MINECRAFT_VERSIONThe current Minecraft version as an int. -
PLAYER_CONNECTION_CACHE
A cache for playerconnections.
-
-
Constructor Details
-
ReflectionUtils
public ReflectionUtils()
-
-
Method Details
-
getPlugin
public static org.bukkit.plugin.Plugin getPlugin()Gets the plugin ParticleLib uses to register eventListeners
and starttasks
.- Returns:
- the plugin ParticleLib should use
-
setPlugin
public static void setPlugin(org.bukkit.plugin.Plugin plugin) Sets the plugin ParticleLib uses to register eventListeners
and starttasks
.- Parameters:
plugin
- the plugin ParticleLib should use
-
getClassSafe
Gets a class but returns null instead of throwing aClassNotFoundException
.- Parameters:
path
- the path of the class- Returns:
- the class. If the class isn't found null
-
getNMSPath
Gets the nms path of a class without depending on versionse.g. getNMSPath("Block") = "net.minecraft.server.v1_14_R1.Block" getNMSPath("Entity") = "net.minecraft.server.v1_12_R1.Entity"
- Parameters:
path
- the path that should be added to the nms path- Returns:
- the nms path
-
getNMSClass
Directly gets the class object over the path- Parameters:
path
- the path of the class- Returns:
- the class. If the class isn't found null
-
getCraftBukkitPath
Gets the craftbukkit path of a class without depending on versionse.g. getCraftBukkitPath("CraftChunk") = "org.bukkit.craftbukkit.v1_15_R1.CraftChunk" getCraftBukkitPath("event.CraftEventFactory") = "org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory"
- Parameters:
path
- the path that should be added to the craftbukkit path- Returns:
- the craftbukkit path
-
getCraftBukkitClass
Method to directly get the class object over the path- Parameters:
path
- the path of the class- Returns:
- the class. If the class isn't found null
-
getMethodOrNull
public static Method getMethodOrNull(Class targetClass, String methodName, Class<?>... parameterTypes) Method to not get disturbed by the forced try catch block -
getFieldOrNull
Method to not get disturbed by the forced try catch block -
getConstructorOrNull
Gets a constructor without throwing exceptions- Parameters:
targetClass
- theClass
theConstructor
is inparameterTypes
- the parameterTypes of theConstructor
- Returns:
- if found the target
Constructor
. If not found null.
-
existsClass
Checks if a class exists- Parameters:
path
- the path of the class that should be checked- Returns:
- true if the defined class exists
-
readField
-
readField
-
readDeclaredField
-
readDeclaredField
-
writeDeclaredField
public static void writeDeclaredField(Class targetClass, String fieldName, Object object, Object value) -
writeDeclaredField
-
writeField
-
writeField
-
getNetMinecraftServerPackagePath
- Returns:
- the nms path
-
getCraftBukkitPackagePath
- Returns:
- the craftbukkit path
-
getMinecraftKey
Creates a new MinecraftKey with the given data.- Parameters:
key
- the data that should be used in the constructor of the key.- Returns:
- the new MinecraftKey
-
createVector3fa
Creates a new Vector3fa instance.- Parameters:
x
- x value of the vector.y
- y value of the vector.z
- z value of the vector.- Returns:
- a Vector3fa instance with the specified coordinates.
-
createBlockPosition
Creates a new BlockPosition.- Parameters:
location
- theLocation
of the block.- Returns:
- the BlockPosition of the location
-
getEntityHandle
Gets the Entity instance of a CraftEntity- Parameters:
entity
- the CraftEntity- Returns:
- the Entity instance of the defined CraftEntity or
null
if either the given parameter is invalid or an error occurs.
-
getPlayerHandle
Gets the EntityPlayer instance of a CraftPlayer- Parameters:
player
- the CraftPlayer- Returns:
- the EntityPlayer instance of the defined CraftPlayer or
null
if either the given parameter is invalid or an error occurs.
-
getPlayerConnection
Gets the PlayerConnection of aPlayer
- Parameters:
target
- the targetPlayer
- Returns:
- the PlayerConnection of the specified target
Player
-
sendPacket
Sends a packet to a defined player.- Parameters:
player
- the player that should receive the packetpacket
- the packet that should be sent
-
getResourceStreamSafe
Gets theInputStream
of a resource.- Parameters:
resource
- the name of the resource- Returns:
- the
InputStream
of the resource
-