Skip to content

Commit

Permalink
Fix player interface drawing when not open
Browse files Browse the repository at this point in the history
Aeltumn committed Oct 28, 2023
1 parent 884a9df commit 9ab5417
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -211,12 +211,14 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
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<I : InterfacesInventory, P : Pane>(
// 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<I : InterfacesInventory, P : Pane>(
// 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) {
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit 9ab5417

Please sign in to comment.