Search in sources :

Example 1 with MAbility

use of com.archyx.aureliumskills.mana.MAbility in project AureliumSkills by Archy-X.

the class AbilityManager method loadOptions.

public void loadOptions() {
    File file = new File(plugin.getDataFolder(), "abilities_config.yml");
    if (!file.exists()) {
        plugin.saveResource("abilities_config.yml", false);
    }
    FileConfiguration config = updateFile(file, YamlConfiguration.loadConfiguration(file));
    migrateOptions(file, config);
    // Loads ability options
    int amountLoaded = 0;
    int amountDisabled = 0;
    long startTime = System.currentTimeMillis();
    ConfigurationSection abilities = config.getConfigurationSection("abilities");
    if (abilities != null) {
        for (Skill skill : plugin.getSkillRegistry().getSkills()) {
            String skillName = skill.name().toLowerCase(Locale.ENGLISH);
            ConfigurationSection skillAbilities = abilities.getConfigurationSection(skillName);
            if (skillAbilities != null) {
                for (String abilityName : skillAbilities.getKeys(false)) {
                    // Check if ability is valid
                    boolean hasKey = false;
                    for (Ability ability : Ability.values()) {
                        if (abilityName.toUpperCase().equals(ability.name())) {
                            hasKey = true;
                            break;
                        }
                    }
                    if (hasKey) {
                        String path = "abilities." + skillName + "." + abilityName + ".";
                        Ability ability = Ability.valueOf(abilityName.toUpperCase());
                        boolean enabled = config.getBoolean(path + "enabled", true);
                        if (!enabled) {
                            amountDisabled++;
                        }
                        double baseValue = config.getDouble(path + "base", ability.getDefaultBaseValue());
                        double valuePerLevel = config.getDouble(path + "per_level", ability.getDefaultValuePerLevel());
                        // Get default unlock value
                        int defUnlock = 2;
                        for (int i = 0; i < skill.getAbilities().size(); i++) {
                            if (skill.getAbilities().get(i).get() == ability) {
                                defUnlock += i;
                                break;
                            }
                        }
                        int unlock = config.getInt(path + "unlock", defUnlock);
                        int levelUp = config.getInt(path + "level_up", 5);
                        int maxLevel = config.getInt(path + "max_level", 0);
                        // Load options
                        Set<String> optionKeys = getOptionKeys(ability);
                        Map<String, OptionValue> options = null;
                        if (optionKeys != null) {
                            options = new HashMap<>();
                            for (String key : optionKeys) {
                                Object value = config.get(path + key);
                                if (value != null) {
                                    options.put(key, new OptionValue(value));
                                }
                            }
                        }
                        AbilityOption option;
                        // Checks if ability has 2 values
                        if (ability.hasTwoValues()) {
                            double baseValue2 = config.getDouble(path + "base_2", ability.getDefaultBaseValue2());
                            double valuePerLevel2 = config.getDouble(path + "per_level_2", ability.getDefaultValuePerLevel2());
                            if (options != null) {
                                option = new AbilityOption(enabled, baseValue, valuePerLevel, baseValue2, valuePerLevel2, unlock, levelUp, maxLevel, options);
                            } else {
                                option = new AbilityOption(enabled, baseValue, valuePerLevel, baseValue2, valuePerLevel2, unlock, levelUp, maxLevel);
                            }
                        } else {
                            if (options != null) {
                                option = new AbilityOption(enabled, baseValue, valuePerLevel, unlock, levelUp, maxLevel, options);
                            } else {
                                option = new AbilityOption(enabled, baseValue, valuePerLevel, unlock, levelUp, maxLevel);
                            }
                        }
                        abilityOptions.put(ability, option);
                        amountLoaded++;
                    }
                }
            }
        }
    }
    ConfigurationSection manaAbilities = config.getConfigurationSection("mana_abilities");
    if (manaAbilities != null) {
        for (String manaAbilityName : manaAbilities.getKeys(false)) {
            boolean hasKey = false;
            for (MAbility manaAbility : MAbility.values()) {
                if (manaAbilityName.toUpperCase().equals(manaAbility.name())) {
                    hasKey = true;
                    break;
                }
            }
            if (hasKey) {
                MAbility mAbility = MAbility.valueOf(manaAbilityName.toUpperCase());
                String path = "mana_abilities." + manaAbilityName + ".";
                boolean enabled = config.getBoolean(path + "enabled", true);
                if (!enabled) {
                    amountDisabled++;
                }
                double baseValue = config.getDouble(path + "base_value", mAbility.getDefaultBaseValue());
                double valuePerLevel = config.getDouble(path + "value_per_level", mAbility.getDefaultValuePerLevel());
                double cooldown = config.getDouble(path + "cooldown", mAbility.getDefaultBaseCooldown());
                double cooldownPerLevel = config.getDouble(path + "cooldown_per_level", mAbility.getDefaultCooldownPerLevel());
                double manaCost = config.getDouble(path + "mana_cost", mAbility.getDefaultBaseManaCost());
                double manaCostPerLevel = config.getDouble(path + "mana_cost_per_level", mAbility.getDefaultManaCostPerLevel());
                int unlock = config.getInt(path + "unlock", 7);
                int levelUp = config.getInt(path + "level_up", 7);
                int maxLevel = config.getInt(path + "max_level", 0);
                // Load options
                Set<String> optionKeys = plugin.getManaAbilityManager().getOptionKeys(mAbility);
                Map<String, OptionValue> options = null;
                if (optionKeys != null) {
                    options = new HashMap<>();
                    for (String key : optionKeys) {
                        Object value = config.get(path + key);
                        if (value != null) {
                            options.put(key, new OptionValue(value));
                        }
                    }
                }
                ManaAbilityOption option;
                if (options != null) {
                    option = new ManaAbilityOption(enabled, baseValue, valuePerLevel, cooldown, cooldownPerLevel, manaCost, manaCostPerLevel, unlock, levelUp, maxLevel, options);
                } else {
                    option = new ManaAbilityOption(enabled, baseValue, valuePerLevel, cooldown, cooldownPerLevel, manaCost, manaCostPerLevel, unlock, levelUp, maxLevel);
                }
                manaAbilityOptions.put(mAbility, option);
                amountLoaded++;
            }
        }
    }
    long endTime = System.currentTimeMillis();
    long timeElapsed = endTime - startTime;
    if (amountDisabled > 0) {
        plugin.getLogger().info("Disabled " + amountDisabled + " Abilities");
    }
    plugin.getLogger().info("Loaded " + amountLoaded + " Ability Options in " + timeElapsed + "ms");
}
Also used : MAbility(com.archyx.aureliumskills.mana.MAbility) ManaAbilityOption(com.archyx.aureliumskills.mana.ManaAbilityOption) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Skill(com.archyx.aureliumskills.skills.Skill) ManaAbilityOption(com.archyx.aureliumskills.mana.ManaAbilityOption) OptionValue(com.archyx.aureliumskills.configuration.OptionValue) MAbility(com.archyx.aureliumskills.mana.MAbility) File(java.io.File) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with MAbility

