Skip to content

Commit

Permalink
Fix dialogue multiple trigger on end
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Jan 8, 2024
1 parent c9fbc25 commit bbc533d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DialogueSequence(private val player: Player, initialEntry: DialogueEntry)
private var currentMessenger = messengerFinder.findMessenger(player, initialEntry)
private var cycle = 0
var isActive = false
private set

val triggers: List<String>
get() = currentMessenger.triggers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import me.gabber235.typewriter.entry.dialogue.DialogueSequence
import me.gabber235.typewriter.entry.entries.*
import me.gabber235.typewriter.entry.entries.SystemTrigger.*
import me.gabber235.typewriter.entry.matches
import me.gabber235.typewriter.entry.triggerEntriesFor
import me.gabber235.typewriter.entry.triggerFor
import org.bukkit.entity.Player
import org.koin.core.component.KoinComponent
Expand Down Expand Up @@ -56,7 +55,7 @@ class Interaction(val player: Player) : KoinComponent {
}
}

private fun handleDialogue(event: Event) {
private suspend fun handleDialogue(event: Event) {
if (DIALOGUE_END in event) {
val dialogue = dialogue ?: return
this.dialogue = null
Expand Down Expand Up @@ -103,13 +102,17 @@ class Interaction(val player: Player) : KoinComponent {
* Called when the player clicks the next button. If there is no next dialogue, the sequence
* will be ended.
*/
private fun onDialogueNext() {
private suspend fun onDialogueNext() {
val dialog = dialogue ?: return
dialog.isActive = false
if (dialog.triggers.isEmpty()) {
DIALOGUE_END triggerFor player
// We need to immediately end the dialogue, otherwise it may be triggered again
onEvent(Event(player, listOf(DIALOGUE_END)))
return
}
dialog.triggers triggerEntriesFor player

// We need to immediately end the dialogue, otherwise it may be triggered again
onEvent(Event(player, dialog.triggers.map(::EntryTrigger)))
return
}

Expand Down

0 comments on commit bbc533d

Please sign in to comment.