Skip to content
This repository was archived by the owner on May 26, 2024. It is now read-only.

Commit 2209d6f

Browse files
committed
Fix folia scheduleSyncDelayed
1 parent 9c34756 commit 2209d6f

File tree

2 files changed

+35
-84
lines changed

2 files changed

+35
-84
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/fr/euphyllia/energie/folia/FoliaScheduler.java

Lines changed: 33 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.jetbrains.annotations.Nullable;
1111

1212
import java.util.Map;
13-
import java.util.concurrent.CompletableFuture;
1413
import java.util.concurrent.ConcurrentHashMap;
1514
import java.util.concurrent.Future;
1615
import java.util.concurrent.TimeUnit;
@@ -239,185 +238,136 @@ public void runTask(@NotNull SchedulerType schedulerType, Entity entity, Schedul
239238

240239
@Override
241240
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack) {
242-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
243241
try {
244242
if (schedulerType.equals(SchedulerType.ASYNC)) {
245-
this.runTask(schedulerType, schedulerTask -> {
246-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
247-
callBack.run(schedulerTask);
248-
});
243+
this.runTask(schedulerType, callBack);
249244
} else {
250245
Bukkit.getGlobalRegionScheduler().execute(this.plugin, () -> {
251-
completableFuture.complete(0);
252246
callBack.run(null);
253247
});
254248
}
249+
return 0;
255250
} catch (Exception ignored) {
256-
completableFuture.complete(-1);
251+
return -1;
257252
}
258-
return completableFuture.join();
259253
}
260254

261255
@Override
262256
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, MultipleRecords.WorldChunk worldChunk, SchedulerCallBack callBack) {
263-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
264257
try {
265258
if (schedulerType.equals(SchedulerType.ASYNC)) {
266-
this.runTask(schedulerType, worldChunk, schedulerTask -> {
267-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
268-
callBack.run(schedulerTask);
269-
});
259+
this.runTask(schedulerType, worldChunk, callBack::run);
270260
} else {
271261
Bukkit.getRegionScheduler().execute(this.plugin, worldChunk.world(), worldChunk.chunkX(), worldChunk.chunkZ(), () -> {
272-
completableFuture.complete(0);
273262
callBack.run(null);
274263
});
275264
}
265+
return 0;
276266
} catch (Exception ignored) {
277-
completableFuture.complete(-1);
267+
return -1;
278268
}
279-
return completableFuture.join();
280269
}
281270

282271
@Override
283272
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, Location location, SchedulerCallBack callBack) {
284-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
285273
try {
286274
if (schedulerType.equals(SchedulerType.ASYNC)) {
287-
this.runTask(schedulerType, location, schedulerTask -> {
288-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
289-
callBack.run(schedulerTask);
290-
});
275+
this.runTask(schedulerType, location, callBack);
291276
} else {
292277
Bukkit.getRegionScheduler().execute(this.plugin, location, () -> {
293-
completableFuture.complete(0);
294278
callBack.run(null);
295279
});
296280
}
281+
return 0;
297282
} catch (Exception ignored) {
298-
completableFuture.complete(-1);
283+
return -1;
299284
}
300-
return completableFuture.join();
301285
}
302286

303287
@Override
304288
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack, long delay) {
305-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
306289
try {
307-
this.runDelayed(schedulerType, schedulerTask -> {
308-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
309-
callBack.run(schedulerTask);
310-
}, delay);
290+
this.runDelayed(schedulerType, callBack, delay);
291+
return 0;
311292
} catch (Exception ignored) {
312-
completableFuture.complete(-1);
293+
return -1;
313294
}
314-
return completableFuture.join();
315295
}
316296

317297
@Override
318298
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, MultipleRecords.WorldChunk worldChunk, SchedulerCallBack callBack, long delay) {
319-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
320299
try {
321-
this.runDelayed(schedulerType, worldChunk, schedulerTask -> {
322-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
323-
callBack.run(schedulerTask);
324-
}, delay);
300+
this.runDelayed(schedulerType, worldChunk, callBack, delay);
301+
return 0;
325302
} catch (Exception ignored) {
326-
completableFuture.complete(-1);
303+
return -1;
327304
}
328-
return completableFuture.join();
329305
}
330306

