-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增操作物品Kether
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters