Skip to content

Commit c720ba1

Browse files
v0.3.4 - Add runAtEntityLater and runAtEntityLater with fallback options. Resolves #12
1 parent b9e22ba commit c720ba1

File tree

6 files changed

+304
-159
lines changed

6 files changed

+304
-159
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
allprojects {
88
apply plugin: 'java'
99

10-
version = '0.3.3'
10+
version = '0.3.4'
1111

1212
repositories {
1313

platform/common/src/main/java/com/tcoded/folialib/impl/ServerImplementation.java

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.bukkit.Location;
66
import org.bukkit.entity.Entity;
77
import org.bukkit.entity.Player;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
810

911
import java.util.List;
1012
import java.util.UUID;
@@ -24,7 +26,7 @@ public interface ServerImplementation {
2426
* @param consumer Task to run
2527
* @return Future when the task is completed
2628
*/
27-
CompletableFuture<Void> runNextTick(Consumer<WrappedTask> consumer);
29+
CompletableFuture<Void> runNextTick(@NotNull Consumer<WrappedTask> consumer);
2830

2931
/**
3032
* Folia: Async
@@ -33,7 +35,7 @@ public interface ServerImplementation {
3335
* @param consumer Task to run
3436
* @return Future when the task is completed
3537
*/
36-
CompletableFuture<Void> runAsync(Consumer<WrappedTask> consumer);
38+
CompletableFuture<Void> runAsync(@NotNull Consumer<WrappedTask> consumer);
3739

3840
// ----- Run Later -----
3941

@@ -45,7 +47,7 @@ public interface ServerImplementation {
4547
* @param delay Delay before execution in ticks
4648
* @return WrappedTask instance
4749
*/
48-
WrappedTask runLater(Runnable runnable, long delay);
50+
WrappedTask runLater(@NotNull Runnable runnable, long delay);
4951

5052
/**
5153
* Folia: Synced with the server daylight cycle tick
@@ -54,7 +56,7 @@ public interface ServerImplementation {
5456
* @param consumer Task to run
5557
* @param delay Delay before execution in ticks
5658
*/
57-
void runLater(Consumer<WrappedTask> consumer, long delay);
59+
void runLater(@NotNull Consumer<WrappedTask> consumer, long delay);
5860

5961
/**
6062
* Folia: Synced with the server daylight cycle tick
@@ -65,7 +67,7 @@ public interface ServerImplementation {
6567
* @param unit Time unit
6668
* @return WrappedTask instance
6769
*/
68-
WrappedTask runLater(Runnable runnable, long delay, TimeUnit unit);
70+
WrappedTask runLater(@NotNull Runnable runnable, long delay, TimeUnit unit);
6971

7072
/**
7173
* Folia: Synced with the server daylight cycle tick
@@ -75,7 +77,7 @@ public interface ServerImplementation {
7577
* @param delay Delay before execution
7678
* @param unit Time unit
7779
*/
78-
void runLater(Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
80+
void runLater(@NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
7981

8082
/**
8183
* Folia: Async
@@ -85,7 +87,7 @@ public interface ServerImplementation {
8587
* @param delay Delay before execution in ticks
8688
* @return WrappedTask instance
8789
*/
88-
WrappedTask runLaterAsync(Runnable runnable, long delay);
90+
WrappedTask runLaterAsync(@NotNull Runnable runnable, long delay);
8991

9092
/**
9193
* Folia: Async
@@ -94,7 +96,7 @@ public interface ServerImplementation {
9496
* @param consumer Task to run
9597
* @param delay Delay before execution in ticks
9698
*/
97-
void runLaterAsync(Consumer<WrappedTask> consumer, long delay);
99+
void runLaterAsync(@NotNull Consumer<WrappedTask> consumer, long delay);
98100

99101
/**
100102
* Folia: Async
@@ -105,7 +107,7 @@ public interface ServerImplementation {
105107
* @param unit Time unit
106108
* @return WrappedTask instance
107109
*/
108-
WrappedTask runLaterAsync(Runnable runnable, long delay, TimeUnit unit);
110+
WrappedTask runLaterAsync(@NotNull Runnable runnable, long delay, TimeUnit unit);
109111

110112
/**
111113
* Folia: Async
@@ -115,7 +117,7 @@ public interface ServerImplementation {
115117
* @param delay Delay before execution
116118
* @param unit Time unit
117119
*/
118-
void runLaterAsync(Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
120+
void runLaterAsync(@NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
119121

120122
// ----- Global Timers -----
121123

@@ -128,7 +130,7 @@ public interface ServerImplementation {
128130
* @param period Delay between executions in ticks
129131
* @return WrappedTask instance
130132
*/
131-
WrappedTask runTimer(Runnable runnable, long delay, long period);
133+
WrappedTask runTimer(@NotNull Runnable runnable, long delay, long period);
132134

133135
/**
134136
* Folia: Synced with the server daylight cycle tick
@@ -138,7 +140,7 @@ public interface ServerImplementation {
138140
* @param delay Delay before first execution in ticks
139141
* @param period Delay between executions in ticks
140142
*/
141-
void runTimer(Consumer<WrappedTask> consumer, long delay, long period);
143+
void runTimer(@NotNull Consumer<WrappedTask> consumer, long delay, long period);
142144

143145
/**
144146
* Folia: Synced with the server daylight cycle tick
@@ -150,7 +152,7 @@ public interface ServerImplementation {
150152
* @param unit Time unit
151153
* @return WrappedTask instance
152154
*/
153-
WrappedTask runTimer(Runnable runnable, long delay, long period, TimeUnit unit);
155+
WrappedTask runTimer(@NotNull Runnable runnable, long delay, long period, TimeUnit unit);
154156

155157
/**
156158
* Folia: Synced with the server daylight cycle tick
@@ -161,7 +163,7 @@ public interface ServerImplementation {
161163
* @param period Delay between executions
162164
* @param unit Time unit
163165
*/
164-
void runTimer(Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
166+
void runTimer(@NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
165167

166168
/**
167169
* Folia: Async
@@ -172,7 +174,7 @@ public interface ServerImplementation {
172174
* @param period Delay between executions in ticks
173175
* @return WrappedTask instance
174176
*/
175-
WrappedTask runTimerAsync(Runnable runnable, long delay, long period);
177+
WrappedTask runTimerAsync(@NotNull Runnable runnable, long delay, long period);
176178

177179
/**
178180
* Folia: Async
@@ -182,7 +184,7 @@ public interface ServerImplementation {
182184
* @param delay Delay before first execution in ticks
183185
* @param period Delay between executions in ticks
184186
*/
185-
void runTimerAsync(Consumer<WrappedTask> consumer, long delay, long period);
187+
void runTimerAsync(@NotNull Consumer<WrappedTask> consumer, long delay, long period);
186188

187189
/**
188190
* Folia: Async
@@ -194,7 +196,7 @@ public interface ServerImplementation {
194196
* @param unit Time unit
195197
* @return WrappedTask instance
196198
*/
197-
WrappedTask runTimerAsync(Runnable runnable, long delay, long period, TimeUnit unit);
199+
WrappedTask runTimerAsync(@NotNull Runnable runnable, long delay, long period, TimeUnit unit);
198200

199201
/**
200202
* Folia: Async
@@ -205,7 +207,7 @@ public interface ServerImplementation {
205207
* @param period Delay between executions
206208
* @param unit Time unit
207209
*/
208-
void runTimerAsync(Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
210+
void runTimerAsync(@NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
209211

210212

211213
// ----- Location/Region based -----
@@ -218,7 +220,7 @@ public interface ServerImplementation {
218220
* @param consumer Task to run
219221
* @return Future when the task is completed
220222
*/
221-
CompletableFuture<Void> runAtLocation(Location location, Consumer<WrappedTask> consumer);
223+
CompletableFuture<Void> runAtLocation(Location location, @NotNull Consumer<WrappedTask> consumer);
222224

223225
/**
224226
* Folia: Synced with the tick of the region of the chunk of the location
@@ -229,7 +231,7 @@ public interface ServerImplementation {
229231
* @param delay Delay before execution in ticks
230232
* @return WrappedTask instance
231233
*/
232-
WrappedTask runAtLocationLater(Location location, Runnable runnable, long delay);
234+
WrappedTask runAtLocationLater(Location location, @NotNull Runnable runnable, long delay);
233235

234236
/**
235237
* Folia: Synced with the tick of the region of the chunk of the location
@@ -239,7 +241,7 @@ public interface ServerImplementation {
239241
* @param consumer Task to run
240242
* @param delay Delay before execution in ticks
241243
*/
242-
void runAtLocationLater(Location location, Consumer<WrappedTask> consumer, long delay);
244+
void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask> consumer, long delay);
243245

244246
/**
245247
* Folia: Synced with the tick of the region of the chunk of the location
@@ -251,7 +253,7 @@ public interface ServerImplementation {
251253
* @param unit Time unit
252254
* @return WrappedTask instance
253255
*/
254-
WrappedTask runAtLocationLater(Location location, Runnable runnable, long delay, TimeUnit unit);
256+
WrappedTask runAtLocationLater(Location location, @NotNull Runnable runnable, long delay, TimeUnit unit);
255257

256258
/**
257259
* Folia: Synced with the tick of the region of the chunk of the location
@@ -262,7 +264,7 @@ public interface ServerImplementation {
262264
* @param delay Delay before execution
263265
* @param unit Time unit
264266
*/
265-
void runAtLocationLater(Location location, Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
267+
void runAtLocationLater(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
266268

267269
/**
268270
* Folia: Synced with the tick of the region of the chunk of the location
@@ -274,7 +276,7 @@ public interface ServerImplementation {
274276
* @param period Delay between executions in ticks
275277
* @return WrappedTask instance
276278
*/
277-
WrappedTask runAtLocationTimer(Location location, Runnable runnable, long delay, long period);
279+
WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runnable, long delay, long period);
278280

279281
/**
280282
* Folia: Synced with the tick of the region of the chunk of the location
@@ -285,7 +287,7 @@ public interface ServerImplementation {
285287
* @param delay Delay before first execution in ticks
286288
* @param period Delay between executions in ticks
287289
*/
288-
void runAtLocationTimer(Location location, Consumer<WrappedTask> consumer, long delay, long period);
290+
void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, long period);
289291

290292
/**
291293
* Folia: Synced with the tick of the region of the chunk of the location
@@ -298,7 +300,7 @@ public interface ServerImplementation {
298300
* @param unit Time unit
299301
* @return WrappedTask instance
300302
*/
301-
WrappedTask runAtLocationTimer(Location location, Runnable runnable, long delay, long period, TimeUnit unit);
303+
WrappedTask runAtLocationTimer(Location location, @NotNull Runnable runnable, long delay, long period, TimeUnit unit);
302304

303305
/**
304306
* Folia: Synced with the tick of the region of the chunk of the location
@@ -310,7 +312,7 @@ public interface ServerImplementation {
310312
* @param period Delay between executions
311313
* @param unit Time unit
312314
*/
313-
void runAtLocationTimer(Location location, Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
315+
void runAtLocationTimer(Location location, @NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
314316

315317

316318
// ----- Entity based -----
@@ -323,7 +325,7 @@ public interface ServerImplementation {
323325
* @param consumer Task to run
324326
* @return Future when the task is completed
325327
*/
326-
CompletableFuture<EntityTaskResult> runAtEntity(Entity entity, Consumer<WrappedTask> consumer);
328+
CompletableFuture<EntityTaskResult> runAtEntity(Entity entity, @NotNull Consumer<WrappedTask> consumer);
327329

328330
/**
329331
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -333,7 +335,7 @@ public interface ServerImplementation {
333335
* @param consumer Task to run
334336
* @return Future when the task is completed
335337
*/
336-
CompletableFuture<EntityTaskResult> runAtEntityWithFallback(Entity entity, Consumer<WrappedTask> consumer, Runnable fallback);
338+
CompletableFuture<EntityTaskResult> runAtEntityWithFallback(Entity entity, @NotNull Consumer<WrappedTask> consumer, @Nullable Runnable fallback);
337339

338340
/**
339341
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -344,7 +346,19 @@ public interface ServerImplementation {
344346
* @param delay Delay before execution in ticks
345347
* @return WrappedTask instance
346348
*/
347-
WrappedTask runAtEntityLater(Entity entity, Runnable runnable, long delay);
349+
WrappedTask runAtEntityLater(Entity entity, @NotNull Runnable runnable, long delay);
350+
351+
/**
352+
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
353+
* Paper: Synced with the server main thread
354+
* Spigot: Synced with the server main thread
355+
* @param entity Entity to run the task at
356+
* @param runnable Task to run
357+
* @param fallback Fallback task to run when the entity is removed
358+
* @param delay Delay before execution in ticks
359+
* @return WrappedTask instance
360+
*/
361+
WrappedTask runAtEntityLater(Entity entity, @NotNull Runnable runnable, @Nullable Runnable fallback, long delay);
348362

349363
/**
350364
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -354,7 +368,18 @@ public interface ServerImplementation {
354368
* @param consumer Task to run
355369
* @param delay Delay before execution in ticks
356370
*/
357-
void runAtEntityLater(Entity entity, Consumer<WrappedTask> consumer, long delay);
371+
void runAtEntityLater(Entity entity, @NotNull Consumer<WrappedTask> consumer, long delay);
372+
373+
/**
374+
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
375+
* Paper: Synced with the server main thread
376+
* Spigot: Synced with the server main thread
377+
* @param entity Entity to run the task at
378+
* @param consumer Task to run
379+
* @param fallback Fallback task to run when the entity is removed
380+
* @param delay Delay before execution in ticks
381+
*/
382+
void runAtEntityLater(Entity entity, @NotNull Consumer<WrappedTask> consumer, Runnable fallback, long delay);
358383

359384
/**
360385
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -366,7 +391,7 @@ public interface ServerImplementation {
366391
* @param unit Time unit
367392
* @return WrappedTask instance
368393
*/
369-
WrappedTask runAtEntityLater(Entity entity, Runnable runnable, long delay, TimeUnit unit);
394+
WrappedTask runAtEntityLater(Entity entity, @NotNull Runnable runnable, long delay, TimeUnit unit);
370395

371396
/**
372397
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -377,7 +402,19 @@ public interface ServerImplementation {
377402
* @param delay Delay before execution
378403
* @param unit Time unit
379404
*/
380-
void runAtEntityLater(Entity entity, Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
405+
void runAtEntityLater(Entity entity, @NotNull Consumer<WrappedTask> consumer, long delay, TimeUnit unit);
406+
407+
/**
408+
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
409+
* Paper: Synced with the server main thread
410+
* Spigot: Synced with the server main thread
411+
* @param entity Entity to run the task at
412+
* @param runnable Task to run
413+
* @param delay Delay before first execution in ticks
414+
* @param period Delay between executions in ticks
415+
* @return WrappedTask instance
416+
*/
417+
WrappedTask runAtEntityTimer(Entity entity, @NotNull Runnable runnable, long delay, long period);
381418

382419
/**
383420
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -389,7 +426,18 @@ public interface ServerImplementation {
389426
* @param period Delay between executions in ticks
390427
* @return WrappedTask instance
391428
*/
392-
WrappedTask runAtEntityTimer(Entity entity, Runnable runnable, long delay, long period);
429+
WrappedTask runAtEntityTimer(Entity entity, @NotNull Runnable runnable, Runnable fallback, long delay, long period);
430+
431+
/**
432+
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
433+
* Paper: Synced with the server main thread
434+
* Spigot: Synced with the server main thread
435+
* @param entity Entity to run the task at
436+
* @param consumer Task to run
437+
* @param delay Delay before first execution in ticks
438+
* @param period Delay between executions in ticks
439+
*/
440+
void runAtEntityTimer(Entity entity, @NotNull Consumer<WrappedTask> consumer, long delay, long period);
393441

394442
/**
395443
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -400,7 +448,7 @@ public interface ServerImplementation {
400448
* @param delay Delay before first execution in ticks
401449
* @param period Delay between executions in ticks
402450
*/
403-
void runAtEntityTimer(Entity entity, Consumer<WrappedTask> consumer, long delay, long period);
451+
void runAtEntityTimer(Entity entity, @NotNull Consumer<WrappedTask> consumer, Runnable fallback, long delay, long period);
404452

405453
/**
406454
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -413,7 +461,7 @@ public interface ServerImplementation {
413461
* @param unit Time unit
414462
* @return WrappedTask instance
415463
*/
416-
WrappedTask runAtEntityTimer(Entity entity, Runnable runnable, long delay, long period, TimeUnit unit);
464+
WrappedTask runAtEntityTimer(Entity entity, @NotNull Runnable runnable, long delay, long period, TimeUnit unit);
417465

418466
/**
419467
* Folia: Synced with the tick of the region of the entity (even if the entity moves)
@@ -425,7 +473,7 @@ public interface ServerImplementation {
425473
* @param period Delay between executions
426474
* @param unit Time unit
427475
*/
428-
void runAtEntityTimer(Entity entity, Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
476+
void runAtEntityTimer(Entity entity, @NotNull Consumer<WrappedTask> consumer, long delay, long period, TimeUnit unit);
429477

430478
/**
431479
* Cancel a task

0 commit comments

Comments
 (0)