-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
AsyncSchedulable.java
38 lines (31 loc) · 1.05 KB
/
AsyncSchedulable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package net.aufdemrand.denizencore.utilities.scheduling;
import net.aufdemrand.denizencore.DenizenCore;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class AsyncSchedulable extends Schedulable {
public static final Executor executor = Executors.newCachedThreadPool();
protected final Schedulable schedulable;
public AsyncSchedulable(Schedulable schedulable) {
this.schedulable = schedulable;
final Runnable runnable = schedulable.run;
this.schedulable.run = new Runnable() {
@Override
public void run() {
if (DenizenCore.MAIN_THREAD == Thread.currentThread()) {
executor.execute(runnable);
}
else {
runnable.run();
}
}
};
}
@Override
public boolean isSync() {
return false;
}
@Override
public boolean tick(float seconds) {
return this.schedulable.tick(seconds);
}
}