Ejemplo n.º 1
0
  @Override
  public void onTarget(EntityTargetEvent event) {
    super.onTarget(event);

    if (event.getReason().equals(TargetReason.FORGOT_TARGET)
        || event.getReason().equals(TargetReason.TARGET_DIED)) {
      this.angry = false;
      for (Entity e : minions) {
        e.getBukkitEntity().remove();
      }
    }
  }
Ejemplo n.º 2
0
 public boolean attack(Entity entity, DamageSource damageSource, float damage) {
   PetAttackEvent attackEvent =
       new PetAttackEvent(this.getPet(), entity.getBukkitEntity(), damage);
   EchoPet.getPlugin().getServer().getPluginManager().callEvent(attackEvent);
   if (!attackEvent.isCancelled()) {
     if (entity instanceof EntityPlayer) {
       if (!(EchoPet.getConfig().getBoolean("canAttackPlayers", false))) {
         return false;
       }
     }
     return entity.damageEntity(damageSource, (float) attackEvent.getDamage());
   }
   return false;
 }
Ejemplo n.º 3
0
  @Override
  public boolean damageEntity(DamageSource source, float damage) {
    if (invulnerable || noDamageTicks > 0) {
      return false;
    }

    DamageCause cause = null;
    org.bukkit.entity.Entity bEntity = null;
    if (source instanceof EntityDamageSource) {
      Entity damager = source.getEntity();
      cause = DamageCause.ENTITY_ATTACK;
      if (source instanceof EntityDamageSourceIndirect) {
        damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
        if (damager.getBukkitEntity() instanceof ThrownPotion) {
          cause = DamageCause.MAGIC;
        } else if (damager.getBukkitEntity() instanceof Projectile) {
          cause = DamageCause.PROJECTILE;
        }
      }

      bEntity = damager.getBukkitEntity();
    } else if (source == DamageSource.FIRE) cause = DamageCause.FIRE;
    else if (source == DamageSource.STARVE) cause = DamageCause.STARVATION;
    else if (source == DamageSource.WITHER) cause = DamageCause.WITHER;
    else if (source == DamageSource.STUCK) cause = DamageCause.SUFFOCATION;
    else if (source == DamageSource.DROWN) cause = DamageCause.DROWNING;
    else if (source == DamageSource.BURN) cause = DamageCause.FIRE_TICK;
    else if (source == CraftEventFactory.MELTING) cause = DamageCause.MELTING;
    else if (source == CraftEventFactory.POISON) cause = DamageCause.POISON;
    else if (source == DamageSource.MAGIC) {
      cause = DamageCause.MAGIC;
    } else if (source == DamageSource.OUT_OF_WORLD) {
      cause = DamageCause.VOID;
    }

    if (cause != null) {
      NPCDamageEvent event = new NPCDamageEvent(npc, bEntity, cause, (double) damage);
      Bukkit.getPluginManager().callEvent(event);
      if (!event.isCancelled()) {
        return super.damageEntity(source, (float) event.getDamage());
      } else {
        return false;
      }
    }

    if (super.damageEntity(source, damage)) {
      if (bEntity != null) {
        Entity e = ((CraftEntity) bEntity).getHandle();
        double d0 = e.locX - this.locX;

        double d1;
        for (d1 = e.locZ - this.locZ;
            d0 * d0 + d1 * d1 < 0.0001D;
            d1 = (Math.random() - Math.random()) * 0.01D) {
          d0 = (Math.random() - Math.random()) * 0.01D;
        }

        a(e, damage, d0, d1);
      }

      return true;
    } else {
      return false;
    }
  }
Ejemplo n.º 4
0
 public CraftEntity getBukkitEntity() {
   return entity.getBukkitEntity();
 }