Search in sources :

Example 1 with SkillLevelUpEvent

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

the class Leveler method levelUpSkill.

private void levelUpSkill(PlayerData playerData, Skill skill) {
    Player player = playerData.getPlayer();
    Locale locale = playerData.getLocale();
    double currentXp = playerData.getSkillXp(skill);
    int level = playerData.getSkillLevel(skill) + 1;
    playerData.setSkillXp(skill, currentXp - xpRequirements.getXpRequired(skill, level));
    playerData.setSkillLevel(skill, level);
    // Give custom rewards
    List<Reward> rewards = plugin.getRewardManager().getRewardTable(skill).getRewards(level);
    for (Reward reward : rewards) {
        reward.giveReward(player, skill, level);
    }
    // Adds money rewards if enabled
    if (plugin.isVaultEnabled()) {
        if (OptionL.getBoolean(Option.SKILL_MONEY_REWARDS_ENABLED)) {
            Economy economy = plugin.getEconomy();
            double base = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_BASE);
            double multiplier = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_MULTIPLIER);
            economy.depositPlayer(player, base + (multiplier * level * level));
        }
    }
    // Reload items and armor to check for newly met requirements
    plugin.getModifierManager().reloadPlayer(player);
    // Calls event
    SkillLevelUpEvent event = new SkillLevelUpEvent(player, skill, level);
    Bukkit.getPluginManager().callEvent(event);
    // Sends messages
    if (OptionL.getBoolean(Option.LEVELER_TITLE_ENABLED)) {
        sendTitle(player, locale, skill, level);
    }
    if (OptionL.getBoolean(Option.LEVELER_SOUND_ENABLED)) {
        playSound(player);
    }
    player.sendMessage(getLevelUpMessage(player, playerData, skill, level, locale, rewards));
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> checkLevelUp(player, skill), OptionL.getInt(Option.LEVELER_DOUBLE_CHECK_DELAY));
}
Also used : Locale(java.util.Locale) Player(org.bukkit.entity.Player) Economy(net.milkbowl.vault.economy.Economy) SkillLevelUpEvent(com.archyx.aureliumskills.api.event.SkillLevelUpEvent) CommandReward(com.archyx.aureliumskills.rewards.CommandReward) MoneyReward(com.archyx.aureliumskills.rewards.MoneyReward) Reward(com.archyx.aureliumskills.rewards.Reward)

Aggregations

SkillLevelUpEvent (com.archyx.aureliumskills.api.event.SkillLevelUpEvent)1 CommandReward (com.archyx.aureliumskills.rewards.CommandReward)1 MoneyReward (com.archyx.aureliumskills.rewards.MoneyReward)1 Reward (com.archyx.aureliumskills.rewards.Reward)1 Locale (java.util.Locale)1 Economy (net.milkbowl.vault.economy.Economy)1 Player (org.bukkit.entity.Player)1