Skip to content

Commit

Permalink
feature: Allow specifying whether a chat query should re-open the view
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Aug 3, 2024
1 parent 66aa972 commit 5d7ff94
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
private data class ChatQuery(
val view: InterfaceView,
val onCancel: suspend () -> Unit,
val onComplete: suspend (Component) -> Unit,
val onComplete: suspend (Component) -> Boolean,
val id: UUID
)

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

// Complete the query and re-open the view
SCOPE.launch {
query.onComplete(event.message())
query.view.open()
if (query.onComplete(event.message())) {
query.view.open()
}
}

// Prevent the message from sending
Expand Down Expand Up @@ -641,7 +642,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
view: InterfaceView,
timeout: Duration,
onCancel: suspend () -> Unit,
onComplete: suspend (Component) -> Unit
onComplete: suspend (Component) -> Boolean
) {
// Determine if the player has this inventory open
if (!view.isOpen()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, T : Interfa
}
}

override fun runChatQuery(timeout: Duration, onCancel: suspend () -> Unit, onComplete: suspend (Component) -> Unit) {
override fun runChatQuery(timeout: Duration, onCancel: suspend () -> Unit, onComplete: suspend (Component) -> Boolean) {
InterfacesListeners.INSTANCE.startChatQuery(this, timeout, onCancel, onComplete)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public interface InterfaceView {
public fun runChatQuery(
timeout: Duration = 30.seconds,
onCancel: suspend () -> Unit = {},
onComplete: suspend (Component) -> Unit
onComplete: suspend (Component) -> Boolean
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PlayerInterfaceView internal constructor(
error("PlayerInventoryView's cannot have a title")
}

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

Expand Down

0 comments on commit 5d7ff94

Please sign in to comment.