io.github.parzivalExe.guiApi.GuiManager.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
import org.bukkit.inventory.Inventory
import kotlin.random.Random
object GuiManager {
private val guis = arrayListOf()
fun isInventoryGui(inventory: Inventory): Boolean {
return guis.any { gui -> gui.inventory == inventory }
}
fun getGuiFromInventory(inventory: Inventory): Gui? {
return guis.firstOrNull { gui -> gui.inventory == inventory }
}
fun initializeGui(gui: Gui): Int {
synchronized(guis) {
var id: Int
do {
id = Random.nextInt()
} while (guis.any { gui -> gui.id == id })
guis.add(gui)
return id
}
}
fun finalizeGui(gui: Gui): Boolean {
synchronized(guis) {
return@synchronized guis.remove(gui)
}
return false
}
fun getAllGuis(): ArrayList {
return guis
}
}