Exemplo n.º 1
0
  private void getBlocking(EnderPearl pearl) {
    double gravity = 0.03F;
    try {
      if (pearl instanceof CustomNMSEntityEnderPearl)
        gravity = ((CustomNMSEntityEnderPearl) pearl).y_adjust_;
      else Bastion.getPlugin().getLogger().info("Humbug not found");

    } catch (NoClassDefFoundError e) {
      Bastion.getPlugin().getLogger().info("Humbug not found");
    }

    Vector speed = pearl.getVelocity();
    Vector twoDSpeed = speed.clone();
    twoDSpeed.setY(0);

    double horizontalSpeed = getLengthSigned(twoDSpeed);
    double verticalSpeed = speed.getY();

    Location loc = pearl.getLocation();

    double maxTicks = getMaxTicks(verticalSpeed, loc.getY(), -gravity);
    double maxDistance = getMaxDistance(horizontalSpeed, maxTicks);

    // check if it has any possibility of going through a bastion
    if (!(maxDistance > Bastion.getConfigManager().getBastionBlockEffectRadius() / 2
        || maxDistance < -1)) {
      return;
    }

    Player threw = null;
    if (pearl.getShooter() instanceof Player) {
      threw = (Player) pearl.getShooter();
    }

    Set<BastionBlock> possible =
        bastions.getPossibleTeleportBlocking(
            pearl.getLocation(), maxDistance); // all the bastion blocks within range of the pearl

    // no need to do anything if there aren't any bastions to run into.
    if (possible.isEmpty()) {
      return;
    }

    Location start = pearl.getLocation();
    Location end = start.clone();
    end.add(twoDSpeed.multiply(maxTicks));

    Set<BastionBlock> couldCollide =
        simpleCollide(
            possible,
            start.clone(),
            end.clone(),
            threw); // all the bastions where the pearl passes over or under their shadow

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

    BastionBlock firstCollision = null;
    long firstCollisionTime = -1;
    for (BastionBlock bastion : couldCollide) {
      long currentCollidesBy =
          (long) collidesBy(bastion, start.clone(), end.clone(), speed, gravity, horizontalSpeed);
      if (currentCollidesBy != -1 && currentCollidesBy < firstCollisionTime) {
        firstCollisionTime = currentCollidesBy;
        firstCollision = bastion;
      }

      // make sure there is at least a starting value Probably better ways of doing this
      if (firstCollisionTime == -1 && currentCollidesBy != -1) {
        firstCollisionTime = currentCollidesBy;
        firstCollision = bastion;
      }
    }
    if (firstCollisionTime != -1) { // if we found something add it
      task.manage(new Flight(pearl, firstCollisionTime, firstCollision));
      return;
    }
  }
Exemplo n.º 2
0
 public void cancel() {
   if (pearl.getShooter() instanceof Player) {
     handleTeleport(blocking, pearl.getLocation(), (Player) pearl.getShooter());
   }
   pearl.remove();
 }