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

Commit 140ed1b

Browse files
committed
Fix Bukkit to be compatible with 1.13+ properly since they changed the PluginMessage system and also change output jar name.
1 parent 5e6ba49 commit 140ed1b

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.badlion</groupId>
88
<artifactId>timer-api</artifactId>
9-
<version>1.2.0</version>
9+
<version>1.2.1</version>
1010

1111
<packaging>jar</packaging>
1212

@@ -27,6 +27,20 @@
2727
</dependencies>
2828

2929
<build>
30+
<defaultGoal>clean install</defaultGoal>
31+
<finalName>badlionclienttimerapi</finalName>
32+
<sourceDirectory>src/main/java</sourceDirectory>
33+
<resources>
34+
<resource>
35+
<targetPath>.</targetPath>
36+
<filtering>true</filtering>
37+
<directory>src/main/resources/</directory>
38+
<includes>
39+
<include>*.yml</include>
40+
</includes>
41+
</resource>
42+
</resources>
43+
3044
<plugins>
3145
<plugin>
3246
<groupId>org.apache.maven.plugins</groupId>

src/main/java/net/badlion/timers/impl/NmsManager.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public class NmsManager {
2525
private static Class<?> packetDataSerializerClass;
2626
private static Constructor<?> packetDataSerializerConstructor;
2727

28+
// Bukkit 1.13+ support
29+
private static Class<?> minecraftKeyClass;
30+
private static Constructor<?> minecraftKeyConstructor;
31+
2832
private static Method wrappedBufferMethod;
2933

3034
public static void init(TimerPlugin plugin) {
@@ -100,7 +104,22 @@ public static void init(TimerPlugin plugin) {
100104
// If we made it this far in theory we are on at least 1.8
101105
NmsManager.packetPlayOutCustomPayloadConstructor = NmsManager.getConstructor(packetPlayOutCustomPayloadClass, String.class, NmsManager.packetDataSerializerClass);
102106
if (NmsManager.packetPlayOutCustomPayloadConstructor == null) {
103-
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor 2x");
107+
// Ok we are in 1.13 or higher now...
108+
NmsManager.minecraftKeyClass = NmsManager.getClass("net.minecraft.server." + NmsManager.versionSuffix + ".MinecraftKey");
109+
if (NmsManager.minecraftKeyClass == null) {
110+
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor or MinecraftKey class");
111+
}
112+
113+
NmsManager.minecraftKeyConstructor = NmsManager.getConstructor(NmsManager.minecraftKeyClass, String.class, String.class);
114+
if (NmsManager.minecraftKeyConstructor == null) {
115+
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor or MinecraftKey constructor");
116+
}
117+
118+
// If we still can't find this...unknown version
119+
NmsManager.packetPlayOutCustomPayloadConstructor = NmsManager.getConstructor(packetPlayOutCustomPayloadClass, NmsManager.minecraftKeyClass, NmsManager.packetDataSerializerClass);
120+
if (NmsManager.packetPlayOutCustomPayloadConstructor == null) {
121+
throw new RuntimeException("Failed to find PacketPlayOutCustomPayload constructor");
122+
}
104123
}
105124
}
106125

@@ -124,13 +143,19 @@ public static void sendPluginMessage(Player player, String channel, byte[] messa
124143
try {
125144
Object packet;
126145

127-
// Newer MC version, setup ByteBuf object
128-
if (NmsManager.packetDataSerializerClass != null) {
146+
// 1.13+
147+
if (NmsManager.minecraftKeyClass != null) {
148+
Object minecraftKey = NmsManager.minecraftKeyConstructor.newInstance("badlion", "timers");
149+
Object byteBuf = NmsManager.wrappedBufferMethod.invoke(null, (Object) message);
150+
Object packetDataSerializer = NmsManager.packetDataSerializerConstructor.newInstance(byteBuf);
151+
152+
packet = NmsManager.packetPlayOutCustomPayloadConstructor.newInstance(minecraftKey, packetDataSerializer);
153+
} else if (NmsManager.packetDataSerializerClass != null) { // 1.8+
129154
Object byteBuf = NmsManager.wrappedBufferMethod.invoke(null, (Object) message);
130155
Object packetDataSerializer = NmsManager.packetDataSerializerConstructor.newInstance(byteBuf);
131156

132157
packet = NmsManager.packetPlayOutCustomPayloadConstructor.newInstance(channel, packetDataSerializer);
133-
} else {
158+
} else { // 1.7
134159
// Work our magic to make the packet
135160
packet = NmsManager.packetPlayOutCustomPayloadConstructor.newInstance(channel, message);
136161
}

0 commit comments

Comments
 (0)