Skip to content

Commit 326ee8f

Browse files
authored
Merge pull request #225 from YsGqHY/stable/v3
feat(menu): 添加物品不可破坏与数据值配置支持
2 parents 87b414a + 1958bd6 commit 326ee8f

18 files changed

Lines changed: 97 additions & 27 deletions

File tree

.github/ISSUE_TEMPLATE/zh_bug_request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ body:
4343
| Server software: xxxx
4444
| Java version: xxxx
4545
46-
| TabooLib: x.x.x
4746
| TrMenu: x.x.x
4847
Installed Plugins:
4948
· XXXXXX - x.x.x

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ subprojects {
6868
PtcObject
6969
)
7070
repoTabooLib = "https://repo.aeoliancloud.com/repository/releases"
71+
// repoTabooLib = project.repositories.mavenLocal().url.toString()
7172
disableOnSkippedVersion = false
7273
}
7374
version {
74-
taboolib = "6.2.3-c573ce52"
75+
taboolib = "6.2.3-d4a5f0ea"
7576
coroutines = null
7677
}
7778
}

common/src/main/kotlin/trplugins/menu/util/EvalResult.kt

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

3+
import taboolib.common5.cint
4+
35
/**
46
* @author Arasple
57
* @date 2021/1/31 11:53
@@ -19,6 +21,10 @@ value class EvalResult(val any: Any? = null) {
1921
return any.toString()
2022
}
2123

24+
fun asInt(def: Int = 0): Int {
25+
return any?.cint ?: def
26+
}
27+
2228
companion object {
2329

2430
val TRUE = EvalResult(true)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ enum class Property(val default: String, val regex: Regex) {
208208
*/
209209
ICON_DISPLAY_LORE("lore", "(display)?-?lores?"),
210210

