diff --git a/common/src/main/java/com/discordsrv/common/future/util/CompletableFutureUtil.java b/common/src/main/java/com/discordsrv/common/future/util/CompletableFutureUtil.java index ea7d8a15..4e94096d 100644 --- a/common/src/main/java/com/discordsrv/common/future/util/CompletableFutureUtil.java +++ b/common/src/main/java/com/discordsrv/common/future/util/CompletableFutureUtil.java @@ -21,6 +21,7 @@ package com.discordsrv.common.future.util; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.function.CheckedRunnable; import com.discordsrv.common.function.CheckedSupplier; +import org.jetbrains.annotations.NotNull; import java.time.Duration; import java.util.ArrayList; @@ -38,24 +39,28 @@ public final class CompletableFutureUtil { /** * Same as {@link CompletableFuture#completedFuture(Object)} but for failing. */ - public static CompletableFuture failed(Throwable throwable) { + @NotNull + public static CompletableFuture failed(@NotNull Throwable throwable) { CompletableFuture future = new CompletableFuture<>(); future.completeExceptionally(throwable); return future; } @SuppressWarnings("unchecked") - public static CompletableFuture> combine(Collection> futures) { + @NotNull + public static CompletableFuture> combine(@NotNull Collection<@NotNull CompletableFuture> futures) { return combine(futures.toArray(new CompletableFuture[0])); } @SuppressWarnings("unchecked") - public static CompletableFuture> combineGeneric(Collection> futures) { + @NotNull + public static CompletableFuture> combineGeneric(@NotNull Collection<@NotNull CompletableFuture> futures) { return combine(futures.toArray(new CompletableFuture[0])); } @SafeVarargs - public static CompletableFuture> combine(CompletableFuture... futures) { + @NotNull + public static CompletableFuture> combine(@NotNull CompletableFuture<@NotNull T>... futures) { return CompletableFuture.allOf(futures).thenApply(v -> { List results = new ArrayList<>(); for (CompletableFuture aFuture : futures) { @@ -65,7 +70,8 @@ public final class CompletableFutureUtil { }); } - public static CompletableFuture timeout(DiscordSRV discordSRV, CompletableFuture future, Duration timeout) { + @NotNull + public static CompletableFuture timeout(@NotNull DiscordSRV discordSRV, @NotNull CompletableFuture future, @NotNull Duration timeout) { ScheduledFuture scheduledFuture = discordSRV.scheduler().runLater(() -> { if (!future.isDone()) { future.completeExceptionally(new TimeoutException()); @@ -78,7 +84,8 @@ public final class CompletableFutureUtil { }); } - public static CompletableFuture supplyAsync(CheckedSupplier supplier, Executor executor) { + @NotNull + public static CompletableFuture supplyAsync(@NotNull CheckedSupplier supplier, @NotNull Executor executor) { CompletableFuture future = new CompletableFuture<>(); executor.execute(() -> { if (future.isCancelled()) { @@ -95,7 +102,8 @@ public final class CompletableFutureUtil { return future; } - public static CompletableFuture runAsync(CheckedRunnable runnable, Executor executor) { + @NotNull + public static CompletableFuture runAsync(@NotNull CheckedRunnable runnable, @NotNull Executor executor) { return supplyAsync(() -> { runnable.run(); return null; diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java index 2a878c52..9f0cc4ac 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java @@ -100,7 +100,10 @@ public abstract class AbstractGameMessageModule> futures = new ArrayList<>(); for (BaseChannelConfig channelConfig : discordSRV.channelConfig().getAllChannels()) { - futures.add(forwardToChannel(event, srvPlayer, channelConfig)); + CompletableFuture future = forwardToChannel(event, srvPlayer, channelConfig); + if (future != null) { + futures.add(future); + } } return CompletableFutureUtil.combine(futures); }