io.pixeloutlaw.minecraft.spigot.plumbing.lib.ItemAttributes.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plumbing-lib Show documentation
Show all versions of plumbing-lib Show documentation
NMS and OBC Adapter Lib for MythicDrops
package io.pixeloutlaw.minecraft.spigot.plumbing.lib
import com.google.common.collect.HashMultimap
import com.google.common.collect.Multimap
import io.pixeloutlaw.minecraft.spigot.plumbing.api.AbstractItemAttributes
import io.pixeloutlaw.minecraft.spigot.plumbing.api.MinecraftVersions
import org.bukkit.attribute.Attribute
import org.bukkit.attribute.AttributeModifier
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
object ItemAttributes {
private val availableEquipmentSlots by lazy {
EquipmentSlot.values()
}
private val itemAttributesByServer: AbstractItemAttributes by lazy {
when (MinecraftVersions.nmsVersion) {
"v1_16_R3" -> io.pixeloutlaw.minecraft.spigot.plumbing.v116R3.ItemAttributes()
"v1_16_R2" -> io.pixeloutlaw.minecraft.spigot.plumbing.v116R2.ItemAttributes()
"v1_16_R1" -> io.pixeloutlaw.minecraft.spigot.plumbing.v116R1.ItemAttributes()
else -> {
NoOpItemAttributes()
}
}
}
/**
* Returns `true` if the version of bukkit
*/
val isSupportedBukkitVersion: Boolean by lazy { MinecraftVersions.isAtLeastMinecraft116 }
fun getDefaultItemAttributes(itemStack: ItemStack): Multimap {
val results = HashMultimap.create()
availableEquipmentSlots.forEach { slot ->
results.putAll(getDefaultItemAttributes(itemStack, slot))
}
return results
}
fun getDefaultItemAttributes(
itemStack: ItemStack,
equipmentSlot: EquipmentSlot
): Multimap {
if (!isSupportedBukkitVersion) return HashMultimap.create()
return itemAttributesByServer.getDefaultItemAttributes(itemStack, equipmentSlot)
}
internal class NoOpItemAttributes : AbstractItemAttributes {
override fun getDefaultItemAttributes(
itemStack: ItemStack,
equipmentSlot: EquipmentSlot
): Multimap {
return HashMultimap.create()
}
}
}