Use #getNMSClass in #sendPacket instead of Class#forName

This commit is contained in:
Eric 2016-08-17 13:16:37 +02:00
parent efaec3cd93
commit f8dd53bf31

View File

@ -201,14 +201,19 @@ public class Utils {
return false; return false;
} }
Class<?> packetClass = Class.forName("net.minecraft.server." + getServerVersion() + ".Packet"); Class<?> packetClass = getNMSClass("Packet");
if (packetClass == null) {
plugin.debug("Failed to send packet: Could not find Packet class");
return false;
}
Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player); Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player);
Object playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer); Object playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
playerConnection.getClass().getMethod("sendPacket", packetClass).invoke(playerConnection, packet); playerConnection.getClass().getMethod("sendPacket", packetClass).invoke(playerConnection, packet);
return true; return true;
} catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException e) {
plugin.getLogger().severe("Failed to send packet " + packet.getClass().getName()); plugin.getLogger().severe("Failed to send packet " + packet.getClass().getName());
plugin.debug("Failed to send packet " + packet.getClass().getName()); plugin.debug("Failed to send packet " + packet.getClass().getName());
plugin.debug(e); plugin.debug(e);