Skip to content

Commit

Permalink
feat(Sequence): cancellation task
Browse files Browse the repository at this point in the history
  • Loading branch information
1zun4 committed Feb 24, 2025
1 parent 798ada8 commit ed4ab87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ open class Sequence(val owner: EventListener, val handler: SuspendableHandler) {

open fun cancel() {
coroutine.cancel()
cancellationTask?.run()
SequenceManager.sequences -= this@Sequence
}

private var continuation: Continuation<Unit>? = null
private var elapsedTicks = 0
private var totalTicks = IntSupplier { 0 }
private var cancellationTask: Runnable? = null

init {
// Note: It is important that this is in the constructor and NOT in the variable declaration, because
Expand Down Expand Up @@ -117,6 +119,13 @@ open class Sequence(val owner: EventListener, val handler: SuspendableHandler) {
}
}

/**
* Adds a task to be executed when the sequence is cancelled.
*/
fun onCancellation(task: Runnable) {
cancellationTask = task
}

/**
* Waits until the [case] is true, then continues. Checks every tick.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ object ModuleSuperKnockback : ClientModule("SuperKnockback", Category.COMBAT, al
return@sequenceHandler
}

onCancellation {
cancelSprint = false
}

cancelSprint = true
waitUntil { !player.isSprinting && !player.lastSprinting }
waitTicks(reSprintTicks.random())
Expand Down Expand Up @@ -145,6 +149,11 @@ object ModuleSuperKnockback : ClientModule("SuperKnockback", Category.COMBAT, al
return@sequenceHandler
}

onCancellation {
cancelMovement = false
inSequence = false
}

inSequence = true
waitTicks(ticksUntilMovementBlock.random())
cancelMovement = true
Expand Down

0 comments on commit ed4ab87

Please sign in to comment.