diff --git a/KotlinCore/src/de/steamwar/kotlin/ui/TestInv.kt b/KotlinCore/src/de/steamwar/kotlin/ui/TestInv.kt index 10738d62..f4e12f26 100644 --- a/KotlinCore/src/de/steamwar/kotlin/ui/TestInv.kt +++ b/KotlinCore/src/de/steamwar/kotlin/ui/TestInv.kt @@ -26,7 +26,7 @@ import org.bukkit.inventory.ItemStack class TestInv(player: Player): UIInventory(player) { - override fun render() { + override fun view() { inventory(3, title = "TEST_TITLE") { group { item { diff --git a/KotlinCore/src/de/steamwar/kotlin/ui/UIInventory.kt b/KotlinCore/src/de/steamwar/kotlin/ui/UIInventory.kt index a8fbc09b..ba7493ed 100644 --- a/KotlinCore/src/de/steamwar/kotlin/ui/UIInventory.kt +++ b/KotlinCore/src/de/steamwar/kotlin/ui/UIInventory.kt @@ -19,28 +19,28 @@ package de.steamwar.kotlin.ui -import de.steamwar.kotlin.KotlinCore import de.steamwar.kotlin.ui.context.WindowContext -import net.kyori.adventure.text.event.ClickEvent -import org.bukkit.Bukkit import org.bukkit.entity.Player -import org.bukkit.event.EventHandler -import org.bukkit.event.Listener -import org.bukkit.event.inventory.InventoryClickEvent -import org.bukkit.event.inventory.InventoryCloseEvent import org.bukkit.event.inventory.InventoryType -abstract class UIInventory(val player: Player) { - lateinit var window: UIWindow +abstract class UIInventory(val player: Player): RenderBoundary() { + var window: UIWindow? = null - abstract fun render() + abstract fun view() fun open() { - if (!::window.isInitialized) { - render() + if (window == null) { + view() + assert(window != null) { "View method must create a inventory" } } - window.open() + window!!.open() + } + + override fun render() { + window?.onClose() + window = null + open() } protected fun inventory(size: Int, title: String, init: WindowContext.() -> Unit) { diff --git a/KotlinCore/src/de/steamwar/kotlin/ui/UIWindow.kt b/KotlinCore/src/de/steamwar/kotlin/ui/UIWindow.kt index deaacb8d..e9398689 100644 --- a/KotlinCore/src/de/steamwar/kotlin/ui/UIWindow.kt +++ b/KotlinCore/src/de/steamwar/kotlin/ui/UIWindow.kt @@ -32,6 +32,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent import org.bukkit.event.inventory.InventoryType import org.bukkit.inventory.Inventory import org.bukkit.inventory.InventoryHolder +import org.bukkit.inventory.InventoryView class UIWindow(val player: Player, val render: WindowContext.() -> Unit): InventoryHolder { val onClicks = mutableMapOf Unit>() diff --git a/KotlinCore/src/de/steamwar/kotlin/util/ItemUtils.kt b/KotlinCore/src/de/steamwar/kotlin/util/ItemUtils.kt index 111b0ea1..d504c679 100644 --- a/KotlinCore/src/de/steamwar/kotlin/util/ItemUtils.kt +++ b/KotlinCore/src/de/steamwar/kotlin/util/ItemUtils.kt @@ -32,7 +32,7 @@ fun ItemStack.count(count: Int) = apply { amount = count } fun ItemStack.name(name: Component) = apply { itemMeta = itemMeta.also { it.displayName(name) } } -fun ItemStack.lore(lore: List) = apply { itemMeta = itemMeta.also { it.lore(lore) } } +fun ItemStack.lored(lore: List) = apply { itemMeta = itemMeta.also { it.lore(lore) } } fun String.asMaterial(): Material = Material.matchMaterial(this) ?: Material.BARRIER