Skip to content

Commit

Permalink
add: onApply teleport context callback
Browse files Browse the repository at this point in the history
  • Loading branch information
BestBearr committed Dec 10, 2024
1 parent 1e27127 commit 76db6ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
final class TeleportCallbacks {
private static final Consumer<TeleportContext> NO_OP = ctx -> {};
private Consumer<TeleportContext> onInit = NO_OP;
private Consumer<TeleportContext> onApply = NO_OP;
private Consumer<TeleportContext> onMove = NO_OP;
private Consumer<TeleportContext> onCountdown = NO_OP;
private Consumer<TeleportContext> onTeleport = NO_OP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public static final class Builder {
return this;
}

public @NotNull Builder onApply(@NotNull Consumer<TeleportContext> contextConsumer) {
Validate.notNull(contextConsumer, "contextConsumer cannot be null");
this.callbacks.setOnApply(contextConsumer);
return this;
}

public @NotNull Builder onMove(@NotNull Consumer<TeleportContext> contextConsumer) {
Validate.notNull(contextConsumer, "contextConsumer cannot be null");
this.callbacks.setOnMove(contextConsumer);
Expand Down

0 comments on commit 76db6ce

Please sign in to comment.