Package org.bukkit.event.entity

Examples of org.bukkit.event.entity.EntityDamageByEntityEvent


     *
     * @param event
     */
    public void onDamage(EntityDamageEvent event) {
        if (event instanceof EntityDamageByEntityEvent) {
            EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
            Entity damager = e.getDamager();
            if (damager != null && damager instanceof LivingEntity) {
                this.targetAggro = true;
                this.targetEntity = ((CraftEntity) damager).getHandle();
            }
        }
View Full Code Here


    //if (event.getEntity() == null || !(event.getEntity() instanceof Player)) return;
    Player player = (Player) event.getEntity();
   
    // player in game and in PVP world? Consider settings and only damage by other entities
    if (hasPlayer(player) && player.getWorld().getPVP() && configuration.getBoolean("noPvP", true) && event instanceof EntityDamageByEntityEvent) {
      EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) event;
      // only consider player damage
      if (damageEvent.getDamager() instanceof Player) {
        event.setCancelled(true); // cancel damage event by caused by other players
        return true;
      }
    }
    return false;
View Full Code Here

public class OpenInvEntityListener implements Listener {
    @EventHandler(priority = EventPriority.LOWEST)
    public void onEntityDamage(EntityDamageEvent event) {
        if (event instanceof EntityDamageByEntityEvent) {
            EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event;
            Entity attacker = evt.getDamager();
            Entity defender = evt.getEntity();

            if (!(attacker instanceof Player) || !(defender instanceof Player)) {
                return;
            }

            Player player = (Player) attacker;

            if (!(player.getItemInHand().getType().getId() == OpenInv.GetItemOpenInvItem()) || (!OpenInv.GetPlayerItemOpenInvStatus(player.getName())) || !OpenInv.hasPermission(player, "OpenInv.openinv")) {
                return;
            }

            Player target = (Player) defender;
            player.performCommand("openinv " + target.getName());

            evt.setDamage(0);
            evt.setCancelled(true);
        }
    }
View Full Code Here

        // Filter some unwanted events right now
        if(event.isCancelled() || !(event instanceof EntityDamageByEntityEvent))
            return;

        final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
        if(!(e.getDamager() instanceof Player)) {
            return;
        }

        if(e.getCause() == DamageCause.ENTITY_ATTACK) {
            normalDamage(e);
        } else if(e.getCause() == DamageCause.CUSTOM) {
            customDamage(e);
        }
    }
View Full Code Here

      }

      Location locKiller = null;
      if (lastDmg instanceof EntityDamageByEntityEvent)
      {
        EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) lastDmg;
        switch (ed.getDamager().getType())
        {
          case CREEPER:
            dmsg = victim.getName() + " was blown up by Creeper";
            break;
          case PRIMED_TNT:
            dmsg = victim.getName() + " was blown up by TNT";
            if (plugin.getTNTOwner(ed.getDamager()) != vapl)
            {
              kapl = plugin.getTNTOwner(ed.getDamager());
              if (kapl != null)
                dmsg = victim.getName() + " was blown up by " + kapl.getName();
            }
            break;
          default:
            // noop
            break;
        }

        if (ed.getDamager() instanceof Projectile)
          locKiller = shotArrows.get(ed.getDamager());
      }

      // update the death message with the changes
      event.setDeathMessage(dmsg);
View Full Code Here

    }

    if (match.getCurrentState().inProgress() &&
      event instanceof EntityDamageByEntityEvent)
    {
      EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) event;
      Player damaged = entityToPlayer(ed.getEntity());

      // enderpearls are a special case!
      if (ed.getDamager().getType() == EntityType.ENDER_PEARL) return;

      Player damager = entityToPlayer(ed.getDamager());
      if (null != damager && ed.getDamager() instanceof Arrow)
      {
        AutoRefPlayer apl = match.getPlayer(damager);
        if (apl != null) apl.incrementShotsHit();

        Arrow arrow = (Arrow) ed.getDamager();
        if (arrow.getShooter().getType() == EntityType.PLAYER)
        {
          AutoRefPlayer shooter = match.getPlayer((Player) arrow.getShooter());
          Location shotFrom = shotArrows.get(arrow);

          if (shooter != null && shotFrom != null)
            shooter.setFurthestShot(arrow.getLocation().distance(shotFrom));
        }
      }

      // spectators cannot cause damage to any entity
      if (match.getCurrentState().inProgress() &&
        null != damager && match.isSpectator(damager))
      { event.setCancelled(true); return; }

      if (null != damager && ed.getEntityType() == EntityType.PIG_ZOMBIE)
      {
        AutoRefPlayer apl = match.getPlayer(damager);
        Long lastAggro = lastPigmenAggro.get(apl);

        long currentTime = ManagementFactory.getRuntimeMXBean().getUptime();
View Full Code Here

  public void entityDamage(EntityDamageEvent event)
  {
    // don't cancel the event if the damager is an admin
    if (event instanceof EntityDamageByEntityEvent)
    {
      EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
      if (checkAdminPrivilege(e.getDamager())) return;
    }
    if (event.getEntity().getWorld() == plugin.getLobbyWorld())
      event.setCancelled(true);
  }
View Full Code Here

    Entity attacker = null;
    Entity defender = null;

    if (event instanceof EntityDamageByEntityEvent) {
      //plugin.sendMsg("EntityDamageByEntityEvent");
      EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) event;
      if (entityEvent.getDamager() instanceof Projectile) {
        Projectile projectile = (Projectile) entityEvent.getDamager();
        attacker = projectile.getShooter();
        defender = entityEvent.getEntity();
      } else {
        attacker = entityEvent.getDamager();
        defender = entityEvent.getEntity();
      }
    }

    if (attacker != null) {
      //plugin.sendMsg("Attacker not null");
View Full Code Here

    if (defenderEntity instanceof Player) {

      // Killed by another entity?
      if (defenderEntity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {

        EntityDamageByEntityEvent damageEvent = (EntityDamageByEntityEvent) defenderEntity.getLastDamageCause();

        Entity attackerEntity = damageEvent.getDamager();
        Player defenderPlayer = (Player) defenderEntity;
        Player attackerPlayer = null;
        Resident attackerResident = null;
        Resident defenderResident = null;
View Full Code Here

TOP

Related Classes of org.bukkit.event.entity.EntityDamageByEntityEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.