updated spigot and added on close function for closing a gui
This commit is contained in:
@@ -24,8 +24,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.spigotmc", "spigot", "1.17-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc", "spigot", "1.17.1-R0.1-SNAPSHOT")
|
||||||
testCompileOnly("org.spigotmc", "spigot", "1.17-R0.1-SNAPSHOT")
|
testCompileOnly("org.spigotmc", "spigot", "1.17.1-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1")
|
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1")
|
||||||
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
|
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
|
||||||
|
@@ -19,6 +19,7 @@ class GUIData<T : ForInventory>(
|
|||||||
val transitionTo: InventoryChangeEffect?,
|
val transitionTo: InventoryChangeEffect?,
|
||||||
val transitionFrom: InventoryChangeEffect?,
|
val transitionFrom: InventoryChangeEffect?,
|
||||||
internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?,
|
internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?,
|
||||||
|
internal val onClose: ((InventoryCloseEvent) -> Unit)?
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract class GUI<T : ForInventory>(
|
abstract class GUI<T : ForInventory>(
|
||||||
@@ -95,9 +96,15 @@ class GUIIndividual<T : ForInventory>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (resetOnClose) {
|
if (resetOnClose || data.onClose != null) {
|
||||||
listen<InventoryCloseEvent> {
|
listen<InventoryCloseEvent> {
|
||||||
deleteInstance(it.player as? Player ?: return@listen)
|
if (data.onClose != null && playerInstances[it.player]?.bukkitInventory == it.inventory) {
|
||||||
|
data.onClose.invoke(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resetOnClose) {
|
||||||
|
deleteInstance(it.player as? Player ?: return@listen)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
package net.axay.kspigot.gui
|
package net.axay.kspigot.gui
|
||||||
|
|
||||||
import net.axay.kspigot.gui.elements.*
|
import net.axay.kspigot.gui.elements.*
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@ class GUIBuilder<T : ForInventory>(
|
|||||||
|
|
||||||
private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
|
private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
|
||||||
|
|
||||||
|
private var onClose: ((InventoryCloseEvent) -> 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.
|
||||||
@@ -63,8 +66,12 @@ class GUIBuilder<T : ForInventory>(
|
|||||||
onClickElement = onClick
|
onClickElement = onClick
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onClose(onClose: (InventoryCloseEvent) -> Unit) {
|
||||||
|
this.onClose = onClose
|
||||||
|
}
|
||||||
|
|
||||||
internal fun build() = guiCreator.createInstance(
|
internal fun build() = guiCreator.createInstance(
|
||||||
GUIData(type, title, guiPages, defaultPage, transitionTo, transitionFrom, onClickElement)
|
GUIData(type, title, guiPages, defaultPage, transitionTo, transitionFrom, onClickElement, onClose)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user