Search in sources :

Example 26 with Skill

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

the class DefenseLeveler method onDamage.

@EventHandler(priority = EventPriority.MONITOR)
@SuppressWarnings("deprecation")
public void onDamage(EntityDamageByEntityEvent event) {
    if (OptionL.isEnabled(Skills.DEFENSE)) {
        // Checks cancelled
        if (OptionL.getBoolean(Option.DEFENSE_CHECK_CANCELLED)) {
            if (event.isCancelled()) {
                return;
            }
        }
        if (event.getEntity() instanceof Player) {
            if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) {
                Player player = (Player) event.getEntity();
                if (blockXpGain(player))
                    return;
                if (!OptionL.getBoolean(Option.DEFENSE_ALLOW_SHIELD_BLOCKING)) {
                    // Check for shield blocking
                    if (player.isBlocking()) {
                        return;
                    }
                }
                Skill skill = Skills.DEFENSE;
                double originalDamage = event.getOriginalDamage(EntityDamageEvent.DamageModifier.BASE);
                if (event.getFinalDamage() < player.getHealth()) {
                    // Player Damage
                    if (event.getDamager() instanceof Player) {
                        if (event.getDamager().equals(player))
                            return;
                        if (originalDamage * getXp(DefenseSource.PLAYER_DAMAGE) <= OptionL.getDouble(Option.DEFENSE_MAX)) {
                            if (originalDamage * getXp(DefenseSource.PLAYER_DAMAGE) >= OptionL.getDouble(Option.DEFENSE_MIN)) {
                                plugin.getLeveler().addXp(player, skill, originalDamage * getXp(player, DefenseSource.PLAYER_DAMAGE));
                            }
                        } else {
                            plugin.getLeveler().addXp(player, skill, getXp(player, OptionL.getDouble(Option.DEFENSE_MAX)));
                        }
                    } else // Mob damage
                    {
                        // Make sure player didn't cause own damage
                        if (event.getDamager() instanceof Projectile) {
                            Projectile projectile = (Projectile) event.getDamager();
                            if (projectile.getShooter() instanceof Player) {
                                if (projectile.getShooter().equals(player))
                                    return;
                            }
                        }
                        if (originalDamage * getXp(DefenseSource.MOB_DAMAGE) <= OptionL.getDouble(Option.DEFENSE_MAX)) {
                            if (originalDamage * getXp(DefenseSource.MOB_DAMAGE) >= OptionL.getDouble(Option.DEFENSE_MIN)) {
                                plugin.getLeveler().addXp(player, skill, originalDamage * getXp(player, DefenseSource.MOB_DAMAGE));
                            }
                        } else {
                            plugin.getLeveler().addXp(player, skill, getXp(player, OptionL.getDouble(Option.DEFENSE_MAX)));
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 27 with Skill

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

the class HealingLeveler method onLingeringPotionSplash.

@EventHandler
@SuppressWarnings("deprecation")
public void onLingeringPotionSplash(LingeringPotionSplashEvent event) {
    if (!OptionL.isEnabled(Skills.HEALING))
        return;
    // Check cancelled
    if (OptionL.getBoolean(Option.HEALING_CHECK_CANCELLED)) {
        if (event.isCancelled()) {
            return;
        }
    }
    ProjectileHitEvent projEvent = event;
    if (!(projEvent.getEntity().getShooter() instanceof Player))
        return;
    Player player = (Player) projEvent.getEntity().getShooter();
    if (player == null) {
        return;
    }
    PotionMeta meta;
    Projectile projectile = projEvent.getEntity();
    if (VersionUtils.isAtLeastVersion(14)) {
        if (!(projectile instanceof ThrownPotion)) {
            return;
        }
        ThrownPotion thrownPotion = (ThrownPotion) projectile;
        if (thrownPotion.getEffects().size() == 0)
            return;
        if (!(thrownPotion.getItem().getItemMeta() instanceof PotionMeta))
            return;
        meta = (PotionMeta) thrownPotion.getItem().getItemMeta();
    } else {
        // 1.12-1.13 compatibility
        if (!(projectile instanceof LingeringPotion)) {
            return;
        }
        LingeringPotion lingeringPotion = (LingeringPotion) projectile;
        if (lingeringPotion.getEffects().size() == 0)
            return;
        if (!(lingeringPotion.getItem().getItemMeta() instanceof PotionMeta))
            return;
        meta = (PotionMeta) lingeringPotion.getItem().getItemMeta();
    }
    PotionData data = meta.getBasePotionData();
    if (OptionL.getBoolean(Option.HEALING_EXCLUDE_NEGATIVE_POTIONS) && PotionUtil.isNegativePotion(data.getType())) {
        return;
    }
    Skill skill = Skills.HEALING;
    if (blockXpGain(player))
        return;
    if (!data.getType().equals(PotionType.MUNDANE) && !data.getType().equals(PotionType.THICK) && !data.getType().equals(PotionType.WATER) && !data.getType().equals(PotionType.AWKWARD)) {
        if (data.isExtended()) {
            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.LINGERING_EXTENDED));
        } else if (data.isUpgraded()) {
            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.LINGERING_UPGRADED));
        } else {
            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.LINGERING_REGULAR));
        }
    }
}
Also used : ProjectileHitEvent(org.bukkit.event.entity.ProjectileHitEvent) Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) PotionData(org.bukkit.potion.PotionData) ThrownPotion(org.bukkit.entity.ThrownPotion) LingeringPotion(org.bukkit.entity.LingeringPotion) PotionMeta(org.bukkit.inventory.meta.PotionMeta) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 28 with Skill

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

