Search in sources :

Example 36 with PlayerData

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

the class ForgingAbilities method anvilMaster.

@EventHandler(priority = EventPriority.MONITOR)
public void anvilMaster(InventoryOpenEvent event) {
    if (event.isCancelled())
        return;
    if (blockDisabled(Ability.ANVIL_MASTER))
        return;
    if (!XMaterial.isNewVersion())
        return;
    Inventory inventory = event.getInventory();
    if (inventory.getType() == InventoryType.ANVIL && inventory instanceof AnvilInventory) {
        AnvilInventory anvil = (AnvilInventory) inventory;
        if (event.getPlayer() instanceof Player) {
            Player player = (Player) event.getPlayer();
            if (blockAbility(player))
                return;
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData == null)
                return;
            if (playerData.getAbilityLevel(Ability.ANVIL_MASTER) > 0) {
                int maxCost = (int) Math.round(getValue(Ability.ANVIL_MASTER, playerData));
                anvil.setMaximumRepairCost(maxCost);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) AnvilInventory(org.bukkit.inventory.AnvilInventory) PlayerData(com.archyx.aureliumskills.data.PlayerData) Inventory(org.bukkit.inventory.Inventory) AnvilInventory(org.bukkit.inventory.AnvilInventory) EventHandler(org.bukkit.event.EventHandler)

Example 37 with PlayerData

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

the class ForgingAbilities method disenchanter.

@EventHandler(priority = EventPriority.MONITOR)
public void disenchanter(InventoryClickEvent event) {
    if (event.isCancelled())
        return;
    if (blockDisabled(Ability.DISENCHANTER))
        return;
    // This ability requires at least 1.14
    if (!VersionUtils.isAtLeastVersion(14))
        return;
    if (event.getWhoClicked() instanceof Player) {
        Player player = (Player) event.getWhoClicked();
        if (blockAbility(player))
            return;
        Inventory inventory = event.getClickedInventory();
        if (inventory == null)
            return;
        ClickType click = event.getClick();
        // Only allow right and left clicks if inventory full
        if (click != ClickType.LEFT && click != ClickType.RIGHT && ItemUtils.isInventoryFull(player))
            return;
        // Make sure the click was successful
        if (event.getResult() != Event.Result.ALLOW)
            return;
        // Make sure cursor is empty
        if (player.getItemOnCursor().getType() != Material.AIR)
            return;
        if (event.getClickedInventory().getType() == InventoryType.GRINDSTONE) {
            if (event.getSlotType() == InventoryType.SlotType.RESULT) {
                PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                if (playerData == null)
                    return;
                if (playerData.getAbilityLevel(Ability.DISENCHANTER) == 0)
                    return;
                Location location = inventory.getLocation();
                if (location == null)
                    return;
                ItemStack first = inventory.getItem(0);
                ItemStack second = inventory.getItem(1);
                if (first != null && second != null) {
                    // If two items, make sure items are the same type
                    if (first.getType() != second.getType()) {
                        return;
                    }
                }
                Set<EnchantmentValue> enchants = new HashSet<>();
                // Add enchants to disenchant
                checkEnchants(first, enchants);
                checkEnchants(second, enchants);
                if (enchants.size() == 0)
                    return;
                // Calculate the sum
                try {
                    int sum = 0;
                    for (EnchantmentValue value : enchants) {
                        String enchantName = value.getEnchantment().getKey().getKey().toUpperCase(Locale.ENGLISH);
                        if (containsEnchant(enchantName)) {
                            sum += GrindstoneEnchant.valueOf(enchantName).getLevel(value.getLevel());
                        }
                    }
                    // Get the average experience that would drop
                    int average = (sum + (int) Math.ceil(((double) sum) / 2)) / 2;
                    int added = (int) Math.round(average * (getValue(Ability.DISENCHANTER, playerData) / 100));
                    World world = location.getWorld();
                    if (world != null) {
                        world.spawn(location, ExperienceOrb.class).setExperience(added);
                    }
                } catch (IllegalArgumentException ignored) {
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ExperienceOrb(org.bukkit.entity.ExperienceOrb) World(org.bukkit.World) EnchantmentValue(com.archyx.aureliumskills.util.mechanics.EnchantmentValue) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) Inventory(org.bukkit.inventory.Inventory) AnvilInventory(org.bukkit.inventory.AnvilInventory) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 38 with PlayerData

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

the class ForgingAbilities method skillMender.

@EventHandler(priority = EventPriority.MONITOR)
@SuppressWarnings("deprecation")
public void skillMender(XpGainEvent event) {
    if (event.isCancelled())
        return;
    if (blockDisabled(Ability.SKILL_MENDER))
        return;
    Player player = event.getPlayer();
    if (blockAbility(player))
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    if (playerData.getAbilityLevel(Ability.SKILL_MENDER) == 0)
        return;
    if (random.nextDouble() < getValue(Ability.SKILL_MENDER, playerData) / 100) {
        // Get all the items that have mending
        List<ItemStack> mendingItems = new ArrayList<>();
        for (ItemStack item : player.getInventory().getArmorContents()) {
            if (item != null) {
                if (item.containsEnchantment(Enchantment.MENDING) && hasDamage(item)) {
                    mendingItems.add(item);
                }
            }
        }
        ItemStack mainHandItem = player.getInventory().getItemInMainHand();
        if (mainHandItem.containsEnchantment(Enchantment.MENDING) && hasDamage(mainHandItem)) {
            mendingItems.add(mainHandItem);
        }
        ItemStack offHandItem = player.getInventory().getItemInOffHand();
        if (offHandItem.containsEnchantment(Enchantment.MENDING) && hasDamage(offHandItem)) {
            mendingItems.add(offHandItem);
        }
        if (mendingItems.size() == 0)
            return;
        // Pick a random item
        ItemStack mendedItem = mendingItems.get(random.nextInt(mendingItems.size()));
        // One durability per 2 skill xp gained
        int durabilityToRepair = (int) Math.round(event.getAmount() / 2);
        // Apply durability repair
        if (XMaterial.isNewVersion()) {
            ItemMeta meta = mendedItem.getItemMeta();
            if (meta == null)
                return;
            if (meta instanceof Damageable) {
                Damageable damageable = (Damageable) meta;
                damageable.setDamage(Math.max(damageable.getDamage() - durabilityToRepair, 0));
                mendedItem.setItemMeta(damageable);
            }
        } else {
            mendedItem.setDurability((short) Math.max(mendedItem.getDurability() - durabilityToRepair, 0));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Damageable(org.bukkit.inventory.meta.Damageable) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 39 with PlayerData

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

the class HealingAbilities method goldenHeart.

@EventHandler(priority = EventPriority.HIGHEST)
public void goldenHeart(EntityDamageEvent event) {
    if (blockDisabled(Ability.GOLDEN_HEART))
        return;
    if (event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if (blockAbility(player))
            return;
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        if (getAbsorptionAmount(player) > 0 && playerData.getAbilityLevel(Ability.GOLDEN_HEART) > 0) {
            double multiplier = 1 - getValue(Ability.GOLDEN_HEART, playerData) / 100;
            if (multiplier < 0.01) {
                // Cap at 99% reduction
                multiplier = 0.01;
            }
            event.setDamage(event.getDamage() * multiplier);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 40 with PlayerData

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

the class HealingAbilities method revival.

@EventHandler
public void revival(PlayerRespawnEvent event) {
    if (blockDisabled(Ability.REVIVAL))
        return;
    Player player = event.getPlayer();
    if (blockAbility(player))
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    if (playerData.getAbilityLevel(Ability.REVIVAL) > 0) {
        double healthBonus = getValue(Ability.REVIVAL, playerData);
        double regenerationBonus = getValue2(Ability.REVIVAL, playerData);
        StatModifier healthModifier = new StatModifier("AureliumSkills.Ability.Revival.Health", Stats.HEALTH, healthBonus);
        StatModifier regenerationModifier = new StatModifier("AureliumSkills.Ability.Revival.Regeneration", Stats.REGENERATION, regenerationBonus);
        playerData.addStatModifier(healthModifier);
        playerData.addStatModifier(regenerationModifier);
        if (plugin.getAbilityManager().getOptionAsBooleanElseTrue(Ability.REVIVAL, "enable_message")) {
            Locale locale = playerData.getLocale();
            plugin.getAbilityManager().sendMessage(player, TextUtil.replace(Lang.getMessage(AbilityMessage.REVIVAL_MESSAGE, locale), "{value}", NumberUtil.format1(healthBonus), "{value_2}", NumberUtil.format1(regenerationBonus)));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                playerData.removeStatModifier("AureliumSkills.Ability.Revival.Health");
                playerData.removeStatModifier("AureliumSkills.Ability.Revival.Regeneration");
            }
        }.runTaskLater(plugin, 30 * 20);
    }
}
Also used : Locale(java.util.Locale) StatModifier(com.archyx.aureliumskills.modifier.StatModifier) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

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