Item.kt
Branches > main > b7f9306 > files / src / main / kotlin / net / bowmap / server / item / Item.kt
package net.bowmap.server.item
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import org.bukkit.inventory.ItemStack
import org.bukkit.Material
import kotlinx.collections.immutable.*
// Bowmap's Item type
// Either a material or a custommodeldata
data class Texture(val material: Material? = null, val customModelData: Int? = null) {
init {
require(material != null || customModelData != null) { "Texture requires either a material or custom model data" }
}
}
enum class Rarity {
COMMON, UNCOMMON, RARE
}
fun rarityLoreComponent(rarity: Rarity): Component = when (rarity) {
Rarity.COMMON -> Component.text("COMMON", NamedTextColor.WHITE).decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)
Rarity.UNCOMMON -> Component.text("UNCOMMON", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)
Rarity.RARE -> Component.text("RARE", NamedTextColor.BLUE).decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)
}
data class Item(
val material: Material,
val amount: Int = 1,
val texture: Texture = Texture(material = material),
// Can have a custom name for its rarity
val name: Component,
val rarity: Rarity = Rarity.COMMON,
// Lore is a function of multiple things about an item
val description: String? = null,
)
fun computeLore(item: Item): PersistentList<Component> {
var loreList = persistentListOf<Component>()
// TODO need spacing, so make a list of these lists and put spaces between them then merge
if (item.description != null) {
// TODO split the lore by text size
loreList = loreList.adding(Component.text(item.description, NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))
}
loreList = loreList.adding(rarityLoreComponent(item.rarity))
return loreList
}