io.github.parzivalExe.guiApi.components.ComponentManager.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiapi-mc1.8 Show documentation
Show all versions of guiapi-mc1.8 Show documentation
With GuiAPI you can create Guis for your Bukkit/Spigot-Plugin in seconds while at the same time saving many lines of code
The newest version!
package io.github.parzivalExe.guiApi.components
import io.github.parzivalExe.guiApi.Gui
import org.bukkit.inventory.ItemStack
import kotlin.random.Random
object ComponentManager {
private val components = arrayListOf()
fun getNewComponentId(): Int {
var id: Int
synchronized(components) {
do {
id = Random.nextInt()
} while (components.any { component -> component.id == id })
}
return id
}
fun initializeComponent(component: Component) {
synchronized(components) {
components.add(component)
}
}
fun finalizeComponent(component: Component): Boolean {
synchronized(components) {
return@synchronized components.remove(component)
}
return false
}
fun isItemComponent(item: ItemStack, itemSlot: Int, gui: Gui): Boolean {
return components.any { component -> component.getGuiItem() == item && gui.hasComponent(component)
&& gui.getPositionOfComponent(component) == itemSlot }
}
fun getComponentFromItem(item: ItemStack, itemSlot: Int, gui: Gui): Component? {
return components.firstOrNull { component -> component.getGuiItem() == item && gui.hasComponent(component)
&& gui.getPositionOfComponent(component) == itemSlot }
}
fun getAllComponents(): ArrayList {
return components
}
}