Little bit DRYer

This commit is contained in:
KHobbits 2012-09-29 23:41:12 +01:00
parent 35259892b8
commit 3083ba2627

View file

@ -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