<commit_before>package com.gmail.nossr50.skills.utilities;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.inventory.ItemStack;

import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.runnables.CombatXpGiver;
import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;

public final class CombatTools {
    private static Config configInstance = Config.getInstance();

    private CombatTools() {}

    /**
     * Apply combat modifiers and process and XP gain.
     *
     * @param event The event to run the combat checks on.
     */
    public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
        boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
        boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;

        if (attacker instanceof Player) {
            Player player = (Player) attacker;

            if (Misc.isNPCEntity(player)) {
                return;
            }

            if (target instanceof Tameable && isFriendlyPet(player, (Tameable) target)) {
                return;
            }

            ItemStack heldItem = player.getItemInHand();
            Material heldItemType = heldItem.getType();
            DamageCause damageCause = event.getCause();

            if (ItemChecks.isSword(heldItem) && damageCause == DamageCause.ENTITY_ATTACK) {
                if (targetIsPlayer || targetIsTamedPet) {
                    if (!SkillType.SWORDS.getPVPEnabled()) {
                        return;
                    }
                }
                else if (!SkillType.SWORDS.getPVEEnabled()) {
                    return;
                }

                if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
                    McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
                    PlayerProfile profile = mcMMOPlayer.getProfile();
                    SwordsManager swordsManager = new SwordsManager(mcMMOPlayer);
                    boolean canSerratedStrike = Permissions.serratedStrikes(player); //So we don't have to check the same permission twice

                    if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
                        SkillTools.abilityCheck(player, SkillType.SWORDS);
                    }

                    if (Permissions.bleed(player)) {
                        swordsManager.bleedCheck(target);
                    }

                    if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
                        swordsManager.serratedStrikes(target, event.getDamage());
                    }

