From 3083ba26279bc1e4002b1db3c8ac7763cfa5b2f4 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 29 Sep 2012 23:41:12 +0100 Subject: [PATCH] Little bit DRYer --- .../src/com/earth2me/essentials/Teleport.java | 69 ++++++++++--------- 1 file 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