-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathCooldownInterceptor.java
More file actions
29 lines (25 loc) · 1.23 KB
/
CooldownInterceptor.java
File metadata and controls
29 lines (25 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package fr.openmc.api.cooldown;
import fr.openmc.core.utils.text.DateUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import revxrsal.commands.bukkit.actor.BukkitCommandActor;
import revxrsal.commands.node.ExecutionContext;
import revxrsal.commands.process.CommandCondition;
public class CooldownInterceptor implements CommandCondition<BukkitCommandActor> {
@Override
public void test(@NotNull ExecutionContext<BukkitCommandActor> context) {
DynamicCooldown cooldown = context.command().annotations().get(DynamicCooldown.class);
if (cooldown == null) {
return;
}
Player player = context.actor().requirePlayer();
if (!DynamicCooldownManager.isReady(player.getUniqueId(), cooldown.group())) {
long remaining = DynamicCooldownManager.getRemaining(player.getUniqueId(), cooldown.group());
String message = cooldown.message();
message = message.replace("%formatTime%", DateUtils.convertSecondToTime(remaining / 1000));
message = message.replace("%sec%", String.valueOf(remaining / 1000));
message = message.replace("%ms%", String.valueOf(remaining));
player.sendMessage(message);
}
}
}