Skip to content

Commit be133e6

Browse files
committed
Add new methods and default implementations to Platform and TaskScheduler interfaces
1 parent 401dbec commit be133e6

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

common/src/main/java/it/renvins/serverpulse/common/platform/Platform.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ public interface Platform {
2121
*/
2222
boolean isPrimaryThread();
2323

24+
/**
25+
* @return the number of online players
26+
*/
2427
int getOnlinePlayerCount();
25-
Map<String, WorldData> getWorldsData();
28+
29+
/**
30+
* @return a map of world names to their data
31+
* @throws UnsupportedOperationException if the platform does not support this method
32+
*/
33+
default Map<String, WorldData> getWorldsData() {
34+
throw new UnsupportedOperationException("This method is not supported on this platform.");
35+
}
2636
}

common/src/main/java/it/renvins/serverpulse/common/scheduler/Task.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
public interface Task {
44

5-
65
/**
76
* Cancels the task
87
*/

common/src/main/java/it/renvins/serverpulse/common/scheduler/TaskScheduler.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,56 @@
22

33
public interface TaskScheduler {
44

5-
void runSync(Runnable task);
5+
/**
6+
* Runs a task synchronously on the main thread.
7+
*
8+
* @param task The task to run
9+
* @throws UnsupportedOperationException if the implementation does not support synchronous task execution
10+
*/
11+
default void runSync(Runnable task) {
12+
throw new UnsupportedOperationException("Synchronous task execution is not supported.");
13+
}
14+
15+
/**
16+
* Runs a task timer synchronously on the main thread.
17+
*
18+
* @param task The task to run
19+
* @throws UnsupportedOperationException if the implementation does not support synchronous task execution
20+
*/
21+
default Task runTaskTimer(Runnable task, long delayTicks, long periodTicks) {
22+
throw new UnsupportedOperationException("Synchronous task execution is not supported.");
23+
}
24+
25+
/**
26+
* Runs a task later synchronously on the main thread.
27+
*
28+
* @param task The task to run
29+
* @throws UnsupportedOperationException if the implementation does not support synchronous task execution
30+
*/
31+
default Task runTaskLater(Runnable task, long delayTicks) {
32+
throw new UnsupportedOperationException("Synchronous task execution is not supported.");
33+
}
34+
35+
/**
36+
* Runs a task asynchronously on a separate thread.
37+
*
38+
* @param task The task to run
39+
*/
640
void runAsync(Runnable task);
741

8-
Task runTaskTimer(Runnable task, long delayTicks, long periodTicks);
42+
/**
43+
* Runs a task timer asynchronously on a separate thread.
44+
*
45+
* @param task The task to run
46+
* @return A Task object representing the task
47+
*/
948
Task runTaskTimerAsync(Runnable task, long delayTicks, long periodTicks);
1049

11-
Task runTaskLater(Runnable task, long delayTicks);
50+
/**
51+
* Runs a task later asynchronously on a separate thread.
52+
*
53+
* @param task The task to run
54+
* @return A Task object representing the task
55+
*/
1256
Task runTaskLaterAsync(Runnable task, long delayTicks);
1357
}

0 commit comments

Comments
 (0)