Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fire successful teleport event on successful teleport #7749

Merged
merged 1 commit into from
Jan 31, 2025
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 @@ -71,9 +71,10 @@ public void run() {
// Teleporting a player can cause the chunk to unload too fast, abandoning pets.
SpawnUtil.addAndRemoveChunkTicket(WorldCoord.parseWorldCoord(player.getLocation()));

PaperLib.teleportAsync(player, request.destinationLocation(), TeleportCause.COMMAND);

BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, request.destinationLocation(), request.teleportCost()));
PaperLib.teleportAsync(player, request.destinationLocation(), TeleportCause.COMMAND).thenAccept(successfulTeleport -> {
if (successfulTeleport)
BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, request.destinationLocation(), request.teleportCost()));
});

if (request.cooldown() > 0)
CooldownTimerTask.addCooldownTimer(resident.getName(), "teleport", request.cooldown());
Expand Down Expand Up @@ -130,7 +131,7 @@ public static boolean abortTeleportRequest(@Nullable Resident resident) {
* @param reason The CancelledSpawnReason this player has had their teleport request cancel.
* @return Whether the resident had an active teleport request.
*/
@Contract("null -> false")
@Contract("null, _ -> false")
public static boolean abortTeleportRequest(@Nullable Resident resident, CancelledTeleportReason reason) {
if (resident == null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,11 @@ private static void initiateSpawn(Player player, Location spawnLoc, int cooldown
// Teleporting a player can cause the chunk to unload too fast, abandoning pets.
addAndRemoveChunkTicket(WorldCoord.parseWorldCoord(player.getLocation()));

PaperLib.teleportAsync(player, spawnLoc, TeleportCause.COMMAND);
BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, spawnLoc, cost));
PaperLib.teleportAsync(player, spawnLoc, TeleportCause.COMMAND).thenAccept(successfulTeleport -> {
if (successfulTeleport)
BukkitTools.fireEvent(new SuccessfulTownyTeleportEvent(resident, spawnLoc, cost));
});

if (cooldown > 0 && !hasPerm(player, PermissionNodes.TOWNY_SPAWN_ADMIN_NOCOOLDOWN))
CooldownTimerTask.addCooldownTimer(player.getName(), "teleport", cooldown);
}
Expand Down