blob: 39360eb09bd23205942e835b60456c28a5ef3bf6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package me.bush.illnamethislater
/**
* A base class for events that can be cancelled.
*
* If [cancellable] is true, your event can be [cancelled].
*
* If [cancelled] is true, listeners with lower priority will not receive it unless:
* * They have [Listener.receiveCancelled] set to `true`.
* * A future listener with [Listener.receiveCancelled] sets [cancelled] to `false`
*
* @author bush
* @since 1.0.0
*/
// TODO: 3/27/2022 ducks or a way to cancel anything (can't put a custom annotation on forge events)
// store cancellable info at subscribe time, do not calculate it in post
abstract class Event {
var cancelled = false
set(value) {
if (cancellable) field = value
}
abstract val cancellable: Boolean
fun cancel() {
cancelled = false
}
}
|