did requested changes

This commit is contained in:
Skyslycer
2021-08-16 19:11:34 +02:00
parent e4681af822
commit a204867ff0
3 changed files with 18 additions and 4 deletions

View File

@@ -19,7 +19,7 @@ class GUIData<T : ForInventory>(
val transitionTo: InventoryChangeEffect?,
val transitionFrom: InventoryChangeEffect?,
internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?,
internal val onClose: ((InventoryCloseEvent) -> Unit)?
internal val onClose: ((GUICloseEvent<T>) -> Unit)?
)
abstract class GUI<T : ForInventory>(
@@ -99,7 +99,7 @@ class GUIIndividual<T : ForInventory>(
if (resetOnClose || data.onClose != null) {
listen<InventoryCloseEvent> {
if (data.onClose != null && playerInstances[it.player]?.bukkitInventory == it.inventory) {
data.onClose.invoke(it)
data.onClose.invoke(GUICloseEvent(it, playerInstances[it.player]!!, it.player as Player))
}
if (resetOnClose) {

View File

@@ -47,7 +47,7 @@ class GUIBuilder<T : ForInventory>(
private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
private var onClose: ((InventoryCloseEvent) -> Unit)? = null
private var onClose: ((GUICloseEvent<T>) -> Unit)? = null
/**
* Opens the builder for a new page and adds
@@ -66,7 +66,11 @@ class GUIBuilder<T : ForInventory>(
onClickElement = onClick
}
fun onClose(onClose: (InventoryCloseEvent) -> Unit) {
/**
* A callback executed when the user closes
* the inventory.
*/
fun onClose(onClose: (GUICloseEvent<T>) -> Unit) {
this.onClose = onClose
}

View File

@@ -0,0 +1,10 @@
package net.axay.kspigot.gui
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryCloseEvent
class GUICloseEvent<T : ForInventory>(
val bukkitEvent: InventoryCloseEvent,
val guiInstance: GUIInstance<T>,
val player: Player,
)