9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 10:59:07 +00:00

Merge pull request #65 from jhqwqmc/dev

fix(network): 适配 Paper1.21.4-222 版本更改
This commit is contained in:
XiaoMoMi
2025-03-28 01:36:24 +08:00
committed by GitHub
2 changed files with 18 additions and 4 deletions

View File

@@ -906,9 +906,14 @@ public class PacketConsumers {
Object id = Reflections.method$CustomPacketPayload$Type$id.invoke(type);
String channel = id.toString();
if (!channel.equals(NetworkManager.MOD_CHANNEL)) return;
ByteBuf buf = (ByteBuf) Reflections.method$DiscardedPayload$data.invoke(payload);
byte[] data = new byte[buf.readableBytes()];
buf.readBytes(data);
byte[] data;
if (Reflections.method$DiscardedPayload$data != null) {
ByteBuf buf = (ByteBuf) Reflections.method$DiscardedPayload$data.invoke(payload);
data = new byte[buf.readableBytes()];
buf.readBytes(data);
} else {
data = (byte[]) Reflections.method$DiscardedPayload$dataByteArray.invoke(payload);
}
String decodeData = new String(data, StandardCharsets.UTF_8);
if (!decodeData.endsWith("init")) return;
int firstColon = decodeData.indexOf(':');

View File

@@ -5668,11 +5668,20 @@ public class Reflections {
.map(it -> ReflectionUtils.getMethod(it, clazz$ResourceLocation))
.orElse(null);
// 1.20.5+
// 1.20.5~1.21.4#221
public static final Method method$DiscardedPayload$data = Optional.ofNullable(clazz$DiscardedPayload)
.map(it -> ReflectionUtils.getMethod(it, ByteBuf.class))
.orElse(null);
// 1.21.4#222+
// 我tm服了这个 sb paper 你 tmd 乱改签名干什么有病啊
public static final Method method$DiscardedPayload$dataByteArray = Optional.ofNullable(method$DiscardedPayload$data)
.map(m -> (Method) null)
.orElseGet(() -> Optional.ofNullable(clazz$DiscardedPayload)
.map(clazz -> ReflectionUtils.getMethod(clazz, byte[].class))
.orElse(null)
);
public static final Class<?> clazz$ClientboundDisconnectPacket = requireNonNull(
ReflectionUtils.getClazz(
BukkitReflectionUtils.assembleMCClass("network.protocol.common.ClientboundDisconnectPacket"),