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

io.github.parzivalExe.guiApi.antlr.converter.InvItemStackConverter.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.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
        }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy