Debounce

class Debounce<K : Any>(timeSource: TimeSource = SystemTimeSource)

Handles debouncing for keys of type K.

Debouncing ensures that an action can only be performed if a certain amount of time has passed since the last successful action for that specific key.

Parameters

K

the type of the key used to identify debounce states

Constructors

Link copied to clipboard
constructor(timeSource: TimeSource = SystemTimeSource)

Functions

Link copied to clipboard
fun allowEvery(key: K, minIntervalMillis: Long): Boolean

Tries to allow an action for the specified key with a minimum interval in milliseconds.

fun allowEvery(key: K, minInterval: Duration): Boolean

Tries to allow an action for the specified key with a minimum interval using a Duration.

Link copied to clipboard
fun PlayerDebounce.allowEvery(player: Player, minInterval: Duration): Boolean

Tries to allow an action for the specified player with the given minInterval.

Link copied to clipboard
fun clear(key: K)

Clears the debounce state for the specified key.

Link copied to clipboard
fun clearAll()

Clears all debounce states currently managed by this instance.

Link copied to clipboard
fun isAllowed(key: K): Boolean

Returns whether the specified key is currently allowed to be used.

Link copied to clipboard

Returns the remaining time until the specified key is allowed to be used again, in milliseconds.