walkmc.extensions.Inventories.kt Maven / Gradle / Ivy
package walkmc.extensions
import org.bukkit.inventory.*
import walkmc.*
import walkmc.graphical.common.*
/**
* Verifies if this inventory contains a item in the specified [slot].
*/
fun Inventory.hasItem(slot: Int) = getItem(slot) != null
/**
* Fills the specified [row] with the specified [item].
*/
fun Inventory.fillRow(row: Int, item: ItemStack, replaces: Boolean = false) {
val start = startSlot(row)
val last = lastSlot(row)
for (i in start..last) {
if (hasItem(i) && !replaces)
continue
setItem(i, item)
}
}
/**
* Fills the specified [row] with the specified [material].
*/
fun Inventory.fillRow(row: Int, material: Materials, replaces: Boolean = false) =
fillRow(row, material.toItem(), replaces)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy