Skip to content
Open
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 @@ -110,21 +110,31 @@ private void warnUser(final IUser user, final double delay) {

@Override
public void now(final Location loc, final boolean cooldown, final TeleportCause cause, final CompletableFuture<Boolean> future) {
now((IUser) null, loc, cooldown, cause, future);
}

@Override
public void now(final IUser teleporter, final Location loc, final boolean cooldown, final TeleportCause cause, final CompletableFuture<Boolean> future) {
if (cooldown && cooldown(false, future)) {
return;
}
final ITarget target = new LocationTarget(loc);
nowAsync(teleportOwner, target, cause, future);
nowAsync(teleporter, teleportOwner, target, cause, future);
}

@Override
public void now(final Player entity, final boolean cooldown, final TeleportCause cause, final CompletableFuture<Boolean> future) {
now((IUser) null, entity, cooldown, cause, future);
}

@Override
public void now(final IUser teleporter, final Player entity, final boolean cooldown, final TeleportCause cause, final CompletableFuture<Boolean> future) {
if (cooldown && cooldown(false, future)) {
future.complete(false);
return;
}
final ITarget target = new PlayerTarget(entity);
nowAsync(teleportOwner, target, cause, future);
nowAsync(teleporter, teleportOwner, target, cause, future);
future.thenAccept(success -> {
if (success) {
teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
Expand Down Expand Up @@ -153,9 +163,16 @@ private void runOnMain(final Runnable runnable) throws ExecutionException, Inter
}

protected void nowAsync(final IUser teleportee, final ITarget target, final TeleportCause cause, final CompletableFuture<Boolean> future) {
nowAsync(null, teleportee, target, cause, future);
}

/**
* @param teleporter the user who initiated the teleport, or null to report the teleportee
*/
protected void nowAsync(final IUser teleporter, final IUser teleportee, final ITarget target, final TeleportCause cause, final CompletableFuture<Boolean> future) {
cancel(false);

final PreTeleportEvent event = new PreTeleportEvent(teleportee, cause, target);
final PreTeleportEvent event = new PreTeleportEvent(teleporter != null ? teleporter : teleportee, teleportee, cause, target);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
future.complete(false);
Expand Down Expand Up @@ -339,7 +356,7 @@ private void teleportOther(final IUser teleporter, final IUser teleportee, final
return;
}

nowAsync(teleportee, target, cause, future);
nowAsync(teleporter, teleportee, target, cause, future);
if (teleporter != null && cashCharge != null) {
cashCharge.charge(teleporter, future);
if (future.isCompletedExceptionally()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void run() {
if (timer_respawn) {
teleport.respawnNow(teleportUser, timer_cause, parentFuture);
} else {
teleport.nowAsync(teleportUser, timer_teleportTarget, timer_cause, parentFuture);
// teleportOwner started the warmup (e.g. the /tphere sender), report it as the teleporter
teleport.nowAsync(teleportOwner, teleportUser, timer_teleportTarget, timer_cause, parentFuture);
}
parentFuture.thenAccept(success -> {
if (timer_chargeFor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ public interface IAsyncTeleport {
*/
void now(Player entity, boolean cooldown, PlayerTeleportEvent.TeleportCause cause, CompletableFuture<Boolean> future);

/**
* Same as {@link #now(Location, boolean, PlayerTeleportEvent.TeleportCause, CompletableFuture)}, but reports
* {@code teleporter} as the user who initiated the teleport in {@link net.ess3.api.events.teleport.PreTeleportEvent}.
*
* @param teleporter - The user who initiated the teleport, or null if unknown (e.g. console)
* @param loc - Where should the player end up
* @param cooldown - If cooldown should be enforced
* @param cause - The reported teleportPlayer cause
* @param future - Future which is completed with the success status of the execution
*/
default void now(IUser teleporter, Location loc, boolean cooldown, PlayerTeleportEvent.TeleportCause cause, CompletableFuture<Boolean> future) {
now(loc, cooldown, cause, future);
}

/**
* Same as {@link #now(Player, boolean, PlayerTeleportEvent.TeleportCause, CompletableFuture)}, but reports
* {@code teleporter} as the user who initiated the teleport in {@link net.ess3.api.events.teleport.PreTeleportEvent}.
*
* @param teleporter - The user who initiated the teleport, or null if unknown (e.g. console)
* @param entity - Where should the player end up
* @param cooldown - If cooldown should be enforced
* @param cause - The reported teleportPlayer cause
* @param future - Future which is completed with the success status of the execution
*/
default void now(IUser teleporter, Player entity, boolean cooldown, PlayerTeleportEvent.TeleportCause cause, CompletableFuture<Boolean> future) {
now(entity, cooldown, cause, future);
}

/**
* Used to skip all safety checks while teleporting a player asynchronously.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void run(final Server server, final User user, final String commandLabel,
throw new TranslatableException("teleportDisabled", target2.getDisplayName());
}
user.sendTl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ());
target2.getAsyncTeleport().now(locposother, false, TeleportCause.COMMAND, future);
target2.getAsyncTeleport().now(user, locposother, false, TeleportCause.COMMAND, future);
future.thenAccept(success -> {
if (success) {
target2.sendTl("teleporting", locposother.getWorld().getName(), locposother.getBlockX(), locposother.getBlockY(), locposother.getBlockZ());
Expand All @@ -106,7 +106,7 @@ public void run(final Server server, final User user, final String commandLabel,
throw new TranslatableException("noPerm", "essentials.worlds." + toPlayer.getWorld().getName());
}
target.sendTl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName());
target.getAsyncTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND, future);
target.getAsyncTeleport().now(user, toPlayer.getBase(), false, TeleportCause.COMMAND, future);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ public void run(final Server server, final CommandSource sender, final String co
private void teleportAllPlayers(final Server server, final CommandSource sender, final User target, final String label) {
sender.sendTl("teleportAll");
final Location loc = target.getLocation();
final User teleporter = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null;
for (final User player : ess.getOnlineUsers()) {
if (target == player) {
continue;
}
if (sender.getSender().equals(target.getBase()) && target.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !target.isAuthorized("essentials.worlds." + target.getWorld().getName())) {
continue;
}
player.getAsyncTeleport().now(loc, false, TeleportCause.COMMAND, getNewExceptionFuture(sender, label));
player.getAsyncTeleport().now(teleporter, loc, false, TeleportCause.COMMAND, getNewExceptionFuture(sender, label));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void run(final Server server, final User user, final String commandLabel,
}

final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
target.getAsyncTeleport().now(toPlayer.getBase(), false, TeleportCause.COMMAND, future);
target.getAsyncTeleport().now(user, toPlayer.getBase(), false, TeleportCause.COMMAND, future);
future.thenAccept(success -> {
if (success) {
target.sendTl("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void run(final Server server, final User user, final String commandLabel,
throw new TranslatableException("noPerm", "essentials.worlds." + user.getWorld().getName());
}

player.getAsyncTeleport().now(user.getBase(), false, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
player.getAsyncTeleport().now(user, user.getBase(), false, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public PreTeleportEvent(final IUser teleportee, final PlayerTeleportEvent.Telepo
super(teleportee, cause, target);
}

public PreTeleportEvent(final IUser teleporter, final IUser teleportee, final PlayerTeleportEvent.TeleportCause cause, final ITarget target) {
super(teleporter, teleportee, cause, target);
}

public static HandlerList getHandlerList() {
return handlers;
}
Expand Down
Loading