@@ -16,6 +16,7 @@ import com.noxcrew.interfaces.transform.AppliedTransform
16
16
import com.noxcrew.interfaces.utilities.CollapsablePaneMap
17
17
import com.noxcrew.interfaces.utilities.InterfacesCoroutineDetails
18
18
import com.noxcrew.interfaces.utilities.forEachInGrid
19
+ import kotlinx.coroutines.CoroutineScope
19
20
import kotlinx.coroutines.Job
20
21
import kotlinx.coroutines.launch
21
22
import kotlinx.coroutines.sync.Mutex
@@ -103,7 +104,8 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, T : Interfa
103
104
* Marks this menu as closed and processes it. This does not actually perform
104
105
* closing the menu, this method only handles the closing.
105
106
*/
106
- internal suspend fun markClosed (
107
+ internal fun markClosed (
108
+ coroutineScope : CoroutineScope ,
107
109
reason : InventoryCloseEvent .Reason = InventoryCloseEvent .Reason .UNKNOWN ,
108
110
changingView : Boolean = reason == InventoryCloseEvent .Reason .OPEN_NEW
109
111
) {
@@ -120,7 +122,11 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, T : Interfa
120
122
(! changingView || builder.callCloseHandlerOnViewSwitch) &&
121
123
::currentInventory.isInitialized
122
124
) {
123
- builder.closeHandlers[reason]?.invoke(reason, this )
125
+ builder.closeHandlers[reason]?.also {
126
+ coroutineScope.launch {
127
+ it.invoke(reason, this @AbstractInterfaceView)
128
+ }
129
+ }
124
130
}
125
131
126
132
// Don't close children when changing views!
@@ -132,7 +138,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, T : Interfa
132
138
// properly.
133
139
for ((child) in children) {
134
140
if (child.shouldBeOpened.get()) {
135
- child.close(reason, false )
141
+ child.close(coroutineScope, reason, false )
136
142
}
137
143
}
138
144
}
@@ -196,8 +202,8 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, T : Interfa
196
202
}
197
203
}
198
204
199
- override suspend fun close (reason : InventoryCloseEvent .Reason , changingView : Boolean ) {
200
- markClosed(reason, changingView)
205
+ override fun close (coroutineScope : CoroutineScope , reason : InventoryCloseEvent .Reason , changingView : Boolean ) {
206
+ markClosed(coroutineScope, reason, changingView)
201
207
202
208
// Ensure we always close on the main thread! Don't close if we are
203
209
// changing views though.
0 commit comments