Search in sources :

Example 16 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class YamlStorageProvider method loadBackup.

@Override
public void loadBackup(FileConfiguration config, CommandSender sender) {
    ConfigurationSection playerDataSection = config.getConfigurationSection("player_data");
    Locale locale = plugin.getLang().getLocale(sender);
    if (playerDataSection != null) {
        try {
            for (String stringId : playerDataSection.getKeys(false)) {
                UUID id = UUID.fromString(stringId);
                // Load levels and xp from backup
                Map<Skill, Integer> levels = getLevelsFromBackup(playerDataSection, stringId);
                Map<Skill, Double> xpLevels = getXpLevelsFromBackup(playerDataSection, stringId);
                PlayerData playerData = playerManager.getPlayerData(id);
                if (playerData != null) {
                    applyData(playerData, levels, xpLevels);
                } else {
                    // Load file for offline players
                    File file = new File(plugin.getDataFolder() + "/playerdata/" + id + ".yml");
                    FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(file);
                    playerConfig.set("uuid", id.toString());
                    // Save skill data
                    for (Skill skill : Skills.values()) {
                        String path = "skills." + skill.toString().toLowerCase(Locale.ROOT) + ".";
                        playerConfig.set(path + "level", levels.get(skill));
                        playerConfig.set(path + "xp", xpLevels.get(skill));
                    }
                    // Save file
                    playerConfig.save(file);
                }
            }
            sender.sendMessage(AureliumSkills.getPrefix(locale) + Lang.getMessage(CommandMessage.BACKUP_LOAD_LOADED, locale));
        } catch (Exception e) {
            sender.sendMessage(AureliumSkills.getPrefix(locale) + TextUtil.replace(Lang.getMessage(CommandMessage.BACKUP_LOAD_ERROR, locale), "{error}", e.getMessage()));
        }
    }
}
Also used : IOException(java.io.IOException) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Skill(com.archyx.aureliumskills.skills.Skill) PlayerData(com.archyx.aureliumskills.data.PlayerData) File(java.io.File) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 17 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class SkillInfoItem method getAbilityLevelsLore.

