summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author@ArkhamNetwork <devane1249@Gmail.com>2014-05-17 01:12:13 +0100
committerKHobbits <rob@khobbits.co.uk>2014-05-17 03:35:44 +0100
commiteafea119a666269dec8c697272c42b5d004df757 (patch)
tree926e6e743042034c92a983f67296f7dd62f5cb66
parente92fdbdc59eccf0896a15f3e14571696aeeff6e6 (diff)
downloadEssentials-eafea119a666269dec8c697272c42b5d004df757.tar
Essentials-eafea119a666269dec8c697272c42b5d004df757.tar.gz
Essentials-eafea119a666269dec8c697272c42b5d004df757.tar.lz
Essentials-eafea119a666269dec8c697272c42b5d004df757.tar.xz
Essentials-eafea119a666269dec8c697272c42b5d004df757.zip
Move the teleport timer to an async task.
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/TimedTeleport.java95
3 files changed, 65 insertions, 42 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index 305fee60e..e600f2cec 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -803,6 +803,12 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
{
return this.getScheduler().runTaskLaterAsynchronously(this, run, delay);
}
+
+ @Override
+ public BukkitTask runTaskTimerAsynchronously(final Runnable run, final long delay, final long period)
+ {
+ return this.getScheduler().runTaskTimerAsynchronously(this, run, delay, period);
+ }
@Override
public int scheduleSyncDelayedTask(final Runnable run)
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
index ea18fb329..1e155976e 100644
--- a/Essentials/src/com/earth2me/essentials/IEssentials.java
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -63,12 +63,14 @@ public interface IEssentials extends Plugin
BukkitTask runTaskAsynchronously(Runnable run);
BukkitTask runTaskLaterAsynchronously(Runnable run, long delay);
+
+ BukkitTask runTaskTimerAsynchronously(Runnable run, long delay, long period);
int scheduleSyncDelayedTask(Runnable run);
int scheduleSyncDelayedTask(Runnable run, long delay);
- int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
+ int scheduleSyncRepeatingTask(Runnable run, long delay, long period);
TNTExplodeListener getTNTListener();
@@ -76,7 +78,7 @@ public interface IEssentials extends Plugin
AlternativeCommandsHandler getAlternativeCommandsHandler();
- void showError(final CommandSource sender, final Throwable exception, final String commandLabel);
+ void showError(CommandSource sender, Throwable exception, String commandLabel);
IItemDb getItemDb();
diff --git a/Essentials/src/com/earth2me/essentials/TimedTeleport.java b/Essentials/src/com/earth2me/essentials/TimedTeleport.java
index edc614235..6b9e88f97 100644
--- a/Essentials/src/com/earth2me/essentials/TimedTeleport.java
+++ b/Essentials/src/com/earth2me/essentials/TimedTeleport.java
@@ -50,7 +50,7 @@ public class TimedTeleport implements Runnable
this.timer_respawn = respawn;
this.timer_canMove = user.isAuthorized("essentials.teleport.timer.move");
- timer_task = ess.scheduleSyncRepeatingTask(this, 20, 20);
+ timer_task = ess.runTaskTimerAsynchronously(this, 20, 20).getTaskId();
}
@Override
@@ -63,7 +63,7 @@ public class TimedTeleport implements Runnable
return;
}
- IUser teleportUser = ess.getUser(this.timer_teleportee);
+ final IUser teleportUser = ess.getUser(this.timer_teleportee);
if (teleportUser == null || !teleportUser.getBase().isOnline())
{
@@ -89,49 +89,64 @@ public class TimedTeleport implements Runnable
return;
}
- timer_health = teleportUser.getBase().getHealth(); // in case user healed, then later gets injured
- final long now = System.currentTimeMillis();
- if (now > timer_started + timer_delay)
+ ess.scheduleSyncDelayedTask(new Runnable()
{
- try
+ @Override
+ public void run()
{
- teleport.cooldown(false);
- }
- catch (Exception ex)
- {
- teleportOwner.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
- if (teleportOwner != teleportUser)
- {
- teleportUser.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
- }
- }
- try
- {
- cancelTimer(false);
- teleportUser.sendMessage(tl("teleportationCommencing"));
- if (timer_chargeFor != null)
- {
- timer_chargeFor.isAffordableFor(teleportOwner);
- }
- if (timer_respawn)
- {
- teleport.respawnNow(teleportUser, timer_cause);
- }
- else
- {
- teleport.now(teleportUser, timer_teleportTarget, timer_cause);
- }
- if (timer_chargeFor != null)
+
+ timer_health = teleportUser.getBase().getHealth(); // in case user healed, then later gets injured
+ final long now = System.currentTimeMillis();
+ if (now > timer_started + timer_delay)
{
- timer_chargeFor.charge(teleportOwner);
+ try
+ {
+ teleport.cooldown(false);
+ }
+ catch (Exception ex)
+ {
+ teleportOwner.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
+ if (teleportOwner != teleportUser)
+ {
+ teleportUser.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
+ }
+ }
+ try
+ {
+ cancelTimer(false);
+ teleportUser.sendMessage(tl("teleportationCommencing"));
+
+ try
+ {
+ if (timer_chargeFor != null)
+ {
+ timer_chargeFor.isAffordableFor(teleportOwner);
+ }
+ if (timer_respawn)
+ {
+ teleport.respawnNow(teleportUser, timer_cause);
+ }
+ else
+ {
+ teleport.now(teleportUser, timer_teleportTarget, timer_cause);
+ }
+ if (timer_chargeFor != null)
+ {
+ timer_chargeFor.charge(teleportOwner);
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+
+ }
+ catch (Exception ex)
+ {
+ ess.showError(teleportOwner.getSource(), ex, "\\ teleport");
+ }
}
}
- catch (Exception ex)
- {
- ess.showError(teleportOwner.getSource(), ex, "\\ teleport");
- }
-
- }
+ });
}
//If we need to cancelTimer a pending teleportPlayer call this method