Exemple #1
0
  /**
   * Increases the blast radius of the explosion.
   *
   * @param player Player triggering the explosion
   * @param event Event whose explosion radius is being changed
   */
  public static void biggerBombs(Player player, ExplosionPrimeEvent event) {
    final int RANK_1_LEVEL = 250;
    final int RANK_2_LEVEL = 500;
    final int RANK_3_LEVEL = 750;
    final int RANK_4_LEVEL = 1000;

    int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
    float radius = event.getRadius();

    if (skillLevel < RANK_1_LEVEL) {
      return;
    }

    if (skillLevel >= RANK_1_LEVEL) {
      radius++;
    }

    if (skillLevel >= RANK_2_LEVEL) {
      radius++;
    }

    if (skillLevel >= RANK_3_LEVEL) {
      radius++;
    }

    if (skillLevel >= RANK_4_LEVEL) {
      radius++;
    }

    event.setRadius(radius);
  }
  // blocks projectiles explosions
  @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  public void onExplosionPrime(ExplosionPrimeEvent event) {
    final Entity entity = event.getEntity();

    if (entity instanceof Projectile) {
      final Projectile projectile = (Projectile) entity;
      if (projectile.getShooter() instanceof Player) {
        if (this.projectileCheck(projectile, projectile.getLocation())) {
          event.setCancelled(true);
          event.setRadius(0);
        }
      }
    }
  }
  /**
   * Event handler called when an explosive is primed.
   *
   * <p>We use it to detect impending creeper explosions. The event is fired immediately before the
   * explosion.
   */
  @EventHandler(ignoreCancelled = true)
  public void onCreeperDetonate(ExplosionPrimeEvent event) {
    if (!CONFIG.isAffectedWorld(event)) {
      return;
    }

    if (event.getEntityType() == EntityType.CREEPER) {
      event.setRadius((float) CONFIG.BLAST_RADIUS_SCALE * event.getRadius());

      Entity creeper = event.getEntity();
      launchReinforcements(creeper);

      Location origin = creeper.getLocation();
      World world = origin.getWorld();
      Firework firework = (Firework) world.spawnEntity(origin, EntityType.FIREWORK);
      if (firework != null) {
        FireworkMeta meta = firework.getFireworkMeta();
        meta.setPower(random(0, 1));
        meta.addEffect(randomFireworkFffect(true));
        firework.setFireworkMeta(meta);
      }
    }
  }
  /**
   * 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()));
    }
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onExplosionPrime(ExplosionPrimeEvent evt) {

    Location l = evt.getEntity().getLocation();
    World w = l.getWorld();
    Chunk c = w.getChunkAt(l);

    if (evt.getEntity() instanceof Creeper) {
      if (GlobalRegionManager.getGlobalWorldSetting(w) != null) {
        if (!GlobalRegionManager.getGlobalWorldSetting(w).creeperExplodes) {
          evt.setCancelled(true);
          evt.setRadius(0);
          return;
        }
      }
    }

    ArrayList<Region> regionSet = new ArrayList<Region>();

    for (Region region : GlobalRegionManager.getRegions()) {
      for (Chunk chunk : region.getChunkGrid().getChunks()) {
        if (chunk.getWorld() == w) {
          if (areChunksEqual(chunk, c)) {
            if (!regionSet.contains(region)) {
              regionSet.add(region);
            }
          }
        }
      }
    }

    if (regionSet.isEmpty()) {
      return;
    }

    ArrayList<Region> currentRegionSet = new ArrayList<Region>();

    for (Region reg : regionSet) {
      Location rl1 = reg.getL1().toBukkitLocation(), rl2 = reg.getL2().toBukkitLocation();
      if (rl1.getX() > rl2.getX()) {
        rl2.subtract(6, 0, 0);
        rl1.add(6, 0, 0);
      } else {
        rl2.add(6, 0, 0);
        rl1.subtract(6, 0, 0);
      }
      if (rl1.getZ() > rl2.getZ()) {
        rl2.subtract(0, 0, 6);
        rl1.add(0, 0, 6);
      } else {
        rl2.add(0, 0, 6);
        rl1.subtract(0, 0, 6);
      }
      if (rl1.getY() > rl2.getY()) {
        rl2.subtract(0, 10, 0);
        rl1.add(0, 10, 0);
      } else {
        rl2.add(0, 10, 0);
        rl1.subtract(0, 10, 0);
      }
      if (extReg.isInsideCuboid(l, rl1, rl2)) {
        currentRegionSet.add(reg);
      }
    }

    if (currentRegionSet.isEmpty()) { // If player is in chunk range but not
      // inside region then cancel the
      // check.
      return;
    } else {
      for (Region r : currentRegionSet) {
        if (r.is_protection()) {
          LogRunner.addLogMessage(r, LogRunner.getPrefix(r) + (" Entity explosion was prevented."));
          evt.setCancelled(true);
          evt.setRadius(0);
          return;
        }
      }
    }
  }