Skip to content

Commit bbdd16f

Browse files
authored
Merge pull request #161 from YsGqHY/stable/v3
feat(plugin): 添加 Tooltip Style 和 ItemModel 功能
2 parents 00bd609 + 53ea96b commit bbdd16f

7 files changed

Lines changed: 44 additions & 5 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ subprojects {
5959
)
6060
}
6161
version {
62-
taboolib = "6.2.3-20d868d"
62+
taboolib = "6.2.3-d89e06f"
6363
coroutines = null
6464
}
6565
}

common/src/main/kotlin/trplugins/menu/util/conf/Property.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ enum class Property(val default: String, val regex: Regex) {
228228
*/
229229
ICON_DISPLAY_NBT("nbt", "nbts?"),
230230

231+
/**
232+
* 菜单图标 - Tooltip Style
233+
*/
234+
ICON_DISPLAY_TOOLTIP("tooltip", "tooltip(_style)?"),
235+
236+
/**
237+
* 菜单图标 - ItemModel
238+
*/
239+
ICON_DISPLAY_ITEM_MODEL("model", "(item)?_?model"),
240+
231241
/**
232242
* 菜单图标 - 子图标
233243
*/

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group=me.arasple.mc.trmenu
2-
version=3.4.2
2+
version=3.4.3

plugin/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ taboolib {
3030
name("Nexo").with("bukkit").optional(true)
3131
name("NBTAPI").with("bukkit").optional(true).loadafter(true)
3232
name("TrMenu-Graal").with("bukkit").optional(true)
33+
name("AzureFlow").with("bukkit").optional(true)
34+
name("CraftEngine").with("bukkit").optional(true)
3335
}
3436
}
3537
relocate("trplugins.menu", group.toString())
36-
relocate("ink.ptms.um","${group}.um")
37-
relocate("top.maplex.arim","${group}.arim")
38+
relocate("ink.ptms.um", "${group}.um")
39+
relocate("top.maplex.arim", "${group}.arim")
3840
}
3941

4042
repositories {

plugin/src/main/kotlin/trplugins/menu/module/conf/MenuSerializer.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ object MenuSerializer : ISerializer {
349349
} else {
350350
ItemTag().also { Property.ICON_DISPLAY_NBT.ofMap(display).forEach { (key, value) -> it[key] = ItemTagData.toNBT(value) } }
351351
}
352+
val tooltipStyle = if (inherit.contains(Property.ICON_DISPLAY_TOOLTIP)) {
353+
def!!.display.meta.tooltip
354+
} else Property.ICON_DISPLAY_TOOLTIP.ofString(display, "")
355+
val itemModel = if (inherit.contains(Property.ICON_DISPLAY_ITEM_MODEL)) {
356+
def!!.display.meta.itemModel
357+
} else Property.ICON_DISPLAY_ITEM_MODEL.ofString(display, "")
352358

353359
// only for the subIcon
354360
val priority = Property.PRIORITY.ofInt(it, order)
@@ -385,7 +391,7 @@ object MenuSerializer : ISerializer {
385391
if (def != null && inherit.contains(Property.ICON_DISPLAY_LORE) && lore.isEmpty()) def.display.lore
386392
else CycleList(lore.map { Lore(line(it)) }),
387393
// 图标附加属性
388-
Meta(amount, shiny, flags, nbt)
394+
Meta(amount, shiny, flags, nbt, tooltipStyle, itemModel)
389395
)
390396

391397
// i18n

plugin/src/main/kotlin/trplugins/menu/module/display/item/Item.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ open class Item(
8787
}
8888
meta.flags(this)
8989
meta.shiny(session, this)
90+
meta.tooltipStyle(session, this)
91+
meta.itemModel(session, this)
9092

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

plugin/src/main/kotlin/trplugins/menu/module/display/item/Meta.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package trplugins.menu.module.display.item
22

3+
import org.bukkit.NamespacedKey
34
import org.bukkit.inventory.ItemFlag
45
import org.bukkit.inventory.ItemStack
56
import org.bukkit.inventory.meta.ItemMeta
@@ -20,6 +21,8 @@ class Meta(
2021
val shiny: String,
2122
val flags: Array<ItemFlag>,
2223
val nbt: ItemTag?,
24+
val tooltip: String?,
25+
val itemModel: String?,
2326
) {
2427

2528
private val isAmountDynamic = amount.toIntOrNull() == null
@@ -60,4 +63,20 @@ class Meta(
6063
return amount.isNotEmpty() || amount.toIntOrNull() != null
6164
}
6265

66+
fun tooltipStyle(session: MenuSession, builder: ItemBuilder) {
67+
if (tooltip.isNullOrEmpty()) {
68+
return
69+
}
70+
val key = session.placeholderPlayer.evalScript(tooltip).asString().let { NamespacedKey.fromString(it) }
71+
builder.tooltipStyle = key
72+
}
73+
74+
fun itemModel(session: MenuSession, builder: ItemBuilder) {
75+
if (itemModel.isNullOrEmpty()) {
76+
return
77+
}
78+
val key = session.placeholderPlayer.evalScript(itemModel).asString().let { NamespacedKey.fromString(it) }
79+
builder.itemModel = key
80+
}
81+
6382
}

0 commit comments

Comments
 (0)