Skip to content

Commit 9ab5417

Browse files
committed
Fix player interface drawing when not open
1 parent 884a9df commit 9ab5417

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

next/src/main/kotlin/org/incendo/interfaces/next/inventory/PlayerInterfacesInventory.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@ public class PlayerInterfacesInventory(
2020
return playerInventory.setItem(index, item)
2121
}
2222

23-
// Nothing in here counts as the player inventory since this is a fake
24-
// inventory. The purpose of this method is to find which slots should
25-
// not be drawn to until the InventoryOpenEvent, but since this is a fake
26-
// inventory it is never opened this this needs to be false.
27-
override fun isPlayerInventory(row: Int, column: Int): Boolean = false
23+
override fun isPlayerInventory(row: Int, column: Int): Boolean = true
2824
}

next/src/main/kotlin/org/incendo/interfaces/next/view/AbstractInterfaceView.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
211211
semaphore.release()
212212
}
213213

214-
protected open fun drawPaneToInventory(opened: Boolean) {
214+
protected open fun drawPaneToInventory(drawNormalInventory: Boolean, drawPlayerInventory: Boolean) {
215215
var madeChanges = false
216216
pane.forEach { row, column, element ->
217217
// We defer drawing of any elements in the player inventory itself
218218
// for later unless the inventory is already open.
219-
if (!opened && currentInventory.isPlayerInventory(row, column)) return@forEach
219+
val isPlayerInventory = currentInventory.isPlayerInventory(row, column)
220+
if (!isPlayerInventory && drawNormalInventory || isPlayerInventory && drawPlayerInventory) return@forEach
221+
220222
currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } })
221223
madeChanges = true
222224
}
@@ -229,15 +231,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
229231
// Whenever we open the inventory we draw all elements in the player inventory
230232
// itself. We do this in this hook because it runs after InventoryCloseEvent so
231233
// it properly happens as the last possible action.
232-
var madeChanges = false
233-
pane.forEach { row, column, element ->
234-
if (!currentInventory.isPlayerInventory(row, column)) return@forEach
235-
currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } })
236-
madeChanges = true
237-
}
238-
if (madeChanges) {
239-
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
240-
}
234+
drawPaneToInventory(drawNormalInventory = false, drawPlayerInventory = true)
241235
}
242236

243237
protected open fun requiresNewInventory(): Boolean = firstPaint
@@ -263,7 +257,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
263257
// updates on menus that have closed do not affect future menus that actually
264258
// ended up being opened.
265259
val isOpen = isOpen(player)
266-
drawPaneToInventory(isOpen)
260+
drawPaneToInventory(drawNormalInventory = true, drawPlayerInventory = isOpen)
267261
callback(createdInventory)
268262

269263
if ((openIfClosed && !isOpen) || createdInventory) {

next/src/main/kotlin/org/incendo/interfaces/next/view/PlayerInterfaceView.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public class PlayerInterfaceView internal constructor(
4444
}
4545
player.openInventory.cursor = null
4646

47-
// Trigger onOpen manually because there is no real inventory being opened
47+
// Trigger onOpen manually because there is no real inventory being opened,
48+
// this will also re-draw the player inventory parts!
4849
onOpen()
4950
}
5051
}

0 commit comments

Comments
 (0)