Skip to content

Commit 2880ec5

Browse files
committed
Properly call onOpen for player interface type views
1 parent e8aa991 commit 2880ec5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,24 +216,32 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
216216
}
217217

218218
protected open fun drawPaneToInventory(opened: Boolean) {
219+
var madeChanges = false
219220
pane.forEach { row, column, element ->
220221
// We defer drawing of any elements in the player inventory itself
221222
// for later unless the inventory is already open.
222223
if (!opened && currentInventory.isPlayerInventory(row, column)) return@forEach
223224
currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } })
225+
madeChanges = true
226+
}
227+
if (madeChanges) {
228+
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
224229
}
225-
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
226230
}
227231

228232
override fun onOpen() {
229233
// Whenever we open the inventory we draw all elements in the player inventory
230234
// itself. We do this in this hook because it runs after InventoryCloseEvent so
231235
// it properly happens as the last possible action.
236+
var madeChanges = false
232237
pane.forEach { row, column, element ->
233238
if (!currentInventory.isPlayerInventory(row, column)) return@forEach
234239
currentInventory.set(row, column, element.itemStack.apply { this?.let { backing.itemPostProcessor?.invoke(it) } })
240+
madeChanges = true
241+
}
242+
if (madeChanges) {
243+
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
235244
}
236-
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player))
237245
}
238246

239247
protected open fun requiresNewInventory(): Boolean = firstPaint

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class PlayerInterfaceView internal constructor(
3636
player.closeInventory()
3737
InterfacesListeners.INSTANCE.setOpenInterface(player.uniqueId, this)
3838
}
39+
40+
// Trigger onOpen manually because there is no real inventory being opened
41+
onOpen()
3942
}
4043

4144
override fun close() {

0 commit comments

Comments
 (0)