All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.parzivalExe.guiApi.GuiManager.kt Maven / Gradle / Ivy

Go to download

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
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy