io.github.parzivalExe.guiApi.antlr.elements.Element.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.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)
}
}
}