dimanche 22 mars 2015

How to call a method from a casted object - Reflection API

I need help using a method from a casted Type in Java. Without reflections it would look like PlayerConnection con = ((CraftPlayer) player).getHandle().playerConnection;, but due to the fact that the API I'm using for this program/plugin, the package suffix changes by version number, so I'm trying to figure out Reflections to get it to work. And later in the code, I'm trying to use the con variable to send it as a packet, using a method inside the PlayerConnection type. So without reflections it would look like con.sendPacket(packet); The packet variable I think I got it.


For background code information, I have already created a method to get the version of the server, and created another method to get the class. So instead of showing Class.forName(); can you type getClass(""), the getClass() method returns Class and already adds the package name inside. For more information this will be an example:



input:
getClass("Packet");

output:
net.minecraft.1_8R2.Packet;


It'll will return the class of that package.






Aucun commentaire:

Enregistrer un commentaire