-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental | Update Skull&Renames&Optimize [skip]
- Loading branch information
1 parent
973ccc4
commit 9436bc5
Showing
12 changed files
with
104 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
...ect/module-item/src/main/kotlin/cn/fd/ratziel/module/item/impl/component/util/HeadUtil.kt
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...ct/module-item/src/main/kotlin/cn/fd/ratziel/module/item/impl/component/util/SkullUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
@file:OptIn(ExperimentalSerializationApi::class) | ||
|
||
package cn.fd.ratziel.module.item.impl.component.util | ||
|
||
import cn.fd.ratziel.module.item.impl.BukkitMaterial | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
import org.bukkit.inventory.ItemStack | ||
import org.bukkit.inventory.meta.SkullMeta | ||
import taboolib.library.xseries.profiles.builder.XSkull | ||
import taboolib.library.xseries.profiles.objects.Profileable | ||
import java.util.concurrent.CompletableFuture | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
typealias SkullData = @Serializable(SkullUtil.Serializer::class) ItemStack | ||
|
||
/** | ||
* SkullUtil - 头颅工具 | ||
* | ||
* @author TheFloodDragon | ||
* @since 2024/8/12 16:13 | ||
*/ | ||
object SkullUtil { | ||
|
||
/** | ||
* 头颅缓存 | ||
*/ | ||
private val CACHE: MutableMap<String, CompletableFuture<SkullData>> = ConcurrentHashMap() | ||
|
||
fun fetchSkull(profileStr: String): ItemStack { | ||
return fetchSkullFuture(profileStr).get() | ||
} | ||
|
||
fun fetchSkullFuture(profileStr: String): CompletableFuture<SkullData> { | ||
return CACHE.computeIfAbsent(profileStr) { generateSkullItem(profileStr) } | ||
} | ||
|
||
fun generateSkullItem(profileStr: String): CompletableFuture<SkullData> { | ||
return XSkull.createItem().profile(Profileable.detect(profileStr)).applyAsync() | ||
} | ||
|
||
fun fetchSkull(skullMeta: SkullMeta): SkullData { | ||
return ItemStack(BukkitMaterial.PLAYER_HEAD).apply { itemMeta = skullMeta } | ||
} | ||
|
||
fun fetchProfileString(skullItem: ItemStack): String? { | ||
return XSkull.of(skullItem).profileString | ||
} | ||
|
||
object Serializer : KSerializer<SkullData> { | ||
|
||
override val descriptor = PrimitiveSerialDescriptor("item.SkullData", PrimitiveKind.STRING) | ||
|
||
override fun deserialize(decoder: Decoder): SkullData { | ||
return fetchSkull(decoder.decodeString()) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: SkullData) { | ||
val profileString = fetchProfileString(value) | ||
if (profileString == null) encoder.encodeNull() else encoder.encodeString(profileString) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters