Introduce runtime-configurable settings and defaults across multiple kits and clean up implementations. Kits (Armorer, Backup, Gladiator, Goblin, IceMage, Puppet, and others) now expose companion-object default constants and read values via override() (SPEEDHG_CUSTOM_SETTINGS) with typed accessors. Activation and tick-time behaviour snapshot these values so mid-round config changes don't produce inconsistent effects. Also includes general refactors: clearer getters, small API/formatting cleanup, improved no-op ability placeholders, and minor behavior protections (e.g. disallow stealing Backup kit).
123 lines
2.0 KiB
Kotlin
123 lines
2.0 KiB
Kotlin
package club.mcscrims.speedhg.util
|
|
|
|
import net.kyori.adventure.text.Component
|
|
import net.kyori.adventure.text.format.TextDecoration
|
|
import net.kyori.adventure.text.minimessage.MiniMessage
|
|
import org.bukkit.Material
|
|
import org.bukkit.NamespacedKey
|
|
import org.bukkit.enchantments.Enchantment
|
|
import org.bukkit.inventory.ItemFlag
|
|
import org.bukkit.inventory.ItemStack
|
|
import org.bukkit.persistence.PersistentDataType
|
|
|
|
class ItemBuilder(
|
|
private val itemStack: ItemStack
|
|
) {
|
|
|
|
private val mm = MiniMessage.miniMessage()
|
|
|
|
constructor(
|
|
type: Material
|
|
) : this(
|
|
ItemStack( type )
|
|
)
|
|
|
|
constructor(
|
|
type: Material,
|
|
amount: Int
|
|
) : this(
|
|
ItemStack( type, amount )
|
|
)
|
|
|
|
constructor() : this(
|
|
ItemStack( Material.STONE )
|
|
)
|
|
|
|
fun name(
|
|
name: String
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta { it.displayName(mm.deserialize( name )) }
|
|
return this
|
|
}
|
|
|
|
fun name(
|
|
name: Component
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta { it.displayName( name ) }
|
|
return this
|
|
}
|
|
|
|
fun lore(
|
|
lore: List<String>
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta { meta ->
|
|
meta.lore(lore.map { line ->
|
|
mm.deserialize( line ).decoration( TextDecoration.ITALIC, false )
|
|
})
|
|
}
|
|
return this
|
|
}
|
|
|
|
fun unbreakable(
|
|
unbreakable: Boolean
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta { it.isUnbreakable = unbreakable }
|
|
return this
|
|
}
|
|
|
|
fun amount(
|
|
amount: Int
|
|
): ItemBuilder
|
|
{
|
|
itemStack.amount = amount
|
|
return this
|
|
}
|
|
|
|
fun <T, Z> pdc(
|
|
key: NamespacedKey,
|
|
dataType: PersistentDataType<T, Z>,
|
|
value: Z
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta {
|
|
it.persistentDataContainer.set( key, dataType, value!! )
|
|
}
|
|
return this
|
|
}
|
|
|
|
fun enchant(
|
|
ench: Enchantment
|
|
): ItemBuilder
|
|
{
|
|
enchant( ench, 1 )
|
|
return this
|
|
}
|
|
|
|
fun enchant(
|
|
ench: Enchantment,
|
|
level: Int
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta { it.addEnchant( ench, level, true ) }
|
|
itemFlag( ItemFlag.HIDE_ENCHANTS )
|
|
return this
|
|
}
|
|
|
|
fun itemFlag(
|
|
flag: ItemFlag
|
|
): ItemBuilder
|
|
{
|
|
itemStack.editMeta { it.addItemFlags( flag ) }
|
|
return this
|
|
}
|
|
|
|
fun build(): ItemStack
|
|
{
|
|
return itemStack
|
|
}
|
|
|
|
} |