diff options
3 files changed, 101 insertions, 55 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index c6106ad24..2f1028243 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -37,13 +37,14 @@ public class Teleport implements Runnable, ITeleport { if (this.name != null) { - + return ess.getServer().getPlayerExact(name).getLocation(); } return location; } } private IUser user; + private IUser teleportUser; private int teleTimer = -1; private long started; // time this task was initiated private long delay; // how long to delay the teleport @@ -62,12 +63,18 @@ public class Teleport implements Runnable, ITeleport private void initTimer(long delay, Target target, Trade chargeFor, TeleportCause cause) { + initTimer(delay, user, target, chargeFor, cause); + } + + private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause) + { this.started = System.currentTimeMillis(); this.delay = delay; - this.health = user.getHealth(); - this.initX = Math.round(user.getLocation().getX() * MOVE_CONSTANT); - this.initY = Math.round(user.getLocation().getY() * MOVE_CONSTANT); - this.initZ = Math.round(user.getLocation().getZ() * MOVE_CONSTANT); + this.health = teleportUser.getHealth(); + this.initX = Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT); + this.initY = Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT); + this.initZ = Math.round(teleportUser.getLocation().getZ() * MOVE_CONSTANT); + this.teleportUser = teleportUser; this.teleportTarget = target; this.chargeFor = chargeFor; this.cause = cause; @@ -79,19 +86,25 @@ public class Teleport implements Runnable, ITeleport if (user == null || !user.isOnline() || user.getLocation() == null) { - cancel(); + cancel(false); + return; + } + if (teleportUser == null || !teleportUser.isOnline() || teleportUser.getLocation() == null) + { + cancel(false); return; } - if (Math.round(user.getLocation().getX() * MOVE_CONSTANT) != initX - || Math.round(user.getLocation().getY() * MOVE_CONSTANT) != initY - || Math.round(user.getLocation().getZ() * MOVE_CONSTANT) != initZ - || user.getHealth() < health) + + if (Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT) != initX + || Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT) != initY + || Math.round(teleportUser.getLocation().getZ() * MOVE_CONSTANT) != initZ + || teleportUser.getHealth() < health) { // user moved, cancel teleport cancel(true); return; } - health = user.getHealth(); // in case user healed, then later gets injured + health = teleportUser.getHealth(); // in case user healed, then later gets injured long now = System.currentTimeMillis(); if (now > started + delay) @@ -99,11 +112,12 @@ public class Teleport implements Runnable, ITeleport try { cooldown(false); - user.sendMessage(_("teleportationCommencing")); + teleportUser.sendMessage(_("teleportationCommencing")); try { - now(teleportTarget, cause); + teleportUser.getTeleport().now(teleportTarget, cause); + cancel(false); if (chargeFor != null) { chargeFor.charge(user); @@ -117,6 +131,10 @@ public class Teleport implements Runnable, ITeleport catch (Exception ex) { user.sendMessage(_("cooldownWithMessage", ex.getMessage())); + if (user != teleportUser) + { + teleportUser.sendMessage(_("cooldownWithMessage", ex.getMessage())); + } } } } @@ -127,22 +145,6 @@ public class Teleport implements Runnable, ITeleport this.ess = ess; } - public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception - { - final Player player = user.getBase(); - final Location bed = player.getBedSpawnLocation(); - final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, bed == null ? player.getWorld().getSpawnLocation() : bed, bed != null); - ess.getServer().getPluginManager().callEvent(pre); - teleport(new Target(pre.getRespawnLocation()), chargeFor, cause); - } - - public void warp(String warp, Trade chargeFor, TeleportCause cause) throws Exception - { - Location loc = ess.getWarps().getWarp(warp); - teleport(new Target(loc), chargeFor, cause); - user.sendMessage(_("warpingTo", warp)); - } - public void cooldown(boolean check) throws Exception { final Calendar time = new GregorianCalendar(); @@ -181,6 +183,7 @@ public class Teleport implements Runnable, ITeleport } } + //If we need to cancel a pending teleport call this method public void cancel(boolean notifyUser) { if (teleTimer == -1) @@ -193,6 +196,10 @@ public class Teleport implements Runnable, ITeleport if (notifyUser) { user.sendMessage(_("pendingTeleportCancelled")); + if (teleportUser != user) + { + teleportUser.sendMessage(_("pendingTeleportCancelled")); + } } } finally @@ -201,16 +208,7 @@ public class Teleport implements Runnable, ITeleport } } - public void cancel() - { - cancel(false); - } - - public void teleport(Location loc, Trade chargeFor) throws Exception - { - teleport(new Target(loc), chargeFor, TeleportCause.PLUGIN); - } - + //The teleport function is used when you want to normally teleport someone to a location or player. public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception { teleport(new Target(loc), chargeFor, cause); @@ -241,7 +239,7 @@ public class Teleport implements Runnable, ITeleport return; } - cancel(); + cancel(false); Calendar c = new GregorianCalendar(); c.add(Calendar.SECOND, (int)delay); c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); @@ -251,48 +249,96 @@ public class Teleport implements Runnable, ITeleport teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } - private void now(Target target, TeleportCause cause) throws Exception + //The now function is used when you want to skip tp delay when teleporting someone to a location or player. + public void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception { - cancel(); - user.setLastLocation(); - user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); + if (cooldown) + { + cooldown(false); + } + now(new Target(loc), cause); } - public void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception + public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception { if (cooldown) { cooldown(false); } - now(new Target(loc), cause); + now(new Target(entity), cause); } - public void now(Location loc, Trade chargeFor, TeleportCause cause) throws Exception + private void now(Target target, TeleportCause cause) throws Exception { - cooldown(false); - chargeFor.charge(user); - now(new Target(loc), cause); + cancel(false); + user.setLastLocation(); + user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); } - public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception + //The teleportToMe function is a wrapper used to handle teleporting players to them, like /tphere + public void teleportToMe(User otherUser, Trade chargeFor, TeleportCause cause) throws Exception { - if (cooldown) + Target target = new Target(user); + + double delay = ess.getSettings().getTeleportDelay(); + + if (chargeFor != null) + { + chargeFor.isAffordableFor(user); + } + cooldown(true); + if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) { cooldown(false); + otherUser.getTeleport().now(target, cause); + if (chargeFor != null) + { + chargeFor.charge(user); + } + return; } - now(new Target(entity), cause); + + cancel(false); + Calendar c = new GregorianCalendar(); + c.add(Calendar.SECOND, (int)delay); + c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); + otherUser.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis()))); + initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause); + + teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); + } + + //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 + { + final Player player = user.getBase(); + final Location bed = player.getBedSpawnLocation(); + final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, bed == null ? player.getWorld().getSpawnLocation() : bed, bed != null); + ess.getServer().getPluginManager().callEvent(pre); + teleport(new Target(pre.getRespawnLocation()), chargeFor, cause); + } + + //The warp function is a wrapper used to teleport a player to a /warp + public void warp(String warp, Trade chargeFor, TeleportCause cause) throws Exception + { + Location loc = ess.getWarps().getWarp(warp); + teleport(new Target(loc), chargeFor, cause); + user.sendMessage(_("warpingTo", warp)); } + //The back function is a wrapper used to teleport a player /back to their previous location. public void back(Trade chargeFor) throws Exception { teleport(new Target(user.getLastLocation()), chargeFor, TeleportCause.COMMAND); } + //This function is used to throw a user back after a jail sentence public void back() throws Exception { now(new Target(user.getLastLocation()), TeleportCause.COMMAND); } + //This function handles teleporting to /home public void home(Location loc, Trade chargeFor) throws Exception { teleport(new Target(loc), chargeFor, TeleportCause.COMMAND); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 3f52e8e01..865492921 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -65,7 +65,7 @@ public class Commandtpaccept extends EssentialsCommand if (user.isTpRequestHere()) { - user.getTeleport().teleport(target, charge, TeleportCause.COMMAND); + target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND); } else { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index 641290575..76041ca6c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -27,7 +27,7 @@ public class Commandtphere extends EssentialsCommand { throw new Exception(_("noPerm", "essentials.worlds." + user.getWorld().getName())); } - player.getTeleport().teleport(user, new Trade(this.getName(), ess), TeleportCause.COMMAND); + user.getTeleport().teleportToMe(player, new Trade(this.getName(), ess), TeleportCause.COMMAND); user.sendMessage(_("teleporting")); player.sendMessage(_("teleporting")); throw new NoChargeException(); |