Search in sources :

Example 6 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project NoCheatPlus by NoCheatPlus.

the class FightListener method onEntityDamage.

/**
 * We listen to EntityDamage events for obvious reasons.
 *
 * @param event
 *            the event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityDamage(final EntityDamageEvent event) {
    final Entity damaged = event.getEntity();
    final Player damagedPlayer = damaged instanceof Player ? (Player) damaged : null;
    final FightData damagedData;
    final boolean damagedIsDead = damaged.isDead();
    final boolean damagedIsFake = !crossPlugin.getHandle().isNativeEntity(damaged);
    IPenaltyList penaltyList = null;
    if (damagedPlayer != null) {
        final IPlayerData damagedPData = DataManager.getPlayerData(damagedPlayer);
        damagedData = damagedPData.getGenericInstance(FightData.class);
        if (!damagedIsDead) {
            // (Do not test the savage.)
            if (damagedPData.isCheckActive(CheckType.FIGHT_GODMODE, damagedPlayer)) {
                if (penaltyList == null) {
                    penaltyList = new DefaultPenaltyList();
                }
                if (godMode.check(damagedPlayer, damagedIsFake, BridgeHealth.getRawDamage(event), damagedData, damagedPData)) {
                    // It requested to "cancel" the players invulnerability, so set their noDamageTicks to 0.
                    damagedPlayer.setNoDamageTicks(0);
                }
            }
            // Adjust buffer for fast heal checks.
            if (BridgeHealth.getHealth(damagedPlayer) >= BridgeHealth.getMaxHealth(damagedPlayer)) {
                // TODO: Might use the same FightData instance for GodMode.
                if (damagedData.fastHealBuffer < 0) {
                    // Reduce negative buffer with each full health.
                    damagedData.fastHealBuffer /= 2;
                }
                // Set reference time.
                damagedData.fastHealRefTime = System.currentTimeMillis();
            }
        // TODO: TEST: Check unused velocity for the damaged player. (Needs more efficient pre condition checks.)
        }
        if (damagedPData.isDebugActive(checkType)) {
            // TODO: Pass result to further checks for reference?
            UnusedVelocity.checkUnusedVelocity(damagedPlayer, CheckType.FIGHT, damagedPData);
        }
    } else {
        damagedData = null;
    }
    // Attacking entities.
    if (event instanceof EntityDamageByEntityEvent) {
        if (penaltyList == null) {
            penaltyList = new DefaultPenaltyList();
        }
        onEntityDamageByEntity(damaged, damagedPlayer, damagedIsDead, damagedIsFake, damagedData, (EntityDamageByEntityEvent) event, penaltyList);
    }
    if (penaltyList != null && !penaltyList.isEmpty()) {
        if (penaltyList.hasGenericPenalties()) {
            penaltyList.applyAllApplicableGenericPenalties(event);
        }
        if (penaltyList.hasNonGenericPenalties()) {
            penaltyList.applyNonGenericPenalties(event);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) DefaultPenaltyList(fr.neatmonster.nocheatplus.actions.types.penalty.DefaultPenaltyList) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) IPenaltyList(fr.neatmonster.nocheatplus.actions.types.penalty.IPenaltyList) EventHandler(org.bukkit.event.EventHandler)

Example 7 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project solinia3-core by mixxit.

the class Solinia3CoreEntityListener method onEntityDamage.

@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if (event.isCancelled())
        return;
    if (!(event instanceof EntityDamageByEntityEvent)) {
        return;
    }
    EntityDamageByEntityEvent damagecause = (EntityDamageByEntityEvent) event;
    // If the event is being blocked by a shield negate 85% of it unless its thorns then always allow it through
    if (damagecause.getDamage(DamageModifier.BLOCKING) < 0) {
        if (event.getCause().equals(DamageCause.THORNS)) {
            damagecause.setDamage(DamageModifier.BLOCKING, 0);
        } else {
            // Only give them 15% blocking
            double newarmour = (damagecause.getDamage(DamageModifier.BLOCKING) / 100) * 15;
            damagecause.setDamage(DamageModifier.BLOCKING, newarmour);
        }
    }
    // and check they are not mezzed
    try {
        if (damagecause.getDamager() instanceof LivingEntity) {
            LivingEntity attacker = (LivingEntity) damagecause.getDamager();
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) attacker;
                if (arr.getShooter() instanceof LivingEntity) {
                    attacker = (LivingEntity) arr.getShooter();
                } else {
                }
            }
            // cancel attacks on mobs mezzed
            if (attacker instanceof Creature && attacker instanceof LivingEntity && event.getEntity() instanceof LivingEntity) {
                ISoliniaLivingEntity solCreatureEntity = SoliniaLivingEntityAdapter.Adapt(attacker);
                if (solCreatureEntity.isPet() || !solCreatureEntity.isPlayer()) {
                    Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) event.getEntity());
                    if (mezExpiry != null) {
                        ((Creature) attacker).setTarget(null);
                        if (solCreatureEntity.isPet()) {
                            Wolf wolf = (Wolf) attacker;
                            wolf.setTarget(null);
                            solCreatureEntity.say("Stopping attacking master, the target is mesmerized");
                        }
                        event.setCancelled(true);
                        return;
                    }
                }
            }
            try {
                Timestamp mzExpiry = StateManager.getInstance().getEntityManager().getMezzed((LivingEntity) attacker);
                if (mzExpiry != null) {
                    if (attacker instanceof Player) {
                        attacker.sendMessage("* You are mezzed!");
                    }
                    Utils.CancelEvent(event);
                    ;
                    return;
                }
            } catch (CoreStateInitException e) {
            }
            List<Integer> removeSpells = new ArrayList<Integer>();
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) attacker).getActiveSpells()) {
                if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
                    if (!removeSpells.contains(spell.getSpell().getId()))
                        removeSpells.add(spell.getSpell().getId());
                }
            }
            for (Integer spellId : removeSpells) {
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) attacker).getUniqueId(), spellId);
            }
        }
    } catch (CoreStateInitException e) {
    // skip
    }
    // Remove buffs on recipient (invis should drop)
    try {
        if (event.getEntity() instanceof LivingEntity) {
            List<Integer> removeSpells = new ArrayList<Integer>();
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells((LivingEntity) event.getEntity()).getActiveSpells()) {
                if (spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Mez) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsUndead2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Invisibility2) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.InvisVsAnimals) || spell.getSpell().getSpellEffectTypes().contains(SpellEffectType.ImprovedInvisAnimals)) {
                    if (!removeSpells.contains(spell.getSpell().getId()))
                        removeSpells.add(spell.getSpell().getId());
                }
            }
            for (Integer spellId : removeSpells) {
                StateManager.getInstance().getEntityManager().removeSpellEffectsOfSpellId(plugin, ((LivingEntity) event.getEntity()).getUniqueId(), spellId);
            }
        }
        // Check for rune damage
        if (event.getEntity() instanceof LivingEntity) {
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            if (soldefender.isInvulnerable()) {
                event.setDamage(0);
                Utils.CancelEvent(event);
                ;
                if (damagecause.getDamager() instanceof Player) {
                    ((Player) damagecause.getDamager()).sendMessage("* Your attack was prevented as the target is Invulnerable!");
                }
                if (event.getEntity() instanceof Player) {
                    ((Player) event.getEntity()).sendMessage("* Your invulnerability prevented the targets attack!");
                }
            }
        }
        // see if any runes want to reduce this damage
        if (event.getEntity() instanceof LivingEntity) {
            if (!event.getCause().equals(DamageCause.THORNS)) {
                ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                event.setDamage(Utils.reduceDamage(soldefender, event.getDamage()));
            }
        }
        // Check for rune damage
        if (event.getEntity() instanceof LivingEntity) {
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            if (soldefender.getRune() > 0) {
                event.setDamage(soldefender.reduceAndRemoveRunesAndReturnLeftover(plugin, (int) event.getDamage()));
                if (event.getDamage() <= 0) {
                    Utils.CancelEvent(event);
                    ;
                    if (damagecause.getDamager() instanceof Player) {
                        ((Player) damagecause.getDamager()).sendMessage("* Your attack was absorbed by the targets Rune");
                    }
                    if (event.getEntity() instanceof Player) {
                        ((Player) event.getEntity()).sendMessage("* Your rune spell absorbed the targets attack!");
                    }
                    return;
                }
            }
        }
    } catch (CoreStateInitException e) {
    // skip
    }
    if ((damagecause.getDamager() instanceof LivingEntity || damagecause.getDamager() instanceof Arrow) && event.getEntity() instanceof LivingEntity) {
        // code
        if (event.getCause().equals(DamageCause.THORNS)) {
            if (damagecause.getDamager() instanceof Player) {
                LivingEntity recipient = (LivingEntity) event.getEntity();
                DecimalFormat df = new DecimalFormat();
                df.setMaximumFractionDigits(2);
                String name = recipient.getName();
                if (recipient.getCustomName() != null)
                    name = recipient.getCustomName();
                ((Player) damagecause.getDamager()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You SPELLDMG'd " + name + " for " + df.format(event.getDamage()) + " [" + df.format(recipient.getHealth() - event.getDamage()) + "/" + df.format(recipient.getMaxHealth()) + "]"));
            }
            if (event.getEntity() instanceof LivingEntity) {
                ISoliniaLivingEntity solentity;
                try {
                    solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
                    if (event.getDamage() > solentity.getBukkitLivingEntity().getHealth() && solentity.hasDeathSave() > 0) {
                        Utils.CancelEvent(event);
                        solentity.removeDeathSaves(plugin);
                        solentity.getBukkitLivingEntity().sendMessage("* Your death/divine save boon has saved you from death!");
                        return;
                    }
                    solentity.damageHook(event.getDamage(), damagecause.getDamager());
                } catch (CoreStateInitException e) {
                // skip
                }
            }
            return;
        }
        try {
            Entity damager = damagecause.getDamager();
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) damagecause.getDamager();
                if (arr.getShooter() instanceof LivingEntity) {
                    damager = (LivingEntity) arr.getShooter();
                    // Modify Player Bow Damage
                    if (arr.getShooter() instanceof Player) {
                        Player shooter = (Player) arr.getShooter();
                        ItemStack mainitem = shooter.getInventory().getItemInMainHand();
                        if (mainitem != null) {
                            if (mainitem.getType() == Material.BOW) {
                                int dmgmodifier = 0;
                                if (Utils.IsSoliniaItem(mainitem)) {
                                    try {
                                        ISoliniaItem item = SoliniaItemAdapter.Adapt(mainitem);
                                        if (item.getDamage() > 0 && item.getBasename().equals("BOW")) {
                                            dmgmodifier = item.getDamage();
                                        }
                                    } catch (SoliniaItemException e) {
                                    // sok just skip
                                    }
                                }
                                event.setDamage(event.getDamage() + dmgmodifier);
                            }
                        }
                    }
                } else {
                }
            }
            if (!(damager instanceof LivingEntity))
                return;
            LivingEntity attacker = (LivingEntity) damager;
            // Change attacker to archer
            if (damagecause.getDamager() instanceof Arrow) {
                Arrow arr = (Arrow) damagecause.getDamager();
                if (arr.getShooter() instanceof LivingEntity) {
                    attacker = (LivingEntity) arr.getShooter();
                } else {
                }
            }
            if (attacker == null)
                return;
            ISoliniaLivingEntity soldefender = SoliniaLivingEntityAdapter.Adapt((LivingEntity) event.getEntity());
            ISoliniaLivingEntity solattacker = SoliniaLivingEntityAdapter.Adapt((LivingEntity) attacker);
            if (attacker instanceof Player && event.getEntity() instanceof Wolf) {
                if (soldefender.isPet()) {
                    Wolf wolf = (Wolf) event.getEntity();
                    if (wolf != null) {
                        if (wolf.getTarget() == null || !wolf.getTarget().equals(attacker)) {
                            Utils.CancelEvent(event);
                            ;
                            return;
                        }
                    } else {
                        Utils.CancelEvent(event);
                        ;
                        return;
                    }
                }
            }
            if (!(event instanceof EntityDamageByEntityEvent)) {
                soldefender.damageHook(event.getDamage(), damagecause.getDamager());
                return;
            }
            solattacker.Attack(soldefender, event, damagecause.getDamager() instanceof Arrow, plugin);
        } catch (CoreStateInitException e) {
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Creature(org.bukkit.entity.Creature) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) Timestamp(java.sql.Timestamp) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) ItemStack(org.bukkit.inventory.ItemStack) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell) EventHandler(org.bukkit.event.EventHandler)

Example 8 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project solinia3-core by mixxit.

the class Solinia3CoreEntityListener method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    if ((event.getEntity() instanceof ArmorStand)) {
        return;
    }
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    if (event.getEntity() instanceof Player)
        return;
    if (!(event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent))
        return;
    if (event.getEntity() instanceof Animals && !Utils.isLivingEntityNPC((LivingEntity) event.getEntity()))
        return;
    EntityDamageByEntityEvent entitykiller = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
    Entity damager = entitykiller.getDamager();
    if (damager instanceof Projectile) {
        Projectile projectile = (Projectile) damager;
        damager = (Entity) projectile.getShooter();
    }
    if (!(damager instanceof LivingEntity))
        return;
    ISoliniaLivingEntity soldamagerentity = null;
    try {
        soldamagerentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) damager);
    } catch (CoreStateInitException e) {
    }
    // something
    if ((!(damager instanceof Player)) && Utils.isLivingEntityNPC((LivingEntity) damager)) {
        soldamagerentity.doSlayChat();
    }
    if (!(damager instanceof Player) && !soldamagerentity.isPet())
        return;
    try {
        ISoliniaLivingEntity livingEntity = SoliniaLivingEntityAdapter.Adapt(event.getEntity());
        ISoliniaPlayer player = null;
        if (damager instanceof Player) {
            player = SoliniaPlayerAdapter.Adapt((Player) damager);
        }
        if (soldamagerentity.isPet()) {
            if (damager instanceof Wolf) {
                Wolf w = (Wolf) damager;
                player = SoliniaPlayerAdapter.Adapt((Player) w.getOwner());
            }
        }
        if (player == null) {
            return;
        }
        Double experience = Utils.getExperienceRewardAverageForLevel(livingEntity.getLevel());
        // try to share with group
        ISoliniaGroup group = StateManager.getInstance().getGroupByMember(player.getUUID());
        if (group != null) {
            Integer dhighestlevel = 0;
            List<Integer> levelranges = new ArrayList<Integer>();
            for (UUID member : group.getMembers()) {
                ISoliniaPlayer playerchecked = SoliniaPlayerAdapter.Adapt(Bukkit.getPlayer(member));
                int checkedlevel = playerchecked.getLevel();
                levelranges.add(checkedlevel);
            }
            Collections.sort(levelranges);
            // get the highest person in the group
            dhighestlevel = levelranges.get(levelranges.size() - 1);
            int ihighlvl = (int) Math.floor(dhighestlevel);
            int ilowlvl = ihighlvl - 7;
            if (ilowlvl < 1) {
                ilowlvl = 1;
            }
            if (player.getLevel() < ilowlvl) {
                // as they are out of range of the group
                if (livingEntity.getLevel() >= player.getLevel() - 7) {
                    player.increasePlayerExperience(experience);
                    // Grant title for killing mob
                    if (livingEntity.getNpcid() > 0) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                        if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                            player.grantTitle(npc.getDeathGrantsTitle());
                        }
                        if (npc.isBoss() || npc.isRaidboss()) {
                            player.grantTitle("the Vanquisher");
                        }
                    }
                } else {
                    player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                }
            } else {
                for (UUID member : group.getMembers()) {
                    Player tgtplayer = Bukkit.getPlayer(member);
                    if (tgtplayer != null) {
                        ISoliniaPlayer tgtsolplayer = SoliniaPlayerAdapter.Adapt(tgtplayer);
                        int tgtlevel = tgtsolplayer.getLevel();
                        if (tgtlevel < ilowlvl) {
                            tgtplayer.sendMessage("You were out of level range to gain experience in this group (Min: " + ilowlvl + " Max: " + ihighlvl + ")");
                            continue;
                        }
                        if (!tgtplayer.getWorld().equals(player.getBukkitPlayer().getWorld())) {
                            tgtplayer.sendMessage("You were out of range for shared group xp (world)");
                            continue;
                        }
                        if (tgtplayer.getLocation().distance(player.getBukkitPlayer().getLocation()) <= 100) {
                            if (livingEntity.getLevel() >= (tgtsolplayer.getLevel() - 7)) {
                                tgtsolplayer.increasePlayerExperience(experience);
                                // Grant title for killing mob
                                if (livingEntity.getNpcid() > 0) {
                                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                                        tgtsolplayer.grantTitle(npc.getDeathGrantsTitle());
                                    }
                                    if (npc.isBoss() || npc.isRaidboss()) {
                                        tgtsolplayer.grantTitle("the Vanquisher");
                                    }
                                }
                            } else {
                                tgtplayer.sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
                            }
                        } else {
                            tgtplayer.sendMessage("You were out of range for shared group xp (distance)");
                            continue;
                        }
                    }
                }
            }
        } else {
            if (livingEntity.getLevel() >= (player.getLevel() - 7)) {
                player.increasePlayerExperience(experience);
                // Grant title for killing mob
                if (livingEntity.getNpcid() > 0) {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
                    if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                        player.grantTitle(npc.getDeathGrantsTitle());
                    }
                    if (npc.isBoss() || npc.isRaidboss()) {
                        player.grantTitle("the Vanquisher");
                    }
                }
            } else {
                player.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* The npc was too low level to gain experience from");
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc.getFactionid() > 0) {
                ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(npc.getFactionid());
                player.decreaseFactionStanding(npc.getFactionid(), 50);
                for (FactionStandingEntry factionEntry : faction.getFactionEntries()) {
                    if (factionEntry.getValue() >= 1500) {
                        // If this is an ally of the faction, grant negative faction
                        player.decreaseFactionStanding(factionEntry.getFactionId(), 10);
                    }
                    if (factionEntry.getValue() <= -1500) {
                        // If this is an enemy of the faction, grant positive faction
                        player.increaseFactionStanding(factionEntry.getFactionId(), 1);
                    }
                }
            }
        }
        if (livingEntity.getNpcid() > 0) {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(livingEntity.getNpcid());
            if (npc != null && !npc.getDeathGrantsTitle().equals("")) {
                player.grantTitle(npc.getDeathGrantsTitle());
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                player.grantTitle("the Vanquisher");
            }
            if (npc.isBoss() || npc.isRaidboss()) {
                Bukkit.broadcastMessage(ChatColor.RED + "[VICTORY] The foundations of the earth shake following the destruction of " + npc.getName() + " at the hands of " + player.getFullNameWithTitle() + "!" + ChatColor.RESET);
            }
        }
        player.giveMoney(1);
        livingEntity.dropLoot();
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaGroup(com.solinia.solinia.Interfaces.ISoliniaGroup) FactionStandingEntry(com.solinia.solinia.Models.FactionStandingEntry) ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ArrayList(java.util.ArrayList) Projectile(org.bukkit.entity.Projectile) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Animals(org.bukkit.entity.Animals) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) ArmorStand(org.bukkit.entity.ArmorStand) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Wolf(org.bukkit.entity.Wolf) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 9 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project Statz by Staartvin.

the class KillsPlayersListener method onDie.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDie(final EntityDeathEvent event) {
    final PlayerStat stat = PlayerStat.KILLS_PLAYERS;
    Entity e = event.getEntity();
    if (!(e.getLastDamageCause() instanceof EntityDamageByEntityEvent)) {
        return;
    }
    EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) e.getLastDamageCause();
    if (nEvent.getDamager() instanceof Player) {
        // Entity died because of Player
        // Killer
        final Player player = (Player) nEvent.getDamager();
        // Do general check
        if (!plugin.doGeneralCheck(player, stat))
            return;
        if (e instanceof Player) {
            // Player killed player
            final Player murderedPlayer = (Player) e;
            // Update value to new stat.
            plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", 1, "world", player.getWorld().getName(), "playerKilled", murderedPlayer.getName()));
        } else {
        // Player killed mob
        // Handled by other listener
        }
    } else {
    // Entity died of something else
    }
// 
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) PlayerStat(me.staartvin.statz.datamanager.player.PlayerStat) EventHandler(org.bukkit.event.EventHandler)

Example 10 with EntityDamageByEntityEvent

use of org.bukkit.event.entity.EntityDamageByEntityEvent in project AuthMeReloaded by AuthMe.

the class EntityListenerTest method shouldCancelEntityDamageByEntityEvent.

@Test
public void shouldCancelEntityDamageByEntityEvent() {
    // given
    EntityDamageByEntityEvent event = mock(EntityDamageByEntityEvent.class);
    Entity player = mock(Player.class);
    given(event.getDamager()).willReturn(player);
    given(listenerService.shouldCancelEvent(player)).willReturn(true);
    // when
    listener.onAttack(event);
    // then
    verify(listenerService).shouldCancelEvent(player);
    verify(event).setCancelled(true);
}
Also used : Entity(org.bukkit.entity.Entity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Test(org.junit.Test)

Aggregations

EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)35 EventHandler (org.bukkit.event.EventHandler)22 Entity (org.bukkit.entity.Entity)19 Player (org.bukkit.entity.Player)17 LivingEntity (org.bukkit.entity.LivingEntity)15 Projectile (org.bukkit.entity.Projectile)12 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)12 ItemStack (org.bukkit.inventory.ItemStack)6 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)5 Element (net.aufdemrand.denizencore.objects.Element)5 ProjectileSource (org.bukkit.projectiles.ProjectileSource)5 EntityTag (com.denizenscript.denizen.objects.EntityTag)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)4 Arrow (org.bukkit.entity.Arrow)4 ArrayList (java.util.ArrayList)3 Animals (org.bukkit.entity.Animals)3 Tameable (org.bukkit.entity.Tameable)3 EntityDamageByBlockEvent (org.bukkit.event.entity.EntityDamageByBlockEvent)3 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2