|
10 | 10 | import org.jetbrains.annotations.Nullable; |
11 | 11 |
|
12 | 12 | import java.util.Map; |
13 | | -import java.util.concurrent.CompletableFuture; |
14 | 13 | import java.util.concurrent.ConcurrentHashMap; |
15 | 14 | import java.util.concurrent.Future; |
16 | 15 | import java.util.concurrent.TimeUnit; |
@@ -239,185 +238,136 @@ public void runTask(@NotNull SchedulerType schedulerType, Entity entity, Schedul |
239 | 238 |
|
240 | 239 | @Override |
241 | 240 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack) { |
242 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
243 | 241 | try { |
244 | 242 | 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); |
249 | 244 | } else { |
250 | 245 | Bukkit.getGlobalRegionScheduler().execute(this.plugin, () -> { |
251 | | - completableFuture.complete(0); |
252 | 246 | callBack.run(null); |
253 | 247 | }); |
254 | 248 | } |
| 249 | + return 0; |
255 | 250 | } catch (Exception ignored) { |
256 | | - completableFuture.complete(-1); |
| 251 | + return -1; |
257 | 252 | } |
258 | | - return completableFuture.join(); |
259 | 253 | } |
260 | 254 |
|
261 | 255 | @Override |
262 | 256 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, MultipleRecords.WorldChunk worldChunk, SchedulerCallBack callBack) { |
263 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
264 | 257 | try { |
265 | 258 | 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); |
270 | 260 | } else { |
271 | 261 | Bukkit.getRegionScheduler().execute(this.plugin, worldChunk.world(), worldChunk.chunkX(), worldChunk.chunkZ(), () -> { |
272 | | - completableFuture.complete(0); |
273 | 262 | callBack.run(null); |
274 | 263 | }); |
275 | 264 | } |
| 265 | + return 0; |
276 | 266 | } catch (Exception ignored) { |
277 | | - completableFuture.complete(-1); |
| 267 | + return -1; |
278 | 268 | } |
279 | | - return completableFuture.join(); |
280 | 269 | } |
281 | 270 |
|
282 | 271 | @Override |
283 | 272 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, Location location, SchedulerCallBack callBack) { |
284 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
285 | 273 | try { |
286 | 274 | 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); |
291 | 276 | } else { |
292 | 277 | Bukkit.getRegionScheduler().execute(this.plugin, location, () -> { |
293 | | - completableFuture.complete(0); |
294 | 278 | callBack.run(null); |
295 | 279 | }); |
296 | 280 | } |
| 281 | + return 0; |
297 | 282 | } catch (Exception ignored) { |
298 | | - completableFuture.complete(-1); |
| 283 | + return -1; |
299 | 284 | } |
300 | | - return completableFuture.join(); |
301 | 285 | } |
302 | 286 |
|
303 | 287 | @Override |
304 | 288 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack, long delay) { |
305 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
306 | 289 | 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; |
311 | 292 | } catch (Exception ignored) { |
312 | | - completableFuture.complete(-1); |
| 293 | + return -1; |
313 | 294 | } |
314 | | - return completableFuture.join(); |
315 | 295 | } |
316 | 296 |
|
317 | 297 | @Override |
318 | 298 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, MultipleRecords.WorldChunk worldChunk, SchedulerCallBack callBack, long delay) { |
319 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
320 | 299 | 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; |
325 | 302 | } catch (Exception ignored) { |
326 | | - completableFuture.complete(-1); |
| 303 | + return -1; |
327 | 304 | } |
328 | | - return completableFuture.join(); |
329 | 305 | } |
330 | 306 |
|
331 | 307 | @Override |
332 | 308 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, Location location, SchedulerCallBack callBack, long delay) { |
333 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
334 | 309 | 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; |
339 | 312 | } catch (Exception ignored) { |
340 | | - completableFuture.complete(-1); |
| 313 | + return -1; |
341 | 314 | } |
342 | | - return completableFuture.join(); |
343 | | - |
344 | 315 | } |
345 | 316 |
|
346 | 317 | @Override |
347 | 318 | public int scheduleSyncDelayed(@NotNull SchedulerType schedulerType, Entity entity, SchedulerCallBack callBack, @Nullable Runnable retired, long delay) { |
348 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
349 | 319 | try { |
350 | 320 | 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); |
355 | 322 | } else { |
356 | 323 | entity.getScheduler().execute(this.plugin, () -> { |
357 | | - completableFuture.complete(0); |
358 | 324 | callBack.run(null); |
359 | 325 | }, retired, delay); |
360 | 326 | } |
| 327 | + return 0; |
361 | 328 | } catch (Exception ignored) { |
362 | | - completableFuture.complete(-1); |
| 329 | + return -1; |
363 | 330 | } |
364 | | - return completableFuture.join(); |
365 | 331 | } |
366 | 332 |
|
367 | 333 | @Override |
368 | 334 | public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, SchedulerCallBack callBack, long delay, long period) { |
369 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
370 | 335 | 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; |
375 | 338 | } catch (Exception ignored) { |
376 | | - completableFuture.complete(-1); |
| 339 | + return -1; |
377 | 340 | } |
378 | | - return completableFuture.join(); |
379 | 341 | } |
380 | 342 |
|
381 | 343 | @Override |
382 | 344 | public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, MultipleRecords.WorldChunk worldChunk, SchedulerCallBack callBack, long delay, long period) { |
383 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
384 | 345 | 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; |
389 | 348 | } catch (Exception ignored) { |
390 | | - completableFuture.complete(-1); |
| 349 | + return -1; |
391 | 350 | } |
392 | | - return completableFuture.join(); |
393 | 351 | } |
394 | 352 |
|
395 | 353 | @Override |
396 | 354 | public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, Location location, SchedulerCallBack callBack, long delay, long period) { |
397 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
398 | 355 | 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; |
403 | 358 | } catch (Exception ignored) { |
404 | | - completableFuture.complete(-1); |
| 359 | + return -1; |
405 | 360 | } |
406 | | - return completableFuture.join(); |
407 | 361 | } |
408 | 362 |
|
409 | 363 | @Override |
410 | 364 | public int scheduleSyncRepeating(@NotNull SchedulerType schedulerType, Entity entity, SchedulerCallBack callBack, @Nullable Runnable retired, long delay, long period) { |
411 | | - CompletableFuture<Integer> completableFuture = new CompletableFuture<>(); |
412 | 365 | 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; |
417 | 368 | } catch (Exception ignored) { |
418 | | - completableFuture.complete(-1); |
| 369 | + return -1; |
419 | 370 | } |
420 | | - return completableFuture.join(); |
421 | 371 | } |
422 | 372 |
|
423 | 373 | @Override @Deprecated |
|
0 commit comments