Skip to content

Commit 116c61b

Browse files
authored
Merge pull request #206 from YsGqHY/stable/v3
3.8.1
2 parents 2efbe53 + 77a2b36 commit 116c61b

File tree

14 files changed

+214
-10
lines changed

14 files changed

+214
-10
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
java
66
idea
77
kotlin("jvm") version "2.1.0"
8-
id("io.izzel.taboolib") version "2.0.25"
8+
id("io.izzel.taboolib") version "2.0.27"
99
}
1010

1111
// 这段。一言难尽,但我不想动 (依托)
@@ -62,7 +62,7 @@ subprojects {
6262
disableOnSkippedVersion = false
6363
}
6464
version {
65-
taboolib = "6.2.3-6b5f38c"
65+
taboolib = "6.2.3-6bdc1c7"
6666
coroutines = null
6767
}
6868
}

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.7.2
2+
version=3.8.1

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import taboolib.common.platform.command.subCommand
88
import taboolib.common.platform.function.adaptCommandSender
99
import taboolib.module.chat.Components
1010
import taboolib.module.nms.MinecraftVersion
11+
import taboolib.platform.BukkitPlugin
1112
import taboolib.platform.util.asLangText
1213
import trplugins.menu.TrMenu
1314
import trplugins.menu.module.internal.command.impl.*
@@ -55,6 +56,10 @@ object CommandHandler {
5556
@CommandBody(permission = "trmenu.command.sounds", optional = true)
5657
var sounds = CommandSounds.command
5758

59+
@AppearHelper
60+
@CommandBody(permission = "trmenu.command.data", optional = true)
61+
val data = CommandData.command
62+
5863
@CommandBody(permission = "trmenu.command.debug", optional = true)
5964
val debug = CommandDebug.command
6065

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package trplugins.menu.module.internal.command.impl
2+
3+
import org.bukkit.command.CommandSender
4+
import org.bukkit.entity.Player
5+
import taboolib.common.platform.ProxyCommandSender
6+
import taboolib.common.platform.ProxyPlayer
7+
import taboolib.common.platform.command.player
8+
import taboolib.common.platform.command.subCommand
9+
import taboolib.common.platform.command.suggest
10+
import taboolib.common.platform.command.suggestUncheck
11+
import taboolib.common.platform.function.onlinePlayers
12+
import taboolib.common.util.asList
13+
import taboolib.platform.util.sendLang
14+
import trplugins.menu.module.internal.command.CommandExpression
15+
import trplugins.menu.module.internal.data.Metadata
16+
17+
/**
18+
* @author 嘿鹰
19+
* @date 2025/8/19 17:39
20+
*/
21+
object CommandData : CommandExpression {
22+
23+
// trm data [modify] [dataType] [dataName] [value] [player]
24+
override val command = subCommand {
25+
dynamic("modify") {
26+
suggest { listOf("add", "remove", "set", "get") }
27+
dynamic("dataType") {
28+
suggest {
29+
listOf("data", "meta", "global")
30+
}
31+
dynamic("dataName") {
32+
suggestUncheck {
33+
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
34+
getSuggestions(sender, dataType)
35+
}
36+
exec<Player> {
37+
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
38+
if (modifyType == Metadata.ModifyType.ADD || modifyType == Metadata.ModifyType.SET) {
39+
sender.sendLang("Command-Data-Invalid-Modify")
40+
return@exec
41+
}
42+
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
43+
val dataName = ctx["dataName"]
44+
Metadata.modifyData(sender, modifyType, dataType, dataName, "", sender)
45+
}
46+
dynamic("value") {
47+
suggestUncheck {
48+
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
49+
if (modifyType == Metadata.ModifyType.GET || modifyType == Metadata.ModifyType.REMOVE) {
50+
onlinePlayers().map { it.name }
51+
} else emptyList()
52+
}
53+
exec<CommandSender> {
54+
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
55+
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
56+
val dataName = ctx["dataName"]
57+
if (modifyType == Metadata.ModifyType.GET || modifyType == Metadata.ModifyType.REMOVE) {
58+
val player = ctx.player("value").cast<Player>()
59+
Metadata.modifyData(player, modifyType, dataType, dataName, "", sender)
60+
} else {
61+
if (sender is Player) {
62+
val value = ctx["value"]
63+
Metadata.modifyData(sender as Player, modifyType, dataType, dataName, value, sender)
64+
}
65+
}
66+
}
67+
player("player", optional = true) {
68+
exec<CommandSender> {
69+
val player = ctx.player("player").cast<Player>()
70+
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
71+
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
72+
val dataName = ctx["dataName"]
73+
val value = ctx["value"]
74+
Metadata.modifyData(player, modifyType, dataType, dataName, value, sender)
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
}
82+
83+
private fun getSuggestions(sender: ProxyCommandSender, dataType: Metadata.DataType): List<String> {
84+
return if (dataType == Metadata.DataType.GLOBAL) {
85+
Metadata.getGlobalDataKeys().asList()
86+
} else {
87+
if (sender is ProxyPlayer) {
88+
if (dataType == Metadata.DataType.DATA) {
89+
Metadata.getData(sender).data.keys.asList()
90+
} else {
91+
Metadata.getMeta(sender).data.keys.asList()
92+
}
93+
} else emptyList()
94+
}
95+
}
96+
97+
98+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package trplugins.menu.module.internal.data
77
@JvmInline
88
value class DataMap(val data: MutableMap<String, Any?> = mutableMapOf()) {
99

10-
operator fun set(key: String, value: String) {
10+
operator fun set(key: String, value: Any?) {
1111
data[key] = value
1212
}
1313

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package trplugins.menu.module.internal.data
22

33
import org.bukkit.Bukkit
4+
import org.bukkit.command.CommandSender
45
import org.bukkit.entity.Player
56
import org.bukkit.metadata.FixedMetadataValue
67
import taboolib.common.LifeCycle
78
import taboolib.common.platform.Awake
89
import taboolib.common.platform.ProxyPlayer
910
import taboolib.common.platform.Schedule
1011
import taboolib.common.platform.function.submitAsync
12+
import taboolib.common5.cdouble
13+
import taboolib.common5.cint
1114
import taboolib.module.configuration.Config
1215
import taboolib.module.configuration.Configuration
16+
import taboolib.platform.util.sendLang
1317
import trplugins.menu.TrMenu
1418
import trplugins.menu.TrMenu.SETTINGS
1519
import trplugins.menu.api.event.CustomDatabaseEvent
@@ -177,4 +181,81 @@ object Metadata {
177181
}
178182
}
179183

184+
185+
fun modifyData(
186+
player: Player,
187+
modifyType: ModifyType,
188+
dataType: DataType,
189+
dataName: String,
190+
value: String,
191+
sender: CommandSender
192+
) {
193+
val data = getData(player, dataType, dataName)
194+
when (modifyType) {
195+
ModifyType.ADD -> {
196+
setData(player, dataType, dataName, calculate(data, value))
197+
}
198+
199+
ModifyType.REMOVE -> {
200+
setData(player, dataType, dataName, null)
201+
}
202+
203+
ModifyType.SET -> {
204+
setData(player, dataType, dataName, value)
205+
}
206+
207+
ModifyType.GET -> {
208+
sender.sendLang(
209+
"Command-Data-Get",
210+
player.name,
211+
dataType,
212+
dataName,
213+
data.toString()
214+
)
215+
}
216+
}
217+
}
218+
219+
fun setData(player: Player, dataType: DataType, dataName: String, value: Any?) {
220+
when (dataType) {
221+
DataType.DATA -> {
222+
getData(player)[dataName] = value
223+
if (!isUseLegacy) {
224+
saveData(player, dataName)
225+
}
226+
}
227+
228+
DataType.META -> {
229+
getMeta(player)[dataName] = value
230+
}
231+
232+
DataType.GLOBAL -> setGlobalData(dataName, value)
233+
}
234+
}
235+
236+
fun getData(player: Player, dataType: DataType, dataName: String): Any? {
237+
return when (dataType) {
238+
DataType.DATA -> getData(player)[dataName]
239+
DataType.META -> getMeta(player)[dataName]
240+
DataType.GLOBAL -> getGlobalData(dataName)
241+
}
242+
}
243+
244+
fun calculate(preValue: Any?, value: String): Any {
245+
val valueIsInt = value.toIntOrNull() != null
246+
return if ((preValue?.toString()?.toIntOrNull() != null || preValue == null) && valueIsInt) {
247+
preValue.cint + value.cint
248+
} else {
249+
preValue.cdouble + value.cdouble
250+
}
251+
}
252+
253+
enum class DataType {
254+
DATA, META, GLOBAL
255+
}
256+
257+
enum class ModifyType {
258+
ADD, REMOVE, SET, GET
259+
}
260+
180261
}

plugin/src/main/kotlin/trplugins/menu/module/internal/listener/ListenerItemInteract.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object ListenerItemInteract {
2424
Baffle.of(TrMenu.SETTINGS.getLong("Menu.Settings.Bound-Item-Interval", 2000), TimeUnit.MILLISECONDS)
2525
}
2626

27-
@SubscribeEvent(priority = EventPriority.HIGHEST)
27+
@SubscribeEvent(priority = EventPriority.HIGHEST, ignoreCancelled = true)
2828
fun onInteract(e: PlayerInteractEvent) {
2929
ListenerItemInteract::interactCooldown.get()
3030

plugin/src/main/resources/lang/en_US.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Command-Item-Description: 'Manipulate items'
6363
Command-Convert-Description: 'Convert menu type'
6464
Command-Action-Description: 'Run actions for test'
6565
Command-Sounds-Description: 'Preview & test sounds'
66+
Command-Data-Description: 'Modify & get data'
6667

6768
Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Unkown trplugins.menu &6{0} &7.'
6869
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &7Player &f{0} &7is not online.'
@@ -91,4 +92,6 @@ Command-List-Format:
9192
Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Unknown menu &6{0} &7.'
9293
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Unknown type &b{0} &7.'
9394
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7The type of menu &6{0} &7 is already &b{1} &7.'
94-
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Typecast menu &6{0} &7 to &b{1}&7.'
95+
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Typecast menu &6{0} &7 to &b{1}&7.'
96+
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Get &6{1} &7data &6{2} &7for player &6{0} &7: &f{3}.'
97+
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'

plugin/src/main/resources/lang/ru_RU.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Command-Item-Description: 'Манипулировать предметами'
6262
Command-Convert-Description: 'Конвертировать тип меню'
6363
Command-Action-Description: 'Выполнить действия для теста'
6464
Command-Sounds-Description: 'Предварительный просмотр и тестирование звуков'
65+
Command-Data-Description: 'Modify & get data'
6566

6667
Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Неизвестное меню: &6{0} &7.'
6768
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &7Игрок &f{0} &7не в сети.'
@@ -91,3 +92,5 @@ Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Неизвестное мен
9192
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Неизвестный вид &b{0} &7.'
9293
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7Вид меню &6{0} &7 находится &b{1} &7.'
9394
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Типичное меню от &6{0} &7 до &b{1}&7.'
95+
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Получение &6{1} &7данных &6{2} &7для &7игрока &6{0}&7: &f{3}'
96+
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'

plugin/src/main/resources/lang/uk_UA.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,6 @@ Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7Тип меню &6{0} &7вже
200200
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Невідомий тип &b{0} &7.'
201201
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Тип меню &6{0} &7було перетворено на &b{1}&7.'
202202
Menu-Loader-Loading: '&8[&3Tr&bMenu&8] &6ПОТІК &8| &3Завантаження меню...'
203+
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Отримати дані про &6{1} &7гравців &6{0} {2} &7: &f{3}'
204+
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'
205+
Command-Data-Description: 'Modify & get data'

0 commit comments

Comments
 (0)