Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ public void back(final CompletableFuture<Boolean> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
Loading