                    startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
                }
            }
            else if (ItemChecks.isAxe(heldItem) && damageCause == DamageCause.ENTITY_ATTACK) {
                if (targetIsPlayer || targetIsTamedPet) {
                    if (!SkillType.AXES.getPVPEnabled()) {
                        return;
                    }
                }
                else if (!SkillType.AXES.getPVEEnabled()) {
                    return;
                }

                if (Permissions.skillEnabled(player, SkillType.AXES)) {
                    McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
                    PlayerProfile profile = mcMMOPlayer.getProfile();
                    AxeManager axeManager = new AxeManager(mcMMOPlayer);
                    boolean canSkullSplit = Permissions.skullSplitter(player); //So we don't have to check the same permission twice
                    if (profile.getToolPreparationMode(ToolType.AXE) && canSkullSplit) {
                        SkillTools.abilityCheck(player, SkillType.AXES);
                    }

                    if (Permissions.bonusDamage(player, axeManager.getSkill())) {
                        axeManager.bonusDamage(event);
                    }

                    if (!target.isDead() && Permissions.criticalStrikes(player)) {
                        axeManager.criticalHitCheck(event, target);
                    }

                    if (!target.isDead() && Permissions.armorImpact(player)) {
                        axeManager.impact(event, target);
                    }

                    if (!target.isDead() && profile.getAbilityMode(AbilityType.SKULL_SPLITTER) && canSkullSplit) {
                        axeManager.skullSplitter(target, event.getDamage());
                    }

                    startGainXp(mcMMOPlayer, target, SkillType.AXES);
                }
            }
            else if (heldItemType == Material.AIR && damageCause == DamageCause.ENTITY_ATTACK) {
                if (targetIsPlayer || targetIsTamedPet) {
                    if (!SkillType.UNARMED.getPVPEnabled()) {
                        return;
                    }
                }
                else if (!SkillType.UNARMED.getPVEEnabled()) {
                    return;
                }

                if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
                    McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
                    PlayerProfile profile = mcMMOPlayer.getProfile();
                    UnarmedManager unarmedManager = new UnarmedManager(mcMMOPlayer);
                    boolean canBerserk = Permissions.berserk(player); //So we don't have to check the same permission twice

                    if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
                        SkillTools.abilityCheck(player, SkillType.UNARMED);
                    }

                    if (Permissions.bonusDamage(player, unarmedManager.getSkill())) {
                        unarmedManager.bonusDamage(event);
                    }

                    if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
                        unarmedManager.berserkDamage(event);
                    }

                    if (target instanceof Player && Permissions.disarm(player)) {
                        unarmedManager.disarmCheck(target);
                    }

                    startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
                }
            }
            else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player) && damageCause == DamageCause.ENTITY_ATTACK) {
                TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
                tamingManager.beastLore(target);
                event.setCancelled(true);
            }
        }

        Entity damager = event.getDamager();

        switch (damager.getType()) {
        case WOLF:
            Wolf wolf = (Wolf) damager;

            if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
                Player master = (Player) wolf.getOwner();

                if (Misc.isNPCEntity(master)) {
                    return;<commit_msg>Fixes wolves gaining combat bonuses based on their owner's held item. Closes #713<commit_after>package com.gmail.nossr50.skills.utilities;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.inventory.ItemStack;

import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.McMMOPlayer;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.skills.acrobatics.Acrobatics;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.axes.AxeManager;
import com.gmail.nossr50.skills.runnables.BleedTimer;
import com.gmail.nossr50.skills.runnables.CombatXpGiver;
import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.Taming;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;

public final class CombatTools {
    private static Config configInstance = Config.getInstance();

    private CombatTools() {}

    /**
     * Apply combat modifiers and process and XP gain.
     *
     * @param event The event to run the combat checks on.
     */
    public static void combatChecks(EntityDamageByEntityEvent event, Entity attacker, LivingEntity target) {
        boolean targetIsPlayer = (target.getType() == EntityType.PLAYER);
        boolean targetIsTamedPet = (target instanceof Tameable) ? ((Tameable) target).isTamed() : false;
        Entity damager = event.getDamager();

        if (attacker instanceof Player && damager.getType() == EntityType.PLAYER) {
            Player player = (Player) attacker;

            if (Misc.isNPCEntity(player)) {
                return;
            }

            if (target instanceof Tameable && isFriendlyPet(player, (Tameable) target)) {
                return;
            }

            ItemStack heldItem = player.getItemInHand();
            Material heldItemType = heldItem.getType();

            if (ItemChecks.isSword(heldItem)) {
                if (targetIsPlayer || targetIsTamedPet) {
                    if (!SkillType.SWORDS.getPVPEnabled()) {
                        return;
                    }
                }
                else if (!SkillType.SWORDS.getPVEEnabled()) {
                    return;
                }

                if (Permissions.skillEnabled(player, SkillType.SWORDS)) {
                    McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
                    PlayerProfile profile = mcMMOPlayer.getProfile();
                    SwordsManager swordsManager = new SwordsManager(mcMMOPlayer);
                    boolean canSerratedStrike = Permissions.serratedStrikes(player); //So we don't have to check the same permission twice

                    if (profile.getToolPreparationMode(ToolType.SWORD) && canSerratedStrike) {
                        SkillTools.abilityCheck(player, SkillType.SWORDS);
                    }

                    if (Permissions.bleed(player)) {
                        swordsManager.bleedCheck(target);
                    }

                    if (profile.getAbilityMode(AbilityType.SERRATED_STRIKES) && canSerratedStrike) {
                        swordsManager.serratedStrikes(target, event.getDamage());
                    }

                    startGainXp(mcMMOPlayer, target, SkillType.SWORDS);
                }
            }
            else if (ItemChecks.isAxe(heldItem)) {
                if (targetIsPlayer || targetIsTamedPet) {
                    if (!SkillType.AXES.getPVPEnabled()) {
                        return;
                    }
                }
                else if (!SkillType.AXES.getPVEEnabled()) {
                    return;
                }

                if (Permissions.skillEnabled(player, SkillType.AXES)) {
                    McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
                    PlayerProfile profile = mcMMOPlayer.getProfile();
                    AxeManager axeManager = new AxeManager(mcMMOPlayer);
                    boolean canSkullSplit = Permissions.skullSplitter(player); //So we don't have to check the same permission twice
                    if (profile.getToolPreparationMode(ToolType.AXE) && canSkullSplit) {
                        SkillTools.abilityCheck(player, SkillType.AXES);
                    }

                    if (Permissions.bonusDamage(player, axeManager.getSkill())) {
                        axeManager.bonusDamage(event);
                    }

                    if (!target.isDead() && Permissions.criticalStrikes(player)) {
                        axeManager.criticalHitCheck(event, target);
                    }

                    if (!target.isDead() && Permissions.armorImpact(player)) {
                        axeManager.impact(event, target);
                    }

                    if (!target.isDead() && profile.getAbilityMode(AbilityType.SKULL_SPLITTER) && canSkullSplit) {
                        axeManager.skullSplitter(target, event.getDamage());
                    }

                    startGainXp(mcMMOPlayer, target, SkillType.AXES);
                }
            }
            else if (heldItemType == Material.AIR) {
                if (targetIsPlayer || targetIsTamedPet) {
                    if (!SkillType.UNARMED.getPVPEnabled()) {
                        return;
                    }
                }
                else if (!SkillType.UNARMED.getPVEEnabled()) {
                    return;
                }

                if (Permissions.skillEnabled(player, SkillType.UNARMED)) {
                    McMMOPlayer mcMMOPlayer = Users.getPlayer(player);
                    PlayerProfile profile = mcMMOPlayer.getProfile();
                    UnarmedManager unarmedManager = new UnarmedManager(mcMMOPlayer);
                    boolean canBerserk = Permissions.berserk(player); //So we don't have to check the same permission twice

                    if (profile.getToolPreparationMode(ToolType.FISTS) && canBerserk) {
                        SkillTools.abilityCheck(player, SkillType.UNARMED);
                    }

                    if (Permissions.bonusDamage(player, unarmedManager.getSkill())) {
                        unarmedManager.bonusDamage(event);
                    }

                    if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
                        unarmedManager.berserkDamage(event);
                    }

                    if (target instanceof Player && Permissions.disarm(player)) {
                        unarmedManager.disarmCheck(target);
                    }

                    startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
                }
            }
            else if (heldItemType == Material.BONE && target instanceof Tameable && Permissions.beastLore(player)) {
                TamingManager tamingManager = new TamingManager(Users.getPlayer(player));
                tamingManager.beastLore(target);
                event.setCancelled(true);
            }
        }

        switch (damager.getType()) {
        case WOLF:
            Wolf wolf = (Wolf) damager;

            if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
                Player master = (Player) wolf.getOwner();

                if (Misc.isNPCEntity(master)) {
                    return;
{'fraction_non_alphanumeric': 0.09308557115395817, 'fraction_numerical': 0.005999883497407817, 'mean_word_length': 1.9930264993026499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6078991', 'n_tokens_mistral': 5110, 'n_tokens_neox': 4759, 'n_words': 790}