diff --git a/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/SelectMenu.java b/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/SelectMenu.java index ed47c399..6e992b30 100644 --- a/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/SelectMenu.java +++ b/api/src/main/java/com/discordsrv/api/discord/entity/interaction/component/impl/SelectMenu.java @@ -28,9 +28,9 @@ import com.discordsrv.api.discord.entity.interaction.component.ComponentIdentifi import com.discordsrv.api.discord.entity.interaction.component.MessageComponent; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.ItemComponent; +import org.jetbrains.annotations.CheckReturnValue; import org.jetbrains.annotations.NotNull; -import javax.annotation.CheckReturnValue; import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/bukkit/folia/src/main/java/com/discordsrv/bukkit/scheduler/IBukkitScheduler.java b/bukkit/folia/src/main/java/com/discordsrv/bukkit/scheduler/IBukkitScheduler.java index 082f09f4..6e33d07a 100644 --- a/bukkit/folia/src/main/java/com/discordsrv/bukkit/scheduler/IBukkitScheduler.java +++ b/bukkit/folia/src/main/java/com/discordsrv/bukkit/scheduler/IBukkitScheduler.java @@ -24,6 +24,7 @@ import com.discordsrv.common.scheduler.ServerScheduler; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.CheckReturnValue; import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; @@ -36,10 +37,12 @@ public interface IBukkitScheduler extends ServerScheduler { runOnMainThread(task); } + @CheckReturnValue default CompletableFuture executeOnMainThread(CommandSender sender, Runnable runnable) { return CompletableFuture.runAsync(runnable, task -> runOnMainThread(sender, task)); } + @CheckReturnValue default CompletableFuture supplyOnMainThread(CommandSender sender, CheckedSupplier supplier) { return CompletableFutureUtil.supplyAsync(supplier, task -> runOnMainThread(sender, task)); } diff --git a/common/src/main/java/com/discordsrv/common/scheduler/Scheduler.java b/common/src/main/java/com/discordsrv/common/scheduler/Scheduler.java index e7f4b8e4..320784dc 100644 --- a/common/src/main/java/com/discordsrv/common/scheduler/Scheduler.java +++ b/common/src/main/java/com/discordsrv/common/scheduler/Scheduler.java @@ -21,10 +21,12 @@ package com.discordsrv.common.scheduler; import com.discordsrv.common.function.CheckedRunnable; import com.discordsrv.common.function.CheckedSupplier; import com.discordsrv.common.future.util.CompletableFutureUtil; +import org.jetbrains.annotations.CheckReturnValue; import org.jetbrains.annotations.NotNull; import java.time.Duration; import java.util.concurrent.*; +import java.util.function.Supplier; @SuppressWarnings({"UnusedReturnValue", "unused"}) // API public interface Scheduler { @@ -38,24 +40,28 @@ public interface Scheduler { * An executor that will actually catch exceptions. * @return the {@link Executor} */ + @CheckReturnValue Executor executor(); /** * Returns the {@link ExecutorService} being used. * @return the {@link ExecutorService} */ + @CheckReturnValue ExecutorService executorService(); /** * Returns the {@link ScheduledExecutorService} being used. * @return the {@link ScheduledExecutorService} */ + @CheckReturnValue ScheduledExecutorService scheduledExecutorService(); /** * Returns the {@link ForkJoinPool} being used. * @return the {@link ForkJoinPool} */ + @CheckReturnValue ForkJoinPool forkJoinPool(); /** @@ -66,12 +72,26 @@ public interface Scheduler { @NotNull Future run(@NotNull Runnable task); + /** + * Helper method for {@link CompletableFuture#runAsync(Runnable)}. + * + * @param task the task to execute + * @return a future + */ @NotNull + @CheckReturnValue default CompletableFuture execute(@NotNull CheckedRunnable task) { return CompletableFutureUtil.runAsync(task, this::run); } + /** + * Helper method for {@link CompletableFuture#supplyAsync(Supplier)}. + * + * @param supplier the supplier + * @return a future + */ @NotNull + @CheckReturnValue default CompletableFuture supply(@NotNull CheckedSupplier supplier) { return CompletableFutureUtil.supplyAsync(supplier, this::run); } @@ -85,12 +105,28 @@ public interface Scheduler { @NotNull ScheduledFuture runLater(@NotNull Runnable task, @NotNull Duration delay); + /** + * Helper method for {@link CompletableFuture#runAsync(Runnable)} with delay. + * + * @param task the task to execute + * @param delay the delay before executing the task + * @return a future + */ @NotNull + @CheckReturnValue default CompletableFuture executeLater(@NotNull CheckedRunnable task, @NotNull Duration delay) { return CompletableFutureUtil.runAsync(task, t -> runLater(t, delay)); } + /** + * Helper method for {@link CompletableFuture#supplyAsync(Supplier)} with delay. + * + * @param supplier the supplier + * @param delay the delay before executing the task + * @return a future + */ @NotNull + @CheckReturnValue default CompletableFuture supplyLater(@NotNull CheckedSupplier supplier, @NotNull Duration delay) { return CompletableFutureUtil.supplyAsync(supplier, task -> runLater(task, delay)); } diff --git a/settings.gradle b/settings.gradle index b29b884f..660f17b3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -50,7 +50,7 @@ dependencyResolutionManagement { library('mcdependencydownload-velocity', 'dev.vankka', 'minecraftdependencydownload-velocity').versionRef('mcdependencydownload') // Annotations - library('jetbrains-annotations', 'org.jetbrains', 'annotations').version('24.0.1') + library('jetbrains-annotations', 'org.jetbrains', 'annotations').version('24.1.0') library('findbugs-annotations', 'com.google.code.findbugs', 'jsr305').version('3.0.2') // JDA