Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Fix Bukkit to be compatible with 1.13+ properly since they changed th…
Browse files Browse the repository at this point in the history
…e PluginMessage system.
  • Loading branch information
mastergberry committed May 20, 2019
1 parent 33d8588 commit d4482c2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion blccpsapibukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>badlionclientclickspersecondapi</artifactId>
<groupId>net.badlion</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class PlayerListener implements Listener {
private Class<?> packetDataSerializerClass;
private Constructor<?> packetDataSerializerConstructor;

// Bukkit 1.13+ support
private Class<?> minecraftKeyClass;
private Constructor<?> minecraftKeyConstructor;

private Method wrappedBufferMethod;

public PlayerListener(BlcCpsApiBukkit plugin) {
Expand Down Expand Up @@ -103,7 +107,22 @@ public PlayerListener(BlcCpsApiBukkit plugin) {
// If we made it this far in theory we are on at least 1.8
this.packetPlayOutCustomPayloadConstructor = this.getConstructor(packetPlayOutCustomPayloadClass, String.class, this.packetDataSerializerClass);
if (this.packetPlayOutCustomPayloadConstructor == null) {
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor 2x");
// Ok we are in 1.13 or higher now...
this.minecraftKeyClass = this.getClass("net.minecraft.server." + this.versionSuffix + ".MinecraftKey");
if (this.minecraftKeyClass == null) {
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor or MinecraftKey class");
}

this.minecraftKeyConstructor = this.getConstructor(this.minecraftKeyClass, String.class, String.class);
if (this.minecraftKeyConstructor == null) {
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor or MinecraftKey constructor");
}

// If we still can't find this...unknown version
this.packetPlayOutCustomPayloadConstructor = this.getConstructor(packetPlayOutCustomPayloadClass, this.minecraftKeyClass, this.packetDataSerializerClass);
if (this.packetPlayOutCustomPayloadConstructor == null) {
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor");
}
}
}

Expand Down Expand Up @@ -134,13 +153,19 @@ public void onPlayerJoin(PlayerJoinEvent event) {
try {
Object packet;

// Newer MC version, setup ByteBuf object
if (this.packetDataSerializerClass != null) {
// 1.13+
if (this.minecraftKeyClass != null) {
Object minecraftKey = this.minecraftKeyConstructor.newInstance("badlion", "cps");
Object byteBuf = this.wrappedBufferMethod.invoke(null, (Object) message);
Object packetDataSerializer = this.packetDataSerializerConstructor.newInstance(byteBuf);

packet = this.packetPlayOutCustomPayloadConstructor.newInstance(minecraftKey, packetDataSerializer);
} else if (this.packetDataSerializerClass != null) { // 1.8+
Object byteBuf = this.wrappedBufferMethod.invoke(null, (Object) message);
Object packetDataSerializer = this.packetDataSerializerConstructor.newInstance(byteBuf);

packet = this.packetPlayOutCustomPayloadConstructor.newInstance(channel, packetDataSerializer);
} else {
} else { // 1.7
// Work our magic to make the packet
packet = this.packetPlayOutCustomPayloadConstructor.newInstance(channel, message);
}
Expand Down
2 changes: 1 addition & 1 deletion blccpsapibungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>badlionclientclickspersecondapi</artifactId>
<groupId>net.badlion</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>net.badlion</groupId>
<artifactId>badlionclientclickspersecondapi</artifactId>
<packaging>pom</packaging>
<version>1.2.0</version>
<version>1.2.1</version>

<modules>
<module>blccpsapibungee</module>
Expand Down

0 comments on commit d4482c2

Please sign in to comment.