io.github.parzivalExe.guiApi.components.GetItemComponent.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.components
import io.github.parzivalExe.guiApi.Gui
import io.github.parzivalExe.guiApi.antlr.converter.InvItemStackConverter
import io.github.parzivalExe.guiApi.antlr.interfaces.XMLAttribute
import io.github.parzivalExe.guiApi.events.GetItemComponentClickedEvent
import io.github.parzivalExe.guiApi.objects.InvItemStack
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.entity.HumanEntity
import org.bukkit.entity.Player
import org.bukkit.event.inventory.ClickType
import org.bukkit.event.inventory.InventoryAction
import org.bukkit.inventory.ItemStack
class GetItemComponent(meta: ComponentMeta, @XMLAttribute(defaultValue = "0=35", converter = InvItemStackConverter::class) var items: ArrayList)
: Component(meta) {
@XMLAttribute
var overrideInInv = true
@XMLAttribute
var closeGui = true
@Suppress("unused")
constructor(meta: ComponentMeta, item: InvItemStack) : this(meta, arrayListOf(item))
constructor(meta: ComponentMeta) : this(meta, arrayListOf())
@Suppress("unused")
@Deprecated("DON'T USE: This Constructor is only used for XML and shouldn't be used in Code itself", ReplaceWith("new GetItemComponent(ComponentMeta)"))
constructor() : this(ComponentMeta("", ItemStack(Material.WOOL)))
override fun componentClicked(whoClicked: HumanEntity, gui: Gui, action: InventoryAction, slot: Int, clickType: ClickType) {
if(whoClicked is Player) {
items.forEach { item -> item.givePlayerItem(whoClicked, overrideInInv) }
whoClicked.updateInventory()
Bukkit.getPluginManager().callEvent(GetItemComponentClickedEvent(this, whoClicked, gui, action, place, clickType, items.toTypedArray()))
}
if(closeGui)
gui.closeGui()
}
}