the class HealingLeveler method onThrow.

@EventHandler(priority = EventPriority.HIGHEST)
public void onThrow(PotionSplashEvent event) {
    if (OptionL.isEnabled(Skills.HEALING)) {
        // Check cancelled
        if (OptionL.getBoolean(Option.HEALING_CHECK_CANCELLED)) {
            if (event.isCancelled()) {
                return;
            }
        }
        if (event.getPotion().getEffects().size() > 0) {
            if (event.getEntity().getShooter() instanceof Player) {
                if (event.getPotion().getItem().getItemMeta() instanceof PotionMeta) {
                    Player player = (Player) event.getEntity().getShooter();
                    PotionMeta meta = (PotionMeta) event.getPotion().getItem().getItemMeta();
                    PotionData data = meta.getBasePotionData();
                    if (OptionL.getBoolean(Option.HEALING_EXCLUDE_NEGATIVE_POTIONS) && PotionUtil.isNegativePotion(data.getType())) {
                        return;
                    }
                    Skill skill = Skills.HEALING;
                    if (blockXpGain(player))
                        return;
                    if (!data.getType().equals(PotionType.MUNDANE) && !data.getType().equals(PotionType.THICK) && !data.getType().equals(PotionType.WATER) && !data.getType().equals(PotionType.AWKWARD)) {
                        if (data.isExtended()) {
                            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.SPLASH_EXTENDED));
                        } else if (data.isUpgraded()) {
                            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.SPLASH_UPGRADED));
                        } else {
                            plugin.getLeveler().addXp(player, skill, getXp(player, HealingSource.SPLASH_REGULAR));
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) PotionData(org.bukkit.potion.PotionData) PotionMeta(org.bukkit.inventory.meta.PotionMeta) EventHandler(org.bukkit.event.EventHandler)

Example 29 with Skill

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

the class HealingLeveler method onConsume.

@EventHandler(priority = EventPriority.HIGHEST)
@SuppressWarnings("deprecation")
public void onConsume(PlayerItemConsumeEvent event) {
    if (OptionL.isEnabled(Skills.HEALING)) {
        // Check cancelled
        if (OptionL.getBoolean(Option.HEALING_CHECK_CANCELLED)) {
            if (event.isCancelled()) {
                return;
            }
        }
        if (blockXpGain(event.getPlayer()))
            return;
        Player player = event.getPlayer();
        Skill skill = Skills.HEALING;
        Leveler leveler = plugin.getLeveler();
        if (event.getItem().getType().equals(Material.POTION)) {
            if (event.getItem().getItemMeta() instanceof PotionMeta) {
                PotionMeta meta = (PotionMeta) event.getItem().getItemMeta();
                PotionData data = meta.getBasePotionData();
                if (OptionL.getBoolean(Option.HEALING_EXCLUDE_NEGATIVE_POTIONS) && PotionUtil.isNegativePotion(data.getType())) {
                    return;
                }
                if (!data.getType().equals(PotionType.MUNDANE) && !data.getType().equals(PotionType.THICK) && !data.getType().equals(PotionType.WATER) && !data.getType().equals(PotionType.AWKWARD)) {
                    if (data.isExtended()) {
                        leveler.addXp(player, skill, getXp(player, HealingSource.DRINK_EXTENDED));
                    } else if (data.isUpgraded()) {
                        leveler.addXp(player, skill, getXp(player, HealingSource.DRINK_UPGRADED));
                    } else {
                        leveler.addXp(player, skill, getXp(player, HealingSource.DRINK_REGULAR));
                    }
                }
            }
        } else if (XMaterial.isNewVersion()) {
            if (event.getItem().getType().equals(Material.GOLDEN_APPLE)) {
                leveler.addXp(player, skill, getXp(player, HealingSource.GOLDEN_APPLE));
            } else if (event.getItem().getType().equals(XMaterial.ENCHANTED_GOLDEN_APPLE.parseMaterial())) {
                leveler.addXp(player, skill, getXp(player, HealingSource.ENCHANTED_GOLDEN_APPLE));
            }
        } else {
            if (event.getItem().getType().equals(Material.GOLDEN_APPLE)) {
                MaterialData materialData = event.getItem().getData();
                if (materialData != null) {
                    if (materialData.getData() == 0) {
                        leveler.addXp(player, skill, getXp(player, HealingSource.GOLDEN_APPLE));
                    } else if (materialData.getData() == 1) {
                        leveler.addXp(player, skill, getXp(player, HealingSource.ENCHANTED_GOLDEN_APPLE));
                    }
                }
            }
        }
    }
}
Also used : Leveler(com.archyx.aureliumskills.leveler.Leveler) SkillLeveler(com.archyx.aureliumskills.leveler.SkillLeveler) Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) PotionData(org.bukkit.potion.PotionData) PotionMeta(org.bukkit.inventory.meta.PotionMeta) MaterialData(org.bukkit.material.MaterialData) EventHandler(org.bukkit.event.EventHandler)

Example 30 with Skill

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

the class AureliumSkills method registerCommands.

private void registerCommands() {
    commandManager.enableUnstableAPI("help");
    commandManager.usePerIssuerLocale(true, false);
    commandManager.getCommandContexts().registerContext(Stat.class, c -> {
        String input = c.popFirstArg();
        Stat stat = statRegistry.getStat(input);
        if (stat != null) {
            return stat;
        } else {
            throw new InvalidCommandArgument("Stat " + input + " not found!");
        }
    });
    commandManager.getCommandContexts().registerContext(Skill.class, c -> {
        String input = c.popFirstArg();
        Skill skill = skillRegistry.getSkill(input);
        if (skill != null) {
            return skill;
        } else {
            throw new InvalidCommandArgument("Skill " + input + " not found!");
        }
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("skills", c -> {
        List<String> values = new ArrayList<>();
        for (Skill skill : skillRegistry.getSkills()) {
            if (OptionL.isEnabled(skill)) {
                values.add(skill.toString().toLowerCase(Locale.ENGLISH));
            }
        }
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("skills_global", c -> {
        List<String> values = new ArrayList<>();
        values.add("global");
        for (Skill skill : skillRegistry.getSkills()) {
            if (OptionL.isEnabled(skill)) {
                values.add(skill.toString().toLowerCase(Locale.ENGLISH));
            }
        }
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("skillTop", c -> {
        List<String> values = new ArrayList<>();
        for (Skill skill : skillRegistry.getSkills()) {
            if (OptionL.isEnabled(skill)) {
                values.add(skill.toString().toLowerCase(Locale.ENGLISH));
            }
        }
        values.add("average");
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("stats", c -> {
        List<String> values = new ArrayList<>();
        for (Stat stat : statRegistry.getStats()) {
            values.add(stat.toString().toLowerCase(Locale.ENGLISH));
        }
        return values;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("lang", c -> Lang.getDefinedLanguagesSet());
    commandManager.getCommandCompletions().registerAsyncCompletion("modifiers", c -> {
        Player player = c.getPlayer();
        PlayerData playerData = getPlayerManager().getPlayerData(player);
        if (playerData != null) {
            return playerData.getStatModifiers().keySet();
        }
        return null;
    });
    commandManager.getCommandCompletions().registerAsyncCompletion("item_keys", c -> itemRegistry.getKeys());
    commandManager.registerCommand(new SkillsCommand(this));
    commandManager.registerCommand(new StatsCommand(this));
    commandManager.registerCommand(new ManaCommand(this));
    if (OptionL.getBoolean(Option.ENABLE_SKILL_COMMANDS)) {
        if (OptionL.isEnabled(Skills.FARMING)) {
            commandManager.registerCommand(new SkillCommands.FarmingCommand(this));
        }
        if (OptionL.isEnabled(Skills.FORAGING)) {
            commandManager.registerCommand(new SkillCommands.ForagingCommand(this));
        }
        if (OptionL.isEnabled(Skills.MINING)) {
            commandManager.registerCommand(new SkillCommands.MiningCommand(this));
        }
        if (OptionL.isEnabled(Skills.FISHING)) {
            commandManager.registerCommand(new SkillCommands.FishingCommand(this));
        }
        if (OptionL.isEnabled(Skills.EXCAVATION)) {
            commandManager.registerCommand(new SkillCommands.ExcavationCommand(this));
        }
        if (OptionL.isEnabled(Skills.ARCHERY)) {
            commandManager.registerCommand(new SkillCommands.ArcheryCommand(this));
        }
        if (OptionL.isEnabled(Skills.DEFENSE)) {
            commandManager.registerCommand(new SkillCommands.DefenseCommand(this));
        }
        if (OptionL.isEnabled(Skills.FIGHTING)) {
            commandManager.registerCommand(new SkillCommands.FightingCommand(this));
        }
        if (OptionL.isEnabled(Skills.ENDURANCE)) {
            commandManager.registerCommand(new SkillCommands.EnduranceCommand(this));
        }
        if (OptionL.isEnabled(Skills.AGILITY)) {
            commandManager.registerCommand(new SkillCommands.AgilityCommand(this));
        }
        if (OptionL.isEnabled(Skills.ALCHEMY)) {
            commandManager.registerCommand(new SkillCommands.AlchemyCommand(this));
        }
        if (OptionL.isEnabled(Skills.ENCHANTING)) {
            commandManager.registerCommand(new SkillCommands.EnchantingCommand(this));
        }
        if (OptionL.isEnabled(Skills.SORCERY)) {
            commandManager.registerCommand(new SkillCommands.SorceryCommand(this));
        }
        if (OptionL.isEnabled(Skills.HEALING)) {
            commandManager.registerCommand(new SkillCommands.HealingCommand(this));
        }
        if (OptionL.isEnabled(Skills.FORGING)) {
            commandManager.registerCommand(new SkillCommands.ForgingCommand(this));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SkillCommands(com.archyx.aureliumskills.commands.SkillCommands) ManaCommand(com.archyx.aureliumskills.commands.ManaCommand) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) StatsCommand(com.archyx.aureliumskills.commands.StatsCommand) SkillsCommand(com.archyx.aureliumskills.commands.SkillsCommand) Player(org.bukkit.entity.Player) Skill(com.archyx.aureliumskills.skills.Skill) PlayerData(com.archyx.aureliumskills.data.PlayerData)

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