Search in sources :

Example 51 with PlayerData

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

the class EnchantingAbilities method luckyTable.

@EventHandler(priority = EventPriority.HIGHEST)
public void luckyTable(EnchantItemEvent event) {
    if (event.isCancelled())
        return;
    if (blockDisabled(Ability.LUCKY_TABLE))
        return;
    Player player = event.getEnchanter();
    if (blockAbility(player))
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    if (playerData.getAbilityLevel(Ability.LUCKY_TABLE) > 0) {
        for (Map.Entry<Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
            if (entry.getKey().getMaxLevel() > entry.getValue()) {
                if (random.nextDouble() < getValue(Ability.LUCKY_TABLE, playerData) / 100) {
                    entry.setValue(entry.getValue() + 1);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Enchantment(org.bukkit.enchantments.Enchantment) PlayerData(com.archyx.aureliumskills.data.PlayerData) Map(java.util.Map) EventHandler(org.bukkit.event.EventHandler)

Example 52 with PlayerData

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

the class EnduranceAbilities method mealSteal.

@EventHandler(priority = EventPriority.HIGH)
public void mealSteal(EntityDamageByEntityEvent event) {
    if (blockDisabled(Ability.MEAL_STEAL))
        return;
    if (!event.isCancelled()) {
        // Checks if entity and damager are players
        if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
            Player player = (Player) event.getDamager();
            Player enemy = (Player) event.getEntity();
            if (blockAbility(player))
                return;
            PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
            if (playerData == null)
                return;
            // Calculates chance
            double chance = getValue(Ability.MEAL_STEAL, playerData) / 100;
            if (r.nextDouble() < chance) {
                // Removes food from enemy
                if (enemy.getFoodLevel() >= 1) {
                    enemy.setFoodLevel(enemy.getFoodLevel() - 1);
                }
                // Adds food level to player
                if (player.getFoodLevel() < 20) {
                    player.setFoodLevel(player.getFoodLevel() + 1);
                } else // Adds saturation if food is full
                if (player.getSaturation() < 20f) {
                    player.setSaturation(player.getSaturation() + 1f);
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 53 with PlayerData

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

the class ExcavationAbilities method biggerScoop.

@SuppressWarnings("deprecation")
public void biggerScoop(ExcavationSource source, Block block, Player player) {
    if (!plugin.getAbilityManager().isEnabled(Ability.BIGGER_SCOOP))
        return;
    PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
    if (playerData == null)
        return;
    if (player.getGameMode() != GameMode.SURVIVAL)
        return;
    if (r.nextDouble() < (getValue(Ability.BIGGER_SCOOP, playerData) / 100)) {
        ItemStack tool = player.getInventory().getItemInMainHand();
        Material mat = block.getType();
        for (ItemStack item : block.getDrops(tool)) {
            // If silk touch
            if (tool.getEnchantmentLevel(Enchantment.SILK_TOUCH) > 0) {
                PlayerLootDropEvent event;
                Location loc = block.getLocation().add(0.5, 0.5, 0.5);
                if (source.getLegacyData() == -1) {
                    event = new PlayerLootDropEvent(player, new ItemStack(mat, 2), loc, LootDropCause.BIGGER_SCOOP);
                } else {
                    if (VersionUtils.isAtLeastVersion(13)) {
                        event = new PlayerLootDropEvent(player, new ItemStack(mat, 2), loc, LootDropCause.BIGGER_SCOOP);
                    } else {
                        event = new PlayerLootDropEvent(player, new ItemStack(mat, 2, source.getLegacyData()), loc, LootDropCause.BIGGER_SCOOP);
                    }
                }
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    block.getWorld().dropItem(event.getLocation(), event.getItemStack());
                }
            } else // Drop regular item if not silk touch
            {
                ItemStack drop = item.clone();
                drop.setAmount(2);
                PlayerLootDropEvent event = new PlayerLootDropEvent(player, drop, block.getLocation().add(0.5, 0.5, 0.5), LootDropCause.BIGGER_SCOOP);
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) {
                    block.getWorld().dropItem(event.getLocation(), event.getItemStack());
                }
            }
        }
    }
}
Also used : PlayerLootDropEvent(com.archyx.aureliumskills.api.event.PlayerLootDropEvent) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.archyx.aureliumskills.data.PlayerData) Location(org.bukkit.Location)

Example 54 with PlayerData

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

the class AgilityAbilities method sugarRushSplash.

// For potion splashes
@EventHandler(priority = EventPriority.HIGH)
public void sugarRushSplash(PotionSplashEvent event) {
    if (!event.isCancelled()) {
        if (blockDisabled(Ability.SUGAR_RUSH))
            return;
        for (PotionEffect effect : event.getPotion().getEffects()) {
            if (effect.getType().equals(PotionEffectType.SPEED) || effect.getType().equals(PotionEffectType.JUMP)) {
                for (LivingEntity entity : event.getAffectedEntities()) {
                    if (entity instanceof Player) {
                        Player player = (Player) entity;
                        if (blockAbility(player))
                            return;
                        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
                        if (playerData == null)
                            return;
                        if (playerData.getAbilityLevel(Ability.SUGAR_RUSH) > 0) {
                            double intensity = event.getIntensity(player);
                            double multiplier = 1 + (getValue(Ability.SUGAR_RUSH, playerData) / 100);
                            PotionUtil.applyEffect(player, new PotionEffect(effect.getType(), (int) (effect.getDuration() * multiplier * intensity), effect.getAmplifier()));
                        }
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) PlayerData(com.archyx.aureliumskills.data.PlayerData) EventHandler(org.bukkit.event.EventHandler)

Example 55 with PlayerData

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

the class AgilityAbilities method sugarRushDrink.

// For potion drinking
@EventHandler(priority = EventPriority.HIGH)
public void sugarRushDrink(PlayerItemConsumeEvent event) {
    if (!event.isCancelled()) {
        if (blockDisabled(Ability.SUGAR_RUSH))
            return;
        Player player = event.getPlayer();
        if (blockAbility(player))
            return;
        PlayerData playerData = plugin.getPlayerManager().getPlayerData(player);
        if (playerData == null)
            return;
        if (playerData.getAbilityLevel(Ability.SUGAR_RUSH) > 0) {
            ItemStack item = event.getItem();
            if (item.getType() == Material.POTION) {
                if (item.getItemMeta() instanceof PotionMeta) {
                    PotionMeta meta = (PotionMeta) item.getItemMeta();
                    PotionData potion = meta.getBasePotionData();
                    double multiplier = 1 + (getValue(Ability.SUGAR_RUSH, playerData) / 100);
                    if (potion.getType() == PotionType.SPEED || potion.getType() == PotionType.JUMP) {
                        int amplifier = 0;
                        if (potion.isUpgraded()) {
                            amplifier = 1;
                        }
                        PotionEffectType potionEffectType;
                        if (potion.getType() == PotionType.SPEED) {
                            potionEffectType = PotionEffectType.SPEED;
                        } else {
                            potionEffectType = PotionEffectType.JUMP;
                        }
                        int duration;
                        if (potion.isExtended()) {
                            duration = 480;
                        } else if (potion.isUpgraded()) {
                            duration = 90;
                        } else {
                            duration = 180;
                        }
                        duration = (int) (multiplier * duration);
                        PotionUtil.applyEffect(player, new PotionEffect(potionEffectType, duration * 20, amplifier));
                    }
                    // Apply custom effects
                    if (meta.hasCustomEffects()) {
                        for (PotionEffect effect : meta.getCustomEffects()) {
                            if (effect.getType().equals(PotionEffectType.SPEED) || effect.getType().equals(PotionEffectType.JUMP)) {
                                PotionUtil.applyEffect(player, new PotionEffect(effect.getType(), (int) (effect.getDuration() * multiplier), effect.getAmplifier()));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PotionData(org.bukkit.potion.PotionData) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack) 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