-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ | |
|
||
TimeUnit unit(); | ||
|
||
String permission() default ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/test/java/dev/velix/imperat/CustomCooldownProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.velix.imperat; | ||
|
||
import dev.velix.imperat.command.CommandUsage; | ||
import dev.velix.imperat.command.cooldown.CooldownHandler; | ||
import dev.velix.imperat.command.processors.CommandPreProcessor; | ||
import dev.velix.imperat.context.Context; | ||
import dev.velix.imperat.context.Source; | ||
import dev.velix.imperat.exception.CooldownException; | ||
import dev.velix.imperat.exception.ImperatException; | ||
|
||
public final class CustomCooldownProcessor<S extends Source> implements CommandPreProcessor<S> { | ||
/** | ||
* Processes context BEFORE the resolving operation. | ||
* | ||
* @param imperat the api | ||
* @param context the context | ||
* @param usage The usage detected | ||
* @throws ImperatException the exception to throw if something happens | ||
*/ | ||
@Override | ||
public void process(Imperat<S> imperat, Context<S> context, CommandUsage<S> usage) throws ImperatException { | ||
CooldownHandler<S> cooldownHandler = usage.getCooldownHandler(); | ||
S source = context.source(); | ||
|
||
if (cooldownHandler.hasCooldown(source) && !imperat.getPermissionResolver().hasPermission(source, "yourpermission")) { | ||
//if there's a cooldown and the source doesn't have a specific permission, let's send him the cooldown message through the exception below | ||
throw new CooldownException( | ||
cooldownHandler.getUsageCooldown().orElseThrow().toMillis(), | ||
cooldownHandler.getLastTimeExecuted(source).orElse(0L) | ||
); | ||
} | ||
|
||
} | ||
} |