Because different version of minecraft uses different package, (net.minecraft.server.1_8_R_1, .1_8_R_2, .1_9_R_1, etc) and in order to make a bukkit plugin cross-version compatible, reflection need to be used. I was trying to make an Anvil GUI, and a packet is need to open the anvil. Originally I uses the following code: (w/o reflection)
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(containerId, "minecraft:anvil", new ChatMessage("hi", new Object[]{}), 0));
Now I changed my code to like this: (using reflection)
getNMSClass("PlayerConnection").getMethod("sendPacket", getNMSClass("Packet")).invoke(getNMSClass("EntityPlayer").getField("playerConnection").get(getEntityHuman(player))
,getNMSClass("PacketPlayOutOpenWindow").getConstructor(int.class,String.class,getNMSClass("IChatBaseComponent")).newInstance(containerId, "minecraft:anvil"
, getNMSClass("ChatMessage").getConstructor(String.class,Object.class).newInstance("hi",new Object[] {},0)));
However I am currently facing the problem that the constructor of ChatMessage uses an Object...
net.minecraft.server.v1_12_R1.ChatMessage.ChatMessage(String arg0, Object... arg1)
So, here's the question... what is the class of Object...
?
Aucun commentaire:
Enregistrer un commentaire