|
3 | 3 | import com.eternalcode.commons.scheduler.Scheduler;
|
4 | 4 | import com.eternalcode.commons.scheduler.Task;
|
5 | 5 | import java.util.concurrent.CompletableFuture;
|
| 6 | +import org.bukkit.Location; |
| 7 | +import org.bukkit.Server; |
| 8 | +import org.bukkit.entity.Entity; |
6 | 9 | import org.bukkit.plugin.Plugin;
|
7 | 10 | import org.bukkit.scheduler.BukkitScheduler;
|
8 | 11 |
|
9 | 12 | import java.time.Duration;
|
10 | 13 | import java.util.function.Supplier;
|
11 | 14 |
|
12 |
| -public class BukkitSchedulerImpl implements Scheduler { |
| 15 | +public class BukkitSchedulerImpl implements MinecraftScheduler { |
13 | 16 |
|
14 | 17 | private final Plugin plugin;
|
| 18 | + private final Server server; |
15 | 19 | private final BukkitScheduler rootScheduler;
|
16 | 20 |
|
17 | 21 | public BukkitSchedulerImpl(Plugin plugin) {
|
18 | 22 | this.plugin = plugin;
|
| 23 | + this.server = plugin.getServer(); |
19 | 24 | this.rootScheduler = plugin.getServer().getScheduler();
|
20 | 25 | }
|
21 | 26 |
|
22 | 27 | @Override
|
23 |
| - public Task sync(Runnable task) { |
| 28 | + public boolean isGlobalTickThread() { |
| 29 | + return this.server.isPrimaryThread(); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public boolean isPrimaryThread() { |
| 34 | + return this.server.isPrimaryThread(); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public boolean isRegionThread(Entity entity) { |
| 39 | + return this.server.isPrimaryThread(); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean isRegionThread(Location location) { |
| 44 | + return this.server.isPrimaryThread(); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Task run(Runnable task) { |
24 | 49 | return new BukkitTaskImpl(this.rootScheduler.runTask(this.plugin, task));
|
25 | 50 | }
|
26 | 51 |
|
27 | 52 | @Override
|
28 |
| - public Task async(Runnable task) { |
| 53 | + public Task runAsync(Runnable task) { |
29 | 54 | return new BukkitTaskImpl(this.rootScheduler.runTaskAsynchronously(this.plugin, task));
|
30 | 55 | }
|
31 | 56 |
|
32 | 57 | @Override
|
33 |
| - public Task laterSync(Runnable task, Duration delay) { |
| 58 | + public Task runLater(Runnable task, Duration delay) { |
34 | 59 | return new BukkitTaskImpl(this.rootScheduler.runTaskLater(this.plugin, task, this.toTick(delay)));
|
35 | 60 | }
|
36 | 61 |
|
37 | 62 | @Override
|
38 |
| - public Task laterAsync(Runnable task, Duration delay) { |
| 63 | + public Task runLaterAsync(Runnable task, Duration delay) { |
39 | 64 | return new BukkitTaskImpl(this.rootScheduler.runTaskLaterAsynchronously(this.plugin, task, this.toTick(delay)));
|
40 | 65 | }
|
41 | 66 |
|
42 | 67 | @Override
|
43 |
| - public Task timerSync(Runnable task, Duration delay, Duration period) { |
44 |
| - return new BukkitTaskImpl(this.rootScheduler.runTaskTimer(this.plugin, task, this.toTick(delay), this.toTick(period))); |
| 68 | + public Task timer(Runnable task, Duration delay, Duration period) { |
| 69 | + return new BukkitTaskImpl(this.rootScheduler.runTaskTimer(this.plugin, task, this.toTick(delay), this.toTick(period)), true); |
45 | 70 | }
|
46 | 71 |
|
47 | 72 | @Override
|
48 | 73 | public Task timerAsync(Runnable task, Duration delay, Duration period) {
|
49 |
| - return new BukkitTaskImpl(this.rootScheduler.runTaskTimerAsynchronously(this.plugin, task, this.toTick(delay), this.toTick(period))); |
| 74 | + return new BukkitTaskImpl(this.rootScheduler.runTaskTimerAsynchronously(this.plugin, task, this.toTick(delay), this.toTick(period)), true); |
50 | 75 | }
|
51 | 76 |
|
52 | 77 | @Override
|
53 |
| - public <T> CompletableFuture<T> completeSync(Supplier<T> task) { |
| 78 | + public <T> CompletableFuture<T> complete(Supplier<T> task) { |
54 | 79 | CompletableFuture<T> completable = new CompletableFuture<>();
|
55 | 80 | this.rootScheduler.runTask(this.plugin, () -> completable.complete(task.get()));
|
56 | 81 | return completable;
|
|
0 commit comments