dimanche 9 juin 2019

Reflection: NoSuchMethodException

I am coding a bukkit plugin with reflections to add a string to the tablist, but there is an error.

The code of the original class: https://github.com/Attano/Spigot-1.8/blob/master/net/minecraft/server/v1_8_R3/PacketPlayOutPlayerInfo.java

I am using Java 8 and Spigot 1.8.8.

Object[] iChatBaseComponentArray = (Object[]) ReflectUtils.getCraftClass("util.CraftChatMessage").getMethod("fromString", String.class).invoke(ReflectUtils.getCraftClass("util.CraftChatMessage"), name);
Class<?> enumGamemode = ReflectUtils.getVersion().startsWith("v1_8") ? ReflectUtils.getNMSClass("WorldSettings").getClasses()[0] : ReflectUtils.getNMSClass("EnumGamemode");
Object packet = ReflectUtils.getNMSClass("PacketPlayOutPlayerInfo").newInstance();
Object playerInfoData = packet.getClass().getClasses()[0].getConstructor(GameProfile.class, int.class, enumGamemode, ReflectUtils.getNMSClass("IChatBaseComponent")).newInstance(new GameProfile(UUIDFetcher.getUUID(name), "§8[§cOffline§8] §7" + name), 1, Enum.class.getMethod("valueOf", String.class).invoke(enumGamemode, "NOT_SET"), iChatBaseComponentArray[0]);

ReflectUtils.setField(playerInfoData.getClass(), "b", Arrays.asList(name));

ReflectUtils.setField(packet.getClass(), "a", Enum.class.getMethod("valueOf", String.class).invoke(ReflectUtils.getNMSClass("EnumPlayerInfoAction"), "REMOVE_PLAYER"));
ReflectUtils.setField(packet.getClass(), "b", Arrays.asList(playerInfoData));

Utils.sendPacket(p, packet);

My error message:

java.lang.NoSuchMethodException: net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo$PlayerInfoData.<init>(com.mojang.authlib.GameProfile, int, net.minecraft.server.v1_8_R3.WorldSettings$EnumGamemode, net.minecraft.server.v1_8_R3.IChatBaseComponent)





Aucun commentaire:

Enregistrer un commentaire