# Solved Find Progress of Delayed Task.

Discussion in 'Plugin Development' started by B3N909, May 8, 2015.

Not open for further replies.
1. Offline

### B3N909

Code:
```Bukkit.getScheduler().delayed...
public void run(){
//Return; We are done... 100%
}
}, iDelay);

public void run(){
getLogger().info("Display % until we finish..");
//When we hit 100% the delay task is finished.
}
}, 0L, 20L);```
So the example here is that we have a DelayedTask running on a variable x called iDelay. I want to know what percent the delayed task is at before running the public void run()? So

#1
2. Offline

### Pik0

You could store a initial time variable and in the task you would calculate the delay between the 2 states of time:

Code:
```long start = System.currentMills();

Bukkit.getScheduler().delayed...

public void run(){
long delay = System.currentMills()-start;

//delay = time in milliseconds between the delayed task start and the repeating task iteration
}
}, 0L, 20L);```

#2
3. Offline

### B3N909

@Pik0 , Thanks. Now how can I turn the Millseconds into the percent completed?

Update: I was able to calculated the guessed time of 100% by doing...
Code:
`float long end = (iDelay / 20) * 1000;`
Which gave me a time in milliseconds. I then did something like this to test it...
Code:
`getLogger().info(delay + "/" + end);`
And this outputted as expected: "1000 / 8000", "2000 / 8000", etc.
Now when I tried to use this by just dividing the two numbers I got a ton of zeros and then are few 1's at the end. Nothing that was a percent? Any ideas?

EDIT by Moderator: merged posts, please use the edit button instead of double posting.

Last edited by a moderator: Jun 12, 2016
#3