Search in sources :

Example 96 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData 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)

Example 97 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class ManaAbilityProvider method hasEnoughMana.

// Returns true if player has enough mana
protected boolean hasEnoughMana(Player player) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return false;
    Locale locale = playerData.getLocale();
    if (playerData.getMana() >= plugin.getManaAbilityManager().getManaCost(mAbility, playerData)) {
        return true;
    } else {
        plugin.getAbilityManager().sendMessage(player, TextUtil.replace(Lang.getMessage(ManaAbilityMessage.NOT_ENOUGH_MANA, locale), "{mana}", NumberUtil.format0(plugin.getManaAbilityManager().getManaCost(mAbility, playerData)), "{current_mana}", String.valueOf(Math.round(playerData.getMana())), "{max_mana}", String.valueOf(Math.round(playerData.getMaxMana()))));
        return false;
    }
}
Also used : Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 98 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class ManaAbilityProvider method activate.

public void activate(Player player) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    int duration = getDuration(playerData);
    ManaAbilityActivateEvent event = new ManaAbilityActivateEvent(player, mAbility, duration);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        return;
    manager.setActivated(player, mAbility, true);
    // Mana ability specific behavior is run
    onActivate(player, playerData);
    consumeMana(player, playerData);
    if (duration != 0) {
        // Schedules stop
        new BukkitRunnable() {

            @Override
            public void run() {
                stop(player);
                manager.setActivated(player, mAbility, false);
                manager.setReady(player.getUniqueId(), mAbility, false);
            }
        }.runTaskLater(plugin, duration);
    } else {
        stop(player);
        manager.setActivated(player, mAbility, false);
        manager.setReady(player.getUniqueId(), mAbility, false);
    }
}
Also used : ManaAbilityActivateEvent(com.archyx.aureliumskills.api.event.ManaAbilityActivateEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerData(com.archyx.aureliumskills.data.PlayerData)

Example 99 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class ReadiedManaAbility method onReady.

@EventHandler
public void onReady(PlayerInteractEvent event) {
    if (!OptionL.isEnabled(skill))
        return;
    if (!plugin.getAbilityManager().isEnabled(mAbility))
        return;
    // Check action is valid
    boolean valid = false;
    for (Action action : actions) {
        if (event.getAction() == action) {
            valid = true;
            break;
        }
    }
    if (!valid)
        return;
    // Check block exclusions
    Block block = event.getClickedBlock();
    if (block != null) {
        if (isExcludedBlock(block))
            return;
    }
    // Match sure material matches
    Player player = event.getPlayer();
    if (!isHoldingMaterial(player)) {
        return;
    }
    if (!isAllowReady(player, event)) {
        return;
    }
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    Locale locale = playerData.getLocale();
    if (playerData.getManaAbilityLevel(mAbility) <= 0) {
        return;
    }
    // Check if already activated
    if (manager.isActivated(player.getUniqueId(), mAbility)) {
        return;
    }
    // Checks if already ready
    if (manager.isReady(player.getUniqueId(), mAbility)) {
        return;
    }
    if (manager.getPlayerCooldown(player.getUniqueId(), mAbility) == 0) {
        // Ready
        manager.setReady(player.getUniqueId(), mAbility, true);
        plugin.getAbilityManager().sendMessage(player, ChatColor.GRAY + Lang.getMessage(ManaAbilityMessage.valueOf(mAbility.name() + "_RAISE"), locale));
        scheduleUnready(player, locale);
    } else {
        // Cannot ready, send cooldown error
        if (manager.getErrorTimer(player.getUniqueId(), mAbility) == 0) {
            plugin.getAbilityManager().sendMessage(player, Lang.getMessage(ManaAbilityMessage.NOT_READY, locale).replace("{cooldown}", NumberUtil.format0((double) plugin.getManaAbilityManager().getPlayerCooldown(player.getUniqueId(), mAbility) / 20)));
            manager.setErrorTimer(player.getUniqueId(), mAbility, 2);
        }
    }
}
Also used : Locale(java.util.Locale) Action(org.bukkit.event.block.Action) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 100 with PlayerData

use of com.archyx.aureliumskills.data.PlayerData in project AureliumSkills by Archy-X.

the class SkillLeveler method getXp.

public double getXp(Player player, double input, Ability ability) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData != null) {
        double output = input;
        if (ability != null) {
            if (plugin.getAbilityManager().isEnabled(ability)) {
                double modifier = 1;
                modifier += plugin.getAbilityManager().getValue(ability, playerData.getAbilityLevel(ability)) / 100;
                output *= modifier;
            }
        }
        return output;
    }
    return 0.0;
}
Also used : PlayerData(com.archyx.aureliumskills.data.PlayerData)

Aggregations

PlayerData (com.archyx.aureliumskills.data.PlayerData)111 Player (org.bukkit.entity.Player)54 EventHandler (org.bukkit.event.EventHandler)43 Locale (java.util.Locale)27 ItemStack (org.bukkit.inventory.ItemStack)25 Skill (com.archyx.aureliumskills.skills.Skill)15 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 Stat (com.archyx.aureliumskills.stats.Stat)9 AttributeInstance (org.bukkit.attribute.AttributeInstance)8 PlayerLootDropEvent (com.archyx.aureliumskills.api.event.PlayerLootDropEvent)7 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)7 Material (org.bukkit.Material)7 LivingEntity (org.bukkit.entity.LivingEntity)7 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)6 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)5 OptionL (com.archyx.aureliumskills.configuration.OptionL)5 AbilityData (com.archyx.aureliumskills.data.AbilityData)5 File (java.io.File)5 IOException (java.io.IOException)5 PlayerDataLoadEvent (com.archyx.aureliumskills.data.PlayerDataLoadEvent)4