9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 21:06:31 +00:00

修复1.20.1

This commit is contained in:
XiaoMoMi
2025-04-17 22:44:11 +08:00
parent 4993532215
commit d629245f63
2 changed files with 16 additions and 2 deletions

View File

@@ -1164,9 +1164,19 @@ public class PacketConsumers {
try {
BukkitServerPlayer player = (BukkitServerPlayer) user;
String name = (String) Reflections.field$ServerboundHelloPacket$name.get(packet);
UUID uuid = (UUID) Reflections.field$ServerboundHelloPacket$uuid.get(packet);
player.setName(name);
player.setUUID(uuid);
if (VersionHelper.isVersionNewerThan1_20_2()) {
UUID uuid = (UUID) Reflections.field$ServerboundHelloPacket$uuid.get(packet);
player.setUUID(uuid);
} else {
@SuppressWarnings("unchecked")
Optional<UUID> uuid = (Optional<UUID>) Reflections.field$ServerboundHelloPacket$uuid.get(packet);
if (uuid.isPresent()) {
player.setUUID(uuid.get());
} else {
player.setUUID(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)));
}
}
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to handle ServerboundHelloPacket", e);
}

View File

@@ -6452,8 +6452,12 @@ public class Reflections {
);
public static final Field field$ServerboundHelloPacket$uuid = requireNonNull(
VersionHelper.isVersionNewerThan1_20_2() ?
ReflectionUtils.getDeclaredField(
clazz$ServerboundHelloPacket, UUID.class, 0
) :
ReflectionUtils.getDeclaredField(
clazz$ServerboundHelloPacket, Optional.class, 0
)
);