@@ -30,6 +30,8 @@ public class PlayerListener implements Listener {
3030
3131 private Class <?> packetPlayOutCustomPayloadClass ;
3232 private Constructor <?> packetPlayOutCustomPayloadConstructor ;
33+ private Constructor <?> packetPlayOutMinecraftKeyConstructor ;
34+ private boolean useMinecraftKey ;
3335
3436 // Bukkit 1.8+ support
3537 private Class <?> packetDataSerializerClass ;
@@ -110,7 +112,17 @@ public PlayerListener(BlcModApiBukkit plugin) {
110112 // If we made it this far in theory we are on at least 1.8
111113 this .packetPlayOutCustomPayloadConstructor = this .getConstructor (this .packetPlayOutCustomPayloadClass , String .class , this .packetDataSerializerClass );
112114 if (this .packetPlayOutCustomPayloadConstructor == null ) {
113- throw new RuntimeException ("Failed to find PacketPlayOutCustomPayload constructor 2x" );
115+ Class <?> minecraftKeyClass = this .getClass ("net.minecraft.server." + this .versionSuffix + ".MinecraftKey" );
116+
117+ // Fix for Paper in newer versions
118+ this .packetPlayOutCustomPayloadConstructor = this .getConstructor (this .packetPlayOutCustomPayloadClass , minecraftKeyClass , this .packetDataSerializerClass );
119+
120+ if (this .packetPlayOutCustomPayloadConstructor == null ) {
121+ throw new RuntimeException ("Failed to find PacketPlayOutCustomPayload constructor 2x" );
122+ } else {
123+ this .useMinecraftKey = true ;
124+ this .packetPlayOutMinecraftKeyConstructor = this .getConstructor (minecraftKeyClass , String .class );
125+ }
114126 }
115127 }
116128
@@ -140,13 +152,17 @@ public void onPlayerJoin(PlayerJoinEvent event) {
140152
141153 try {
142154 Object packet ;
143-
144155 // Newer MC version, setup ByteBuf object
145156 if (this .packetDataSerializerClass != null ) {
146157 Object byteBuf = this .wrappedBufferMethod .invoke (null , message );
147158 Object packetDataSerializer = this .packetDataSerializerConstructor .newInstance (byteBuf );
148159
149- packet = this .packetPlayOutCustomPayloadConstructor .newInstance (channel , packetDataSerializer );
160+ if (this .useMinecraftKey ) {
161+ Object key = this .packetPlayOutMinecraftKeyConstructor .newInstance (channel );
162+ packet = this .packetPlayOutCustomPayloadConstructor .newInstance (key , packetDataSerializer );
163+ } else {
164+ packet = this .packetPlayOutCustomPayloadConstructor .newInstance (channel , packetDataSerializer );
165+ }
150166 } else {
151167 // Work our magic to make the packet
152168 packet = this .packetPlayOutCustomPayloadConstructor .newInstance (channel , message );
0 commit comments