ScriptsLab
WikiDownloadsSourcesSupport
ScriptsLab
DocumentationDownloadsGitHubDiscord

© 2026 ScriptsLab

Back to src/main/java/com/scriptslab/api/scheduler
J

TaskScheduler.java

Java · 107 lines · 2.6 KB

src/main/java/com/scriptslab/api/scheduler/TaskScheduler.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.scriptslab.api.scheduler;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * Task scheduler for running tasks on the server.
 * Wrapper around BukkitScheduler with better API.
 */
public interface TaskScheduler {
    
    /**
     * Runs a task on the main thread.
     * 
     * @param task task to run
     * @return scheduled task
     */
    ScheduledTask runTask(Runnable task);
    
    /**
     * Runs a task asynchronously.
     * 
     * @param task task to run
     * @return scheduled task
     */
    ScheduledTask runTaskAsync(Runnable task);
    
    /**
     * Runs a task later on the main thread.
     * 
     * @param task task to run
     * @param delay delay before execution
     * @param unit time unit
     * @return scheduled task
     */
    ScheduledTask runTaskLater(Runnable task, long delay, TimeUnit unit);
    
    /**
     * Runs a task later asynchronously.
     * 
     * @param task task to run
     * @param delay delay before execution
     * @param unit time unit
     * @return scheduled task
     */
    ScheduledTask runTaskLaterAsync(Runnable task, long delay, TimeUnit unit);
    
    /**
     * Runs a repeating task on the main thread.
     * 
     * @param task task to run
     * @param delay initial delay
     * @param period repeat period
     * @param unit time unit
     * @return scheduled task
     */
    ScheduledTask runTaskTimer(Runnable task, long delay, long period, TimeUnit unit);
    
    /**
     * Runs a repeating task asynchronously.
     * 
     * @param task task to run
     * @param delay initial delay
     * @param period repeat period
     * @param unit time unit
     * @return scheduled task
     */
    ScheduledTask runTaskTimerAsync(Runnable task, long delay, long period, TimeUnit unit);
    
    /**
     * Runs a task and returns a CompletableFuture.
     * 
     * @param task task to run
     * @param <T> result type
     * @return future with result
     */
    <T> CompletableFuture<T> supply(java.util.function.Supplier<T> task);
    
    /**
     * Runs a task asynchronously and returns a CompletableFuture.
     * 
     * @param task task to run
     * @param <T> result type
     * @return future with result
     */
    <T> CompletableFuture<T> supplyAsync(java.util.function.Supplier<T> task);
    
    /**
     * Cancels all tasks for a specific owner.
     * 
     * @param owner task owner
     */
    void cancelTasks(Object owner);
    
    /**
     * Cancels all tasks.
     */
    void cancelAllTasks();
    
    /**
     * Gets the number of active tasks.
     * 
     * @return task count
     */
    int getActiveTaskCount();
}