Removed "Inventory" from the GUI API names

This commit is contained in:
bluefireoly
2020-10-24 23:25:32 +02:00
parent 3c029eb292
commit 7ba75f3250
25 changed files with 262 additions and 262 deletions

View File

@@ -218,7 +218,7 @@ firstAsync {
Inventories are great for viewing GUI information. However, they are not designed for developing GUIs. The KSpigot Inventory GUI API provides an easy way to build inventory GUIs the way you would expect such an API to be. In addition, it offers full type safety for slots. Inventories are great for viewing GUI information. However, they are not designed for developing GUIs. The KSpigot Inventory GUI API provides an easy way to build inventory GUIs the way you would expect such an API to be. In addition, it offers full type safety for slots.
```kotlin ```kotlin
val gui = kSpigotGUI(InventoryGUIType.FIVE_BY_NINE) { val gui = kSpigotGUI(GUIType.FIVE_BY_NINE) {
title = "Example Inventory" title = "Example Inventory"
@@ -231,8 +231,8 @@ val gui = kSpigotGUI(InventoryGUIType.FIVE_BY_NINE) {
page(1) { page(1) {
// define fancy transitions // define fancy transitions
transitionFrom = InventoryGUIPageChangeEffect.SLIDE_HORIZONTALLY transitionFrom = PageChangeEffect.SLIDE_HORIZONTALLY
transitionTo = InventoryGUIPageChangeEffect.SLIDE_HORIZONTALLY transitionTo = PageChangeEffect.SLIDE_HORIZONTALLY
// get special slot compounds easily with constants like Slots.Border // get special slot compounds easily with constants like Slots.Border
placeholder(Slots.Border, ItemStack(Material.GLASS_PANE)) placeholder(Slots.Border, ItemStack(Material.GLASS_PANE))

View File

@@ -1,23 +1,23 @@
@file:Suppress("MemberVisibilityCanBePrivate") @file:Suppress("MemberVisibilityCanBePrivate")
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import org.bukkit.inventory.Inventory import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
private const val DEFAULT_PAGE = 1 private const val DEFAULT_PAGE = 1
class InventoryGUIData<T : ForInventory>( class GUIData<T : ForInventory>(
val inventoryType: InventoryType<T>, val guiType: GUIType<T>,
val title: String?, val title: String?,
internal val pages: Map<Int, InventoryGUIPage<T>>, internal val pages: Map<Int, GUIPage<T>>,
val transitionTo: InventoryChangeEffect?, val transitionTo: InventoryChangeEffect?,
val transitionFrom: InventoryChangeEffect?, val transitionFrom: InventoryChangeEffect?,
internal val generalOnClick: ((InventoryGUIClickEvent<T>) -> Unit)? internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?
) )
abstract class InventoryGUI<T : ForInventory>( abstract class GUI<T : ForInventory>(
val data: InventoryGUIData<T> val data: GUIData<T>
) { ) {
var currentPageInt: Int = DEFAULT_PAGE; protected set var currentPageInt: Int = DEFAULT_PAGE; protected set
@@ -29,7 +29,7 @@ abstract class InventoryGUI<T : ForInventory>(
internal var isInMove: Boolean = false internal var isInMove: Boolean = false
internal val currentElements = HashSet<InventoryGUIElement<*>>() internal val currentElements = HashSet<GUIElement<*>>()
internal abstract fun loadPageUnsafe( internal abstract fun loadPageUnsafe(
page: Int, page: Int,
@@ -38,13 +38,13 @@ abstract class InventoryGUI<T : ForInventory>(
) )
internal abstract fun loadPageUnsafe( internal abstract fun loadPageUnsafe(
page: InventoryGUIPage<*>, page: GUIPage<*>,
offsetHorizontally: Int = 0, offsetHorizontally: Int = 0,
offsetVertically: Int = 0 offsetVertically: Int = 0
) )
internal abstract fun loadContent( internal abstract fun loadContent(
content: Map<Int, InventoryGUISlot<*>>, content: Map<Int, GUISlot<*>>,
offsetHorizontally: Int = 0, offsetHorizontally: Int = 0,
offsetVertically: Int = 0 offsetVertically: Int = 0
) )
@@ -55,23 +55,23 @@ abstract class InventoryGUI<T : ForInventory>(
abstract fun isThisInv(inventory: Inventory): Boolean abstract fun isThisInv(inventory: Inventory): Boolean
/** /**
* Registers this InventoryGUI. * Registers this GUI.
* (KSpigot will listen for actions in the inventory.) * (KSpigot will listen for actions in the inventory.)
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun register() = InventoryGUIHolder.register(this as InventoryGUI<ForInventory>) fun register() = GUIHolder.register(this as GUI<ForInventory>)
/** /**
* Stops KSpigot from listening to actions in this * Stops KSpigot from listening to actions in this
* InventoryGUI anymore. * GUI anymore.
*/ */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
fun unregister() = InventoryGUIHolder.unregister(this as InventoryGUI<ForInventory>) fun unregister() = GUIHolder.unregister(this as GUI<ForInventory>)
/** /**
* Loads the specified page in order to display it in the GUI. * Loads the specified page in order to display it in the GUI.
*/ */
fun loadPage(page: InventoryGUIPage<T>) = loadPageUnsafe(page) fun loadPage(page: GUIPage<T>) = loadPageUnsafe(page)
/** /**
* Temporarily sets the given item at the given slots. * Temporarily sets the given item at the given slots.
@@ -95,11 +95,11 @@ abstract class InventoryGUI<T : ForInventory>(
// Inventory GUI implementations // Inventory GUI implementations
class InventoryGUIShared<T : ForInventory>( class GUIShared<T : ForInventory>(
inventoryGUIData: InventoryGUIData<T> GUIData: GUIData<T>
) : InventoryGUI<T>(inventoryGUIData) { ) : GUI<T>(GUIData) {
override val bukkitInventory = data.inventoryType.createBukkitInv(null, data.title) override val bukkitInventory = data.guiType.createBukkitInv(null, data.title)
init { init {
loadPageUnsafe(DEFAULT_PAGE) loadPageUnsafe(DEFAULT_PAGE)
@@ -111,7 +111,7 @@ class InventoryGUIShared<T : ForInventory>(
data.pages[page]?.let { loadPageUnsafe(it, offsetHorizontally, offsetVertically) } data.pages[page]?.let { loadPageUnsafe(it, offsetHorizontally, offsetVertically) }
} }
override fun loadPageUnsafe(page: InventoryGUIPage<*>, offsetHorizontally: Int, offsetVertically: Int) { override fun loadPageUnsafe(page: GUIPage<*>, offsetHorizontally: Int, offsetVertically: Int) {
val ifOffset = offsetHorizontally != 0 || offsetVertically != 0 val ifOffset = offsetHorizontally != 0 || offsetVertically != 0
@@ -122,7 +122,7 @@ class InventoryGUIShared<T : ForInventory>(
currentElements.clear() currentElements.clear()
// register this inv for all new elements // register this inv for all new elements
HashSet(page.slots.values).forEach { if (it is InventoryGUIElement) { HashSet(page.slots.values).forEach { if (it is GUIElement) {
currentElements += it currentElements += it
it.startUsing(this) it.startUsing(this)
} } } }
@@ -136,14 +136,14 @@ class InventoryGUIShared<T : ForInventory>(
} }
override fun loadContent( override fun loadContent(
content: Map<Int, InventoryGUISlot<*>>, content: Map<Int, GUISlot<*>>,
offsetHorizontally: Int, offsetHorizontally: Int,
offsetVertically: Int offsetVertically: Int
) { ) {
val ifOffset = offsetHorizontally != 0 || offsetVertically != 0 val ifOffset = offsetHorizontally != 0 || offsetVertically != 0
val dimensions = data.inventoryType.dimensions val dimensions = data.guiType.dimensions
// clear the space which will be redefined // clear the space which will be redefined
if (ifOffset) { if (ifOffset) {
@@ -157,7 +157,7 @@ class InventoryGUIShared<T : ForInventory>(
content.forEach { content.forEach {
val slot = it.value val slot = it.value
if (slot is InventoryGUIElement) { if (slot is GUIElement) {
if (ifOffset) { if (ifOffset) {
val invSlot = InventorySlot.fromRealSlot(it.key, dimensions) val invSlot = InventorySlot.fromRealSlot(it.key, dimensions)
@@ -174,7 +174,7 @@ class InventoryGUIShared<T : ForInventory>(
} }
override operator fun set(slot: InventorySlotCompound<T>, value: ItemStack) { override operator fun set(slot: InventorySlotCompound<T>, value: ItemStack) {
slot.realSlotsWithInvType(data.inventoryType).forEach { slot.realSlotsWithInvType(data.guiType).forEach {
bukkitInventory.setItem(it, value) bukkitInventory.setItem(it, value)
} }
} }

View File

@@ -1,20 +1,20 @@
@file:Suppress("MemberVisibilityCanBePrivate", "unused") @file:Suppress("MemberVisibilityCanBePrivate", "unused")
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import net.axay.kspigot.inventory.elements.* import net.axay.kspigot.gui.elements.*
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
fun <T : ForInventory> kSpigotGUI( fun <T : ForInventory> kSpigotGUI(
type: InventoryType<T>, type: GUIType<T>,
shared: Boolean = true, shared: Boolean = true,
builder: InventoryGUIBuilder<T>.() -> Unit, builder: GUIBuilder<T>.() -> Unit,
) = InventoryGUIBuilder(type, shared).apply(builder).build() ) = GUIBuilder(type, shared).apply(builder).build()
class InventoryGUIBuilder<T : ForInventory>( class GUIBuilder<T : ForInventory>(
val type: InventoryType<T>, val type: GUIType<T>,
val shared: Boolean val shared: Boolean
) { ) {
var title: String = "" var title: String = ""
@@ -22,45 +22,45 @@ class InventoryGUIBuilder<T : ForInventory>(
var transitionTo: InventoryChangeEffect? = null var transitionTo: InventoryChangeEffect? = null
var transitionFrom: InventoryChangeEffect? = null var transitionFrom: InventoryChangeEffect? = null
private val guiSlots = HashMap<Int, InventoryGUIPage<T>>() private val guiSlots = HashMap<Int, GUIPage<T>>()
private var onClickElement: ((InventoryGUIClickEvent<T>) -> Unit)? = null private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
/** /**
* Opens the builder for a new page and adds * Opens the builder for a new page and adds
* the new page to the GUI. * the new page to the GUI.
* @param page The index of the page. * @param page The index of the page.
*/ */
fun page(page: Int, builder: InventoryGUIPageBuilder<T>.() -> Unit) { fun page(page: Int, builder: GUIPageBuilder<T>.() -> Unit) {
guiSlots[page] = InventoryGUIPageBuilder(type, page).apply(builder).build() guiSlots[page] = GUIPageBuilder(type, page).apply(builder).build()
} }
fun onClickElement(onClick: (InventoryGUIClickEvent<T>) -> Unit) { fun onClickElement(onClick: (GUIClickEvent<T>) -> Unit) {
onClickElement = onClick onClickElement = onClick
} }
internal fun build(): InventoryGUI<T> { internal fun build(): GUI<T> {
val guiData = InventoryGUIData(type, title, guiSlots, transitionTo, transitionFrom, onClickElement) val guiData = GUIData(type, title, guiSlots, transitionTo, transitionFrom, onClickElement)
val gui = val gui =
if (shared) InventoryGUIShared(guiData) else TODO("Currently, there is no non-shared GUI implementation available.") if (shared) GUIShared(guiData) else TODO("Currently, there is no non-shared GUI implementation available.")
return gui.apply { register() } return gui.apply { register() }
} }
} }
class InventoryGUIPageBuilder<T : ForInventory>( class GUIPageBuilder<T : ForInventory>(
private val type: InventoryType<T>, private val type: GUIType<T>,
val page: Int val page: Int
) { ) {
private val guiSlots = HashMap<Int, InventoryGUISlot<T>>() private val guiSlots = HashMap<Int, GUISlot<T>>()
var transitionTo: PageChangeEffect? = null var transitionTo: PageChangeEffect? = null
var transitionFrom: PageChangeEffect? = null var transitionFrom: PageChangeEffect? = null
internal fun build() = InventoryGUIPage(page, guiSlots, transitionTo, transitionFrom) internal fun build() = GUIPage(page, guiSlots, transitionTo, transitionFrom)
private fun defineSlots(slots: InventorySlotCompound<T>, element: InventoryGUISlot<T>) = private fun defineSlots(slots: InventorySlotCompound<T>, element: GUISlot<T>) =
slots.withInvType(type).forEach { curSlot -> slots.withInvType(type).forEach { curSlot ->
curSlot.realSlotIn(type.dimensions)?.let { guiSlots[it] = element } curSlot.realSlotIn(type.dimensions)?.let { guiSlots[it] = element }
} }
@@ -70,22 +70,22 @@ class InventoryGUIPageBuilder<T : ForInventory>(
* actions. If clicked, the specified [onClick] * actions. If clicked, the specified [onClick]
* function is invoked. * function is invoked.
*/ */
fun button(slots: InventorySlotCompound<T>, itemStack: ItemStack, onClick: (InventoryGUIClickEvent<T>) -> Unit) = fun button(slots: InventorySlotCompound<T>, itemStack: ItemStack, onClick: (GUIClickEvent<T>) -> Unit) =
defineSlots(slots, InventoryGUIButton(itemStack, onClick)) defineSlots(slots, GUIButton(itemStack, onClick))
/** /**
* An item protected from any player actions. * An item protected from any player actions.
* This is not a button. * This is not a button.
*/ */
fun placeholder(slots: InventorySlotCompound<T>, itemStack: ItemStack) = fun placeholder(slots: InventorySlotCompound<T>, itemStack: ItemStack) =
defineSlots(slots, InventoryGUIPlaceholder(itemStack)) defineSlots(slots, GUIPlaceholder(itemStack))
/** /**
* A free slot does not block any player actions. * A free slot does not block any player actions.
* The player can put items in this slot or take * The player can put items in this slot or take
* items out of it. * items out of it.
*/ */
fun freeSlot(slots: InventorySlotCompound<T>) = defineSlots(slots, InventoryGUIFreeSlot()) fun freeSlot(slots: InventorySlotCompound<T>) = defineSlots(slots, GUIFreeSlot())
/** /**
* This is a button which loads the specified * This is a button which loads the specified
@@ -95,11 +95,11 @@ class InventoryGUIPageBuilder<T : ForInventory>(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
icon: ItemStack, icon: ItemStack,
toPage: Int, toPage: Int,
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null onChange: ((GUIClickEvent<T>) -> Unit)? = null
) = defineSlots( ) = defineSlots(
slots, InventoryGUIButtonPageChange( slots, GUIButtonPageChange(
icon, icon,
InventoryGUIPageChangeCalculator.InventoryGUIConsistentPageCalculator(toPage), GUIPageChangeCalculator.GUIConsistentPageCalculator(toPage),
onChange onChange
) )
) )
@@ -112,11 +112,11 @@ class InventoryGUIPageBuilder<T : ForInventory>(
fun previousPage( fun previousPage(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
icon: ItemStack, icon: ItemStack,
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null onChange: ((GUIClickEvent<T>) -> Unit)? = null
) = defineSlots( ) = defineSlots(
slots, InventoryGUIButtonPageChange( slots, GUIButtonPageChange(
icon, icon,
InventoryGUIPageChangeCalculator.InventoryGUIPreviousPageCalculator, GUIPageChangeCalculator.GUIPreviousPageCalculator,
onChange onChange
) )
) )
@@ -129,27 +129,27 @@ class InventoryGUIPageBuilder<T : ForInventory>(
fun nextPage( fun nextPage(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
icon: ItemStack, icon: ItemStack,
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null onChange: ((GUIClickEvent<T>) -> Unit)? = null
) = defineSlots( ) = defineSlots(
slots, InventoryGUIButtonPageChange( slots, GUIButtonPageChange(
icon, icon,
InventoryGUIPageChangeCalculator.InventoryGUINextPageCalculator, GUIPageChangeCalculator.GUINextPageCalculator,
onChange onChange
) )
) )
/** /**
* By pressing this button, the player switches to another * By pressing this button, the player switches to another
* InventoryGUI. The transition effect is applied. * GUI. The transition effect is applied.
*/ */
fun changeGUI( fun changeGUI(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
icon: ItemStack, icon: ItemStack,
newGUI: () -> InventoryGUI<*>, newGUI: () -> GUI<*>,
newPage: Int? = null, newPage: Int? = null,
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? = null onChange: ((GUIClickEvent<T>) -> Unit)? = null
) = defineSlots( ) = defineSlots(
slots, InventoryGUIButtonInventoryChange( slots, GUIButtonInventoryChange(
icon, icon,
newGUI, newGUI,
newPage, newPage,
@@ -163,8 +163,8 @@ class InventoryGUIPageBuilder<T : ForInventory>(
*/ */
fun <E> createCompound( fun <E> createCompound(
iconGenerator: (E) -> ItemStack, iconGenerator: (E) -> ItemStack,
onClick: (clickEvent: InventoryGUIClickEvent<T>, element: E) -> Unit onClick: (clickEvent: GUIClickEvent<T>, element: E) -> Unit
) = InventoryGUISpaceCompound(type, iconGenerator, onClick) ) = GUISpaceCompound(type, iconGenerator, onClick)
/** /**
* Creates a new compound, holding data which can be displayed * Creates a new compound, holding data which can be displayed
@@ -176,10 +176,10 @@ class InventoryGUIPageBuilder<T : ForInventory>(
fromSlot: SingleInventorySlot<out T>, fromSlot: SingleInventorySlot<out T>,
toSlot: SingleInventorySlot<out T>, toSlot: SingleInventorySlot<out T>,
iconGenerator: (E) -> ItemStack, iconGenerator: (E) -> ItemStack,
onClick: (clickEvent: InventoryGUIClickEvent<T>, element: E) -> Unit onClick: (clickEvent: GUIClickEvent<T>, element: E) -> Unit
): InventoryGUIRectSpaceCompound<T, E> { ): GUIRectSpaceCompound<T, E> {
val rectSlotCompound = fromSlot rectTo toSlot val rectSlotCompound = fromSlot rectTo toSlot
return InventoryGUIRectSpaceCompound( return GUIRectSpaceCompound(
type, type,
iconGenerator, iconGenerator,
onClick, onClick,
@@ -188,7 +188,7 @@ class InventoryGUIPageBuilder<T : ForInventory>(
addSlots(rectSlotCompound) addSlots(rectSlotCompound)
defineSlots( defineSlots(
rectSlotCompound, rectSlotCompound,
InventoryGUISpaceCompoundElement(this) GUISpaceCompoundElement(this)
) )
} }
} }
@@ -199,12 +199,12 @@ class InventoryGUIPageBuilder<T : ForInventory>(
*/ */
fun <E> compoundSpace( fun <E> compoundSpace(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
compound: AbstractInventoryGUISpaceCompound<T, E> compound: AbstractGUISpaceCompound<T, E>
) { ) {
compound.addSlots(slots) compound.addSlots(slots)
defineSlots( defineSlots(
slots, slots,
InventoryGUISpaceCompoundElement(compound) GUISpaceCompoundElement(compound)
) )
} }
@@ -215,13 +215,13 @@ class InventoryGUIPageBuilder<T : ForInventory>(
fun compoundScroll( fun compoundScroll(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
icon: ItemStack, icon: ItemStack,
compound: InventoryGUISpaceCompound<T, *>, compound: GUISpaceCompound<T, *>,
scrollDistance: Int = 1, scrollDistance: Int = 1,
scrollTimes: Int = 1, scrollTimes: Int = 1,
reverse: Boolean = false reverse: Boolean = false
) = defineSlots( ) = defineSlots(
slots, slots,
InventoryGUISpaceCompoundScrollButton( GUISpaceCompoundScrollButton(
icon, icon,
compound, compound,
scrollDistance.absoluteValue, scrollDistance.absoluteValue,
@@ -237,12 +237,12 @@ class InventoryGUIPageBuilder<T : ForInventory>(
fun compoundScroll( fun compoundScroll(
slots: InventorySlotCompound<T>, slots: InventorySlotCompound<T>,
icon: ItemStack, icon: ItemStack,
compound: InventoryGUIRectSpaceCompound<T, *>, compound: GUIRectSpaceCompound<T, *>,
scrollTimes: Int = 1, scrollTimes: Int = 1,
reverse: Boolean = false reverse: Boolean = false
) = defineSlots( ) = defineSlots(
slots, slots,
InventoryGUISpaceCompoundScrollButton( GUISpaceCompoundScrollButton(
icon, icon,
compound, compound,
compound.compoundWidth, compound.compoundWidth,

View File

@@ -0,0 +1,8 @@
package net.axay.kspigot.gui
import org.bukkit.event.inventory.InventoryClickEvent
class GUIClickEvent<T : ForInventory>(
val bukkitEvent: InventoryClickEvent,
val gui: GUI<T>
)

View File

@@ -0,0 +1,25 @@
package net.axay.kspigot.gui
import org.bukkit.inventory.ItemStack
abstract class GUISlot<T : ForInventory> {
abstract fun onClick(clickEvent: GUIClickEvent<T>)
}
// ELEMENT
abstract class GUIElement<T : ForInventory> : GUISlot<T>() {
abstract fun getItemStack(slot: Int): ItemStack
final override fun onClick(clickEvent: GUIClickEvent<T>) {
clickEvent.gui.data.generalOnClick?.invoke(clickEvent)
onClickElement(clickEvent)
}
protected abstract fun onClickElement(clickEvent: GUIClickEvent<T>)
internal open fun startUsing(gui: GUI<*>) { }
internal open fun stopUsing(gui: GUI<*>) { }
}

View File

@@ -1,9 +1,9 @@
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import org.bukkit.entity.HumanEntity import org.bukkit.entity.HumanEntity
import org.bukkit.inventory.InventoryView import org.bukkit.inventory.InventoryView
fun HumanEntity.openGUI(gui: InventoryGUI<*>, page: Int? = null): InventoryView? { fun HumanEntity.openGUI(gui: GUI<*>, page: Int? = null): InventoryView? {
closeInventory() closeInventory()

View File

@@ -1,19 +1,19 @@
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import net.axay.kspigot.event.listen import net.axay.kspigot.event.listen
import org.bukkit.event.inventory.InventoryAction import org.bukkit.event.inventory.InventoryAction
import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.InventoryClickEvent
object InventoryGUIHolder : AutoCloseable { object GUIHolder : AutoCloseable {
private val registered = HashSet<InventoryGUI<ForInventory>>() private val registered = HashSet<GUI<ForInventory>>()
fun register(inventoryGUI: InventoryGUI<ForInventory>) { fun register(GUI: GUI<ForInventory>) {
registered.add(inventoryGUI) registered.add(GUI)
} }
fun unregister(inventoryGUI: InventoryGUI<ForInventory>) { fun unregister(GUI: GUI<ForInventory>) {
registered.remove(inventoryGUI) registered.remove(GUI)
} }
init { init {
@@ -30,7 +30,7 @@ object InventoryGUIHolder : AutoCloseable {
} }
if (it.action.isGUIClick) if (it.action.isGUIClick)
inv.currentPage.slots[it.slot]?.onClick(InventoryGUIClickEvent(it, inv)) ?: kotlin.run { inv.currentPage.slots[it.slot]?.onClick(GUIClickEvent(it, inv)) ?: kotlin.run {
it.isCancelled = true it.isCancelled = true
} }
else else

View File

@@ -0,0 +1,8 @@
package net.axay.kspigot.gui
class GUIPage<T : ForInventory>(
val number: Int,
internal val slots: Map<Int, GUISlot<T>>,
val transitionTo: PageChangeEffect?,
val transitionFrom: PageChangeEffect?
)

View File

@@ -1,22 +1,22 @@
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import net.axay.kspigot.runnables.task import net.axay.kspigot.runnables.task
abstract class InventoryGUIPageChangeCalculator { abstract class GUIPageChangeCalculator {
abstract fun calculateNewPage(currentPage: Int, pages: Collection<Int>): Int? abstract fun calculateNewPage(currentPage: Int, pages: Collection<Int>): Int?
object InventoryGUIPreviousPageCalculator : InventoryGUIPageChangeCalculator() { object GUIPreviousPageCalculator : GUIPageChangeCalculator() {
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) = override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) =
pages.sortedDescending().find { it < currentPage } pages.sortedDescending().find { it < currentPage }
} }
object InventoryGUINextPageCalculator : InventoryGUIPageChangeCalculator() { object GUINextPageCalculator : GUIPageChangeCalculator() {
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) = override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) =
pages.sorted().find { it > currentPage } pages.sorted().find { it > currentPage }
} }
class InventoryGUIConsistentPageCalculator(private val toPage: Int) : InventoryGUIPageChangeCalculator() { class GUIConsistentPageCalculator(private val toPage: Int) : GUIPageChangeCalculator() {
override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) = toPage override fun calculateNewPage(currentPage: Int, pages: Collection<Int>) = toPage
} }
@@ -36,10 +36,10 @@ enum class InventoryChangeEffect(
INSTANT(PageChangeEffect.INSTANT) INSTANT(PageChangeEffect.INSTANT)
} }
internal fun InventoryGUI<*>.changePage( internal fun GUI<*>.changePage(
effect: PageChangeEffect, effect: PageChangeEffect,
fromPage: InventoryGUIPage<*>, fromPage: GUIPage<*>,
toPage: InventoryGUIPage<*> toPage: GUIPage<*>
) { ) {
val fromPageInt = fromPage.number val fromPageInt = fromPage.number
@@ -51,7 +51,7 @@ internal fun InventoryGUI<*>.changePage(
PageChangeEffect.SLIDE_HORIZONTALLY -> { PageChangeEffect.SLIDE_HORIZONTALLY -> {
val width = data.inventoryType.dimensions.width val width = data.guiType.dimensions.width
changePageEffect(fromPageInt, toPageInt, width) { currentOffset, ifInverted -> changePageEffect(fromPageInt, toPageInt, width) { currentOffset, ifInverted ->
if (ifInverted) { if (ifInverted) {
@@ -67,7 +67,7 @@ internal fun InventoryGUI<*>.changePage(
PageChangeEffect.SLIDE_VERTICALLY -> { PageChangeEffect.SLIDE_VERTICALLY -> {
val height = data.inventoryType.dimensions.height val height = data.guiType.dimensions.height
changePageEffect(fromPageInt, toPageInt, height) { currentOffset, ifInverted -> changePageEffect(fromPageInt, toPageInt, height) { currentOffset, ifInverted ->
if (ifInverted) { if (ifInverted) {
@@ -83,7 +83,7 @@ internal fun InventoryGUI<*>.changePage(
PageChangeEffect.SWIPE_HORIZONTALLY -> { PageChangeEffect.SWIPE_HORIZONTALLY -> {
val width = data.inventoryType.dimensions.width val width = data.guiType.dimensions.width
changePageEffect(fromPageInt, toPageInt, width) { currentOffset, ifInverted -> changePageEffect(fromPageInt, toPageInt, width) { currentOffset, ifInverted ->
if (ifInverted) { if (ifInverted) {
@@ -97,7 +97,7 @@ internal fun InventoryGUI<*>.changePage(
PageChangeEffect.SWIPE_VERTICALLY -> { PageChangeEffect.SWIPE_VERTICALLY -> {
val height = data.inventoryType.dimensions.height val height = data.guiType.dimensions.height
changePageEffect(fromPageInt, toPageInt, height) { currentOffset, ifInverted -> changePageEffect(fromPageInt, toPageInt, height) { currentOffset, ifInverted ->
if (ifInverted) { if (ifInverted) {
@@ -112,10 +112,10 @@ internal fun InventoryGUI<*>.changePage(
} }
} }
internal fun InventoryGUI<*>.changeGUI( internal fun GUI<*>.changeGUI(
effect: InventoryChangeEffect, effect: InventoryChangeEffect,
fromPage: InventoryGUIPage<*>, fromPage: GUIPage<*>,
toPage: InventoryGUIPage<*> toPage: GUIPage<*>
) = changePage(effect.effect, fromPage, toPage) ) = changePage(effect.effect, fromPage, toPage)
private inline fun changePageEffect( private inline fun changePageEffect(

View File

@@ -1,6 +1,6 @@
@file:Suppress("unused", "MemberVisibilityCanBePrivate") @file:Suppress("unused", "MemberVisibilityCanBePrivate")
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import net.axay.kspigot.languageextensions.kotlinextensions.MinMaxPair import net.axay.kspigot.languageextensions.kotlinextensions.MinMaxPair
@@ -70,9 +70,9 @@ data class InventorySlot(val row: Int, val slotInRow: Int) : Comparable<Inventor
interface InventorySlotCompound<out T : ForInventory> { interface InventorySlotCompound<out T : ForInventory> {
fun withInvType(invType: InventoryType<T>): Collection<InventorySlot> fun withInvType(invType: GUIType<T>): Collection<InventorySlot>
fun realSlotsWithInvType(invType: InventoryType<T>) = fun realSlotsWithInvType(invType: GUIType<T>) =
withInvType(invType).mapNotNull { it.realSlotIn(invType.dimensions) } withInvType(invType).mapNotNull { it.realSlotIn(invType.dimensions) }
} }
@@ -85,7 +85,7 @@ open class SingleInventorySlot<T : ForInventory> internal constructor(
private val slotAsList = listOf(inventorySlot) private val slotAsList = listOf(inventorySlot)
override fun withInvType(invType: InventoryType<T>) = slotAsList override fun withInvType(invType: GUIType<T>) = slotAsList
} }
@@ -112,7 +112,7 @@ class InventorySlotRange<out T : ForInventory> internal constructor(
endInclusive = minMaxPair.max endInclusive = minMaxPair.max
} }
override fun withInvType(invType: InventoryType<T>) = LinkedHashSet<InventorySlot>().apply { override fun withInvType(invType: GUIType<T>) = LinkedHashSet<InventorySlot>().apply {
when (type) { when (type) {
InventorySlotRangeType.RECTANGLE -> { InventorySlotRangeType.RECTANGLE -> {
@@ -166,7 +166,7 @@ class InventoryRowSlots<T : ForInventory> internal constructor(
val row: Int val row: Int
) : InventorySlotCompound<T> { ) : InventorySlotCompound<T> {
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply { override fun withInvType(invType: GUIType<T>) = HashSet<InventorySlot>().apply {
for (slotInRow in 1..invType.dimensions.width) for (slotInRow in 1..invType.dimensions.width)
this += InventorySlot(row, slotInRow) this += InventorySlot(row, slotInRow)
} }
@@ -177,7 +177,7 @@ class InventoryColumnSlots<T : ForInventory> internal constructor(
val column: Int val column: Int
) : InventorySlotCompound<T> { ) : InventorySlotCompound<T> {
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply { override fun withInvType(invType: GUIType<T>) = HashSet<InventorySlot>().apply {
for (row in 1..invType.dimensions.height) for (row in 1..invType.dimensions.height)
this += InventorySlot(row, column) this += InventorySlot(row, column)
} }
@@ -188,7 +188,7 @@ class InventoryBorderSlots<T : ForInventory> internal constructor(
val padding: Int val padding: Int
) : InventorySlotCompound<T> { ) : InventorySlotCompound<T> {
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply { override fun withInvType(invType: GUIType<T>) = HashSet<InventorySlot>().apply {
val dimensions = invType.dimensions val dimensions = invType.dimensions
@@ -214,7 +214,7 @@ class InventoryCornerSlots<T : ForInventory> internal constructor(
val ifTopRight: Boolean = false val ifTopRight: Boolean = false
) : InventorySlotCompound<T> { ) : InventorySlotCompound<T> {
override fun withInvType(invType: InventoryType<T>) = HashSet<InventorySlot>().apply { override fun withInvType(invType: GUIType<T>) = HashSet<InventorySlot>().apply {
val dimensions = invType.dimensions val dimensions = invType.dimensions

View File

@@ -1,29 +1,29 @@
@file:Suppress("MemberVisibilityCanBePrivate", "CanBeParameter") @file:Suppress("MemberVisibilityCanBePrivate", "CanBeParameter")
package net.axay.kspigot.inventory package net.axay.kspigot.gui
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.event.inventory.InventoryType import org.bukkit.event.inventory.InventoryType
import org.bukkit.inventory.Inventory import org.bukkit.inventory.Inventory
import org.bukkit.inventory.InventoryHolder import org.bukkit.inventory.InventoryHolder
class InventoryType<in T : ForInventory>( class GUIType<in T : ForInventory>(
val dimensions: InventoryDimensions, val dimensions: InventoryDimensions,
val bukkitType: InventoryType? = null val bukkitType: InventoryType? = null
) { ) {
companion object { companion object {
val ONE_BY_NINE = InventoryType<ForInventoryOneByNine>(InventoryDimensions(9, 1)) val ONE_BY_NINE = GUIType<ForInventoryOneByNine>(InventoryDimensions(9, 1))
val TWO_BY_NINE = InventoryType<ForInventoryTwoByNine>(InventoryDimensions(9, 2)) val TWO_BY_NINE = GUIType<ForInventoryTwoByNine>(InventoryDimensions(9, 2))
val THREE_BY_NINE = InventoryType<ForInventoryThreeByNine>(InventoryDimensions(9, 3)) val THREE_BY_NINE = GUIType<ForInventoryThreeByNine>(InventoryDimensions(9, 3))
val FOUR_BY_NINE = InventoryType<ForInventoryFourByNine>(InventoryDimensions(9, 4)) val FOUR_BY_NINE = GUIType<ForInventoryFourByNine>(InventoryDimensions(9, 4))
val FIVE_BY_NINE = InventoryType<ForInventoryFiveByNine>(InventoryDimensions(9, 5)) val FIVE_BY_NINE = GUIType<ForInventoryFiveByNine>(InventoryDimensions(9, 5))
val SIX_BY_NINE = InventoryType<ForInventorySixByNine>(InventoryDimensions(9, 6)) val SIX_BY_NINE = GUIType<ForInventorySixByNine>(InventoryDimensions(9, 6))
val ONE_BY_FIVE = val ONE_BY_FIVE =
InventoryType<ForInventoryOneByFive>(InventoryDimensions(5, 1), bukkitType = InventoryType.HOPPER) GUIType<ForInventoryOneByFive>(InventoryDimensions(5, 1), bukkitType = InventoryType.HOPPER)
val THREE_BY_THREE = val THREE_BY_THREE =
InventoryType<ForInventoryThreeByThree>(InventoryDimensions(3, 3), bukkitType = InventoryType.DROPPER) GUIType<ForInventoryThreeByThree>(InventoryDimensions(3, 3), bukkitType = InventoryType.DROPPER)
} }

View File

@@ -0,0 +1,18 @@
package net.axay.kspigot.gui.elements
import net.axay.kspigot.gui.*
import org.bukkit.inventory.ItemStack
open class GUIButton<T : ForInventory>(
private val icon: ItemStack,
private val action: (GUIClickEvent<T>) -> Unit,
) : GUIElement<T>() {
final override fun getItemStack(slot: Int) = icon
override fun onClickElement(clickEvent: GUIClickEvent<T>) {
clickEvent.bukkitEvent.isCancelled = true
action(clickEvent)
}
}

View File

@@ -1,14 +1,14 @@
package net.axay.kspigot.inventory.elements package net.axay.kspigot.gui.elements
import net.axay.kspigot.inventory.* import net.axay.kspigot.gui.*
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
class InventoryGUIButtonInventoryChange<T : ForInventory>( class GUIButtonInventoryChange<T : ForInventory>(
icon: ItemStack, icon: ItemStack,
changeToGUICallback: () -> InventoryGUI<*>, changeToGUICallback: () -> GUI<*>,
changeToPageInt: Int?, changeToPageInt: Int?,
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? onChange: ((GUIClickEvent<T>) -> Unit)?
) : InventoryGUIButton<T>(icon, { ) : GUIButton<T>(icon, {
val changeToGUI = changeToGUICallback.invoke() val changeToGUI = changeToGUICallback.invoke()

View File

@@ -1,13 +1,13 @@
package net.axay.kspigot.inventory.elements package net.axay.kspigot.gui.elements
import net.axay.kspigot.inventory.* import net.axay.kspigot.gui.*
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
class InventoryGUIButtonPageChange<T : ForInventory>( class GUIButtonPageChange<T : ForInventory>(
icon: ItemStack, icon: ItemStack,
calculator: InventoryGUIPageChangeCalculator, calculator: GUIPageChangeCalculator,
onChange: ((InventoryGUIClickEvent<T>) -> Unit)? onChange: ((GUIClickEvent<T>) -> Unit)?
) : InventoryGUIButton<T>(icon, { ) : GUIButton<T>(icon, {
val currentPage = it.gui.currentPage val currentPage = it.gui.currentPage
val newPage = it.gui.getPage(calculator.calculateNewPage(it.gui.currentPageInt, it.gui.data.pages.keys)) val newPage = it.gui.getPage(calculator.calculateNewPage(it.gui.currentPageInt, it.gui.data.pages.keys))

View File

@@ -0,0 +1,11 @@
package net.axay.kspigot.gui.elements
import net.axay.kspigot.gui.ForInventory
import net.axay.kspigot.gui.GUIClickEvent
import net.axay.kspigot.gui.GUISlot
class GUIFreeSlot<T : ForInventory> : GUISlot<T>() {
override fun onClick(clickEvent: GUIClickEvent<T>) {
/* do nothing */
}
}

View File

@@ -0,0 +1,16 @@
package net.axay.kspigot.gui.elements
import net.axay.kspigot.gui.*
import org.bukkit.inventory.ItemStack
class GUIPlaceholder<T : ForInventory>(
private val icon: ItemStack
) : GUIElement<T>() {
override fun getItemStack(slot: Int) = icon
override fun onClickElement(clickEvent: GUIClickEvent<T>) {
clickEvent.bukkitEvent.isCancelled = true
}
}

View File

@@ -1,53 +1,53 @@
@file:Suppress("MemberVisibilityCanBePrivate") @file:Suppress("MemberVisibilityCanBePrivate")
package net.axay.kspigot.inventory.elements package net.axay.kspigot.gui.elements
import net.axay.kspigot.inventory.* import net.axay.kspigot.gui.*
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
class InventoryGUISpaceCompoundElement<T : ForInventory, E> internal constructor( class GUISpaceCompoundElement<T : ForInventory, E> internal constructor(
private val compound: AbstractInventoryGUISpaceCompound<T, E> private val compound: AbstractGUISpaceCompound<T, E>
) : InventoryGUIElement<T>() { ) : GUIElement<T>() {
override fun getItemStack(slot: Int) = compound.getItemStack(slot) override fun getItemStack(slot: Int) = compound.getItemStack(slot)
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) { override fun onClickElement(clickEvent: GUIClickEvent<T>) {
compound.onClickElement(clickEvent) compound.onClickElement(clickEvent)
} }
override fun startUsing(gui: InventoryGUI<*>) = compound.registerGUI(gui) override fun startUsing(gui: GUI<*>) = compound.registerGUI(gui)
override fun stopUsing(gui: InventoryGUI<*>) = compound.unregisterGUI(gui) override fun stopUsing(gui: GUI<*>) = compound.unregisterGUI(gui)
} }
class InventoryGUIRectSpaceCompound<T : ForInventory, E>( class GUIRectSpaceCompound<T : ForInventory, E>(
invType: InventoryType<T>, invType: GUIType<T>,
iconGenerator: (E) -> ItemStack, iconGenerator: (E) -> ItemStack,
onClick: (InventoryGUIClickEvent<T>, E) -> Unit, onClick: (GUIClickEvent<T>, E) -> Unit,
internal val compoundWidth: Int internal val compoundWidth: Int
) : AbstractInventoryGUISpaceCompound<T, E>(invType, iconGenerator, onClick) { ) : AbstractGUISpaceCompound<T, E>(invType, iconGenerator, onClick) {
override fun handleScrollEndReached(newProgress: Int, internalSlotsSize: Int, contentSize: Int) = override fun handleScrollEndReached(newProgress: Int, internalSlotsSize: Int, contentSize: Int) =
(internalSlotsSize + newProgress <= contentSize + (compoundWidth - (contentSize % compoundWidth))) (internalSlotsSize + newProgress <= contentSize + (compoundWidth - (contentSize % compoundWidth)))
} }
class InventoryGUISpaceCompound<T : ForInventory, E>( class GUISpaceCompound<T : ForInventory, E>(
invType: InventoryType<T>, invType: GUIType<T>,
iconGenerator: (E) -> ItemStack, iconGenerator: (E) -> ItemStack,
onClick: (InventoryGUIClickEvent<T>, E) -> Unit onClick: (GUIClickEvent<T>, E) -> Unit
) : AbstractInventoryGUISpaceCompound<T, E>(invType, iconGenerator, onClick) { ) : AbstractGUISpaceCompound<T, E>(invType, iconGenerator, onClick) {
override fun handleScrollEndReached(newProgress: Int, internalSlotsSize: Int, contentSize: Int) = false override fun handleScrollEndReached(newProgress: Int, internalSlotsSize: Int, contentSize: Int) = false
} }
abstract class AbstractInventoryGUISpaceCompound<T : ForInventory, E> internal constructor( abstract class AbstractGUISpaceCompound<T : ForInventory, E> internal constructor(
val invType: InventoryType<T>, val guiType: GUIType<T>,
private val iconGenerator: (E) -> ItemStack, private val iconGenerator: (E) -> ItemStack,
private val onClick: (InventoryGUIClickEvent<T>, E) -> Unit private val onClick: (GUIClickEvent<T>, E) -> Unit
) { ) {
private val content = ArrayList<E>() private val content = ArrayList<E>()
@@ -59,7 +59,7 @@ abstract class AbstractInventoryGUISpaceCompound<T : ForInventory, E> internal c
private var contentSort: () -> Unit = { } private var contentSort: () -> Unit = { }
private val registeredGUIs = HashSet<InventoryGUI<*>>() private val registeredGUIs = HashSet<GUI<*>>()
private fun contentAtSlot(slot: Int) = currentContent.getOrNull(internalSlots.indexOf(slot)) private fun contentAtSlot(slot: Int) = currentContent.getOrNull(internalSlots.indexOf(slot))
@@ -107,7 +107,7 @@ abstract class AbstractInventoryGUISpaceCompound<T : ForInventory, E> internal c
?: ItemStack(Material.AIR) ?: ItemStack(Material.AIR)
} }
internal fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) { internal fun onClickElement(clickEvent: GUIClickEvent<T>) {
val element = contentAtSlot(clickEvent.bukkitEvent.slot) ?: kotlin.run { val element = contentAtSlot(clickEvent.bukkitEvent.slot) ?: kotlin.run {
clickEvent.bukkitEvent.isCancelled = true clickEvent.bukkitEvent.isCancelled = true
return return
@@ -116,18 +116,18 @@ abstract class AbstractInventoryGUISpaceCompound<T : ForInventory, E> internal c
} }
internal fun addSlots(slots: InventorySlotCompound<T>) { internal fun addSlots(slots: InventorySlotCompound<T>) {
slots.realSlotsWithInvType(invType).forEach { slots.realSlotsWithInvType(guiType).forEach {
if (!internalSlots.contains(it)) if (!internalSlots.contains(it))
internalSlots.add(it) internalSlots.add(it)
} }
internalSlots.sort() internalSlots.sort()
} }
internal fun registerGUI(gui: InventoryGUI<*>) { internal fun registerGUI(gui: GUI<*>) {
registeredGUIs += gui registeredGUIs += gui
} }
internal fun unregisterGUI(gui: InventoryGUI<*>) { internal fun unregisterGUI(gui: GUI<*>) {
registeredGUIs -= gui registeredGUIs -= gui
} }

View File

@@ -1,16 +1,16 @@
package net.axay.kspigot.inventory.elements package net.axay.kspigot.gui.elements
import net.axay.kspigot.inventory.ForInventory import net.axay.kspigot.gui.ForInventory
import net.axay.kspigot.runnables.task import net.axay.kspigot.runnables.task
import org.bukkit.inventory.ItemStack import org.bukkit.inventory.ItemStack
class InventoryGUISpaceCompoundScrollButton<T : ForInventory>( class GUISpaceCompoundScrollButton<T : ForInventory>(
icon: ItemStack, icon: ItemStack,
private val compound: AbstractInventoryGUISpaceCompound<T, *>, private val compound: AbstractGUISpaceCompound<T, *>,
private val scrollDistance: Int, private val scrollDistance: Int,
private val scrollTimes: Int, private val scrollTimes: Int,
private val reverse: Boolean = false private val reverse: Boolean = false
) : InventoryGUIButton<T>(icon, { ) : GUIButton<T>(icon, {
if (scrollTimes > 1) { if (scrollTimes > 1) {
task( task(
period = 1, period = 1,

View File

@@ -1,8 +0,0 @@
package net.axay.kspigot.inventory
import org.bukkit.event.inventory.InventoryClickEvent
class InventoryGUIClickEvent<T : ForInventory>(
val bukkitEvent: InventoryClickEvent,
val gui: InventoryGUI<T>
)

View File

@@ -1,25 +0,0 @@
package net.axay.kspigot.inventory
import org.bukkit.inventory.ItemStack
abstract class InventoryGUISlot<T : ForInventory> {
abstract fun onClick(clickEvent: InventoryGUIClickEvent<T>)
}
// ELEMENT
abstract class InventoryGUIElement<T : ForInventory> : InventoryGUISlot<T>() {
abstract fun getItemStack(slot: Int): ItemStack
final override fun onClick(clickEvent: InventoryGUIClickEvent<T>) {
clickEvent.gui.data.generalOnClick?.invoke(clickEvent)
onClickElement(clickEvent)
}
protected abstract fun onClickElement(clickEvent: InventoryGUIClickEvent<T>)
internal open fun startUsing(gui: InventoryGUI<*>) { }
internal open fun stopUsing(gui: InventoryGUI<*>) { }
}

View File

@@ -1,8 +0,0 @@
package net.axay.kspigot.inventory
class InventoryGUIPage<T : ForInventory>(
val number: Int,
internal val slots: Map<Int, InventoryGUISlot<T>>,
val transitionTo: PageChangeEffect?,
val transitionFrom: PageChangeEffect?
)

View File

@@ -1,18 +0,0 @@
package net.axay.kspigot.inventory.elements
import net.axay.kspigot.inventory.*
import org.bukkit.inventory.ItemStack
open class InventoryGUIButton<T : ForInventory>(
private val icon: ItemStack,
private val action: (InventoryGUIClickEvent<T>) -> Unit,
) : InventoryGUIElement<T>() {
final override fun getItemStack(slot: Int) = icon
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
clickEvent.bukkitEvent.isCancelled = true
action(clickEvent)
}
}

View File

@@ -1,11 +0,0 @@
package net.axay.kspigot.inventory.elements
import net.axay.kspigot.inventory.ForInventory
import net.axay.kspigot.inventory.InventoryGUIClickEvent
import net.axay.kspigot.inventory.InventoryGUISlot
class InventoryGUIFreeSlot<T : ForInventory> : InventoryGUISlot<T>() {
override fun onClick(clickEvent: InventoryGUIClickEvent<T>) {
/* do nothing */
}
}

View File

@@ -1,16 +0,0 @@
package net.axay.kspigot.inventory.elements
import net.axay.kspigot.inventory.*
import org.bukkit.inventory.ItemStack
class InventoryGUIPlaceholder<T : ForInventory>(
private val icon: ItemStack
) : InventoryGUIElement<T>() {
override fun getItemStack(slot: Int) = icon
override fun onClickElement(clickEvent: InventoryGUIClickEvent<T>) {
clickEvent.bukkitEvent.isCancelled = true
}
}

View File

@@ -1,6 +1,6 @@
package net.axay.kspigot.main package net.axay.kspigot.main
import net.axay.kspigot.inventory.InventoryGUIHolder import net.axay.kspigot.gui.GUIHolder
import net.axay.kspigot.languageextensions.kotlinextensions.closeIfInitialized import net.axay.kspigot.languageextensions.kotlinextensions.closeIfInitialized
import net.axay.kspigot.runnables.KRunnableHolder import net.axay.kspigot.runnables.KRunnableHolder
import org.bukkit.plugin.java.JavaPlugin import org.bukkit.plugin.java.JavaPlugin
@@ -22,10 +22,10 @@ abstract class KSpigot : JavaPlugin() {
// lazy properties // lazy properties
private val kRunnableHolderProperty = lazy { KRunnableHolder } private val kRunnableHolderProperty = lazy { KRunnableHolder }
private val inventoryGUIHolderProperty = lazy { InventoryGUIHolder } private val guiHolderProperty = lazy { GUIHolder }
internal val kRunnableHolder by kRunnableHolderProperty internal val kRunnableHolder by kRunnableHolderProperty
internal val inventoryGUIHolder by inventoryGUIHolderProperty internal val guiHolder by guiHolderProperty
/** /**
* Called when the plugin was loaded * Called when the plugin was loaded
@@ -57,7 +57,7 @@ abstract class KSpigot : JavaPlugin() {
// avoid unnecessary load of lazy properties // avoid unnecessary load of lazy properties
kRunnableHolderProperty.closeIfInitialized() kRunnableHolderProperty.closeIfInitialized()
inventoryGUIHolderProperty.closeIfInitialized() guiHolderProperty.closeIfInitialized()
} }