331307
@Override
332308
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, Location location, SchedulerCallBack callBack, long delay) {
333-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
334309
try {
335-
this.runDelayed(schedulerType, location, schedulerTask -> {
336-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
337-
callBack.run(schedulerTask);
338-
}, delay);
310+
this.runDelayed(schedulerType, location, callBack, delay);
311+
return 0;
339312
} catch (Exception ignored) {
340-
completableFuture.complete(-1);
313+
return -1;
341314
}
342-
return completableFuture.join();
343-
344315
}
345316

346317
@Override
347318
public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, Entity entity, SchedulerCallBack callBack, @Nullable Runnable retired, long delay) {
348-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
349319
try {
350320
if (schedulerType.equals(SchedulerType.ASYNC)) {
351-
this.runDelayed(schedulerType, entity, schedulerTask -> {
352-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
353-
callBack.run(schedulerTask);
354-
}, retired, delay);
321+
this.runDelayed(schedulerType, entity, callBack, retired, delay);
355322
} else {
356323
entity.getScheduler().execute(this.plugin, () -> {
357-
completableFuture.complete(0);
358324
callBack.run(null);
359325
}, retired, delay);
360326
}
327+
return 0;
361328
} catch (Exception ignored) {
362-
completableFuture.complete(-1);
329+
return -1;
363330
}
364-
return completableFuture.join();
365331
}
366332

367333
@Override
368334
public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack, long delay, long period) {
369-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
370335
try {
371-
this.runAtFixedRate(schedulerType, schedulerTask -> {
372-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
373-
callBack.run(schedulerTask);
374-
}, delay, period);
336+
this.runAtFixedRate(schedulerType, callBack, delay, period);
337+
return 0;
375338
} catch (Exception ignored) {
376-
completableFuture.complete(-1);
339+
return -1;
377340
}
378-
return completableFuture.join();
379341
}
380342

381343
@Override
382344
public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, MultipleRecords.WorldChunk worldChunk, SchedulerCallBack callBack, long delay, long period) {
383-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
384345
try {
385-
this.runAtFixedRate(schedulerType, worldChunk, schedulerTask -> {
386-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
387-
callBack.run(schedulerTask);
388-
}, delay, period);
346+
this.runAtFixedRate(schedulerType, worldChunk, callBack, delay, period);
347+
return 0;
389348
} catch (Exception ignored) {
390-
completableFuture.complete(-1);
349+
return -1;
391350
}
392-
return completableFuture.join();
393351
}
394352

395353
@Override
396354
public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, Location location, SchedulerCallBack callBack, long delay, long period) {
397-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
398355
try {
399-
this.runAtFixedRate(schedulerType, location, schedulerTask -> {
400-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
401-
callBack.run(schedulerTask);
402-
}, delay, period);
356+
this.runAtFixedRate(schedulerType, location, callBack, delay, period);
357+
return 0;
403358
} catch (Exception ignored) {
404-
completableFuture.complete(-1);
359+
return -1;
405360
}
406-
return completableFuture.join();
407361
}
408362

409363
@Override
410364
public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, Entity entity, SchedulerCallBack callBack, @Nullable Runnable retired, long delay, long period) {
411-
CompletableFuture<Integer> completableFuture = new CompletableFuture<>();
412365
try {
413-
this.runAtFixedRate(schedulerType, entity, schedulerTask -> {
414-
completableFuture.complete(schedulerTask != null ? schedulerTask.getTaskId() : 0);
415-
callBack.run(schedulerTask);
416-
}, retired, delay, period);
366+
this.runAtFixedRate(schedulerType, entity, callBack, retired, delay, period);
367+
return 0;
417368
} catch (Exception ignored) {
418-
completableFuture.complete(-1);
369+
return -1;
419370
}
420-
return completableFuture.join();
421371
}
422372

423373
@Override @Deprecated

0 commit comments

Comments
 (0)