From f8dd53bf319cb2aa01bed1330d8d59ecc7447260 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 17 Aug 2016 13:16:37 +0200 Subject: [PATCH] Use #getNMSClass in #sendPacket instead of Class#forName --- src/main/java/de/epiceric/shopchest/utils/Utils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/utils/Utils.java b/src/main/java/de/epiceric/shopchest/utils/Utils.java index 692774b..d4855c6 100644 --- a/src/main/java/de/epiceric/shopchest/utils/Utils.java +++ b/src/main/java/de/epiceric/shopchest/utils/Utils.java @@ -201,14 +201,19 @@ public class Utils { 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 playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer); playerConnection.getClass().getMethod("sendPacket", packetClass).invoke(playerConnection, packet); 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.debug("Failed to send packet " + packet.getClass().getName()); plugin.debug(e);