Search in sources :

Example 26 with PlayerData

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

the class ArmorModifierListener method onJoin.

@EventHandler(priority = EventPriority.LOWEST)
public void onJoin(PlayerDataLoadEvent event) {
    Player player = event.getPlayerData().getPlayer();
    PlayerData playerData = event.getPlayerData();
    for (ItemStack armor : player.getInventory().getArmorContents()) {
        if (armor != null) {
            if (OptionL.getBoolean(Option.MODIFIER_ARMOR_TIMER_ENABLED)) {
                storedArmor.computeIfAbsent(player.getUniqueId(), k -> new HashMap<>()).put(ArmorType.matchType(armor), armor.clone());
            }
            if (!armor.getType().equals(Material.AIR)) {
                if (requirements.meetsRequirements(ModifierType.ARMOR, armor, player)) {
                    for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, armor)) {
                        playerData.addStatModifier(modifier, false);
                    }
                    for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, armor)) {
                        playerData.addMultiplier(multiplier);
                    }
                }
            }
        }
    }
}
Also used : java.util(java.util) Requirements(com.archyx.aureliumskills.requirement.Requirements) PlayerDataLoadEvent(com.archyx.aureliumskills.data.PlayerDataLoadEvent) StatLeveler(com.archyx.aureliumskills.stats.StatLeveler) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) OptionL(com.archyx.aureliumskills.configuration.OptionL) Player(org.bukkit.entity.Player) ArmorEquipEvent(com.archyx.aureliumskills.util.armor.ArmorEquipEvent) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler) Option(com.archyx.aureliumskills.configuration.Option) AureliumSkills(com.archyx.aureliumskills.AureliumSkills) Stat(com.archyx.aureliumskills.stats.Stat) EventPriority(org.bukkit.event.EventPriority) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) PlayerData(com.archyx.aureliumskills.data.PlayerData) ArmorType(com.archyx.aureliumskills.util.armor.ArmorType) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 27 with PlayerData

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

the class ArmorModifierListener method onEquip.

