@@ -84,7 +84,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
84
84
/* * Marks this menu as closed and processes it. */
85
85
internal suspend fun markClosed (
86
86
reason : InventoryCloseEvent .Reason = InventoryCloseEvent .Reason .UNKNOWN ,
87
- closeInventory : Boolean = reason ! = InventoryCloseEvent .Reason .OPEN_NEW
87
+ changingView : Boolean = reason = = InventoryCloseEvent .Reason .OPEN_NEW
88
88
) {
89
89
// End a possible chat query with the listener
90
90
InterfacesListeners .INSTANCE .abortQuery(player.uniqueId, this )
@@ -93,18 +93,21 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
93
93
openIfClosed.set(false )
94
94
95
95
// Run a generic close handler if it's still opened
96
- if (shouldBeOpened.compareAndSet(true , false )) {
96
+ if (shouldBeOpened.compareAndSet(true , false ) && ( ! changingView || backing.properties.callCloseHandlerOnViewSwitch) ) {
97
97
backing.properties.closeHandlers[reason]?.invoke(reason, this )
98
98
}
99
99
100
- // Close any children, this is a bit of a lossy system,
101
- // we don't particularly care if this happens nicely we
102
- // just want to make sure the ones that need closing get
103
- // closed. The hashmap is weak so children can get GC'd
104
- // properly.
105
- for ((child) in children) {
106
- if (child.shouldBeOpened.get()) {
107
- child.close(reason, closeInventory)
100
+ // Don't close children when changing views!
101
+ if (! changingView) {
102
+ // Close any children, this is a bit of a lossy system,
103
+ // we don't particularly care if this happens nicely we
104
+ // just want to make sure the ones that need closing get
105
+ // closed. The hashmap is weak so children can get GC'd
106
+ // properly.
107
+ for ((child) in children) {
108
+ if (child.shouldBeOpened.get()) {
109
+ child.close(reason, false )
110
+ }
108
111
}
109
112
}
110
113
}
@@ -156,11 +159,12 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
156
159
}
157
160
}
158
161
159
- override suspend fun close (reason : InventoryCloseEvent .Reason , closeInventory : Boolean ) {
160
- markClosed(reason, closeInventory )
162
+ override suspend fun close (reason : InventoryCloseEvent .Reason , changingView : Boolean ) {
163
+ markClosed(reason, changingView )
161
164
162
- if (isOpen() && closeInventory) {
163
- // Ensure we always close on the main thread!
165
+ // Ensure we always close on the main thread! Don't close if we are
166
+ // changing views though.
167
+ if (! changingView && isOpen()) {
164
168
runSync {
165
169
player.closeInventory()
166
170
}
0 commit comments