Skip to content

Commit 4047711

Browse files
committed
chore: 更新依赖版本并优化数据处理逻辑
- 将 taboolib 版本从 6.2.4-7f8b30dc 更新至 6.2.4-abd325ee - 插件版本号从 3.9.10 升级到 3.9.11 - 修改 Menu 类中的 lang 字段类型为 Map<String, Map<String, Type>> - 在 MenuSerializer 中使用 ConcurrentHashMap 替代 HashMap 提高并发安全性 - 优化 Metadata 类的数据加载与推送逻辑,增强空安全处理 - 当 isUseLegacy 为 false 时,database 初始化返回 null 避免不必要的实例化
1 parent f65fa2c commit 4047711

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ subprojects {
7272
disableOnSkippedVersion = false
7373
}
7474
version {
75-
taboolib = "6.2.4-7f8b30dc"
75+
taboolib = "6.2.4-abd325ee"
7676
coroutines = null
7777
}
7878
}

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.9.10
2+
version=3.9.11

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import trplugins.menu.util.collections.IndivList
4242
import trplugins.menu.util.conf.Property
4343
import trplugins.menu.util.parseIconId
4444
import java.io.File
45+
import java.util.concurrent.ConcurrentHashMap
46+
import kotlin.collections.forEach
4547
import kotlin.jvm.optionals.getOrNull
4648
import kotlin.math.max
4749

@@ -104,10 +106,10 @@ object MenuSerializer : ISerializer {
104106
}
105107

106108
// 读取菜单语言
107-
val lang: Map<String, HashMap<String, taboolib.module.lang.Type>>? = if (languages.isEmpty()) null else {
108-
val map = HashMap<String, HashMap<String, taboolib.module.lang.Type>>()
109+
val lang: Map<String, ConcurrentHashMap<String, taboolib.module.lang.Type>>? = if (languages.isEmpty()) null else {
110+
val map = mutableMapOf<String, ConcurrentHashMap<String, taboolib.module.lang.Type>>()
109111
languages.forEach { entry ->
110-
val nodes = serializeLocaleNodes(entry.key, entry.value, HashMap())
112+
val nodes = serializeLocaleNodes(entry.key, entry.value, ConcurrentHashMap())
111113
if (nodes.isNotEmpty()) {
112114
map[entry.key.lowercase()] = nodes
113115
}
@@ -432,7 +434,7 @@ object MenuSerializer : ISerializer {
432434
// Method body taken from Taboolib, licensed under the MIT License
433435
//
434436
// Copyright (c) 2018 Bkm016
435-
private fun serializeLocaleNodes(code: String, file: ConfigurationSection, nodes: HashMap<String, taboolib.module.lang.Type>, root: String = ""): HashMap<String, taboolib.module.lang.Type> {
437+
private fun serializeLocaleNodes(code: String, file: ConfigurationSection, nodes: ConcurrentHashMap<String, taboolib.module.lang.Type>, root: String = ""): ConcurrentHashMap<String, taboolib.module.lang.Type> {
436438
file.getKeys(false).forEach { node ->
437439
val key = "$root$node"
438440
when (val obj = file[node]) {

plugin/src/main/kotlin/trplugins/menu/module/display/Menu.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Menu(
3434
val icons: Set<Icon>,
3535
conf: Configuration,
3636
private val langKey: String? = null,
37-
lang: Map<String, HashMap<String, Type>>? = null
37+
lang: Map<String, Map<String, Type>>? = null
3838
) {
3939

4040
companion object {
@@ -47,7 +47,7 @@ class Menu(
4747
var conf: Configuration = conf
4848
internal set
4949

50-
var lang: Map<String, HashMap<String, Type>>? = lang
50+
var lang: Map<String, Map<String, Type>>? = lang
5151
internal set
5252

5353
val viewers: MutableSet<String> = mutableSetOf()

plugin/src/main/kotlin/trplugins/menu/module/internal/data/Metadata.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ object Metadata {
4949

5050
// Copy in the Adyeshach
5151
val database by lazy {
52+
if (!isUseLegacy) return@lazy null
5253
when (val db = SETTINGS.getString("Database.Method")?.uppercase()) {
5354
"LOCAL", "SQLITE", null -> DatabaseSQLite()
5455
"SQL" -> DatabaseSQL()
@@ -90,31 +91,31 @@ object Metadata {
9091

9192
fun pushData(player: Player, dataMap: DataMap = getData(player)) {
9293
if (isUseLegacy) {
93-
getLocalePlayer(player).let {
94+
getLocalePlayer(player)?.let {
9495
it.getConfigurationSection("TrMenu.Data")?.getKeys(true)?.forEach { key ->
9596
if (!dataMap.data.containsKey(key)) {
9697
it["TrMenu.Data.$key"] = null
9798
}
9899
}
99100
dataMap.data.forEach { (key, value) -> it["TrMenu.Data.$key"] = value }
100101
}
101-
database.push(player)
102+
database?.push(player)
102103
} else {
103104
dataMap.data.forEach { (key, value) ->
104105
MetaDataDao.door.update(DataEntity.constructor(player, key, value?.toString() ?: ""))
105106
}
106107
}
107108
}
108109

109-
private fun getLocalePlayer(player: Player): Configuration {
110-
return database.pull(player)
110+
private fun getLocalePlayer(player: Player): Configuration? {
111+
return database?.pull(player)
111112
}
112113

113114
fun loadData(player: Player) {
114115
val map: MutableMap<String, Any?> = mutableMapOf()
115116

116117
if (isUseLegacy) {
117-
getLocalePlayer(player).getConfigurationSection("TrMenu.Data")?.let { section ->
118+
getLocalePlayer(player)?.getConfigurationSection("TrMenu.Data")?.let { section ->
118119
section.getKeys(true).forEach { key -> map[key] = section[key] }
119120
}
120121
} else {

0 commit comments

Comments
 (0)