diff --git a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java index fc98e97e175..b5e687f2557 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java @@ -457,6 +457,10 @@ public void back(final CompletableFuture future) { nowAsync(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), TeleportCause.COMMAND, future); } + public TeleportType getTpType() { + return this.tpType; + } + public void setTpType(final TeleportType tpType) { this.tpType = tpType; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/AsyncTimedTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/AsyncTimedTeleport.java index 784b3eb89a1..d1c37423c06 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AsyncTimedTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AsyncTimedTeleport.java @@ -1,12 +1,15 @@ package com.earth2me.essentials; -import net.ess3.api.IEssentials; -import net.ess3.api.IUser; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + import org.bukkit.Location; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; +import net.ess3.api.IEssentials; +import net.ess3.api.IUser; +import net.essentialsx.api.v2.events.TeleportWarmupCancelledEvent; +import net.essentialsx.api.v2.events.TeleportWarmupCancelledEvent.CancelReason; public class AsyncTimedTeleport implements Runnable { private static final double MOVE_CONSTANT = 0.3; @@ -149,6 +152,14 @@ void cancelTimer(final boolean notifyUser) { } try { ess.getServer().getScheduler().cancelTask(timer_task); + + final IUser teleportUser = ess.getUser(this.timer_teleportee); + if (teleportUser != null && teleportUser.getBase() != null) { + final TeleportWarmupCancelledEvent.CancelReason cancelReason = teleportUser.getBase().isOnline() ? CancelReason.MOVE : CancelReason.LEAVE; + final TeleportWarmupCancelledEvent event = new TeleportWarmupCancelledEvent(teleportUser.getBase(), this.teleport.getTpType(), cancelReason, notifyUser); + ess.getServer().getPluginManager().callEvent(event); + } + if (notifyUser) { teleportOwner.sendTl("pendingTeleportCancelled"); if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) { diff --git a/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportWarmupCancelledEvent.java b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportWarmupCancelledEvent.java new file mode 100644 index 00000000000..58ac59f35e6 --- /dev/null +++ b/Essentials/src/main/java/net/essentialsx/api/v2/events/TeleportWarmupCancelledEvent.java @@ -0,0 +1,77 @@ +package net.essentialsx.api.v2.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import com.earth2me.essentials.AsyncTeleport.TeleportType; + +/** + * Called when a player's teleport warmup is cancelled. + */ +public class TeleportWarmupCancelledEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private final Player player; + private final TeleportType teleportType; + private final CancelReason cancelReason; + private final boolean notifyUser; + + public TeleportWarmupCancelledEvent(final Player player, final TeleportType teleportType, CancelReason cancelReason, final boolean notifyUser) { + this.player = player; + this.teleportType = teleportType; + this.cancelReason = cancelReason; + this.notifyUser = notifyUser; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + /** + * @return the player whose teleport was canceled. + */ + public Player getPlayer() { + return this.player; + } + + /** + * @return the type of teleport that was canceled. + */ + public TeleportType getTeleportType() { + return this.teleportType; + } + + /** + * @return the reason the teleport was cancelled. + */ + public CancelReason getCancelReason() { + return this.cancelReason; + } + + /** + * @return true if the player was notified that the teleport was canceled, otherwise false. + */ + public boolean isPlayerNotified() { + return this.notifyUser; + } + + /** + * Indicates the reason why the teleportation was cancelled. + */ + public enum CancelReason { + /** + * Indicates that the cancellation occurred because the player disconnected + */ + LEAVE, + /** + * Indicates that the cancellation occurred because the player moved + */ + MOVE, + } +}