aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/me/bush/eventbuskotlin/Event.kt
diff options
context:
space:
mode:
authortherealbush <therealbush@users.noreply.github.com>2022-04-23 15:22:18 -0700
committertherealbush <therealbush@users.noreply.github.com>2022-04-23 15:22:18 -0700
commitc12696bd528e891b9da126d3b92f3db089b4b6e6 (patch)
tree6683284c29f6dd7b9d65fae881527e05b54b3a84 /src/main/kotlin/me/bush/eventbuskotlin/Event.kt
parent1cb96200f8844e9192f55037cfc11bfb42e1d94f (diff)
downloadeventbus-kotlin-c12696bd528e891b9da126d3b92f3db089b4b6e6.tar.gz
eventbus-kotlin-c12696bd528e891b9da126d3b92f3db089b4b6e6.tar.bz2
eventbus-kotlin-c12696bd528e891b9da126d3b92f3db089b4b6e6.zip
some changes
Diffstat (limited to 'src/main/kotlin/me/bush/eventbuskotlin/Event.kt')
-rw-r--r--src/main/kotlin/me/bush/eventbuskotlin/Event.kt40
1 files changed, 40 insertions, 0 deletions
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
+ }
+}