@EventHandler
public void onEquip(ArmorEquipEvent event) {
    // Don't use if timer is enabled
    if (OptionL.getBoolean(Option.MODIFIER_ARMOR_TIMER_ENABLED))
        return;
    Player player = event.getPlayer();
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData != null) {
        // Equip
        if (event.getNewArmorPiece() != null && event.getNewArmorPiece().getType() != Material.AIR) {
            ItemStack item = event.getNewArmorPiece();
            if (requirements.meetsRequirements(ModifierType.ARMOR, item, player)) {
                for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, item)) {
                    playerData.addStatModifier(modifier);
                }
                for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, item)) {
                    playerData.addMultiplier(multiplier);
                }
            }
        }
        // Un-equip
        if (event.getOldArmorPiece() != null && event.getOldArmorPiece().getType() != Material.AIR) {
            ItemStack item = event.getOldArmorPiece();
            for (StatModifier modifier : modifiers.getModifiers(ModifierType.ARMOR, item)) {
                playerData.removeStatModifier(modifier.getName());
            }
            for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ARMOR, item)) {
                playerData.removeMultiplier(multiplier.getName());
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 28 with PlayerData

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

the class ItemListener method onJoin.

@EventHandler(priority = EventPriority.LOW)
public void onJoin(PlayerDataLoadEvent event) {
    Player player = event.getPlayerData().getPlayer();
    ItemStack held = player.getInventory().getItemInMainHand();
    heldItems.put(player.getUniqueId(), held);
    PlayerData playerData = event.getPlayerData();
    if (!held.getType().equals(Material.AIR)) {
        if (OptionL.getBoolean(Option.MODIFIER_AUTO_CONVERT_FROM_LEGACY)) {
            held = requirements.convertFromLegacy(modifiers.convertFromLegacy(held));
            if (!held.equals(player.getInventory().getItemInMainHand())) {
                player.getInventory().setItemInMainHand(held);
            }
        }
        for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, held)) {
            playerData.addStatModifier(modifier, false);
        }
        for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, held)) {
            playerData.addMultiplier(multiplier);
        }
    }
    if (OptionL.getBoolean(Option.MODIFIER_ITEM_ENABLE_OFF_HAND)) {
        ItemStack offHandItem = player.getInventory().getItemInOffHand();
        offHandItems.put(player.getUniqueId(), offHandItem);
        if (!offHandItem.getType().equals(Material.AIR)) {
            if (OptionL.getBoolean(Option.MODIFIER_AUTO_CONVERT_FROM_LEGACY)) {
                offHandItem = requirements.convertFromLegacy(modifiers.convertFromLegacy(offHandItem));
                if (!offHandItem.equals(player.getInventory().getItemInOffHand())) {
                    player.getInventory().setItemInOffHand(offHandItem);
                }
            }
            for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, offHandItem)) {
                StatModifier offHandModifier = new StatModifier(modifier.getName() + ".Offhand", modifier.getStat(), modifier.getValue());
                playerData.addStatModifier(offHandModifier);
            }
            for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, offHandItem)) {
                Multiplier offHandMultiplier = new Multiplier(multiplier.getName() + ".Offhand", multiplier.getSkill(), multiplier.getValue());
                playerData.addMultiplier(offHandMultiplier);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 29 with PlayerData

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

the class ItemListener method onSwap.

@EventHandler(priority = EventPriority.MONITOR)
public void onSwap(PlayerSwapHandItemsEvent event) {
    if (!event.isCancelled()) {
        // Make sure event is not cancelled
        if (OptionL.getBoolean(Option.MODIFIER_ITEM_ENABLE_OFF_HAND)) {
            // Check off hand support is enabled
            Player player = event.getPlayer();
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData != null) {
                // Get items switched
                ItemStack itemOffHand = event.getOffHandItem();
                ItemStack itemMainHand = event.getMainHandItem();
                // Update items
                offHandItems.put(player.getUniqueId(), itemOffHand);
                heldItems.put(player.getUniqueId(), itemMainHand);
                // Things to prevent double reloads
                Set<String> offHandModifiers = new HashSet<>();
                Set<Stat> statsToReload = new HashSet<>();
                Set<String> offHandMultipliers = new HashSet<>();
                // Check off hand item
                if (itemOffHand != null) {
                    if (itemOffHand.getType() != Material.AIR) {
                        // Get whether player meets requirements
                        boolean meetsRequirements = requirements.meetsRequirements(ModifierType.ITEM, itemOffHand, player);
                        // For each modifier on the item
                        for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemOffHand)) {
                            // Removes the old modifier from main hand
                            StatModifier offHandModifier = new StatModifier(modifier.getName() + ".Offhand", modifier.getStat(), modifier.getValue());
                            playerData.removeStatModifier(modifier.getName(), false);
                            // Add new one if meets requirements
                            if (meetsRequirements) {
                                playerData.addStatModifier(offHandModifier, false);
                            }
                            // Reload check stuff
                            offHandModifiers.add(offHandModifier.getName());
                            statsToReload.add(modifier.getStat());
                        }
                        for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemOffHand)) {
                            Multiplier offHandMultiplier = new Multiplier(multiplier.getName() + ".Offhand", multiplier.getSkill(), multiplier.getValue());
                            playerData.removeMultiplier(multiplier.getName());
                            if (meetsRequirements) {
                                playerData.addMultiplier(offHandMultiplier);
                            }
                            offHandMultipliers.add(offHandMultiplier.getName());
                        }
                    }
                }
                // Check main hand item
                if (itemMainHand != null) {
                    if (itemMainHand.getType() != Material.AIR) {
                        // Get whether player meets requirements
                        boolean meetsRequirements = requirements.meetsRequirements(ModifierType.ITEM, itemMainHand, player);
                        // For each modifier on the item
                        for (StatModifier modifier : modifiers.getModifiers(ModifierType.ITEM, itemMainHand)) {
                            // Removes the offhand modifier if wasn't already added
                            if (!offHandModifiers.contains(modifier.getName() + ".Offhand")) {
                                playerData.removeStatModifier(modifier.getName() + ".Offhand", false);
                            }
                            // Add if meets requirements
                            if (meetsRequirements) {
                                playerData.addStatModifier(modifier, false);
                            }
                            // Reload check stuff
                            statsToReload.add(modifier.getStat());
                        }
                        for (Multiplier multiplier : multipliers.getMultipliers(ModifierType.ITEM, itemMainHand)) {
                            if (!offHandMultipliers.contains(multiplier.getName() + ".Offhand")) {
                                playerData.removeMultiplier(multiplier.getName() + ".Offhand");
                            }
                            if (meetsRequirements) {
                                playerData.addMultiplier(multiplier);
                            }
                        }
                    }
                }
                // Reload stats
                for (Stat stat : statsToReload) {
                    statLeveler.reloadStat(player, stat);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Stat(com.archyx.aureliumskills.stats.Stat) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 30 with PlayerData

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

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