private String getAbilityLevelsLore(Skill skill, PlayerData playerData, Locale locale) {
    StringBuilder abilityLevelsLore = new StringBuilder();
    if (skill.getAbilities().size() == 5) {
        String levelsMessage = Lang.getMessage(MenuMessage.ABILITY_LEVELS, locale);
        int num = 1;
        List<Ability> abilities = new ArrayList<>();
        for (Supplier<Ability> abilitySupplier : skill.getAbilities()) {
            abilities.add(abilitySupplier.get());
        }
        abilities.sort(Comparator.comparingInt(a -> plugin.getAbilityManager().getUnlock(a)));
        for (Ability ability : abilities) {
            if (plugin.getAbilityManager().isEnabled(ability)) {
                if (playerData.getAbilityLevel(ability) > 0) {
                    int abilityLevel = playerData.getAbilityLevel(ability);
                    levelsMessage = TextUtil.replace(levelsMessage, "{ability_" + num + "}", TextUtil.replace(Lang.getMessage(MenuMessage.ABILITY_LEVEL_ENTRY, locale), "{ability}", ability.getDisplayName(locale), "{level}", RomanNumber.toRoman(playerData.getAbilityLevel(ability)), "{info}", TextUtil.replace(ability.getInfo(locale), "{value}", NumberUtil.format1(plugin.getAbilityManager().getValue(ability, abilityLevel)), "{value_2}", NumberUtil.format1(plugin.getAbilityManager().getValue2(ability, abilityLevel)))));
                } else {
                    levelsMessage = TextUtil.replace(levelsMessage, "{ability_" + num + "}", TextUtil.replace(Lang.getMessage(MenuMessage.ABILITY_LEVEL_ENTRY_LOCKED, locale), "{ability}", ability.getDisplayName(locale)));
                }
            } else {
                levelsMessage = TextUtil.replace(levelsMessage, "\\n  {ability_" + num + "}", "", "{ability_" + num + "}", "");
            }
            num++;
        }
        abilityLevelsLore.append(levelsMessage);
    }
    return abilityLevelsLore.toString();
}
Also used : MAbility(com.archyx.aureliumskills.mana.MAbility) Ability(com.archyx.aureliumskills.ability.Ability) MenuMessage(com.archyx.aureliumskills.lang.MenuMessage) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) OptionL(com.archyx.aureliumskills.configuration.OptionL) Player(org.bukkit.entity.Player) Supplier(java.util.function.Supplier) MessageKey(com.archyx.aureliumskills.lang.MessageKey) TextUtil(com.archyx.aureliumskills.util.text.TextUtil) Option(com.archyx.aureliumskills.configuration.Option) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Lang(com.archyx.aureliumskills.lang.Lang) ImmutableList(com.google.common.collect.ImmutableList) MAbility(com.archyx.aureliumskills.mana.MAbility) Skill(com.archyx.aureliumskills.skills.Skill) ItemUtils(com.archyx.aureliumskills.util.item.ItemUtils) RomanNumber(com.archyx.aureliumskills.util.math.RomanNumber) ManaAbilityManager(com.archyx.aureliumskills.mana.ManaAbilityManager) PlaceholderAPI(me.clip.placeholderapi.PlaceholderAPI) ItemStack(org.bukkit.inventory.ItemStack) Stat(com.archyx.aureliumskills.stats.Stat) NumberUtil(com.archyx.aureliumskills.util.math.NumberUtil) PlayerData(com.archyx.aureliumskills.data.PlayerData) ChatColor(org.bukkit.ChatColor) Ability(com.archyx.aureliumskills.ability.Ability) ManaAbilityMessage(com.archyx.aureliumskills.lang.ManaAbilityMessage)

Example 18 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class SkillTemplate method load.

@Override
public void load(ConfigurationSection config) {
    try {
        for (String posInput : config.getStringList("pos")) {
            String[] splitInput = posInput.split(" ");
            Skill skill = plugin.getSkillRegistry().getSkill(splitInput[0]);
            if (skill != null) {
                int row = Integer.parseInt(splitInput[1]);
                int column = Integer.parseInt(splitInput[2]);
                positions.put(skill, SlotPos.of(row, column));
            }
        }
        // Load base items
        for (String materialInput : config.getStringList("material")) {
            String[] splitInput = materialInput.split(" ", 2);
            Skill skill;
            try {
                skill = plugin.getSkillRegistry().getSkill(splitInput[0]);
            } catch (IllegalArgumentException e) {
                Bukkit.getLogger().warning("[AureliumSkills] Error while loading SKILL template, " + splitInput[0].toUpperCase() + " is not a valid skill! Using FARMING as a default");
                skill = Skills.FARMING;
            }
            baseItems.put(skill, MenuLoader.parseItem(splitInput[1]));
        }
        displayName = TextUtil.replace(Objects.requireNonNull(config.getString("display_name")), "&", "§");
        // Load lore
        List<String> lore = new ArrayList<>();
        Map<Integer, Set<String>> lorePlaceholders = new HashMap<>();
        int lineNum = 0;
        for (String line : config.getStringList("lore")) {
            Set<String> linePlaceholders = new HashSet<>();
            lore.add(TextUtil.replace(line, "&", "§"));
            // Find lore placeholders
            for (String placeholder : definedPlaceholders) {
                if (line.contains("{" + placeholder + "}")) {
                    linePlaceholders.add(placeholder);
                }
            }
            lorePlaceholders.put(lineNum, linePlaceholders);
            lineNum++;
        }
        this.lore = lore;
        this.lorePlaceholders = lorePlaceholders;
    } catch (Exception e) {
        e.printStackTrace();
        Bukkit.getLogger().warning("[AureliumSkills] Error parsing template " + templateType.toString() + ", check error above for details!");
    }
}
Also used : Skill(com.archyx.aureliumskills.skills.Skill)

