mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-01 18:53:27 +02:00
Little bit DRYer
This commit is contained in:
@@ -207,6 +207,32 @@ public class Teleport implements Runnable, ITeleport
|
|||||||
teleTimer = -1;
|
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.
|
//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
|
public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception
|
||||||
@@ -240,41 +266,12 @@ public class Teleport implements Runnable, ITeleport
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancel(false);
|
cancel(false);
|
||||||
Calendar c = new GregorianCalendar();
|
warnUser(user);
|
||||||
c.add(Calendar.SECOND, (int)delay);
|
|
||||||
c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
|
||||||
user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis())));
|
|
||||||
initTimer((long)(delay * 1000.0), target, chargeFor, cause);
|
initTimer((long)(delay * 1000.0), target, chargeFor, cause);
|
||||||
|
|
||||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
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
|
//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
|
public void teleportToMe(User otherUser, Trade chargeFor, TeleportCause cause) throws Exception
|
||||||
{
|
{
|
||||||
@@ -299,14 +296,18 @@ public class Teleport implements Runnable, ITeleport
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancel(false);
|
cancel(false);
|
||||||
Calendar c = new GregorianCalendar();
|
warnUser(otherUser);
|
||||||
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);
|
initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause);
|
||||||
|
|
||||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
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
|
//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
|
public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception
|
||||||
|
Reference in New Issue
Block a user