Search in sources :

Example 1 with CommandCooldownException

use of gg.projecteden.nexus.framework.exceptions.postconfigured.CommandCooldownException in project Nexus by ProjectEdenGG.

the class ICustomCommand method checkCooldown.

private void checkCooldown(CustomCommand command, Cooldown cooldown, String commandId) {
    if (cooldown != null) {
        boolean bypass = false;
        if (!(command.getEvent().getSender() instanceof Player))
            bypass = true;
        else if (cooldown.bypass().length() > 0 && command.getEvent().getPlayer().hasPermission(cooldown.bypass()))
            bypass = true;
        if (!bypass) {
            int ticks = cooldown.value().x(cooldown.x());
            CooldownService service = new CooldownService();
            UUID uuid = cooldown.global() ? UUID0 : ((Player) command.getEvent().getSender()).getUniqueId();
            String type = "command:" + commandId;
            if (!service.check(uuid, type, ticks))
                throw new CommandCooldownException(uuid, type);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CommandCooldownException(gg.projecteden.nexus.framework.exceptions.postconfigured.CommandCooldownException) CooldownService(gg.projecteden.nexus.models.cooldown.CooldownService) PathParser.getPathString(gg.projecteden.nexus.framework.commands.models.PathParser.getPathString) UUID(java.util.UUID)

Example 2 with CommandCooldownException

use of gg.projecteden.nexus.framework.exceptions.postconfigured.CommandCooldownException in project Nexus by ProjectEdenGG.

the class DailyRewardsCommand method reset.

@Confirm
@Path("reset [player]")
void reset(@Arg(value = "self", permission = Group.ADMIN) DailyRewardUser user) {
    try {
        if (!new CooldownService().check(player(), resetCooldownType, TickTime.DAY))
            throw new CommandCooldownException(player(), resetCooldownType);
        user.endStreak();
        service.save(user);
        send(player(), PREFIX + "Your streak has been cleared");
        player().closeInventory();
    } catch (CommandCooldownException ex) {
        send(player(), ex.getMessage());
    }
}
Also used : CommandCooldownException(gg.projecteden.nexus.framework.exceptions.postconfigured.CommandCooldownException) CooldownService(gg.projecteden.nexus.models.cooldown.CooldownService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Confirm(gg.projecteden.nexus.framework.commands.models.annotations.Confirm)

Aggregations

CommandCooldownException (gg.projecteden.nexus.framework.exceptions.postconfigured.CommandCooldownException)2 CooldownService (gg.projecteden.nexus.models.cooldown.CooldownService)2 PathParser.getPathString (gg.projecteden.nexus.framework.commands.models.PathParser.getPathString)1 Confirm (gg.projecteden.nexus.framework.commands.models.annotations.Confirm)1 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)1 UUID (java.util.UUID)1 Player (org.bukkit.entity.Player)1