io.github.parzivalExe.guiApi.antlr.converter.InvItemStackConverter.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.converter
import io.github.parzivalExe.guiApi.objects.InvItemStack
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
class InvItemStackConverter : Converter {
override fun attributeStringToValue(attrString: String, defaultValue: Any?): Any? {
if(attrString.isEmpty())
return defaultValue
var string = attrString
var position = InvItemStack.NO_POSITION
if(string.contains(Regex("="))) {
position = changeStringToPosition(string.split("=")[0])
string = string.split("=")[1]
}
val item = ItemStackConverter().attributeStringToValue(string, ItemStack(Material.STONE)) as ItemStack
@Suppress("DEPRECATION")
return InvItemStack(item, position)
}
@Suppress("SpellCheckingInspection")
private fun changeStringToPosition(string: String): Int =
when {
string == "HELMET" -> -1
string == "CHEST" || string == "CHESTPLATE" -> -2
string =="LEGGINGS" -> -3
string == "BOOTS" -> -4
Regex("LOW\\d+").matches(string) -> Regex("LOW").replace(string, "").toInt()
Regex("UP\\d+").matches(string) -> Regex("UP").replace(string, "").toInt() + InvItemStack.POSITION_UP_OFFSET
else -> string.toInt() + 9
}
}