Skip to content

Commit

Permalink
Only fire successful teleport event on successful teleport
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr committed Jan 29, 2025
1 parent 11a57af commit 79231db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit 79231db

Please sign in to comment.