Skip to content

Commit

Permalink
make it possible to override the fallback group
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Jan 5, 2024
1 parent 1998e8c commit 46dc689
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
public interface Cooldown<C> extends Command.Builder.Applicable<C> {

/**
* Returns a new cooldown with the given {@code duration} using {@link CooldownGroup#command(Command)} as the group.
* Returns a new cooldown with the given {@code duration}
* using {@link CooldownConfiguration#fallbackGroup()} as the group.
*
* @param <C> command sender type
* @param duration the duration
Expand Down Expand Up @@ -86,7 +87,7 @@ public interface Cooldown<C> extends Command.Builder.Applicable<C> {

/**
* Returns the group that this instance belongs to.
* If set to {@code null} then {@link CooldownGroup#command(Command)} will be used.
* If set to {@code null} then {@link CooldownConfiguration#fallbackGroup()} will be used.
*
* @return the cooldown group
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
//
package org.incendo.cloud.processors.cooldown;

import cloud.commandframework.Command;
import cloud.commandframework.context.CommandContext;
import java.time.Clock;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down Expand Up @@ -106,4 +108,14 @@ public interface CooldownConfiguration<C> {
default @NonNull CooldownProfileFactory profileFactory() {
return new StandardCooldownProfileFactory(this);
}

/**
* Returns the function that determines the fallback {@link CooldownGroup} in case no group has been provided
* to the {@link Cooldown}.
*
* @return the fallback group function
*/
default @NonNull Function<@NonNull Command<C>, @NonNull CooldownGroup> fallbackGroup() {
return CooldownGroup::command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void accept(final @NonNull CommandPostprocessingContext<C> context) {
if (cooldown.group() != null) {
group = Objects.requireNonNull(cooldown.group(), "group");
} else {
group = CooldownGroup.command(context.command());
group = this.cooldownManager.configuration().fallbackGroup().apply(context.command());
}

final CooldownInstance cooldownInstance = profile.getCooldown(group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
//
package org.incendo.cloud.processors.cooldown.annotations;

import cloud.commandframework.Command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.time.temporal.ChronoUnit;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.processors.cooldown.CooldownConfiguration;

/**
* Adds a cooldown to the command.
Expand Down Expand Up @@ -59,7 +59,7 @@
/**
* Returns the cooldown group.
*
* <p>If this is empty then {@link org.incendo.cloud.processors.cooldown.CooldownGroup#command(Command)} will be used.</p>
* <p>If this is empty then {@link CooldownConfiguration#fallbackGroup()} will be used.</p>
*
* @return the cooldown group
*/
Expand Down

0 comments on commit 46dc689

Please sign in to comment.