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
FieldsModifier and TypeFieldDescriptionstatic final doubleThe current Minecraft version as an int.static final PlayerConnectionCacheA cache for playerconnections. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectcreateBlockPosition(org.bukkit.Location location) Creates a new BlockPosition.static ObjectcreateVector3fa(float x, float y, float z) Creates a new Vector3fa instance.static booleanexistsClass(String path) Checks if a class existsstatic Class<?>getClassSafe(String path) Gets a class but returns null instead of throwing aClassNotFoundException.static ConstructorgetConstructorOrNull(Class targetClass, Class... parameterTypes) Gets a constructor without throwing exceptionsstatic Class<?>getCraftBukkitClass(String path) Method to directly get the class object over the pathstatic Stringstatic StringgetCraftBukkitPath(String path) Gets the craftbukkit path of a class without depending on versionsstatic ObjectgetEntityHandle(org.bukkit.entity.Entity entity) Gets the Entity instance of a CraftEntitystatic FieldgetFieldOrNull(Class targetClass, String fieldName, boolean declared) Method to not get disturbed by the forced try catch blockstatic MethodgetMethodOrNull(Class targetClass, String methodName, Class<?>... parameterTypes) Method to not get disturbed by the forced try catch blockstatic ObjectgetMinecraftKey(String key) Creates a new MinecraftKey with the given data.static Stringstatic Class<?>getNMSClass(String path) Directly gets the class object over the pathstatic StringgetNMSPath(String path) Gets the nms path of a class without depending on versionsstatic ObjectgetPlayerConnection(org.bukkit.entity.Player target) Gets the PlayerConnection of aPlayerstatic ObjectgetPlayerHandle(org.bukkit.entity.Player player) Gets the EntityPlayer instance of a CraftPlayerstatic org.bukkit.plugin.PluginGets the plugin ParticleLib uses to register eventListenersand starttasks.static InputStreamgetResourceStreamSafe(String resource) Gets theInputStreamof a resource.static ObjectreadDeclaredField(Class targetClass, String fieldName, Object object) Gets the specified declared Field over the specified fieldName and the given targetClass.static <T> TreadDeclaredField(Field field, Object object) static ObjectGets the specified Field over the specified fieldName and the given targetClass.static <T> Tstatic voidsendPacket(org.bukkit.entity.Player player, Object packet) Sends a packet to a defined player.static voidsetPlugin(org.bukkit.plugin.Plugin plugin) Sets the plugin ParticleLib uses to register eventListenersand starttasks.static voidwriteDeclaredField(Class targetClass, String fieldName, Object object, Object value) Gets the specified declaredFieldover the specified fieldName and the given targetClass.static voidwriteDeclaredField(Field field, Object object, Object value) static voidwriteField(Class targetClass, String fieldName, Object object, Object value) Gets the specifiedFieldover the specified fieldName and the given targetClass.static voidwriteField(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 eventListenersand starttasks.- Returns:
- the plugin ParticleLib should use
-
setPlugin
public static void setPlugin(org.bukkit.plugin.Plugin plugin) Sets the plugin ParticleLib uses to register eventListenersand 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- theClasstheConstructoris 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- theLocationof 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
nullif 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
nullif 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 theInputStreamof a resource.- Parameters:
resource- the name of the resource- Returns:
- the
InputStreamof the resource
-