211+
/**
212+
* 菜单图标显示 - 物品损伤值
213+
*/
214+
ICON_DISPLAY_DATA("data", "(display)?-?data"),
215+
211216
/**
212217
* 菜单图标显示 - 物品数量
213218
*/
@@ -243,6 +248,11 @@ enum class Property(val default: String, val regex: Regex) {
243248
*/
244249
ICON_DISPLAY_HIDE_TOOLTIP("hide_tooltip", "hide_?tool(tip)?"),
245250

251+
/**
252+
* 菜单图标 - Unbreakable
253+
*/
254+
ICON_DISPLAY_UNBREAKABLE("unbreakable", "unbreak(able)?"),
255+
246256
/**
247257
* 菜单图标 - 子图标
248258
*/

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.8.9
2+
version=3.9.7

plugin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ dependencies {
6767
compileOnly("org.apache.commons:commons-lang3:3.17.0")
6868

6969
// Server Core
70+
compileOnly("ink.ptms.core:v12005:12005-minimize:mapped")
71+
compileOnly("ink.ptms.core:v12005:12005-minimize:universal")
7072
compileOnly("ink.ptms.core:v12002:12002-minimize:mapped")
7173
compileOnly("ink.ptms.core:v12002:12002-minimize:universal")
7274
compileOnly("ink.ptms.core:v11904:11904-minimize:mapped")

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ object MenuSerializer : ISerializer {
360360
val hideTooltip = if (inherit.contains(Property.ICON_DISPLAY_HIDE_TOOLTIP)) {
361361
def!!.display.meta.hideTooltip
362362
} else Property.ICON_DISPLAY_HIDE_TOOLTIP.ofString(display, "false")
363+
val unbreakable = if (inherit.contains(Property.ICON_DISPLAY_UNBREAKABLE)) {
364+
def!!.display.meta.unbreakable
365+
} else Property.ICON_DISPLAY_UNBREAKABLE.ofString(display, "false")
366+
val data = if (inherit.contains(Property.ICON_DISPLAY_DATA)) {
367+
def!!.display.meta.data
368+
} else Property.ICON_DISPLAY_DATA.ofString(display, "")
363369

364370
// only for the subIcon
365371
val priority = Property.PRIORITY.ofInt(it, order)
@@ -396,7 +402,7 @@ object MenuSerializer : ISerializer {
396402
if (def != null && inherit.contains(Property.ICON_DISPLAY_LORE) && lore.isEmpty()) def.display.lore
397403
else CycleList(lore.map { Lore(line(it)) }),
398404
// 图标附加属性
399-
Meta(amount, shiny, flags, nbt, tooltipStyle, itemModel, hideTooltip)
405+
Meta(amount, shiny, flags, nbt, tooltipStyle, itemModel, hideTooltip, unbreakable, data)
400406
)
401407

402408
// i18n

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ open class Item(
9090
meta.tooltipStyle(session, this)
9191
meta.itemModel(session, this)
9292
meta.hideTooltip(session, this)
93+
meta.unbreakable(session, this)
94+
meta.data(session, this)
9395

9496
if (meta.hasAmount()) this.amount = meta.amount(session)
9597
}
@@ -132,7 +134,7 @@ open class Item(
132134
else {
133135
val current = cache[session.id]
134136
try {
135-
val new = buildItem(current!!) { name = parsedName(session) }
137+
val new = buildItem(current!!) { parsedName(session)?.let { name = it } }
136138
cache[session.id] = new
137139
} catch (t: Throwable) {
138140
t.stackTrace

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ class Meta(
2424
val tooltip: String?,
2525
val itemModel: String?,
2626
val hideTooltip: String,
27+
val unbreakable: String,
28+
val data: String,
2729
) {
2830

2931
private val isAmountDynamic = amount.toIntOrNull() == null
3032
private val isShinyDynamic = !shiny.matches(Regexs.BOOLEAN)
3133
private val isHideTooltipDynamic = !hideTooltip.matches(Regexs.BOOLEAN)
3234
private val isNBTDynamic = nbt != null && Regexs.containsPlaceholder(nbt.toJsonSimplified())
35+
private val isUnbreakableDynamic = !unbreakable.matches(Regexs.BOOLEAN)
36+
private val isDataDynamic = data.toIntOrNull() == null
3337
val isDynamic = isAmountDynamic || isNBTDynamic || isShinyDynamic || isHideTooltipDynamic
3438

3539
fun amount(session: MenuSession): Int {
@@ -82,9 +86,23 @@ class Meta(
8286
}
8387

8488
fun hideTooltip(session: MenuSession, builder: ItemBuilder) {
85-
if ((hideTooltip.toBoolean()) || (isHideTooltipDynamic && session.placeholderPlayer.evalScript(hideTooltip).asBoolean())) {
89+
if (hideTooltip.toBoolean() || (isHideTooltipDynamic && session.placeholderPlayer.evalScript(hideTooltip).asBoolean())) {
8690
builder.isHideTooltip = true
8791
}
8892
}
8993

94+
fun unbreakable(session: MenuSession, builder: ItemBuilder) {
95+
if (unbreakable.toBoolean() || (isUnbreakableDynamic && session.placeholderPlayer.evalScript(unbreakable).asBoolean())) {
96+
builder.isUnbreakable = true
97+
}
98+
}
99+
100+
fun data(session: MenuSession, builder: ItemBuilder) {
101+
if (data.isEmpty()) {
102+
return
103+
}
104+
val evalData = session.parse(amount).toIntOrNull() ?: session.placeholderPlayer.evalScript(data).asInt(0)
105+
builder.damage = evalData
106+
}
107+
90108
}

plugin/src/main/kotlin/trplugins/menu/module/internal/command/impl/CommandDebug.kt

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package trplugins.menu.module.internal.command.impl
33
import org.bukkit.Bukkit
44
import org.bukkit.command.CommandSender
55
import org.bukkit.entity.Player
6+
import taboolib.common.io.newFile
67
import taboolib.common.platform.command.subCommand
78
import taboolib.common.platform.function.adaptCommandSender
9+
import taboolib.common.platform.function.getDataFolder
810
import taboolib.common.platform.function.pluginVersion
9-
import taboolib.common.platform.function.submit
1011
import taboolib.module.chat.HexColor
12+
import taboolib.platform.util.sendLang
1113
import trplugins.menu.TrMenu
1214
import trplugins.menu.api.TrMenuAPI
1315
import trplugins.menu.module.display.Menu
@@ -84,27 +86,44 @@ object CommandDebug : CommandExpression {
8486
val dump = buildString {
8587
append("TrMenu Dump Information (Date: ${Time.formatDate()})\n\n")
8688
append("| Server OS: ${properties["os.name"]} ${properties["os.arch"]} ${properties["os.version"]}\n")
87-
append("| Server software: ${Bukkit.getServer().version} (${Bukkit.getServer().bukkitVersion})\n")
88-
append("| Java version: ${System.getProperty("java.version")}\n\n")
89+
append("| Server software: ${Bukkit.getName()} - ${Bukkit.getServer().version} (${Bukkit.getServer().bukkitVersion})\n")
90+
append("| Java version: ${getJavaVendorDetailed()}\n\n")
8991
append("| TrMenu: ${pluginVersion}\n")
9092
// append(" ${description.getString("built-time")} by ${description.getString("built-by")})\n\n")
9193
append("Installed Plugins: \n")
9294
Bukkit.getPluginManager().plugins.sortedBy { it.name }.forEach { plugin ->
93-
var file: File? = null
94-
try {
95-
Class.forName("org.bukkit.plugin.java.JavaPlugin").also { it ->
96-
file = it.getMethod("getFile").also { it.isAccessible = true }.invoke(plugin) as File
97-
}
98-
} catch (t: Throwable) {
99-
t.stackTrace
100-
}
101-
val size = (file?.length() ?: 0) / 1024
102-
append("· ${plugin.name} - ${plugin.description.version} ($size KB)\n")
95+
append("· ${plugin.name} - ${plugin.description.version}\n")
10396
}
10497
}
98+
val fileName = "dump-info-${System.currentTimeMillis()}.log"
99+
val file = newFile(getDataFolder(), "debug/$fileName")
100+
file.writeText(dump)
101+
sender.sendLang("Dump-Info-Created", file.absolutePath)
105102
Paster.paste(adaptCommandSender(sender), dump)
106103
}
107104

105+
private fun getJavaVendorDetailed(): String {
106+
val vendor = System.getProperty("java.vendor") ?: "Unknown"
107+
val version = System.getProperty("java.version") ?: "?"
108+
val runtimeName = System.getProperty("java.runtime.name") ?: ""
109+
val runtimeVersion = System.getProperty("java.runtime.version") ?: ""
110+
111+
return buildString {
112+
append(vendor)
113+
append(" (")
114+
append(runtimeName)
115+
if (runtimeVersion.isNotBlank()) {
116+
append(" ")
117+
append(runtimeVersion)
118+
} else {
119+
append(" v")
120+
append(version)
121+
}
122+
append(")")
123+
}
124+
}
125+
126+
108127
/**
109128
* 服务器信息查看
110129
*/

0 commit comments

Comments
 (0)