From 9ab5417181848dc494f13b0a673cd0f8bdc6fbad Mon Sep 17 00:00:00 2001 From: Aeltumn Date: Wed, 25 Oct 2023 15:57:47 +0200 Subject: [PATCH] Fix player interface drawing when not open --- .../inventory/PlayerInterfacesInventory.kt | 6 +----- .../next/view/AbstractInterfaceView.kt | 18 ++++++------------ .../next/view/PlayerInterfaceView.kt | 3 ++- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/next/src/main/kotlin/org/incendo/interfaces/next/inventory/PlayerInterfacesInventory.kt b/next/src/main/kotlin/org/incendo/interfaces/next/inventory/PlayerInterfacesInventory.kt index a1dd48f..47cb444 100644 --- a/next/src/main/kotlin/org/incendo/interfaces/next/inventory/PlayerInterfacesInventory.kt +++ b/next/src/main/kotlin/org/incendo/interfaces/next/inventory/PlayerInterfacesInventory.kt @@ -20,9 +20,5 @@ public class PlayerInterfacesInventory( return playerInventory.setItem(index, item) } - // Nothing in here counts as the player inventory since this is a fake - // inventory. The purpose of this method is to find which slots should - // not be drawn to until the InventoryOpenEvent, but since this is a fake - // inventory it is never opened this this needs to be false. - override fun isPlayerInventory(row: Int, column: Int): Boolean = false + override fun isPlayerInventory(row: Int, column: Int): Boolean = true } diff --git a/next/src/main/kotlin/org/incendo/interfaces/next/view/AbstractInterfaceView.kt b/next/src/main/kotlin/org/incendo/interfaces/next/view/AbstractInterfaceView.kt index 7890ec4..a3c6ce6 100644 --- a/next/src/main/kotlin/org/incendo/interfaces/next/view/AbstractInterfaceView.kt +++ b/next/src/main/kotlin/org/incendo/interfaces/next/view/AbstractInterfaceView.kt @@ -211,12 +211,14 @@ public abstract class AbstractInterfaceView( semaphore.release() } - protected open fun drawPaneToInventory(opened: Boolean) { + protected open fun drawPaneToInventory(drawNormalInventory: Boolean, drawPlayerInventory: Boolean) { var madeChanges = false pane.forEach { row, column, element -> // We defer drawing of any elements in the player inventory itself // for later unless the inventory is already open. - if (!opened && currentInventory.isPlayerInventory(row, column)) return@forEach + val isPlayerInventory = currentInventory.isPlayerInventory(row, column) + if (!isPlayerInventory && drawNormalInventory || isPlayerInventory && drawPlayerInventory) return@forEach + currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } }) madeChanges = true } @@ -229,15 +231,7 @@ public abstract class AbstractInterfaceView( // Whenever we open the inventory we draw all elements in the player inventory // itself. We do this in this hook because it runs after InventoryCloseEvent so // it properly happens as the last possible action. - var madeChanges = false - pane.forEach { row, column, element -> - if (!currentInventory.isPlayerInventory(row, column)) return@forEach - currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } }) - madeChanges = true - } - if (madeChanges) { - Bukkit.getPluginManager().callEvent(DrawPaneEvent(player)) - } + drawPaneToInventory(drawNormalInventory = false, drawPlayerInventory = true) } protected open fun requiresNewInventory(): Boolean = firstPaint @@ -263,7 +257,7 @@ public abstract class AbstractInterfaceView( // updates on menus that have closed do not affect future menus that actually // ended up being opened. val isOpen = isOpen(player) - drawPaneToInventory(isOpen) + drawPaneToInventory(drawNormalInventory = true, drawPlayerInventory = isOpen) callback(createdInventory) if ((openIfClosed && !isOpen) || createdInventory) { diff --git a/next/src/main/kotlin/org/incendo/interfaces/next/view/PlayerInterfaceView.kt b/next/src/main/kotlin/org/incendo/interfaces/next/view/PlayerInterfaceView.kt index 30330da..28574b6 100644 --- a/next/src/main/kotlin/org/incendo/interfaces/next/view/PlayerInterfaceView.kt +++ b/next/src/main/kotlin/org/incendo/interfaces/next/view/PlayerInterfaceView.kt @@ -44,7 +44,8 @@ public class PlayerInterfaceView internal constructor( } player.openInventory.cursor = null - // Trigger onOpen manually because there is no real inventory being opened + // Trigger onOpen manually because there is no real inventory being opened, + // this will also re-draw the player inventory parts! onOpen() } }