Search in sources :

Example 1 with ManaAbilityRefreshEvent

use of com.archyx.aureliumskills.api.event.ManaAbilityRefreshEvent in project AureliumSkills by Archy-X.

the class ManaAbilityManager method startTimer.

private void startTimer() {
    new BukkitRunnable() {

        @Override
        public void run() {
            for (UUID id : cooldowns.keySet()) {
                Map<MAbility, Integer> abilityCooldowns = cooldowns.get(id);
                if (abilityCooldowns != null) {
                    for (MAbility ab : abilityCooldowns.keySet()) {
                        int cooldown = abilityCooldowns.get(ab);
                        if (cooldown >= 2) {
                            abilityCooldowns.put(ab, cooldown - 2);
                        } else if (cooldown == 1) {
                            abilityCooldowns.put(ab, 0);
                        }
                        if (cooldown == 2 || cooldown == 1) {
                            PlayerData playerData = plugin.getPlayerManager().getPlayerData(id);
                            if (playerData != null) {
                                ManaAbilityRefreshEvent event = new ManaAbilityRefreshEvent(playerData.getPlayer(), ab);
                                Bukkit.getPluginManager().callEvent(event);
                            }
                        }
                    }
                } else {
                    cooldowns.put(id, new HashMap<>());
                }
            }
        }
    }.runTaskTimer(plugin, 0L, 2L);
    new BukkitRunnable() {

        @Override
        public void run() {
            for (UUID id : errorTimer.keySet()) {
                Map<MAbility, Integer> errorTimers = errorTimer.get(id);
                if (errorTimers != null) {
                    for (MAbility ab : errorTimers.keySet()) {
                        int timer = errorTimers.get(ab);
                        if (timer > 0) {
                            errorTimers.put(ab, timer - 1);
                        }
                    }
                } else {
                    errorTimer.put(id, new HashMap<>());
                }
            }
        }
    }.runTaskTimer(plugin, 0L, 20L);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerData(com.archyx.aureliumskills.data.PlayerData) ManaAbilityRefreshEvent(com.archyx.aureliumskills.api.event.ManaAbilityRefreshEvent)

Aggregations

ManaAbilityRefreshEvent (com.archyx.aureliumskills.api.event.ManaAbilityRefreshEvent)1 PlayerData (com.archyx.aureliumskills.data.PlayerData)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1