Example 19 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class StatTemplate method getItem.

public ItemStack getItem(Stat stat, PlayerData playerData, Player player, Locale locale) {
    ItemStack item = baseItems.get(stat);
    if (item == null) {
        item = new ItemStack(Material.STONE);
    }
    item = item.clone();
    ItemMeta meta = item.getItemMeta();
    if (meta != null) {
        meta.setDisplayName(applyPlaceholders(TextUtil.replace(displayName, "{color}", stat.getColor(locale), "{stat}", stat.getDisplayName(locale)), player));
        List<String> builtLore = new ArrayList<>();
        for (int i = 0; i < lore.size(); i++) {
            String line = lore.get(i);
            Set<String> placeholders = lorePlaceholders.get(i);
            for (String placeholder : placeholders) {
                switch(placeholder) {
                    case "stat_desc":
                        line = TextUtil.replace(line, "{stat_desc}", stat.getDescription(locale));
                        break;
                    case "skills":
                        List<Skill> skillsLeveledBy = plugin.getRewardManager().getSkillsLeveledBy(stat);
                        StringBuilder skillList = new StringBuilder();
                        for (Skill skill : skillsLeveledBy) {
                            skillList.append(skill.getDisplayName(locale)).append(", ");
                        }
                        if (skillList.length() > 1) {
                            skillList.delete(skillList.length() - 2, skillList.length());
                        }
                        if (skillsLeveledBy.size() > 0) {
                            line = TextUtil.replace(line, "{skills}", TextUtil.replace(Lang.getMessage(MenuMessage.SKILLS, locale), "{skills}", skillList.toString()));
                        } else {
                            line = TextUtil.replace(line, "{skills}", "");
                        }
                        break;
                    case "your_level":
                        line = TextUtil.replace(line, "{your_level}", TextUtil.replace(Lang.getMessage(MenuMessage.YOUR_LEVEL, locale), "{color}", stat.getColor(locale), "{level}", NumberUtil.format1(playerData.getStatLevel(stat))));
                        break;
                    case "descriptors":
                        switch(stat.name()) {
                            case "STRENGTH":
                                double strengthLevel = playerData.getStatLevel(Stats.STRENGTH);
                                double attackDamage = strengthLevel * OptionL.getDouble(Option.STRENGTH_MODIFIER);
                                if (OptionL.getBoolean(Option.STRENGTH_DISPLAY_DAMAGE_WITH_HEALTH_SCALING) && !OptionL.getBoolean(Option.STRENGTH_USE_PERCENT)) {
                                    attackDamage *= OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING);
                                }
                                line = TextUtil.replace(line, "{descriptors}", TextUtil.replace(Lang.getMessage(MenuMessage.ATTACK_DAMAGE, locale), "{value}", NumberUtil.format2(attackDamage)));
                                break;
                            case "HEALTH":
                                double modifier = playerData.getStatLevel(Stats.HEALTH) * OptionL.getDouble(Option.HEALTH_MODIFIER);
                                double scaledHealth = modifier * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING);
                                line = TextUtil.replace(line, "{descriptors}", TextUtil.replace(Lang.getMessage(MenuMessage.HP, locale), "{value}", NumberUtil.format2(scaledHealth)));
                                break;
                            case "REGENERATION":
                                double regenLevel = playerData.getStatLevel(Stats.REGENERATION);
                                double saturatedRegen = regenLevel * OptionL.getDouble(Option.REGENERATION_SATURATED_MODIFIER) * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING);
                                double hungerFullRegen = regenLevel * OptionL.getDouble(Option.REGENERATION_HUNGER_FULL_MODIFIER) * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING);
                                double almostFullRegen = regenLevel * OptionL.getDouble(Option.REGENERATION_HUNGER_ALMOST_FULL_MODIFIER) * OptionL.getDouble(Option.HEALTH_HP_INDICATOR_SCALING);
                                double manaRegen = playerData.getManaRegen();
                                line = TextUtil.replace(line, "{descriptors}", TextUtil.replace(Lang.getMessage(MenuMessage.SATURATED_REGEN, locale), "{value}", NumberUtil.format2(saturatedRegen)) + "\n" + TextUtil.replace(Lang.getMessage(MenuMessage.FULL_HUNGER_REGEN, locale), "{value}", NumberUtil.format2(hungerFullRegen)) + "\n" + TextUtil.replace(Lang.getMessage(MenuMessage.ALMOST_FULL_HUNGER_REGEN, locale), "{value}", NumberUtil.format2(almostFullRegen)) + "\n" + TextUtil.replace(Lang.getMessage(MenuMessage.MANA_REGEN, locale), "{value}", String.valueOf((int) manaRegen)));
                                break;
                            case "LUCK":
                                double luckLevel = playerData.getStatLevel(Stats.LUCK);
                                double luck = luckLevel * OptionL.getDouble(Option.LUCK_MODIFIER);
                                double doubleDropChance = luckLevel * OptionL.getDouble(Option.LUCK_DOUBLE_DROP_MODIFIER) * 100;
                                if (doubleDropChance > OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX)) {
                                    doubleDropChance = OptionL.getDouble(Option.LUCK_DOUBLE_DROP_PERCENT_MAX);
                                }
                                line = TextUtil.replace(line, "{descriptors}", TextUtil.replace(Lang.getMessage(MenuMessage.LUCK, locale), "{value}", NumberUtil.format2(luck)) + "\n" + TextUtil.replace(Lang.getMessage(MenuMessage.DOUBLE_DROP_CHANCE, locale), "{value}", NumberUtil.format2(doubleDropChance)));
                                break;
                            case "WISDOM":
                                double wisdomLevel = playerData.getStatLevel(Stats.WISDOM);
                                double xpModifier = wisdomLevel * OptionL.getDouble(Option.WISDOM_EXPERIENCE_MODIFIER) * 100;
                                double anvilCostReduction = (-1.0 * Math.pow(1.025, -1.0 * wisdomLevel * OptionL.getDouble(Option.WISDOM_ANVIL_COST_MODIFIER)) + 1) * 100;
                                double maxMana = playerData.getMaxMana();
                                line = TextUtil.replace(line, "{descriptors}", TextUtil.replace(Lang.getMessage(MenuMessage.XP_GAIN, locale), "{value}", NumberUtil.format2(xpModifier)) + "\n" + TextUtil.replace(Lang.getMessage(MenuMessage.ANVIL_COST_REDUCTION, locale), "{value}", NumberUtil.format1(anvilCostReduction)) + " " + "\n" + TextUtil.replace(Lang.getMessage(MenuMessage.MAX_MANA, locale), "{value}", NumberUtil.format1(maxMana)));
                                break;
                            case "TOUGHNESS":
                                double toughness = playerData.getStatLevel(Stats.TOUGHNESS) * OptionL.getDouble(Option.TOUGHNESS_NEW_MODIFIER);
                                double damageReduction = (-1.0 * Math.pow(1.01, -1.0 * toughness) + 1) * 100;
                                line = TextUtil.replace(line, "{descriptors}", TextUtil.replace(Lang.getMessage(MenuMessage.INCOMING_DAMAGE, locale), "{value}", NumberUtil.format2(damageReduction)));
                        }
                        break;
                }
            }
            builtLore.add(line);
        }
        meta.setLore(ItemUtils.formatLore(applyPlaceholders(builtLore, player)));
        item.setItemMeta(meta);
    }
    return item;
}
Also used : Skill(com.archyx.aureliumskills.skills.Skill) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 20 with Skill

use of com.archyx.aureliumskills.skills.Skill in project AureliumSkills by Archy-X.

the class SkillsMenu method init.

public void init(Player player, InventoryContents contents) {
    // Fill item
    if (options.isFillEnabled()) {
        contents.fill(ClickableItem.empty(options.getFillItem()));
    }
    // Close item
    CloseItem closeItem = (CloseItem) options.getItem(ItemType.CLOSE);
    contents.set(closeItem.getPos(), ClickableItem.of(closeItem.getItem(player, locale), e -> player.closeInventory()));
    // Your skills item
    YourSkillsItem yourSkillsItem = (YourSkillsItem) options.getItem(ItemType.YOUR_SKILLS);
    contents.set(yourSkillsItem.getPos(), ClickableItem.empty(yourSkillsItem.getItem(player, locale)));
    // Skill items
    SkillTemplate skillTemplate = (SkillTemplate) options.getTemplate(TemplateType.SKILL);
    if (OptionL.isEnabled(Skills.FARMING)) {
        contents.set(skillTemplate.getPosition(Skills.FARMING), ClickableItem.of(skillTemplate.getItem(Skills.FARMING, playerData, player, locale), e -> open(player, playerData, Skills.FARMING)));
    }
    if (OptionL.isEnabled(Skills.FORAGING)) {
        contents.set(skillTemplate.getPosition(Skills.FORAGING), ClickableItem.of(skillTemplate.getItem(Skills.FORAGING, playerData, player, locale), e -> open(player, playerData, Skills.FORAGING)));
    }
    if (OptionL.isEnabled(Skills.MINING)) {
        contents.set(skillTemplate.getPosition(Skills.MINING), ClickableItem.of(skillTemplate.getItem(Skills.MINING, playerData, player, locale), e -> open(player, playerData, Skills.MINING)));
    }
    if (OptionL.isEnabled(Skills.FISHING)) {
        contents.set(skillTemplate.getPosition(Skills.FISHING), ClickableItem.of(skillTemplate.getItem(Skills.FISHING, playerData, player, locale), e -> open(player, playerData, Skills.FISHING)));
    }
    if (OptionL.isEnabled(Skills.EXCAVATION)) {
        contents.set(skillTemplate.getPosition(Skills.EXCAVATION), ClickableItem.of(skillTemplate.getItem(Skills.EXCAVATION, playerData, player, locale), e -> open(player, playerData, Skills.EXCAVATION)));
    }
    // Combat Skills
    if (OptionL.isEnabled(Skills.ARCHERY)) {
        contents.set(skillTemplate.getPosition(Skills.ARCHERY), ClickableItem.of(skillTemplate.getItem(Skills.ARCHERY, playerData, player, locale), e -> open(player, playerData, Skills.ARCHERY)));
    }
    if (OptionL.isEnabled(Skills.DEFENSE)) {
        contents.set(skillTemplate.getPosition(Skills.DEFENSE), ClickableItem.of(skillTemplate.getItem(Skills.DEFENSE, playerData, player, locale), e -> open(player, playerData, Skills.DEFENSE)));
    }
    if (OptionL.isEnabled(Skills.FIGHTING)) {
        contents.set(skillTemplate.getPosition(Skills.FIGHTING), ClickableItem.of(skillTemplate.getItem(Skills.FIGHTING, playerData, player, locale), e -> open(player, playerData, Skills.FIGHTING)));
    }
    if (OptionL.isEnabled(Skills.ENDURANCE)) {
        contents.set(skillTemplate.getPosition(Skills.ENDURANCE), ClickableItem.of(skillTemplate.getItem(Skills.ENDURANCE, playerData, player, locale), e -> open(player, playerData, Skills.ENDURANCE)));
    }
    if (OptionL.isEnabled(Skills.AGILITY)) {
        contents.set(skillTemplate.getPosition(Skills.AGILITY), ClickableItem.of(skillTemplate.getItem(Skills.AGILITY, playerData, player, locale), e -> open(player, playerData, Skills.AGILITY)));
    }
    // Magic Skills
    if (OptionL.isEnabled(Skills.ALCHEMY)) {
        contents.set(skillTemplate.getPosition(Skills.ALCHEMY), ClickableItem.of(skillTemplate.getItem(Skills.ALCHEMY, playerData, player, locale), e -> open(player, playerData, Skills.ALCHEMY)));
    }
    if (OptionL.isEnabled(Skills.ENCHANTING)) {
        contents.set(skillTemplate.getPosition(Skills.ENCHANTING), ClickableItem.of(skillTemplate.getItem(Skills.ENCHANTING, playerData, player, locale), e -> open(player, playerData, Skills.ENCHANTING)));
    }
    if (OptionL.isEnabled(Skills.SORCERY)) {
        contents.set(skillTemplate.getPosition(Skills.SORCERY), ClickableItem.of(skillTemplate.getItem(Skills.SORCERY, playerData, player, locale), e -> open(player, playerData, Skills.SORCERY)));
    }
    if (OptionL.isEnabled(Skills.HEALING)) {
        contents.set(skillTemplate.getPosition(Skills.HEALING), ClickableItem.of(skillTemplate.getItem(Skills.HEALING, playerData, player, locale), e -> open(player, playerData, Skills.HEALING)));
    }
    if (OptionL.isEnabled(Skills.FORGING)) {
        contents.set(skillTemplate.getPosition(Skills.FORGING), ClickableItem.of(skillTemplate.getItem(Skills.FORGING, playerData, player, locale), e -> open(player, playerData, Skills.FORGING)));
    }
}
Also used : CloseItem(com.archyx.aureliumskills.menu.items.CloseItem) TemplateType(com.archyx.aureliumskills.menu.templates.TemplateType) MenuMessage(com.archyx.aureliumskills.lang.MenuMessage) SmartInventory(fr.minuskube.inv.SmartInventory) OptionL(com.archyx.aureliumskills.configuration.OptionL) Player(org.bukkit.entity.Player) Nullable(org.jetbrains.annotations.Nullable) SkillTemplate(com.archyx.aureliumskills.menu.templates.SkillTemplate) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Lang(com.archyx.aureliumskills.lang.Lang) CloseItem(com.archyx.aureliumskills.menu.items.CloseItem) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) Locale(java.util.Locale) PlayerData(com.archyx.aureliumskills.data.PlayerData) Skill(com.archyx.aureliumskills.skills.Skill) ItemType(com.archyx.aureliumskills.menu.items.ItemType) YourSkillsItem(com.archyx.aureliumskills.menu.items.YourSkillsItem) Skills(com.archyx.aureliumskills.skills.Skills) ClickableItem(fr.minuskube.inv.ClickableItem) SkillTemplate(com.archyx.aureliumskills.menu.templates.SkillTemplate) YourSkillsItem(com.archyx.aureliumskills.menu.items.YourSkillsItem)

Aggregations

Skill (com.archyx.aureliumskills.skills.Skill)54 PlayerData (com.archyx.aureliumskills.data.PlayerData)15 Locale (java.util.Locale)15 Player (org.bukkit.entity.Player)13 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)12 File (java.io.File)11 IOException (java.io.IOException)9 ItemStack (org.bukkit.inventory.ItemStack)8 EventHandler (org.bukkit.event.EventHandler)7 Stat (com.archyx.aureliumskills.stats.Stat)6 InvalidCommandArgument (co.aikar.commands.InvalidCommandArgument)5 SkillValue (com.archyx.aureliumskills.leaderboard.SkillValue)5 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 AbilityData (com.archyx.aureliumskills.data.AbilityData)4 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)4 Map (java.util.Map)4 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)3 OptionL (com.archyx.aureliumskills.configuration.OptionL)3 Lang (com.archyx.aureliumskills.lang.Lang)3