diff --git a/common/src/main/java/revxrsal/commands/Lamp.java b/common/src/main/java/revxrsal/commands/Lamp.java index 689d0b1b..920b6b1c 100644 --- a/common/src/main/java/revxrsal/commands/Lamp.java +++ b/common/src/main/java/revxrsal/commands/Lamp.java @@ -612,8 +612,9 @@ public Builder() { responseHandler(CompletionStageResponseHandler.INSTANCE); responseHandler(OptionalResponseHandler.INSTANCE); commandCondition(PermissionConditionChecker.INSTANCE); - commandCondition(CooldownCondition.INSTANCE); - hooks().onPostCommandExecuted(CooldownCondition.INSTANCE); + ThreadExecutorCooldownCondition cooldownCondition = new ThreadExecutorCooldownCondition(); + commandCondition(cooldownCondition); + hooks().onPostCommandExecuted(cooldownCondition); accept(KotlinFeatureRegistry.INSTANCE); } diff --git a/common/src/main/java/revxrsal/commands/command/CooldownCondition.java b/common/src/main/java/revxrsal/commands/command/ThreadExecutorCooldownCondition.java similarity index 83% rename from common/src/main/java/revxrsal/commands/command/CooldownCondition.java rename to common/src/main/java/revxrsal/commands/command/ThreadExecutorCooldownCondition.java index 25b49a03..71b4086f 100644 --- a/common/src/main/java/revxrsal/commands/command/CooldownCondition.java +++ b/common/src/main/java/revxrsal/commands/command/ThreadExecutorCooldownCondition.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import revxrsal.commands.annotation.Cooldown; import revxrsal.commands.exception.CooldownException; import revxrsal.commands.hook.PostCommandExecutedHook; @@ -38,11 +39,10 @@ import java.util.concurrent.ScheduledExecutorService; @ApiStatus.Internal -public enum CooldownCondition implements CommandCondition, PostCommandExecutedHook { - - INSTANCE; +public final class ThreadExecutorCooldownCondition implements CommandCondition, PostCommandExecutedHook { private static final ScheduledExecutorService COOLDOWN_POOL = Executors.newSingleThreadScheduledExecutor(); + private final Map> cooldowns = new ConcurrentHashMap<>(); @Override @@ -55,12 +55,16 @@ public void onPostExecuted(@NotNull ExecutableCommand command, @No } @Override public void test(@NotNull ExecutionContext context) { - Cooldown cooldown = context.command().annotations().get(Cooldown.class); - if (cooldown == null || cooldown.value() == 0) return; + @Nullable Cooldown cooldown = context.command().annotations().get(Cooldown.class); + if (cooldown == null || cooldown.value() == 0) + return; UUID uuid = context.actor().uniqueId(); - Map spans = cooldowns.get(uuid); - if (spans == null) return; - long created = spans.get(context.command().hashCode()); + @Nullable Map spans = cooldowns.get(uuid); + if (spans == null) + return; + @Nullable Long created = spans.get(context.command().hashCode()); + if (created == null) + return; long passed = System.currentTimeMillis() - created; long left = cooldown.unit().toMillis(cooldown.value()) - passed; if (left > 0 && left < 1000)