Skip to content

Commit 0c8f86b

Browse files
committed
fix(heads): 适配 Minecraft 1.21+ ResolvableProfile 类型变更
修复 seekTexture 中反射读取 CraftMetaSkull.profile 字段时, 1.21+ 的 ResolvableProfile 类型强转 GameProfile 导致 ClassCastException。 改为先取 Any 再判断实际类型进行兼容处理。
1 parent af8ab8e commit 0c8f86b

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • plugin/src/main/kotlin/trplugins/menu/util/bukkit

plugin/src/main/kotlin/trplugins/menu/util/bukkit/Heads.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,17 @@ object Heads {
126126
meta.owningPlayer?.name?.let { return it }
127127
}
128128

129-
meta.getProperty<GameProfile>("profile")?.properties?.values()?.forEach {
129+
val profileValue = meta.getProperty<Any>("profile") ?: return null
130+
131+
val gameProfile: GameProfile? = if (profileValue is GameProfile) {
132+
profileValue
133+
} else {
134+
// Minecraft 1.21+ 将 profile 字段改为 ResolvableProfile
135+
val optional = runCatching { profileValue.invokeMethod<Any>("gameProfile") }.getOrNull()
136+
runCatching { optional?.invokeMethod<GameProfile>("orElse", null) }.getOrNull()
137+
}
138+
139+
gameProfile?.properties?.values()?.forEach {
130140
if (it.getProperty<String>(NAME) == "textures") return it.getProperty<String>(VALUE)
131141
}
132142
return null

0 commit comments

Comments
 (0)