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

io.github.parzivalExe.guiApi.antlr.elements.Element.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.antlr.IXMLRule
import java.lang.Exception

@Suppress("MemberVisibilityCanBePrivate")
abstract class Element(val tagName: String) : IXMLRule {

    var attributes = arrayListOf()
    var content: Content? = null

    //region Attribute-Methods

    fun getAttributeWithName(name: String): Attribute =
        getAttributeWithNameOrNull(name) ?: throw Exception("No attribute \'$name\' found for Element \'$tagName\'")
    fun getAttributeWithNameOrNull(name: String): Attribute? =
        attributes.find { it.name == name }
    fun getValueForAttribute(attrName: String): String =
        getAttributeWithName(attrName).value
    fun getValueForAttributeOrNull(attrName: String): String? =
        getAttributeWithNameOrNull(attrName)?.value
    fun getValueForAttributeOrDefault(attrName: String, default: String): String =
        getAttributeWithNameOrNull(attrName)?.value ?: default

    fun containsAttributeWithName(name: String): Boolean =
        attributes.any { it.name == name }

    //endregion

    companion object {
        @JvmStatic
        fun getElementFromName(elementName: String): Element = when(elementName) {
            "Library" -> LibraryElement()
            "Include" -> IncludeElement()
            "Gui" -> GuiElement(elementName)
            else -> DynamicElement(elementName)
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy