Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
新增操作物品Kether
  • Loading branch information
YsGqHY committed Dec 10, 2024
1 parent f0face4 commit e110478
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=kim.azure.kether
version=1.0.0
version=1.1.0
62 changes: 62 additions & 0 deletions src/main/kotlin/kim/azure/kether/kether/ItemAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package kim.azure.kether.kether

import kim.azure.kether.getBukkitPlayer
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta
import taboolib.common5.cint
import taboolib.module.kether.KetherParser
import taboolib.module.kether.ScriptFrame
import taboolib.module.kether.combinationParser
import taboolib.platform.util.modifyMeta

/**
* 扣除触发的物品数量
* azure-item take 123
*
* 给予触发的物品数量
* azure-item give 123
*
* 触发的物品重命名
* azure-item rename "666 66 6"
*/
object ItemAction {
/**
* 获取物品原始 ItemStack
*/
fun ScriptFrame.getItemStack(): ItemStack {
return variables().get<Any?>("@AzureItemStack").orElse(null) as? ItemStack ?: error("No item selected.")
}

@KetherParser(["azure-item"], shared = true)
fun put() = combinationParser {
it.group(
text(),
text()
).apply(it) { oper, token ->
now {
when (oper) {
"take", "remove", "consume" -> {
getItemStack().amount -= token.cint
}

"give", "add" -> {
val item = getItemStack().clone().also { i -> i.amount = 1 }
val inv = getBukkitPlayer().inventory
repeat(token.cint) {
inv.addItem(item)
}
}

"rename" -> {
getItemStack().modifyMeta<ItemMeta> { setDisplayName(token) }
}

else -> {
null
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object KetherResolver : PrefixSupportResolver("ke") {
actionBindings: ActionBindings,
actionableObject: AzureFlowActionableObject
): Boolean {
args.evalKether(actionableObject.player, mapOf("item-amount" to actionableObject.itemStack?.amount))
args.evalKether(actionableObject.player, mapOf("item-amount" to actionableObject.itemStack?.amount), listOf("@AzureItemStack" to actionableObject.itemStack))
return true
}

Expand Down

0 comments on commit e110478

Please # to comment.