package org.serverct.nanmui.inventory.common.api.attribute.impl
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.serverct.ersha.api.AttributeAPI
import org.serverct.ersha.attribute.data.AttributeSource
import org.serverct.nanmui.inventory.common.api.IInventoryPage
import org.serverct.nanmui.inventory.common.api.InventoryAPI
import org.serverct.nanmui.inventory.common.api.attribute.AttributeHandler
class AttributePlusV3 : AttributeHandler {
override val name: String = "AttributePlus_v3"
override val mainAttributeHook: Boolean = true
override fun registerCondition(): Boolean {
val plugin = Bukkit.getPluginManager().getPlugin("AttributePlus")
if (plugin != null) {
val description = plugin.description
if (description.version.first() == '3') {
return true
}
}
return false
}
override fun addSourceAttribute(player: Player, source: String, items: List<ItemStack>) {
val data = AttributeAPI.getAttrData(player)
val attributeSource = AttributeSource().apply {
items.forEach { item ->
val attribute = AttributeSource(player, item)
this.merge(attribute)
}
}
AttributeAPI.addSourceAttribute(data, source, attributeSource)
}
override fun addSourceAttributeFromList(player: Player, source: String, attributes: List<String>) {
val data = AttributeAPI.getAttrData(player)
AttributeAPI.addSourceAttribute(data, source, attributes)
}
override fun deleteSourceAttribute(player: Player, source: String) {
val data = AttributeAPI.getAttrData(player)
AttributeAPI.takeSourceAttribute(data, source)
}
}