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

io.github.parzivalExe.guiApi.antlr.elements.GuiElement.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.antlr.elements

import io.github.parzivalExe.guiApi.Gui
import io.github.parzivalExe.guiApi.antlr.converter.ItemStackConverter
import io.github.parzivalExe.guiApi.components.Component
import org.bukkit.inventory.ItemStack

class GuiElement(tagName: String) : DynamicElement(tagName) {

    override fun createObject(library: Library): Any = createGui(library)

    fun createGui(library: Library): Gui {
        val gui = Gui(getValueForAttribute("title"))
        gui.fillEmptyPlaces = getValueForAttributeOrDefault("fillEmptySpaces", "true").toBoolean()
        gui.fillItem = ItemStackConverter().attributeStringToValue(getValueForAttributeOrDefault("fillItem", "160:7"), gui.fillItem) as ItemStack
        gui.forcedSize = getValueForAttributeOrDefault("forcedSize", "-1").toInt()


        val components = arrayListOf()
        //val library: Library = (content?.elements?.first { element -> element is LibraryElement } as LibraryElement).CreateLibrary()
        content?.elements?.forEach { componentElement ->
            if(componentElement is DynamicElement) {
                val clazz = componentElement.getCreateObjectClass(library)
                if(clazz != null && Component::class.java.isAssignableFrom(clazz)) {
                    val component = (componentElement.createObject(library) ?: return@forEach) as Component
                    components.add(component)
                }
            }
        }
        components.forEach { component -> gui.addComponent(component) }

        return gui
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy