mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Fix ScheduledTask timer.
This commit is contained in:
@@ -28,8 +28,7 @@ public abstract class ScheduledTask {
|
|||||||
* Creates a new scheduled task.
|
* Creates a new scheduled task.
|
||||||
*
|
*
|
||||||
* @param delay The delay between executions of the task, in pulses.
|
* @param delay The delay between executions of the task, in pulses.
|
||||||
* @param immediate A flag indicating if this task should (for the first execution) be ran immediately, or after the
|
* @param immediate Indicates whether or not this task should be executed immediately, or after the {@code delay}.
|
||||||
* {@code delay}.
|
|
||||||
* @throws IllegalArgumentException If the delay is less than or equal to zero.
|
* @throws IllegalArgumentException If the delay is less than or equal to zero.
|
||||||
*/
|
*/
|
||||||
public ScheduledTask(int delay, boolean immediate) {
|
public ScheduledTask(int delay, boolean immediate) {
|
||||||
@@ -37,11 +36,6 @@ public abstract class ScheduledTask {
|
|||||||
pulses = immediate ? 0 : delay;
|
pulses = immediate ? 0 : delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes this task.
|
|
||||||
*/
|
|
||||||
public abstract void execute();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this task is running.
|
* Checks if this task is running.
|
||||||
*
|
*
|
||||||
@@ -51,16 +45,6 @@ public abstract class ScheduledTask {
|
|||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Pulses this task: updates the delay and calls {@link #execute()} if necessary.
|
|
||||||
*/
|
|
||||||
final void pulse() {
|
|
||||||
if (running && pulses-- == 0) {
|
|
||||||
execute();
|
|
||||||
pulses = delay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the delay.
|
* Sets the delay.
|
||||||
*
|
*
|
||||||
@@ -79,4 +63,19 @@ public abstract class ScheduledTask {
|
|||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes this task.
|
||||||
|
*/
|
||||||
|
public abstract void execute();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pulses this task: updates the delay and calls {@link #execute()} if necessary.
|
||||||
|
*/
|
||||||
|
final void pulse() {
|
||||||
|
if (running && --pulses <= 0) {
|
||||||
|
execute();
|
||||||
|
pulses = delay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user