summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/Teleport.java
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-06-10 21:55:48 +0100
committerKHobbits <rob@khobbits.co.uk>2012-06-10 21:55:48 +0100
commitbdd64da24920a041950a43cbcd3a019d41ad300a (patch)
tree38119e75c1ba6ff8300b77a861890b397b2d111c /Essentials/src/com/earth2me/essentials/Teleport.java
parent0bbd094236d482aff5251a023c5b3102ed06bc26 (diff)
downloadEssentials-bdd64da24920a041950a43cbcd3a019d41ad300a.tar
Essentials-bdd64da24920a041950a43cbcd3a019d41ad300a.tar.gz
Essentials-bdd64da24920a041950a43cbcd3a019d41ad300a.tar.lz
Essentials-bdd64da24920a041950a43cbcd3a019d41ad300a.tar.xz
Essentials-bdd64da24920a041950a43cbcd3a019d41ad300a.zip
Try to be a little more sensible with stored cooldowns.
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/Teleport.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java34
1 files changed, 25 insertions, 9 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java
index 6569a1689..a920544cb 100644
--- a/Essentials/src/com/earth2me/essentials/Teleport.java
+++ b/Essentials/src/com/earth2me/essentials/Teleport.java
@@ -145,23 +145,39 @@ public class Teleport implements Runnable, ITeleport
public void cooldown(boolean check) throws Exception
{
- Calendar now = new GregorianCalendar();
+ final Calendar time = new GregorianCalendar();
if (user.getLastTeleportTimestamp() > 0)
{
- double cooldown = ess.getSettings().getTeleportCooldown();
- Calendar cooldownTime = new GregorianCalendar();
- cooldownTime.setTimeInMillis(user.getLastTeleportTimestamp());
- cooldownTime.add(Calendar.SECOND, (int)cooldown);
- cooldownTime.add(Calendar.MILLISECOND, (int)((cooldown * 1000.0) % 1000.0));
- if (cooldownTime.after(now) && !user.isAuthorized("essentials.teleport.cooldown.bypass"))
+ // Take the current time, and remove the delay from it.
+ final double cooldown = ess.getSettings().getTeleportCooldown();
+ final Calendar earliestTime = new GregorianCalendar();
+ earliestTime.add(Calendar.SECOND, -(int)cooldown);
+ earliestTime.add(Calendar.MILLISECOND, -(int)((cooldown * 1000.0) % 1000.0));
+ // This value contains the most recent time a teleport could have been used that would allow another use.
+ final long earliestLong = earliestTime.getTimeInMillis();
+
+ // When was the last teleport used?
+ final Long lastTime = user.getLastTeleportTimestamp();
+
+ if (lastTime > time.getTimeInMillis())
{
- throw new Exception(_("timeBeforeTeleport", Util.formatDateDiff(cooldownTime.getTimeInMillis())));
+ // This is to make sure time didn't get messed up on last kit use.
+ // If this happens, let's give the user the benifit of the doubt.
+ user.setLastTeleportTimestamp(time.getTimeInMillis());
+ return;
+ }
+ else if (lastTime > earliestLong && !user.isAuthorized("essentials.teleport.cooldown.bypass"))
+ {
+ time.setTimeInMillis(lastTime);
+ time.add(Calendar.SECOND, (int)delay);
+ time.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
+ throw new Exception(_("timeBeforeTeleport", Util.formatDateDiff(time.getTimeInMillis())));
}
}
// if justCheck is set, don't update lastTeleport; we're just checking
if (!check)
{
- user.setLastTeleportTimestamp(now.getTimeInMillis());
+ user.setLastTeleportTimestamp(time.getTimeInMillis());
}
}