From c12696bd528e891b9da126d3b92f3db089b4b6e6 Mon Sep 17 00:00:00 2001 From: therealbush Date: Sat, 23 Apr 2022 15:22:18 -0700 Subject: some changes --- src/main/kotlin/me/bush/eventbuskotlin/Event.kt | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/kotlin/me/bush/eventbuskotlin/Event.kt (limited to 'src/main/kotlin/me/bush/eventbuskotlin/Event.kt') diff --git a/src/main/kotlin/me/bush/eventbuskotlin/Event.kt b/src/main/kotlin/me/bush/eventbuskotlin/Event.kt new file mode 100644 index 0000000..50f1131 --- /dev/null +++ b/src/main/kotlin/me/bush/eventbuskotlin/Event.kt @@ -0,0 +1,40 @@ +package me.bush.eventbuskotlin + +/** + * A base class for events that can be cancelled. + * + * [Information and examples](https://github.com/therealbush/eventbus-kotlin#ththingtodo) + * + * @author bush + * @since 1.0.0 + */ +abstract class Event { + + /** + * Whether this event is cancelled or not. If it is, only future listeners with + * [Listener.receiveCancelled] will receive it. However, it can be set back to + * `false`, and listeners will be able to receive it again. + * + * [Information and examples](https://github.com/therealbush/eventbus-kotlin#tododothething) + */ + var cancelled = false + set(value) { + if (cancellable) field = value + } + + /** + * Determines if this event can be [cancelled]. This does not have to return a constant value. + * + * [Information and examples](https://github.com/therealbush/eventbus-kotlin#tododothething) + */ + protected abstract val cancellable: Boolean + + /** + * Sets [cancelled] to true. + * + * [Information and examples](https://github.com/therealbush/eventbus-kotlin#tododothething) + */ + fun cancel() { + cancelled = true + } +} -- cgit