mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-11-23 11:07:05 +01:00
Use #getNMSClass in #sendPacket instead of Class#forName
This commit is contained in:
parent
efaec3cd93
commit
f8dd53bf31
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user