Ejemplo n.º 1
0
  /**
   * Monitor EntityDamage events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof FakeEntityDamageEvent) {
      return;
    }

    Entity entity = event.getEntity();
    EntityType type = entity.getType();
    DamageCause cause = event.getCause();

    switch (type) {
      case PLAYER:

        /* Check for invincibility */
        Player player = (Player) entity;
        PlayerProfile PP = Users.getProfile(player);

        if (PP.getGodMode()) {
          event.setCancelled(true);
          return;
        }

        if (!m.isInvincible(player, event)) {
          if (cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) {
            Acrobatics.acrobaticsCheck(player, event);
          } else if (cause == DamageCause.BLOCK_EXPLOSION
              && mcPermissions.getInstance().demolitionsExpertise(player)) {
            BlastMining.demolitionsExpertise(player, event);
          }

          if (event.getDamage() >= 1) {
            PP.setRecentlyHurt(System.currentTimeMillis());
          }
        }
        break;

      case WOLF:
        Wolf wolf = (Wolf) entity;

        if ((!m.isInvincible(wolf, event))
            && wolf.isTamed()
            && (wolf.getOwner() instanceof Player)) {
          Taming.preventDamage(event);
        }
        break;

      default:
        break;
    }
  }