use of com.archyx.aureliumskills.mana.MAbility in project AureliumSkills by Archy-X.

the class SkillInfoItem method getManaAbilityLore.

private String getManaAbilityLore(Skill skill, PlayerData playerData, Locale locale) {
    StringBuilder manaAbilityLore = new StringBuilder();
    MAbility mAbility = skill.getManaAbility();
    if (mAbility != null) {
        int level = playerData.getManaAbilityLevel(mAbility);
        if (level > 0 && plugin.getAbilityManager().isEnabled(mAbility)) {
            ManaAbilityManager manager = plugin.getManaAbilityManager();
            manaAbilityLore.append(TextUtil.replace(Lang.getMessage(getManaAbilityMessage(mAbility), locale), "{mana_ability}", mAbility.getDisplayName(locale), "{level}", RomanNumber.toRoman(level), "{duration}", NumberUtil.format1(getDuration(mAbility, level)), "{value}", NumberUtil.format1(manager.getDisplayValue(mAbility, level)), "{mana_cost}", NumberUtil.format1(manager.getManaCost(mAbility, level)), "{cooldown}", NumberUtil.format1(manager.getCooldown(mAbility, level))));
        }
    }
    return manaAbilityLore.toString();
}
Also used : MAbility(com.archyx.aureliumskills.mana.MAbility) ManaAbilityManager(com.archyx.aureliumskills.mana.ManaAbilityManager)

