Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Sequence): cancellation task #5698

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ object SequenceManager : EventListener {

}

@Suppress("TooManyFunctions")
open class Sequence(val owner: EventListener, val handler: SuspendableHandler) {
private var coroutine: Job

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 +120,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
Loading