diff --git a/base/main/src/main/java/cc/carm/lib/easyplugin/EasyPlugin.java b/base/main/src/main/java/cc/carm/lib/easyplugin/EasyPlugin.java index 3e48999..7b2558e 100644 --- a/base/main/src/main/java/cc/carm/lib/easyplugin/EasyPlugin.java +++ b/base/main/src/main/java/cc/carm/lib/easyplugin/EasyPlugin.java @@ -145,6 +145,13 @@ public abstract class EasyPlugin extends JavaPlugin { if (isDebugging()) print("&8[DEBUG] &r", messages); } + /** + * 在主线程唤起一个事件,并支持获取事件的结果。 + * + * @param event 同步事件 (isAsync=false) + * @param 事件类型 + * @return CompletableFuture + */ public @NotNull CompletableFuture callSync(T event) { CompletableFuture future = new CompletableFuture<>(); getScheduler().run(() -> { @@ -154,11 +161,24 @@ public abstract class EasyPlugin extends JavaPlugin { return future; } + /** + * 在异步线程中唤起一个事件,并支持获取事件的结果。 + * + * @param event 异步事件 (isAsync=true) + * @param 事件类型 + * @return CompletableFuture + */ public @NotNull CompletableFuture callAsync(T event) { - return CompletableFuture.supplyAsync(() -> { + CompletableFuture future = new CompletableFuture<>(); + getScheduler().runAsync(() -> { Bukkit.getPluginManager().callEvent(event); - return event; + future.complete(event); }); + return future; + } + + protected void setMessageProvider(@NotNull EasyPluginMessageProvider provider) { + this.messageProvider = provider; } @SuppressWarnings("BooleanMethodIsAlwaysInverted")