Skip to content

Commit

Permalink
oopsie daisy
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed May 18, 2023
1 parent d38e0f8 commit 17061da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.effects.Effects
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import java.util.Objects

class EcoItem(
Expand Down Expand Up @@ -46,13 +45,11 @@ class EcoItem(
ItemStackBuilder(Items.lookup(itemConfig.getString("item")).item).apply {
setDisplayName(itemConfig.getFormattedString("display-name"))
addLoreLines(
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" })
writeMetaKey(
plugin.namespacedKeyFactory.create("item"),
PersistentDataType.STRING,
id
itemConfig.getFormattedStrings("lore").map { "${Display.PREFIX}$it" }
)
}.build()
}.build().apply {
ecoItem = this@EcoItem
}
}

val itemStack: ItemStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object EcoItems : ConfigCategory("item", "items") {
return null
}

return registry[this.id]
return registry[id]
}

fun values(): List<EcoItem> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ import org.bukkit.persistence.PersistentDataType
private val legacyKey = namespacedKeyOf("ecoweapons", "weapon")
private val key = namespacedKeyOf("ecoitems", "item")

val ItemStack?.ecoItem: EcoItem?
var ItemStack?.ecoItem: EcoItem?
get() {
this ?: return null
val fis = this.fast()
return fis.ecoItem
}
set(value) {
this ?: return
val fis = this.fast()
fis.ecoItem = value
}

val FastItemStack.ecoItem: EcoItem?
var FastItemStack.ecoItem: EcoItem?
get() {
val pdc = this.persistentDataContainer

Expand All @@ -31,6 +36,15 @@ val FastItemStack.ecoItem: EcoItem?

return EcoItems.getByID(pdc.get(key, PersistentDataType.STRING))
}
set(value) {
val pdc = this.persistentDataContainer

if (value == null) {
pdc.remove(key)
} else {
pdc.set(key, PersistentDataType.STRING, value.id.key)
}
}

val Player.ecoItems: Collection<ItemProvidedHolder>
get() = ItemSlots.flatMap { slot ->
Expand Down

0 comments on commit 17061da

Please sign in to comment.