File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
src/main/kotlin/com/mineinabyss/extracommands/commands Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -7,15 +7,22 @@ import com.mineinabyss.idofront.messaging.error
77import com.mineinabyss.idofront.textcomponents.miniMsg
88import com.mineinabyss.idofront.textcomponents.serialize
99import com.mojang.brigadier.arguments.StringArgumentType
10+ import org.bukkit.NamespacedKey
1011import org.bukkit.entity.Player
12+ import org.bukkit.inventory.ItemStack
13+ import org.bukkit.persistence.PersistentDataType
1114
15+ val EMOJY_ORIGINAL_ITEM_RENAME_TEXT = NamespacedKey .fromString(" emojy:original_item_rename" )!!
1216fun RootIdoCommands.itemRenameCommand () {
1317 " itemrename" {
1418 playerExecutes(StringArgumentType .greedyString().suggests {
1519 (context.source.executor as ? Player )?.inventory?.itemInMainHand?.itemMeta?.displayName()?.serialize()?.let { suggestFiltering(it) }
1620 }.default { " " }) { renamed ->
17- player.inventory.itemInMainHand.takeIf { ! it.isEmpty }?.editItemMeta {
18- displayName(renamed?.takeIf { it.isNotEmpty() }?.miniMsg())
21+ player.inventory.itemInMainHand.takeUnless (ItemStack ::isEmpty)?.editItemMeta {
22+ if (renamed.isNullOrEmpty()) persistentDataContainer.remove(EMOJY_ORIGINAL_ITEM_RENAME_TEXT )
23+ else persistentDataContainer.set(EMOJY_ORIGINAL_ITEM_RENAME_TEXT , PersistentDataType .STRING , renamed)
24+
25+ displayName(renamed.takeUnless { it.isNullOrEmpty() }?.miniMsg())
1926 } ? : sender.error(" You must be holding an item to rename it!" )
2027 }
2128 }
You can’t perform that action at this time.
0 commit comments