diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-09-29 23:41:12 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-09-29 23:41:12 +0100 |
commit | 3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4 (patch) | |
tree | 064e64440c9080f49e9af9eabca0122f280b6f58 | |
parent | 35259892b8f23940a717565443204b9f7fac5404 (diff) | |
download | Essentials-3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4.tar Essentials-3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4.tar.gz Essentials-3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4.tar.lz Essentials-3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4.tar.xz Essentials-3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4.zip |
Little bit DRYer
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Teleport.java | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 2f1028243..17dbca0f2 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -207,6 +207,32 @@ public class Teleport implements Runnable, ITeleport teleTimer = -1; } } + + //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 + { + if (cooldown) + { + cooldown(false); + } + now(new Target(loc), cause); + } + + public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception + { + if (cooldown) + { + cooldown(false); + } + now(new Target(entity), cause); + } + + private void now(Target target, TeleportCause cause) throws Exception + { + cancel(false); + user.setLastLocation(); + user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); + } //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 @@ -240,41 +266,12 @@ public class Teleport implements Runnable, ITeleport } cancel(false); - Calendar c = new GregorianCalendar(); - c.add(Calendar.SECOND, (int)delay); - c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); - user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis()))); + warnUser(user); initTimer((long)(delay * 1000.0), target, chargeFor, cause); teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } - //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 - { - if (cooldown) - { - cooldown(false); - } - now(new Target(loc), cause); - } - - public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception - { - if (cooldown) - { - cooldown(false); - } - now(new Target(entity), cause); - } - - private void now(Target target, TeleportCause cause) throws Exception - { - cancel(false); - user.setLastLocation(); - user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); - } - //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 { @@ -299,14 +296,18 @@ public class Teleport implements Runnable, ITeleport } 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()))); + warnUser(otherUser); initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause); teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } + + private void warnUser(final IUser user) { + Calendar c = new GregorianCalendar(); + c.add(Calendar.SECOND, (int)delay); + c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); + user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis()))); + } //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 |