From 76db6cebc26692402809afd30aa360fc88418d3e Mon Sep 17 00:00:00 2001 From: BestBearr <32557819+BestBearr@users.noreply.github.com> Date: Mon, 9 Dec 2024 22:43:17 -0500 Subject: [PATCH] add: onApply teleport context callback --- .../alpinecore/framework/teleport/TeleportCallbacks.java | 1 + .../alpinecore/framework/teleport/TeleportHandler.java | 8 ++++++++ .../alpinecore/framework/teleport/TeleportManager.java | 8 ++++++++ .../alpinecore/framework/teleport/TeleportTask.java | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportCallbacks.java b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportCallbacks.java index a118423..f7ac2b3 100644 --- a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportCallbacks.java +++ b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportCallbacks.java @@ -14,6 +14,7 @@ final class TeleportCallbacks { private static final Consumer NO_OP = ctx -> {}; private Consumer onInit = NO_OP; + private Consumer onApply = NO_OP; private Consumer onMove = NO_OP; private Consumer onCountdown = NO_OP; private Consumer onTeleport = NO_OP; diff --git a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportHandler.java b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportHandler.java index e38bb92..6777f03 100644 --- a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportHandler.java +++ b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportHandler.java @@ -18,6 +18,14 @@ public interface TeleportHandler { */ void onInit(@NotNull TeleportContext context); + + /** + * Applies the teleport process with the given context. + * + * @param context the context containing information about the teleportation + */ + void onApply(@NotNull TeleportContext context); + /** * Handles the countdown phase of the teleport process. * diff --git a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportManager.java b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportManager.java index 7df4684..391722e 100644 --- a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportManager.java +++ b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportManager.java @@ -70,8 +70,16 @@ public void registerHandler(@NotNull TeleportHandler handler) { public void initiateTeleport(@NotNull TeleportTask task) { TeleportHandler handler = this.getTeleportHandler(); TeleportContext context = task.createContext(false); + + // Initialize the teleport process (i.e., mark as instantaneous or cancel) task.getCallbacks().getOnInit().accept(context); handler.onInit(context); + + // Apply the teleportation + task.getCallbacks().getOnApply().accept(context); + handler.onApply(context); + + // Copy to the task task.apply(context); if (!context.isCancelled()) { diff --git a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportTask.java b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportTask.java index 4ffa3a7..3329e44 100644 --- a/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportTask.java +++ b/src/main/java/co/crystaldev/alpinecore/framework/teleport/TeleportTask.java @@ -122,6 +122,12 @@ public static final class Builder { return this; } + public @NotNull Builder onApply(@NotNull Consumer contextConsumer) { + Validate.notNull(contextConsumer, "contextConsumer cannot be null"); + this.callbacks.setOnApply(contextConsumer); + return this; + } + public @NotNull Builder onMove(@NotNull Consumer contextConsumer) { Validate.notNull(contextConsumer, "contextConsumer cannot be null"); this.callbacks.setOnMove(contextConsumer);