Skip to content

Commit 5d7ff94

Browse files
committed
feature: Allow specifying whether a chat query should re-open the view
1 parent 66aa972 commit 5d7ff94

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

interfaces/src/main/kotlin/com/noxcrew/interfaces/InterfacesListeners.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
133133
private data class ChatQuery(
134134
val view: InterfaceView,
135135
val onCancel: suspend () -> Unit,
136-
val onComplete: suspend (Component) -> Unit,
136+
val onComplete: suspend (Component) -> Boolean,
137137
val id: UUID
138138
)
139139

@@ -499,8 +499,9 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
499499

500500
// Complete the query and re-open the view
501501
SCOPE.launch {
502-
query.onComplete(event.message())
503-
query.view.open()
502+
if (query.onComplete(event.message())) {
503+
query.view.open()
504+
}
504505
}
505506

506507
// Prevent the message from sending
@@ -641,7 +642,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
641642
view: InterfaceView,
642643
timeout: Duration,
643644
onCancel: suspend () -> Unit,
644-
onComplete: suspend (Component) -> Unit
645+
onComplete: suspend (Component) -> Boolean
645646
) {
646647
// Determine if the player has this inventory open
647648
if (!view.isOpen()) return

interfaces/src/main/kotlin/com/noxcrew/interfaces/view/AbstractInterfaceView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, T : Interfa
424424
}
425425
}
426426

427-
override fun runChatQuery(timeout: Duration, onCancel: suspend () -> Unit, onComplete: suspend (Component) -> Unit) {
427+
override fun runChatQuery(timeout: Duration, onCancel: suspend () -> Unit, onComplete: suspend (Component) -> Boolean) {
428428
InterfacesListeners.INSTANCE.startChatQuery(this, timeout, onCancel, onComplete)
429429
}
430430
}

interfaces/src/main/kotlin/com/noxcrew/interfaces/view/InterfaceView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public interface InterfaceView {
6868
public fun runChatQuery(
6969
timeout: Duration = 30.seconds,
7070
onCancel: suspend () -> Unit = {},
71-
onComplete: suspend (Component) -> Unit
71+
onComplete: suspend (Component) -> Boolean
7272
)
7373
}

interfaces/src/main/kotlin/com/noxcrew/interfaces/view/PlayerInterfaceView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class PlayerInterfaceView internal constructor(
2424
error("PlayerInventoryView's cannot have a title")
2525
}
2626

27-
override fun runChatQuery(timeout: Duration, onCancel: suspend () -> Unit, onComplete: suspend (Component) -> Unit) {
27+
override fun runChatQuery(timeout: Duration, onCancel: suspend () -> Unit, onComplete: suspend (Component) -> Boolean) {
2828
error("PlayerInventoryView does not support chat queries")
2929
}
3030

0 commit comments

Comments
 (0)