Delay sending respawn event until we actually try to respawn user.

This commit is contained in:
KHobbits 2012-12-09 17:32:02 +00:00
parent 0b95a691a6
commit 3dcb2a828e

View File

@ -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);
}
}