-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: update Minecraft/Velocity versions in examples * improve bukkit scheduler * improve bungee scheduler * rework core scheduler and use it for bungee * implement Sponge scheduler * Revert "build: update Minecraft/Velocity versions in examples" This reverts commit 47496d5. * revert disabling examples (i didnt want to commit that) * fix compilation * fix bugs * Support Fabric Scheduler (#1) * add fabric server scheduler * fix server, update ExampleCommand * del mixin * add FabricClientScheduler * fix later * fix later, update ClientCommands * fix tests * Don't use Throwables * Wrap using the default implementation (#2) * add fabric server scheduler * fix server, update ExampleCommand * del mixin * add FabricClientScheduler * fix later * fix later, update ClientCommands * extend SchedulerExecutorPoolImpl * Revert SchedulerExecutorPoolImpl * Create SchedulerMainThreadBased to simplify implementations * Make fabric implementation more simpler. * Revert unit tests changes. * Revert unit tests changes. * SpongeScheduler code style changes. * Implement important notes from BlackBaroness to the old scheduler. * Rename AbstractMainThreadBasedScheduler. Remove unused scheduler. * Fix runAsynchronous * Fix runAsynchronous * improve comments * improve comments * improve Sponge scheduler * remove empty lines * improve Sponge scheduler * Improve the language of an error * Update litecommands-sponge/src/dev/rollczi/litecommands/sponge/SpongeScheduler.java Co-authored-by: Norbert Dejlich <[email protected]> --------- Co-authored-by: huanmeng_qwq <[email protected]> Co-authored-by: Rollczi <[email protected]>
- Loading branch information
1 parent
5cc1cc8
commit 4020847
Showing
17 changed files
with
330 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,5 +74,4 @@ void testAsyncArgsAndMethod() { | |
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...ommands-core/src/dev/rollczi/litecommands/scheduler/AbstractMainThreadBasedScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package dev.rollczi.litecommands.scheduler; | ||
|
||
import dev.rollczi.litecommands.shared.ThrowingSupplier; | ||
import java.time.Duration; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public abstract class AbstractMainThreadBasedScheduler implements Scheduler { | ||
|
||
@Override | ||
public final <T> CompletableFuture<T> supplyLater(SchedulerPoll type, Duration delay, ThrowingSupplier<T, Throwable> supplier) { | ||
SchedulerPoll resolved = type.resolve(SchedulerPoll.MAIN, SchedulerPoll.ASYNCHRONOUS); | ||
CompletableFuture<T> future = new CompletableFuture<>(); | ||
|
||
if (resolved.equals(SchedulerPoll.MAIN)) { | ||
runSynchronous(() -> tryRun(type, future, supplier), delay); | ||
return future; | ||
} | ||
|
||
if (resolved.equals(SchedulerPoll.ASYNCHRONOUS)) { | ||
runAsynchronous(() -> tryRun(type, future, supplier), delay); | ||
return future; | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown scheduler poll type: " + type); | ||
} | ||
|
||
abstract protected void runSynchronous(Runnable task, Duration delay); | ||
|
||
protected abstract void runAsynchronous(Runnable task, Duration delay); | ||
|
||
private <T> void tryRun(SchedulerPoll type, CompletableFuture<T> future, ThrowingSupplier<T, Throwable> supplier) { | ||
try { | ||
future.complete(supplier.get()); | ||
} | ||
catch (Throwable throwable) { | ||
future.completeExceptionally(throwable); | ||
|
||
if (type.isLogging()) { | ||
this.log(throwable); | ||
} | ||
} | ||
} | ||
|
||
protected void log(Throwable throwable) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ | |
public interface ThrowingRunnable<E extends Throwable> { | ||
|
||
void run() throws E; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.