diff options
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/event/TaskEvent.java')
-rw-r--r-- | src/main/java/net/elytrium/limboauth/event/TaskEvent.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/main/java/net/elytrium/limboauth/event/TaskEvent.java b/src/main/java/net/elytrium/limboauth/event/TaskEvent.java index 4df70c8..30e7947 100644 --- a/src/main/java/net/elytrium/limboauth/event/TaskEvent.java +++ b/src/main/java/net/elytrium/limboauth/event/TaskEvent.java @@ -17,6 +17,7 @@ package net.elytrium.limboauth.event; +import java.util.function.Consumer; import net.elytrium.limboauth.Settings; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -28,6 +29,12 @@ public abstract class TaskEvent { private Result result = Result.NORMAL; private Component reason = defaultReason; + private final Consumer<TaskEvent> onComplete; + + public TaskEvent(Consumer<TaskEvent> onComplete) { + this.onComplete = onComplete; + } + public Result getResult() { return this.result; } @@ -45,9 +52,28 @@ public abstract class TaskEvent { return this.reason; } + public void complete(Result result) { + if (this.result != Result.WAIT) { + return; + } + + this.result = result; + this.onComplete.accept(this); + } + + public void completeAndCancel(@NotNull Component c) { + if (this.result != Result.WAIT) { + return; + } + + this.cancel(c); + this.onComplete.accept(this); + } + public enum Result { CANCEL, BYPASS, - NORMAL + NORMAL, + WAIT } } |