Skip to content

Commit

Permalink
Properly call onOpen for player interface type views
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Oct 28, 2023
1 parent e8aa991 commit 2880ec5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,32 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
}

protected open fun drawPaneToInventory(opened: 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
currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } })
madeChanges = true
}
if (madeChanges) {
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
}
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
}

override fun onOpen() {
// 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))
}
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
}

protected open fun requiresNewInventory(): Boolean = firstPaint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class PlayerInterfaceView internal constructor(
player.closeInventory()
InterfacesListeners.INSTANCE.setOpenInterface(player.uniqueId, this)
}

// Trigger onOpen manually because there is no real inventory being opened
onOpen()
}

override fun close() {
Expand Down

0 comments on commit 2880ec5

Please sign in to comment.