Search in sources :

Example 6 with Stat

use of com.archyx.aureliumskills.stats.Stat in project AureliumSkills by Archy-X.

the class ModifierManager method reloadPlayer.

public void reloadPlayer(Player player) {
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    Requirements requirements = new Requirements(plugin);
    Modifiers modifiers = new Modifiers(plugin);
    Multipliers multipliers = new Multipliers(plugin);
    if (playerData != null) {
        Set<Stat> statsToReload = new HashSet<>();
        ItemStack item = player.getInventory().getItemInMainHand();
        if (!(item.getType() == Material.AIR)) {
            for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, item)) {
                playerData.removeStatModifier(modifier.getName());
                statsToReload.add(modifier.getStat());
            }
            for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, item)) {
                playerData.removeMultiplier(multiplier.getName());
            }
            if (requirements.meetsRequirements(ModifierType.ITEM, item, player)) {
                for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, item)) {
                    playerData.addStatModifier(modifier, false);
                    statsToReload.add(modifier.getStat());
                }
                for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, item)) {
                    playerData.addMultiplier(multiplier);
                }
            }
        }
        ItemStack itemOffHand = player.getInventory().getItemInOffHand();
        if (!(itemOffHand.getType() == Material.AIR)) {
            for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemOffHand)) {
                playerData.removeStatModifier(modifier.getName() + ".Offhand");
                statsToReload.add(modifier.getStat());
            }
            for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemOffHand)) {
                playerData.removeMultiplier(multiplier.getName() + ".Offhand");
            }
            if (requirements.meetsRequirements(ModifierType.ITEM, itemOffHand, player)) {
                for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemOffHand)) {
                    StatModifier offHandModifier = new StatModifier(modifier.getName() + ".Offhand", modifier.getStat(), modifier.getValue());
                    playerData.addStatModifier(offHandModifier, false);
                    statsToReload.add(modifier.getStat());
                }
                for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemOffHand)) {
                    Multiplier offHandMultiplier = new Multiplier(multiplier.getName() + ".Offhand", multiplier.getSkill(), multiplier.getValue());
                    playerData.addMultiplier(offHandMultiplier);
                }
            }
        }
        EntityEquipment equipment = player.getEquipment();
        if (equipment != null) {
            for (ItemStack armor : equipment.getArmorContents()) {
                if (armor != null) {
                    if (!(armor.getType() == Material.AIR)) {
                        for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, armor)) {
                            playerData.removeStatModifier(modifier.getName());
                            statsToReload.add(modifier.getStat());
                        }
                        for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, armor)) {
                            playerData.removeMultiplier(multiplier.getName());
                        }
                        if (requirements.meetsRequirements(ModifierType.ARMOR, armor, player)) {
                            for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, armor)) {
                                playerData.addStatModifier(modifier, false);
                                statsToReload.add(modifier.getStat());
                            }
                            for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, armor)) {
                                playerData.addMultiplier(multiplier);
                            }
                        }
                    }
                }
            }
        }
        for (Stat stat : statsToReload) {
            statLeveler.reloadStat(player, stat);
        }
    }
}
Also used : Stat(com.archyx.aureliumskills.stats.Stat) EntityEquipment(org.bukkit.inventory.EntityEquipment) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) Requirements(com.archyx.aureliumskills.requirement.Requirements) HashSet(java.util.HashSet)

Example 7 with Stat

use of com.archyx.aureliumskills.stats.Stat in project AureliumSkills by Archy-X.

the class Modifiers method getLegacyModifiers.

public List<StatModifier> getLegacyModifiers(ModifierType type, NBTItem nbtItem) {
    if (isNBTDisabled())
        return new ArrayList<>();
    List<StatModifier> modifiers = new ArrayList<>();
    for (String key : nbtItem.getKeys()) {
        if (key.contains("skillsmodifier-" + type.name().toLowerCase(Locale.ENGLISH) + "-")) {
            String[] keySplit = key.split("-");
            if (keySplit.length == 3) {
                Stat stat = plugin.getStatRegistry().getStat(key.split("-")[2]);
                if (stat != null) {
                    int value = nbtItem.getInteger(key);
                    modifiers.add(new StatModifier(key, stat, value));
                }
            } else if (keySplit.length == 4) {
                Stat stat = plugin.getStatRegistry().getStat(key.split("-")[3]);
                if (stat != null) {
                    int value = nbtItem.getInteger(key);
                    modifiers.add(new StatModifier(key, stat, value));
                }
            }
        }
    }
    return modifiers;
}
Also used : Stat(com.archyx.aureliumskills.stats.Stat) ArrayList(java.util.ArrayList)

