Skip to content

Commit

Permalink
fix: don't create empty disc item meta on burn/erase commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed Mar 21, 2024
1 parent 1c7d518 commit 5c59b45
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/main/kotlin/su/plo/voice/discs/DiscsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class DiscsPlugin : JavaPlugin() {
itemMeta.persistentDataContainer.set(forbidGrindstoneKey, PersistentDataType.BYTE, 1)
}

fun allowGrindstone(itemMeta: ItemMeta) {
itemMeta.persistentDataContainer.remove(forbidGrindstoneKey)
}

companion object {

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,40 +100,33 @@ class BurnCommand(handler: CommandHandler) : SubCommand(handler) {
return@launch
}

val item = suspendSync(player, handler.plugin) { player.inventory.itemInMainHand }

if (!checkBurnable(voicePlayer, item)) return@launch

val meta = handler.plugin.server.itemFactory.getItemMeta(item.type)

meta.addItemFlags(*ItemFlag.values())
suspendSync(player.location, handler.plugin) {
val item = player.inventory.itemInMainHand
if (!checkBurnable(voicePlayer, item)) return@suspendSync

meta.persistentDataContainer.set(
handler.plugin.identifierKey,
PersistentDataType.STRING,
identifier
)
item.editMeta { meta ->
meta.addItemFlags(*ItemFlag.values())

if (handler.plugin.addonConfig.addGlintToCustomDiscs) {
handler.plugin.forbidGrindstone(meta)
}
meta.persistentDataContainer.set(
handler.plugin.identifierKey,
PersistentDataType.STRING,
identifier
)

if (handler.plugin.addonConfig.addGlintToCustomDiscs) {
meta.addEnchant(Enchantment.MENDING, 1, false)
}
if (handler.plugin.addonConfig.addGlintToCustomDiscs) {
handler.plugin.forbidGrindstone(meta)
meta.addEnchant(Enchantment.MENDING, 1, false)
}

val loreName = Component.text()
.content(name)
.decoration(TextDecoration.ITALIC, false)
.color(NamedTextColor.GRAY)
.build()
val loreName = Component.text()
.content(name)
.decoration(TextDecoration.ITALIC, false)
.color(NamedTextColor.GRAY)
.build()

meta.lore(listOf(loreName))
meta.lore(listOf(loreName))
}

suspendSync(player.location, handler.plugin) {
val item = player.inventory.itemInMainHand
if (!checkBurnable(voicePlayer, item)) return@suspendSync
item.itemMeta = meta
voicePlayer.instance.sendTranslatable("pv.addon.discs.success.burn", name)
}
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package su.plo.voice.discs.command.subcommand

import org.bukkit.command.CommandSender
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemFlag
import su.plo.lib.api.server.permission.PermissionDefault
import su.plo.voice.discs.command.CommandHandler
import su.plo.voice.discs.command.SubCommand
Expand Down Expand Up @@ -37,9 +39,17 @@ class EraseCommand(handler: CommandHandler) : SubCommand(handler) {
return
}

val meta = source.server.itemFactory.getItemMeta(item.type)
item.editMeta { meta ->
meta.removeItemFlags(*ItemFlag.values())
meta.persistentDataContainer.remove(handler.plugin.identifierKey)

item.itemMeta = meta
if (handler.plugin.addonConfig.addGlintToCustomDiscs) {
handler.plugin.allowGrindstone(meta)
meta.removeEnchant(Enchantment.MENDING)
}

meta.lore(null)
}

voicePlayer.instance.sendTranslatable("pv.addon.discs.success.erase")
}
Expand Down

0 comments on commit 5c59b45

Please sign in to comment.