Example 3 with MAbility

use of com.archyx.aureliumskills.mana.MAbility in project AureliumSkills by Archy-X.

the class AbilityManager method migrateOptions.

private void migrateOptions(File file, FileConfiguration abilitiesConfig) {
    FileConfiguration config = plugin.getConfig();
    ConfigurationSection abilities = config.getConfigurationSection("abilities");
    if (abilities == null)
        return;
    try {
        for (String abilityName : abilities.getKeys(false)) {
            String newKey = TextUtil.replace(abilityName, "-", "_").toUpperCase();
            if (isAbility(newKey)) {
                Ability ability = Ability.valueOf(newKey);
                boolean enabled = abilities.getBoolean(abilityName + ".enabled", true);
                double base = abilities.getDouble(abilityName + ".base", ability.getDefaultBaseValue());
                double per_level = abilities.getDouble(abilityName + ".per-level", ability.getDefaultValuePerLevel());
                String path = "abilities." + ability.getSkill().name().toLowerCase(Locale.ENGLISH) + "." + newKey.toLowerCase(Locale.ENGLISH) + ".";
                abilitiesConfig.set(path + "enabled", enabled);
                abilitiesConfig.set(path + "base", base);
                abilitiesConfig.set(path + "per_level", per_level);
                if (ability.hasTwoValues()) {
                    double base_2 = abilities.getDouble(abilityName + ".base-2", ability.getDefaultBaseValue2());
                    double per_level_2 = abilities.getDouble(abilityName + ".per_level-2", ability.getDefaultValuePerLevel2());
                    abilitiesConfig.set(path + "base_2", base_2);
                    abilitiesConfig.set(path + "per_level_2", per_level_2);
                }
            }
        }
        config.set("abilities", null);
        ConfigurationSection manaAbilities = config.getConfigurationSection("mana-abilities");
        if (manaAbilities != null) {
            for (String manaAbilityName : manaAbilities.getKeys(false)) {
                String newKey = TextUtil.replace(manaAbilityName, "-", "_").toUpperCase();
                if (isManaAbility(newKey)) {
                    MAbility mAbility = MAbility.valueOf(newKey);
                    boolean enabled = manaAbilities.getBoolean(manaAbilityName + ".enabled", true);
                    double base = manaAbilities.getDouble(manaAbilityName + ".base-value", mAbility.getDefaultBaseValue());
                    double per_level = manaAbilities.getDouble(manaAbilityName + ".value-per-level", mAbility.getDefaultValuePerLevel());
                    double cooldown = manaAbilities.getDouble(manaAbilityName + ".cooldown", mAbility.getDefaultBaseCooldown());
                    double cooldown_per_level = manaAbilities.getDouble(manaAbilityName + ".cooldown-per-level", mAbility.getDefaultCooldownPerLevel());
                    double mana_cost = manaAbilities.getDouble(manaAbilityName + ".mana-cost", mAbility.getDefaultBaseManaCost());
                    double mana_cost_per_level = manaAbilities.getDouble(manaAbilityName + ".mana-cost-per-level", mAbility.getDefaultManaCostPerLevel());
                    String path = "mana_abilities." + newKey.toLowerCase(Locale.ENGLISH) + ".";
                    abilitiesConfig.set(path + "enabled", enabled);
                    abilitiesConfig.set(path + "base_value", base);
                    abilitiesConfig.set(path + "value_per_level", per_level);
                    abilitiesConfig.set(path + "cooldown", cooldown);
                    abilitiesConfig.set(path + "cooldown_per_level", cooldown_per_level);
                    abilitiesConfig.set(path + "mana_cost", mana_cost);
                    abilitiesConfig.set(path + "mana_cost_per_level", mana_cost_per_level);
                }
            }
            config.set("mana-abilities", null);
        }
        plugin.saveConfig();
        abilitiesConfig.save(file);
        Bukkit.getLogger().warning("[AureliumSkills] Your existing ability options have been migrated to abilities_config.yml and the old options in config.yml have been deleted, this is normal if you are updating to Alpha 1.6.0 or above from before Alpha 1.6.0!");
    } catch (Exception e) {
        e.printStackTrace();
        Bukkit.getLogger().severe("[AureliumSkills] An error occurred while migrating ability options, please report this as a bug!");
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MAbility(com.archyx.aureliumskills.mana.MAbility) MAbility(com.archyx.aureliumskills.mana.MAbility) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 4 with MAbility

use of com.archyx.aureliumskills.mana.MAbility in project AureliumSkills by Archy-X.

the class ProgressLevelItem method getManaAbilityLore.

public String getManaAbilityLore(Skill skill, int level, Locale locale) {
    ManaAbilityManager manager = plugin.getManaAbilityManager();
    MAbility mAbility = manager.getManaAbility(skill, level);
    StringBuilder manaAbilityLore = new StringBuilder();
    if (mAbility != null) {
        if (plugin.getAbilityManager().isEnabled(mAbility)) {
            if (level == manager.getUnlock(mAbility)) {
                manaAbilityLore.append(TextUtil.replace(Lang.getMessage(MenuMessage.MANA_ABILITY_UNLOCK, locale), "{mana_ability}", mAbility.getDisplayName(locale), "{desc}", TextUtil.replace(mAbility.getDescription(locale), "{value}", NumberUtil.format1(manager.getDisplayValue(mAbility, 1)), "{duration}", NumberUtil.format1(getDuration(mAbility, 1)), "{haste_level}", String.valueOf(manager.getOptionAsInt(MAbility.SPEED_MINE, "haste_level", 10)))));
            } else {
                int manaAbilityLevel = ((level - manager.getUnlock(mAbility)) / manager.getLevelUp(mAbility)) + 1;
                if (manaAbilityLevel <= manager.getMaxLevel(mAbility) || manager.getMaxLevel(mAbility) == 0) {
                    manaAbilityLore.append(TextUtil.replace(Lang.getMessage(MenuMessage.MANA_ABILITY_LEVEL, locale), "{mana_ability}", mAbility.getDisplayName(locale), "{level}", RomanNumber.toRoman(manaAbilityLevel), "{desc}", TextUtil.replace(mAbility.getDescription(locale), "{value}", NumberUtil.format1(manager.getDisplayValue(mAbility, manaAbilityLevel)), "{duration}", NumberUtil.format1(getDuration(mAbility, manaAbilityLevel)), "{haste_level}", String.valueOf(manager.getOptionAsInt(MAbility.SPEED_MINE, "haste_level", 10)))));
                }
            }
        }
    }
    return manaAbilityLore.toString();
}
Also used : MAbility(com.archyx.aureliumskills.mana.MAbility) ManaAbilityManager(com.archyx.aureliumskills.mana.ManaAbilityManager)

Example 5 with MAbility

use of com.archyx.aureliumskills.mana.MAbility in project AureliumSkills by Archy-X.

the class Leveler method getLevelUpMessage.

private String getLevelUpMessage(Player player, PlayerData playerData, Skill skill, int newLevel, Locale locale, List<Reward> rewards) {
    String message = TextUtil.replace(Lang.getMessage(LevelerMessage.LEVEL_UP, locale), "{skill}", skill.getDisplayName(locale), "{old}", RomanNumber.toRoman(newLevel - 1), "{new}", RomanNumber.toRoman(newLevel));
    if (plugin.isPlaceholderAPIEnabled()) {
        message = PlaceholderAPI.setPlaceholders(player, message);
    }
    StringBuilder rewardMessage = new StringBuilder();
    for (Reward reward : rewards) {
        rewardMessage.append(reward.getChatMessage(player, locale, skill, newLevel));
    }
    // Ability unlocks and level ups
    StringBuilder abilityUnlockMessage = new StringBuilder();
    StringBuilder abilityLevelUpMessage = new StringBuilder();
    for (Ability ability : plugin.getAbilityManager().getAbilities(skill, newLevel)) {
        if (plugin.getAbilityManager().isEnabled(ability)) {
            if (plugin.getAbilityManager().getUnlock(ability) == newLevel) {
                abilityUnlockMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.ABILITY_UNLOCK, locale), "{ability}", ability.getDisplayName(locale)));
            } else {
                abilityLevelUpMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.ABILITY_LEVEL_UP, locale), "{ability}", ability.getDisplayName(locale), "{level}", RomanNumber.toRoman(playerData.getAbilityLevel(ability))));
            }
        }
    }
    message = TextUtil.replace(message, "{stat_level}", rewardMessage.toString(), "{ability_unlock}", abilityUnlockMessage.toString(), "{ability_level_up}", abilityLevelUpMessage.toString());
    // Mana ability unlocks and level ups
    StringBuilder manaAbilityUnlockMessage = new StringBuilder();
    StringBuilder manaAbilityLevelUpMessage = new StringBuilder();
    MAbility mAbility = plugin.getManaAbilityManager().getManaAbility(skill, newLevel);
    if (mAbility != null) {
        if (plugin.getAbilityManager().isEnabled(mAbility)) {
            if (plugin.getManaAbilityManager().getUnlock(mAbility) == newLevel) {
                manaAbilityUnlockMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.MANA_ABILITY_UNLOCK, locale), "{mana_ability}", mAbility.getDisplayName(locale)));
            } else {
                manaAbilityLevelUpMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.MANA_ABILITY_LEVEL_UP, locale), "{mana_ability}", mAbility.getDisplayName(locale), "{level}", RomanNumber.toRoman(playerData.getManaAbilityLevel(mAbility))));
            }
        }
    }
    message = TextUtil.replace(message, "{mana_ability_unlock}", manaAbilityUnlockMessage.toString(), "{mana_ability_level_up}", manaAbilityLevelUpMessage.toString());
    // Build money rewards
    StringBuilder moneyRewardMessage = new StringBuilder();
    double totalMoney = 0;
    // Legacy system
    if (plugin.isVaultEnabled()) {
        if (OptionL.getBoolean(Option.SKILL_MONEY_REWARDS_ENABLED)) {
            double base = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_BASE);
            double multiplier = OptionL.getDouble(Option.SKILL_MONEY_REWARDS_MULTIPLIER);
            totalMoney += base + (multiplier * newLevel * newLevel);
        }
    }
    // New rewards
    for (MoneyReward reward : plugin.getRewardManager().getRewardTable(skill).searchRewards(MoneyReward.class, newLevel)) {
        totalMoney += reward.getAmount();
    }
    if (totalMoney > 0) {
        NumberFormat nf = new DecimalFormat("#.##");
        moneyRewardMessage.append(TextUtil.replace(Lang.getMessage(LevelerMessage.MONEY_REWARD, locale), "{amount}", nf.format(totalMoney)));
    }
    message = TextUtil.replace(message, "{money_reward}", moneyRewardMessage.toString());
    return message.replaceAll("(\\u005C\\u006E)|(\\n)", "\n");
}
Also used : MAbility(com.archyx.aureliumskills.mana.MAbility) Ability(com.archyx.aureliumskills.ability.Ability) DecimalFormat(java.text.DecimalFormat) MAbility(com.archyx.aureliumskills.mana.MAbility) MoneyReward(com.archyx.aureliumskills.rewards.MoneyReward) CommandReward(com.archyx.aureliumskills.rewards.CommandReward) MoneyReward(com.archyx.aureliumskills.rewards.MoneyReward) Reward(com.archyx.aureliumskills.rewards.Reward) NumberFormat(java.text.NumberFormat)

Aggregations

MAbility (com.archyx.aureliumskills.mana.MAbility)5 ManaAbilityManager (com.archyx.aureliumskills.mana.ManaAbilityManager)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 Ability (com.archyx.aureliumskills.ability.Ability)1 OptionValue (com.archyx.aureliumskills.configuration.OptionValue)1 ManaAbilityOption (com.archyx.aureliumskills.mana.ManaAbilityOption)1 CommandReward (com.archyx.aureliumskills.rewards.CommandReward)1 MoneyReward (com.archyx.aureliumskills.rewards.MoneyReward)1 Reward (com.archyx.aureliumskills.rewards.Reward)1 Skill (com.archyx.aureliumskills.skills.Skill)1 File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1