From 3dcb2a828e41492530557f9d14485493dab10c1a Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 9 Dec 2012 17:32:02 +0000 Subject: [PATCH] Delay sending respawn event until we actually try to respawn user. --- .../src/com/earth2me/essentials/Teleport.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index dd39b98ed..241a8328d 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -58,6 +58,7 @@ public class Teleport implements Runnable, ITeleport private long initY; private long initZ; private Target teleportTarget; + private boolean respawn; private Trade chargeFor; private final IEssentials ess; private static final Logger logger = Logger.getLogger("Minecraft"); @@ -65,10 +66,10 @@ public class Teleport implements Runnable, ITeleport private void initTimer(long delay, Target target, Trade chargeFor, TeleportCause cause) { - initTimer(delay, user, target, chargeFor, cause); + initTimer(delay, user, target, chargeFor, cause, false); } - private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause) + private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause, boolean respawn) { this.started = System.currentTimeMillis(); this.tpdelay = delay; @@ -80,6 +81,7 @@ public class Teleport implements Runnable, ITeleport this.teleportTarget = target; this.chargeFor = chargeFor; this.cause = cause; + this.respawn = respawn; } @Override @@ -117,8 +119,12 @@ public class Teleport implements Runnable, ITeleport teleportUser.sendMessage(_("teleportationCommencing")); try { - - teleportUser.getTeleport().now(teleportTarget, cause); + if (respawn) { + teleportUser.getTeleport().respawn(cause); + } + else { + teleportUser.getTeleport().now(teleportTarget, cause); + } cancel(false); if (chargeFor != null) { @@ -285,7 +291,6 @@ public class Teleport implements Runnable, ITeleport public void teleportToMe(User otherUser, Trade chargeFor, TeleportCause cause) throws Exception { Target target = new Target(user); - double delay = ess.getSettings().getTeleportDelay(); if (chargeFor != null) @@ -306,8 +311,7 @@ public class Teleport implements Runnable, ITeleport cancel(false); warnUser(otherUser, delay); - initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause); - + initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause, false); teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } @@ -321,18 +325,42 @@ public class Teleport implements Runnable, ITeleport //The respawn function is a wrapper used to handle tp fallback, on /jail and /home public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception + { + double delay = ess.getSettings().getTeleportDelay(); + if (chargeFor != null) + { + chargeFor.isAffordableFor(user); + } + cooldown(true); + if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) + { + cooldown(false); + respawn(cause); + if (chargeFor != null) + { + chargeFor.charge(user); + } + return; + } + + cancel(false); + initTimer((long)(delay * 1000.0), user, null, chargeFor, cause, true); + teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); + } + + public void respawn(TeleportCause cause) throws Exception { final Player player = user.getBase(); Location bed = player.getBedSpawnLocation(); if (bed != null && bed.getBlock().getType() != Material.BED_BLOCK) { - teleport(bed, chargeFor, cause); + now(new Target(bed), cause); } else { final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); - teleport(new Target(pre.getRespawnLocation()), chargeFor, cause); + now(new Target(pre.getRespawnLocation()), cause); } }