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

Commit d4482c2

Browse files
committed
Fix Bukkit to be compatible with 1.13+ properly since they changed the PluginMessage system.
1 parent 33d8588 commit d4482c2

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

blccpsapibukkit/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>badlionclientclickspersecondapi</artifactId>
77
<groupId>net.badlion</groupId>
8-
<version>1.2.0</version>
8+
<version>1.2.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

blccpsapibukkit/src/main/java/net/badlion/blccpsapibukkit/listener/PlayerListener.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

blccpsapibungee/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>badlionclientclickspersecondapi</artifactId>
77
<groupId>net.badlion</groupId>
8-
<version>1.2.0</version>
8+
<version>1.2.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<groupId>net.badlion</groupId>
99
<artifactId>badlionclientclickspersecondapi</artifactId>
1010
<packaging>pom</packaging>
11-
<version>1.2.0</version>
11+
<version>1.2.1</version>
1212

1313
<modules>
1414
<module>blccpsapibungee</module>

0 commit comments

Comments
 (0)