Skip to content

Commit edce89a

Browse files
committed
feat(hook): 优化SkinsRestorer集成并改进纹理处理
- 在HookSkinsRestorer中添加纹理缓存机制,使用ConcurrentHashMap存储玩家皮肤纹理 - 实现异步加载皮肤纹理,避免主线程阻塞,提升性能 - 添加加载状态跟踪,防止重复请求相同玩家的皮肤数据 - 在Texture模块中添加容错处理,当JSON解析失败时使用回退材质 - 当原始纹理无法解析时自动创建默认材质并设置纹理名称为物品显示名
1 parent b6fc097 commit edce89a

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

plugin/src/main/kotlin/trplugins/menu/module/display/texture/Texture.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ class Texture(
139139
if (type == TextureType.NORMAL) {
140140
if (Regexs.JSON_TEXTURE.find(texture) != null) {
141141
type = TextureType.RAW
142-
if (!dynamic) static = ItemHelper.fromJson(texture)!!
142+
if (!dynamic) static = ItemHelper.fromJson(texture) ?: buildItem(XMaterial.matchXMaterial(FALL_BACK)) {
143+
name = texture
144+
}
143145
}
144146
}
145147
return Texture(raw, type, texture, dynamic, static, meta)

plugin/src/main/kotlin/trplugins/menu/module/internal/hook/impl/HookSkinsRestorer.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package trplugins.menu.module.internal.hook.impl
22

33
import net.skinsrestorer.api.SkinsRestorer
44
import net.skinsrestorer.api.SkinsRestorerProvider
5+
import taboolib.common.platform.function.submit
56
import trplugins.menu.module.internal.hook.HookAbstract
7+
import java.util.concurrent.ConcurrentHashMap
68

79
/**
810
* @author Arasple
@@ -22,14 +24,31 @@ class HookSkinsRestorer : HookAbstract() {
2224
return@lazy skinsRestorer != null
2325
}
2426

27+
private val textureCache = ConcurrentHashMap<String, String>()
28+
private val loading = ConcurrentHashMap.newKeySet<String>()
29+
2530
fun getPlayerSkinTexture(name: String): String? {
31+
val key = name.lowercase()
32+
textureCache[key]?.let {
33+
return it
34+
}
35+
2636
skinsRestorer?.let {
27-
val skinData = it.skinStorage.findOrCreateSkinData(name)
28-
if (skinData.isPresent) {
29-
return skinData.get().property.value
37+
if (loading.add(key)) {
38+
submit(async = true) {
39+
try {
40+
val skinData = it.skinStorage.findOrCreateSkinData(name)
41+
if (skinData.isPresent) {
42+
textureCache[key] = skinData.get().property.value
43+
}
44+
} catch (_: Throwable) {
45+
} finally {
46+
loading.remove(key)
47+
}
48+
}
3049
}
3150
}
3251
return null
3352
}
3453

35-
}
54+
}

0 commit comments

Comments
 (0)