Skip to content
Merged

3.8.1 #206

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
java
idea
kotlin("jvm") version "2.1.0"
id("io.izzel.taboolib") version "2.0.25"
id("io.izzel.taboolib") version "2.0.27"
}

// 这段。一言难尽,但我不想动 (依托)
Expand Down Expand Up @@ -62,7 +62,7 @@ subprojects {
disableOnSkippedVersion = false
}
version {
taboolib = "6.2.3-6b5f38c"
taboolib = "6.2.3-6bdc1c7"
coroutines = null
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=me.arasple.mc.trmenu
version=3.7.2
version=3.8.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import taboolib.common.platform.command.subCommand
import taboolib.common.platform.function.adaptCommandSender
import taboolib.module.chat.Components
import taboolib.module.nms.MinecraftVersion
import taboolib.platform.BukkitPlugin
import taboolib.platform.util.asLangText
import trplugins.menu.TrMenu
import trplugins.menu.module.internal.command.impl.*
Expand Down Expand Up @@ -55,6 +56,10 @@ object CommandHandler {
@CommandBody(permission = "trmenu.command.sounds", optional = true)
var sounds = CommandSounds.command

@AppearHelper
@CommandBody(permission = "trmenu.command.data", optional = true)
val data = CommandData.command

@CommandBody(permission = "trmenu.command.debug", optional = true)
val debug = CommandDebug.command

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package trplugins.menu.module.internal.command.impl

import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.ProxyPlayer
import taboolib.common.platform.command.player
import taboolib.common.platform.command.subCommand
import taboolib.common.platform.command.suggest
import taboolib.common.platform.command.suggestUncheck
import taboolib.common.platform.function.onlinePlayers
import taboolib.common.util.asList
import taboolib.platform.util.sendLang
import trplugins.menu.module.internal.command.CommandExpression
import trplugins.menu.module.internal.data.Metadata

/**
* @author 嘿鹰
* @date 2025/8/19 17:39
*/
object CommandData : CommandExpression {

// trm data [modify] [dataType] [dataName] [value] [player]
override val command = subCommand {
dynamic("modify") {
suggest { listOf("add", "remove", "set", "get") }
dynamic("dataType") {
suggest {
listOf("data", "meta", "global")
}
dynamic("dataName") {
suggestUncheck {
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
getSuggestions(sender, dataType)
}
exec<Player> {
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
if (modifyType == Metadata.ModifyType.ADD || modifyType == Metadata.ModifyType.SET) {
sender.sendLang("Command-Data-Invalid-Modify")
return@exec
}
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
val dataName = ctx["dataName"]
Metadata.modifyData(sender, modifyType, dataType, dataName, "", sender)
}
dynamic("value") {
suggestUncheck {
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
if (modifyType == Metadata.ModifyType.GET || modifyType == Metadata.ModifyType.REMOVE) {
onlinePlayers().map { it.name }
} else emptyList()
}
exec<CommandSender> {
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
val dataName = ctx["dataName"]
if (modifyType == Metadata.ModifyType.GET || modifyType == Metadata.ModifyType.REMOVE) {
val player = ctx.player("value").cast<Player>()
Metadata.modifyData(player, modifyType, dataType, dataName, "", sender)
} else {
if (sender is Player) {
val value = ctx["value"]
Metadata.modifyData(sender as Player, modifyType, dataType, dataName, value, sender)
}
}
}
player("player", optional = true) {
exec<CommandSender> {
val player = ctx.player("player").cast<Player>()
val modifyType = Metadata.ModifyType.valueOf(ctx["modify"].uppercase())
val dataType = Metadata.DataType.valueOf(ctx["dataType"].uppercase())
val dataName = ctx["dataName"]
val value = ctx["value"]
Metadata.modifyData(player, modifyType, dataType, dataName, value, sender)
}
}
}
}
}
}
}

private fun getSuggestions(sender: ProxyCommandSender, dataType: Metadata.DataType): List<String> {
return if (dataType == Metadata.DataType.GLOBAL) {
Metadata.getGlobalDataKeys().asList()
} else {
if (sender is ProxyPlayer) {
if (dataType == Metadata.DataType.DATA) {
Metadata.getData(sender).data.keys.asList()
} else {
Metadata.getMeta(sender).data.keys.asList()
}
} else emptyList()
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package trplugins.menu.module.internal.data
@JvmInline
value class DataMap(val data: MutableMap<String, Any?> = mutableMapOf()) {

operator fun set(key: String, value: String) {
operator fun set(key: String, value: Any?) {
data[key] = value
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package trplugins.menu.module.internal.data

import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.metadata.FixedMetadataValue
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.ProxyPlayer
import taboolib.common.platform.Schedule
import taboolib.common.platform.function.submitAsync
import taboolib.common5.cdouble
import taboolib.common5.cint
import taboolib.module.configuration.Config
import taboolib.module.configuration.Configuration
import taboolib.platform.util.sendLang
import trplugins.menu.TrMenu
import trplugins.menu.TrMenu.SETTINGS
import trplugins.menu.api.event.CustomDatabaseEvent
Expand Down Expand Up @@ -177,4 +181,81 @@ object Metadata {
}
}


fun modifyData(
player: Player,
modifyType: ModifyType,
dataType: DataType,
dataName: String,
value: String,
sender: CommandSender
) {
val data = getData(player, dataType, dataName)
when (modifyType) {
ModifyType.ADD -> {
setData(player, dataType, dataName, calculate(data, value))
}

ModifyType.REMOVE -> {
setData(player, dataType, dataName, null)
}

ModifyType.SET -> {
setData(player, dataType, dataName, value)
}

ModifyType.GET -> {
sender.sendLang(
"Command-Data-Get",
player.name,
dataType,
dataName,
data.toString()
)
}
}
}

fun setData(player: Player, dataType: DataType, dataName: String, value: Any?) {
when (dataType) {
DataType.DATA -> {
getData(player)[dataName] = value
if (!isUseLegacy) {
saveData(player, dataName)
}
}

DataType.META -> {
getMeta(player)[dataName] = value
}

DataType.GLOBAL -> setGlobalData(dataName, value)
}
}

fun getData(player: Player, dataType: DataType, dataName: String): Any? {
return when (dataType) {
DataType.DATA -> getData(player)[dataName]
DataType.META -> getMeta(player)[dataName]
DataType.GLOBAL -> getGlobalData(dataName)
}
}

fun calculate(preValue: Any?, value: String): Any {
val valueIsInt = value.toIntOrNull() != null
return if ((preValue?.toString()?.toIntOrNull() != null || preValue == null) && valueIsInt) {
preValue.cint + value.cint
} else {
preValue.cdouble + value.cdouble
}
}

enum class DataType {
DATA, META, GLOBAL
}

enum class ModifyType {
ADD, REMOVE, SET, GET
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ListenerItemInteract {
Baffle.of(TrMenu.SETTINGS.getLong("Menu.Settings.Bound-Item-Interval", 2000), TimeUnit.MILLISECONDS)
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
@SubscribeEvent(priority = EventPriority.HIGHEST, ignoreCancelled = true)
fun onInteract(e: PlayerInteractEvent) {
ListenerItemInteract::interactCooldown.get()

Expand Down
5 changes: 4 additions & 1 deletion plugin/src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Command-Item-Description: 'Manipulate items'
Command-Convert-Description: 'Convert menu type'
Command-Action-Description: 'Run actions for test'
Command-Sounds-Description: 'Preview & test sounds'
Command-Data-Description: 'Modify & get data'

Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Unkown trplugins.menu &6{0} &7.'
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &7Player &f{0} &7is not online.'
Expand Down Expand Up @@ -91,4 +92,6 @@ Command-List-Format:
Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Unknown menu &6{0} &7.'
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Unknown type &b{0} &7.'
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7The type of menu &6{0} &7 is already &b{1} &7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Typecast menu &6{0} &7 to &b{1}&7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Typecast menu &6{0} &7 to &b{1}&7.'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Get &6{1} &7data &6{2} &7for player &6{0} &7: &f{3}.'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'
3 changes: 3 additions & 0 deletions plugin/src/main/resources/lang/ru_RU.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Command-Item-Description: 'Манипулировать предметами'
Command-Convert-Description: 'Конвертировать тип меню'
Command-Action-Description: 'Выполнить действия для теста'
Command-Sounds-Description: 'Предварительный просмотр и тестирование звуков'
Command-Data-Description: 'Modify & get data'

Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Неизвестное меню: &6{0} &7.'
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &7Игрок &f{0} &7не в сети.'
Expand Down Expand Up @@ -91,3 +92,5 @@ Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Неизвестное мен
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Неизвестный вид &b{0} &7.'
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7Вид меню &6{0} &7 находится &b{1} &7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Типичное меню от &6{0} &7 до &b{1}&7.'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Получение &6{1} &7данных &6{2} &7для &7игрока &6{0}&7: &f{3}'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'
3 changes: 3 additions & 0 deletions plugin/src/main/resources/lang/uk_UA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,6 @@ Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7Тип меню &6{0} &7вже
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Невідомий тип &b{0} &7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Тип меню &6{0} &7було перетворено на &b{1}&7.'
Menu-Loader-Loading: '&8[&3Tr&bMenu&8] &6ПОТІК &8| &3Завантаження меню...'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Отримати дані про &6{1} &7гравців &6{0} {2} &7: &f{3}'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'
Command-Data-Description: 'Modify & get data'
5 changes: 4 additions & 1 deletion plugin/src/main/resources/lang/vi_VN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Command-Item-Description: 'Thao tác các vật phẩm'
Command-Convert-Description: 'Convert menu type'
Command-Action-Description: 'Chạy các hành động để kiểm tra'
Command-Sounds-Description: 'Xem trước & thử các âm thanh'
Command-Data-Description: 'Modify & get data'

Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Không xác định trplugins.menu &6{0} &7.'
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &Người chơi &f{0} &7không trực tuyến.'
Expand Down Expand Up @@ -91,4 +92,6 @@ Command-List-Format:
Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7Unknown menu &6{0} &7.'
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7Unknown type &b{0} &7.'
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7The type of menu &6{0} &7 is already &b{1} &7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Typecast menu &6{0} &7 to &b{1}&7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7Typecast menu &6{0} &7 to &b{1}&7.'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7Nhận &6{1} &7dữ liệu &6{2} &7của người chơi &6{0}&7: &f{3}'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &cInvalid modify type.'
5 changes: 4 additions & 1 deletion plugin/src/main/resources/lang/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Command-Item-Description: '操作物品信息'
Command-Convert-Description: '转换菜单类型'
Command-Action-Description: '执行动作'
Command-Sounds-Description: '试听 & 调试声音'
Command-Data-Description: '修改 & 获取数据'

Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7未知菜单 &6{0} &7.'
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &7玩家 &f{0} &7未在线.'
Expand Down Expand Up @@ -94,4 +95,6 @@ Command-List-Format:
Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7未知菜单 &6{0} &7.'
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7未知类型 &b{0} &7.'
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7菜单 &6{0} &7的类型已经是 &b{1} &7了.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7已将菜单 &6{0} &7的类型转换为 &b{1}&7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7已将菜单 &6{0} &7的类型转换为 &b{1}&7.'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7获取玩家 &6{0} &7的 &6{1} &7数据 &6{2} &7: &f{3}'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &c无效的修改类型'
5 changes: 4 additions & 1 deletion plugin/src/main/resources/lang/zh_HK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Command-Item-Description: '操作物品信息'
Command-Convert-Description: '轉換菜單類型'
Command-Action-Description: '執行動作'
Command-Sounds-Description: '試聽 & 調試聲音'
Command-Data-Description: '修改 & 獲取數據'

Command-Open-Unknown-Menu: '&8[&3Tr&bMenu&8] &7未知菜單 &6{0} &7.'
Command-Open-Unknown-Player: '&8[&3Tr&bMenu&8] &7玩家 &f{0} &7未在線.'
Expand Down Expand Up @@ -91,4 +92,6 @@ Command-List-Format:
Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7未知菜單 &6{0} &7.'
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7未知類型 &b{0} &7.'
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7菜單 &6{0} &7的類型已經是 &b{1} &7了.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7已將菜單 &6{0} &7的類型轉換為 &b{1}&7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7已將菜單 &6{0} &7的類型轉換為 &b{1}&7.'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7獲取玩家 &6{0} &7的 &6{1} &7數據 &6{2} &7: &f{3}'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &c無效的修改類型'
4 changes: 3 additions & 1 deletion plugin/src/main/resources/lang/zh_TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ Command-List-Format:
Command-Convert-Unknown-Menu: '&8[&3Tr&bMenu&8] &7未知菜單 &6{0} &7.'
Command-Convert-Unknown-Type: '&8[&3Tr&bMenu&8] &7未知類型 &b{0} &7.'
Command-Convert-Type-Already: '&8[&3Tr&bMenu&8] &7菜單 &6{0} &7的類型已經是 &b{1} &7了.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7已將菜單 &6{0} &7的類型轉換為 &b{1}&7.'
Command-Convert-Converted: '&8[&3Tr&bMenu&8] &7已將菜單 &6{0} &7的類型轉換為 &b{1}&7.'
Command-Data-Get: '&8[&3Tr&bMenu&8] &7獲取玩家 &6{0} &7的 &6{1} &7數據 &6{2} &7: &f{3}'
Command-Data-Invalid-Modify: '&8[&3Tr&bMenu&8] &c無效的修改類型'