@@ -29,6 +29,10 @@ public class PlayerListener implements Listener {
2929 private Class <?> packetDataSerializerClass ;
3030 private Constructor <?> packetDataSerializerConstructor ;
3131
32+ // Bukkit 1.13+ support
33+ private Class <?> minecraftKeyClass ;
34+ private Constructor <?> minecraftKeyConstructor ;
35+
3236 private Method wrappedBufferMethod ;
3337
3438 public PlayerListener (BlcCpsApiBukkit plugin ) {
@@ -103,7 +107,22 @@ public PlayerListener(BlcCpsApiBukkit plugin) {
103107 // If we made it this far in theory we are on at least 1.8
104108 this .packetPlayOutCustomPayloadConstructor = this .getConstructor (packetPlayOutCustomPayloadClass , String .class , this .packetDataSerializerClass );
105109 if (this .packetPlayOutCustomPayloadConstructor == null ) {
106- throw new RuntimeException ("Failed to find PacketPlayOutCustomPayload constructor 2x" );
110+ // Ok we are in 1.13 or higher now...
111+ this .minecraftKeyClass = this .getClass ("net.minecraft.server." + this .versionSuffix + ".MinecraftKey" );
112+ if (this .minecraftKeyClass == null ) {
113+ throw new RuntimeException ("Failed to find PacketPlayOutCustomPayload constructor or MinecraftKey class" );
114+ }
115+
116+ this .minecraftKeyConstructor = this .getConstructor (this .minecraftKeyClass , String .class , String .class );
117+ if (this .minecraftKeyConstructor == null ) {
118+ throw new RuntimeException ("Failed to find PacketPlayOutCustomPayload constructor or MinecraftKey constructor" );
119+ }
120+
121+ // If we still can't find this...unknown version
122+ this .packetPlayOutCustomPayloadConstructor = this .getConstructor (packetPlayOutCustomPayloadClass , this .minecraftKeyClass , this .packetDataSerializerClass );
123+ if (this .packetPlayOutCustomPayloadConstructor == null ) {
124+ throw new RuntimeException ("Failed to find PacketPlayOutCustomPayload constructor" );
125+ }
107126 }
108127 }
109128
@@ -134,13 +153,19 @@ public void onPlayerJoin(PlayerJoinEvent event) {
134153 try {
135154 Object packet ;
136155
137- // Newer MC version, setup ByteBuf object
138- if (this .packetDataSerializerClass != null ) {
156+ // 1.13+
157+ if (this .minecraftKeyClass != null ) {
158+ Object minecraftKey = this .minecraftKeyConstructor .newInstance ("badlion" , "cps" );
159+ Object byteBuf = this .wrappedBufferMethod .invoke (null , (Object ) message );
160+ Object packetDataSerializer = this .packetDataSerializerConstructor .newInstance (byteBuf );
161+
162+ packet = this .packetPlayOutCustomPayloadConstructor .newInstance (minecraftKey , packetDataSerializer );
163+ } else if (this .packetDataSerializerClass != null ) { // 1.8+
139164 Object byteBuf = this .wrappedBufferMethod .invoke (null , (Object ) message );
140165 Object packetDataSerializer = this .packetDataSerializerConstructor .newInstance (byteBuf );
141166
142167 packet = this .packetPlayOutCustomPayloadConstructor .newInstance (channel , packetDataSerializer );
143- } else {
168+ } else { // 1.7
144169 // Work our magic to make the packet
145170 packet = this .packetPlayOutCustomPayloadConstructor .newInstance (channel , message );
146171 }
0 commit comments