Skip to content

Commit

Permalink
Add Timer#start method
Browse files Browse the repository at this point in the history
  • Loading branch information
aumgn committed Aug 24, 2012
1 parent 753559c commit d89f874
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/fr/aumgn/bukkitutils/timer/Timer.java
Expand Up @@ -57,6 +57,10 @@ private void scheduleAndPrintTime(int delay) {
long minutes = TimeUnit.SECONDS.toMinutes(remainingTime);
String msg = String.format(format, minutes, remainingTime % 60);
sendTimeMessage(getCurrentColor() + msg);
schedule(delay);
}

private void schedule(int delay) {
currentDelay = delay;
watch = new Stopwatch();
watch.start();
Expand All @@ -78,6 +82,19 @@ public int getRemainingTime() {
return remainingTime;
}

public void start() {
remainingTime -= currentDelay;
if (remainingTime > majorDelay) {
schedule(majorDelay);
} else if (remainingTime > minorDelay) {
schedule(minorDelay);
} else if (remainingTime > 0) {
schedule(1);
} else {
runnable.run();
}
}

@Override
public void run() {
remainingTime -= currentDelay;
Expand Down

0 comments on commit d89f874

Please sign in to comment.