mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-12-23 09:31:46 +00: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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user