Exemplo n.º 1
0
  /**
   * Handle EntityExplode events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEnitityExplode(EntityExplodeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
      return;
    }

    // We can make this assumption because we (should) be the only ones using this exact metadata
    Player player =
        plugin
            .getServer()
            .getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());

    if (Misc.isNPCEntity(player)) {
      return;
    }

    MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();

    if (miningManager.canUseBlastMining()) {
      miningManager.blastMiningDropProcessing(event.getYield(), event.blockList());
      event.setYield(0);
    }
  }
Exemplo n.º 2
0
  /**
   * Handle ExplosionPrime events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onExplosionPrime(ExplosionPrimeEvent event) {
    Entity entity = event.getEntity();

    if (!(entity instanceof TNTPrimed) || !entity.hasMetadata(mcMMO.tntMetadataKey)) {
      return;
    }

    // We can make this assumption because we (should) be the only ones using this exact metadata
    Player player =
        plugin
            .getServer()
            .getPlayerExact(entity.getMetadata(mcMMO.tntMetadataKey).get(0).asString());

    if (Misc.isNPCEntity(player)) {
      return;
    }

    MiningManager miningManager = UserManager.getPlayer(player).getMiningManager();

    if (miningManager.canUseBiggerBombs()) {
      event.setRadius(miningManager.biggerBombs(event.getRadius()));
    }
  }
Exemplo n.º 3
0
  /**
   * Handle EntityDamage events that involve modifying the event.
   *
   * @param event The event to modify
   */
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {
    if (event instanceof FakeEntityDamageEvent) {
      return;
    }

    double damage = event.getDamage();

    if (damage <= 0) {
      return;
    }

    Entity entity = event.getEntity();

    if (entity.hasMetadata(mcMMO.customDamageKey)) {
      entity.removeMetadata(mcMMO.customDamageKey, plugin);
      return;
    }

    if (Misc.isNPCEntity(entity) || !entity.isValid() || !(entity instanceof LivingEntity)) {
      return;
    }

    LivingEntity livingEntity = (LivingEntity) entity;

    if (CombatUtils.isInvincible(livingEntity, damage)) {
      return;
    }

    DamageCause cause = event.getCause();

    if (livingEntity instanceof Player) {
      Player player = (Player) entity;
      McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);

      /* Check for invincibility */
      if (mcMMOPlayer.getGodMode()) {
        event.setCancelled(true);
        return;
      }

      switch (cause) {
        case FALL:
          if (Config.getInstance().getPreventXPAfterTeleport()
              && SkillUtils.calculateTimeLeft(
                      (long) mcMMOPlayer.getTeleportATS() * Misc.TIME_CONVERSION_FACTOR, 5, player)
                  > 0) {
            return;
          }

          AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager();

          if (acrobaticsManager.canRoll()) {
            event.setDamage(acrobaticsManager.rollCheck(event.getDamage()));

            if (event.getDamage() == 0) {
              event.setCancelled(true);
              return;
            }
          }
          break;

        case BLOCK_EXPLOSION:
          MiningManager miningManager = mcMMOPlayer.getMiningManager();

          if (miningManager.canUseDemolitionsExpertise()) {
            event.setDamage(miningManager.processDemolitionsExpertise(event.getDamage()));

            if (event.getDamage() == 0) {
              event.setCancelled(true);
              return;
            }
          }
          break;

        default:
          break;
      }

      if (event.getDamage() >= 1) {
        mcMMOPlayer.actualizeRecentlyHurt();
      }
    } else if (livingEntity instanceof Tameable) {
      Tameable pet = (Tameable) livingEntity;
      AnimalTamer owner = pet.getOwner();

      if (Taming.canPreventDamage(pet, owner)) {
        Player player = (Player) owner;
        Wolf wolf = (Wolf) pet;

        TamingManager tamingManager = UserManager.getPlayer(player).getTamingManager();

        switch (cause) {
          case CONTACT:
          case FIRE:
          case LAVA:
            if (tamingManager.canUseEnvironmentallyAware()) {
              tamingManager.processEnvironmentallyAware(wolf, event.getDamage());
            }
            return;

          case FALL:
            if (tamingManager.canUseEnvironmentallyAware()) {
              event.setCancelled(true);
            }
            return;

          case ENTITY_ATTACK:
          case PROJECTILE:
            if (tamingManager.canUseThickFur()) {
              event.setDamage(Taming.processThickFur(wolf, event.getDamage()));

              if (event.getDamage() == 0) {
                event.setCancelled(true);
              }
            }
            return;

          case FIRE_TICK:
            if (tamingManager.canUseThickFur()) {
              Taming.processThickFurFire(wolf);
            }
            return;

          case MAGIC:
          case POISON:
          case WITHER:
            if (tamingManager.canUseHolyHound()) {
              Taming.processHolyHound(wolf, event.getDamage());
            }
            return;

          case BLOCK_EXPLOSION:
          case ENTITY_EXPLOSION:
          case LIGHTNING:
            if (tamingManager.canUseShockProof()) {
              event.setDamage(Taming.processShockProof(wolf, event.getDamage()));

              if (event.getDamage() == 0) {
                event.setCancelled(true);
              }
            }
            return;

          default:
            return;
        }
      }
    }
  }