Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
跳过 TabooLib 单独处理头
Browse files Browse the repository at this point in the history
现在菜单头显示正常了,但可能部分细节设置还是不好用,代码也不优雅,但总之,它能用了
  • Loading branch information
Ghost-chu committed Jan 21, 2024
1 parent e23f9e9 commit 65be5db
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 44 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ subprojects {

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

// Java 版本设置
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

val archiveName = if (project == rootProject)
Expand Down
69 changes: 53 additions & 16 deletions plugin/src/main/kotlin/trplugins/menu/module/display/item/Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package trplugins.menu.module.display.item

import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.SkullMeta
import org.bukkit.profile.PlayerProfile
import taboolib.module.nms.getName
import taboolib.module.nms.setDisplayName
import taboolib.module.nms.setLore
import taboolib.platform.util.buildItem
import taboolib.platform.util.isAir
import trplugins.menu.api.menu.IItem
Expand All @@ -15,10 +20,10 @@ import trplugins.menu.util.collections.CycleList
* @date 2021/1/25 10:48
*/
class Item(
val texture: CycleList<Texture>,
val name: CycleList<String>,
val lore: CycleList<Lore>,
val meta: Meta
val texture: CycleList<Texture>,
var name: CycleList<String>,
val lore: CycleList<Lore>,
val meta: Meta
) : IItem {

internal val cache = mutableMapOf<Int, ItemStack>()
Expand All @@ -39,28 +44,60 @@ class Item(
return item
}

val itemStack = buildItem(item) {
if (item.itemMeta != null) {
name?.let { this.name = it }
lore?.let { this.lore.addAll(it) }
var itemStack = item.clone();

if (itemStack.hasItemMeta() && itemStack.itemMeta is SkullMeta) {
// Fix taboolib bad skull things
val itemMeta = itemStack.itemMeta;
val tabooLibItem = buildItem(item) {
if (item.itemMeta != null) {
name?.let { this.name = it }
lore?.let { this.lore.addAll(it) }
}
meta.flags(this)
meta.shiny(session, this)

if (meta.hasAmount()) this.amount = meta.amount(session)
}
tabooLibItem.itemMeta?.itemFlags?.forEach{ itemFlag -> itemMeta?.addItemFlags(itemFlag) }
tabooLibItem.itemMeta?.enchants?.forEach { enchant -> itemMeta?.addEnchant(enchant.key, enchant.value.toInt(), true) }
if(tabooLibItem.itemMeta?.hasCustomModelData() == true) {
itemMeta?.setCustomModelData(tabooLibItem.itemMeta?.customModelData)
}
if(tabooLibItem.itemMeta?.hasDisplayName() == true) {
itemMeta?.setDisplayName(tabooLibItem.itemMeta?.displayName)
}else{
itemMeta?.setDisplayName(null)
}
if(tabooLibItem.itemMeta?.hasLore() == true) {
itemMeta?.lore = tabooLibItem.itemMeta?.lore
}else{
itemMeta?.lore = null;
}
meta.flags(this)
meta.shiny(session, this)
itemStack.itemMeta = itemMeta
} else {
itemStack = buildItem(item) {
if (item.itemMeta != null) {
name?.let { this.name = it }
lore?.let { this.lore.addAll(it) }
}
meta.flags(this)
meta.shiny(session, this)

if (meta.hasAmount()) this.amount = meta.amount(session)
}
if (meta.hasAmount()) this.amount = meta.amount(session)
}

}
meta.nbt(session, itemStack)?.run {
itemStack.itemMeta = this
}

return itemStack
}

private fun build(
session: MenuSession,
name: String? = name(session),
lore: List<String>? = lore(session)
session: MenuSession,
name: String? = name(session),
lore: List<String>? = lore(session)
): ItemStack {
val item = generate(session, texture.current(session.id)!!, name, lore, meta)
cache[session.id] = item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package trplugins.menu.module.display.texture

import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.LeatherArmorMeta
Expand All @@ -23,12 +24,12 @@ import trplugins.menu.util.bukkit.ItemHelper
* @date 2021/1/24 11:50
*/
class Texture(
val raw: String,
val type: TextureType,
val texture: String,
val dynamic: Boolean,
private var static: ItemStack?,
val meta: Map<TextureMeta, String>
val raw: String,
val type: TextureType,
val texture: String,
val dynamic: Boolean,
private var static: ItemStack?,
val meta: Map<TextureMeta, String>
) : ITexture {

override fun generate(session: MenuSession): ItemStack {
Expand All @@ -46,22 +47,25 @@ class Texture(
if (itemStack != null) {
if (itemStack.type == Material.AIR || itemStack.type.name.endsWith("_AIR")) {
return itemStack
} else itemStack = buildItem(itemStack) {
meta.forEach { (meta, metaValue) ->
val value = session.parse(metaValue)
when (meta) {
TextureMeta.DATA_VALUE -> damage = value.toIntOrNull() ?: 0
TextureMeta.MODEL_DATA -> customModelData = value.toInt()
TextureMeta.LEATHER_DYE -> color = ItemHelper.serializeColor(value)
TextureMeta.BANNER_PATTERN -> ItemHelper.deserializePattern(this, value)
} else if (itemStack.itemMeta is SkullMeta) {
return itemStack
} else {
itemStack = buildItem(itemStack) {
meta.forEach { (meta, metaValue) ->
val value = session.parse(metaValue)
when (meta) {
TextureMeta.DATA_VALUE -> damage = value.toIntOrNull() ?: 0
TextureMeta.MODEL_DATA -> customModelData = value.toInt()
TextureMeta.LEATHER_DYE -> color = ItemHelper.serializeColor(value)
TextureMeta.BANNER_PATTERN -> ItemHelper.deserializePattern(this, value)
}
}
}
}
if (type == TextureType.NORMAL && !dynamic) {
static = itemStack
}
}

return itemStack ?: FALL_BACK
}

Expand All @@ -80,14 +84,14 @@ class Texture(
// Head Meta
if (itemMeta is SkullMeta) {
val hdb =
if (HookPlugin.getHeadDatabase().isHooked) {
HookPlugin.getHeadDatabase().getId(itemStack)
} else null
if (HookPlugin.getHeadDatabase().isHooked) {
HookPlugin.getHeadDatabase().getId(itemStack)
} else null
val skulls =
if (hdb != null) null
else if (HookPlugin[HookSkulls::class.java].isHooked) {
HookPlugin[HookSkulls::class.java].getId(itemStack)
} else null
if (hdb != null) null
else if (HookPlugin[HookSkulls::class.java].isHooked) {
HookPlugin[HookSkulls::class.java].getId(itemStack)
} else null


return when {
Expand Down Expand Up @@ -156,10 +160,10 @@ class Texture(
} catch (e: Throwable) {
runCatching {
XMaterial.entries.find { it.name.equals(id.toString(), true) }
?: XMaterial.entries.find { it -> it.legacy.any { it == id.toString() } }
?: XMaterial.entries.maxByOrNull { similarDegree(id.toString(), it.name) }
?: XMaterial.entries.find { it -> it.legacy.any { it == id.toString() } }
?: XMaterial.entries.maxByOrNull { similarDegree(id.toString(), it.name) }
}.getOrNull()?.parseItem()
?: FALL_BACK
?: FALL_BACK
}

return item
Expand Down

0 comments on commit 65be5db

Please sign in to comment.