summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-12-09 17:32:02 +0000
committerKHobbits <rob@khobbits.co.uk>2012-12-09 17:32:02 +0000
commit3dcb2a828e41492530557f9d14485493dab10c1a (patch)
tree1efeba5a37f54d296fb47c5c99f32190243ef2f3
parent0b95a691a6e61d3cb52cc030729a037760d5cd88 (diff)
downloadEssentials-3dcb2a828e41492530557f9d14485493dab10c1a.tar
Essentials-3dcb2a828e41492530557f9d14485493dab10c1a.tar.gz
Essentials-3dcb2a828e41492530557f9d14485493dab10c1a.tar.lz
Essentials-3dcb2a828e41492530557f9d14485493dab10c1a.tar.xz
Essentials-3dcb2a828e41492530557f9d14485493dab10c1a.zip
Delay sending respawn event until we actually try to respawn user.
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java46
1 files 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);
}
@@ -322,17 +326,41 @@ 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);
}
}