Example 8 with Stat

use of com.archyx.aureliumskills.stats.Stat in project AureliumSkills by Archy-X.

the class Modifiers method removeLore.

public void removeLore(ItemStack item, Stat stat, Locale locale) {
    ItemMeta meta = item.getItemMeta();
    if (meta != null) {
        List<String> lore = meta.getLore();
        if (lore != null && lore.size() > 0)
            lore.removeIf(line -> line.contains(stat.getDisplayName(locale)));
        meta.setLore(lore);
    }
    item.setItemMeta(meta);
}
Also used : ItemUtils(com.archyx.aureliumskills.util.item.ItemUtils) StringUtils(org.apache.commons.lang.StringUtils) ItemMeta(org.bukkit.inventory.meta.ItemMeta) NBTItem(de.tr7zw.changeme.nbtapi.NBTItem) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) TextUtil(com.archyx.aureliumskills.util.text.TextUtil) NBTCompound(de.tr7zw.changeme.nbtapi.NBTCompound) NBTAPIUser(com.archyx.aureliumskills.util.item.NBTAPIUser) List(java.util.List) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Lang(com.archyx.aureliumskills.lang.Lang) Stat(com.archyx.aureliumskills.stats.Stat) NumberUtil(com.archyx.aureliumskills.util.math.NumberUtil) Locale(java.util.Locale) CommandMessage(com.archyx.aureliumskills.lang.CommandMessage) LinkedList(java.util.LinkedList) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 9 with Stat

use of com.archyx.aureliumskills.stats.Stat in project AureliumSkills by Archy-X.

the class SkullItem method getItem.

public ItemStack getItem(Player player, PlayerData playerData, Locale locale) {
    ItemStack item = SkullCreator.itemFromUuid(player.getUniqueId());
    ItemMeta meta = item.getItemMeta();
    if (meta != null) {
        meta.setDisplayName(applyPlaceholders(TextUtil.replace(displayName, "{player}", player.getName()), 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) {
                Stat stat = plugin.getStatRegistry().getStat(placeholder);
                if (stat != null) {
                    line = TextUtil.replace(line, "{" + placeholder + "}", TextUtil.replace(Lang.getMessage(MenuMessage.PLAYER_STAT_ENTRY, locale), "{color}", stat.getColor(locale), "{symbol}", stat.getSymbol(locale), "{stat}", stat.getDisplayName(locale), "{level}", NumberUtil.format1(playerData.getStatLevel(stat))));
                }
            }
            builtLore.add(line);
        }
        meta.setLore(ItemUtils.formatLore(applyPlaceholders(builtLore, player)));
        item.setItemMeta(meta);
    }
    return item;
}
Also used : Stat(com.archyx.aureliumskills.stats.Stat) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 10 with Stat

use of com.archyx.aureliumskills.stats.Stat in project AureliumSkills by Archy-X.

the class StatModifier method applyPlaceholders.

public static String applyPlaceholders(String input, StatModifier modifier, Locale locale) {
    Stat stat = modifier.getStat();
    double value = modifier.getValue();
    String name = modifier.getName();
    return input.replace("{color}", stat.getColor(locale)).replace("{symbol}", stat.getSymbol(locale)).replace("{stat}", stat.getDisplayName(locale)).replace("{value}", NumberUtil.format1(value)).replace("{name}", name);
}
Also used : Stat(com.archyx.aureliumskills.stats.Stat)

Aggregations

Stat (com.archyx.aureliumskills.stats.Stat)16 PlayerData (com.archyx.aureliumskills.data.PlayerData)7 Skill (com.archyx.aureliumskills.skills.Skill)5 ItemStack (org.bukkit.inventory.ItemStack)5 ArrayList (java.util.ArrayList)4 StatModifier (com.archyx.aureliumskills.modifier.StatModifier)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 AbstractAbility (com.archyx.aureliumskills.ability.AbstractAbility)2 AbilityData (com.archyx.aureliumskills.data.AbilityData)2 PlayerDataLoadEvent (com.archyx.aureliumskills.data.PlayerDataLoadEvent)2 KeyIntPair (com.archyx.aureliumskills.util.misc.KeyIntPair)2 NBTCompound (de.tr7zw.changeme.nbtapi.NBTCompound)2 NBTItem (de.tr7zw.changeme.nbtapi.NBTItem)2 IOException (java.io.IOException)2 List (java.util.List)2 Player (org.bukkit.entity.Player)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 AureliumSkills (com.archyx.aureliumskills.AureliumSkills)1 CommandMessage (com.archyx.aureliumskills.lang.CommandMessage)1 Lang (com.archyx.aureliumskills.lang.Lang)1