Пример #1
0
  public void attack(EntityDamageEvent source) {
    if (hasEffect(Effect.FIRE_RESISTANCE)
        && (source.getCause() == EntityDamageEvent.CAUSE_FIRE
            || source.getCause() == EntityDamageEvent.CAUSE_FIRE_TICK
            || source.getCause() == EntityDamageEvent.CAUSE_LAVA)) {
      source.setCancelled();
    }

    getServer().getPluginManager().callEvent(source);
    if (source.isCancelled()) {
      return;
    }
    setLastDamageCause(source);
    setHealth(getHealth() - source.getFinalDamage());
  }
Пример #2
0
  @Override
  public void attack(EntityDamageEvent source) {
    super.attack(source);
    if (source.isCancelled()) return;
    if (source instanceof EntityDamageByEntityEvent) {
      Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
      if (damager instanceof Player) {
        if (((Player) damager).isCreative()) {
          this.kill();
        }
        if (this.getHealth() <= 0) {
          if (((Player) damager).isSurvival()) {
            this.level.dropItem(this, new ItemBoat());
          }
          this.close();
        }
      }
    }

    EntityEventPacket pk = new EntityEventPacket();
    pk.eid = this.getId();
    pk.event =
        this.getHealth() <= 0
            ? EntityEventPacket.DEATH_ANIMATION
            : EntityEventPacket.HURT_ANIMATION;
    Server.broadcastPacket(this.hasSpawned.values(), pk);
  }