private double getLengthSigned(Vector vec) {
    double length = vec.length();

    // if(Math.signum(vec.getZ())==-1||Math.signum(vec.getX())==-1||Math.signum(vec.getY())==-1)
    // length*=-1;

    return length;
  }
 private void affect(Entity entity) {
   BendingHitEvent event = new BendingHitEvent(this, entity);
   Bending.callEvent(event);
   if (event.isCancelled()) {
     return;
   }
   if (entity == player) {
     return;
   }
   Vector direction = origin.clone().subtract(entity.getLocation()).toVector();
   double distance = direction.length();
   entity.setVelocity(
       entity.getVelocity().add(direction.normalize().multiply(PUSH * distance / RADIUS)));
   entity.setFallDistance(0);
 }
Exemple #3
0
  private Collection<GlowPlayer> damageEntities() {
    float power = this.power;
    this.power *= 2f;

    Collection<GlowPlayer> affectedPlayers = new ArrayList<>();

    Collection<GlowLivingEntity> entities = getNearbyEntities();
    for (GlowLivingEntity entity : entities) {
      double disDivPower = distanceTo(entity) / (double) this.power;
      if (disDivPower > 1.0D) continue;

      Vector vecDistance = distanceToHead(entity);
      if (vecDistance.length() == 0.0) continue;

      vecDistance.normalize();

      double basicDamage = calculateDamage(entity, disDivPower);
      int explosionDamage =
          (int) ((basicDamage * basicDamage + basicDamage) * 4 * (double) power + 1.0D);

      if (!(entity instanceof GlowHumanEntity)) {
        EntityDamageEvent.DamageCause damageCause;
        if (source == null || source.getType() == EntityType.PRIMED_TNT) {
          damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
        } else {
          damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
        }
        entity.damage(explosionDamage, source, damageCause);
      }

      double enchantedDamage = calculateEnchantedDamage(basicDamage, entity);
      vecDistance.multiply(enchantedDamage);

      Vector currentVelocity = entity.getVelocity();
      currentVelocity.add(vecDistance);
      entity.setVelocity(currentVelocity);

      if (entity instanceof GlowPlayer) {
        affectedPlayers.add((GlowPlayer) entity);
      }
    }

    this.power = power;

    return affectedPlayers;
  }
  @SuppressWarnings("deprecation")
  @Override
  public boolean execute() {
    if (!super.execute()) {
      return false;
    }
    final int r = getRadius();
    Set<Material> set = new HashSet<Material>();
    set.add(Material.AIR);
    final Block target =
        getPlayer().getPlayer().getTargetBlock(set, r * 2).getRelative(BlockFace.UP);
    Vector v =
        target
            .getLocation()
            .toVector()
            .subtract(getPlayer().getPlayer().getEyeLocation().toVector());
    ParticleEffect.EXPLOSION_NORMAL.display(v, 0.2F, getPlayer().getPlayer().getEyeLocation(), 30D);
    Manager.scheduleTask(
        new Runnable() {
          @Override
          public void run() {
            ParticleEffect.EXPLOSION_LARGE.display(
                0.2F, 0.2F, 0.2F, 0.2F, 5, target.getLocation(), 30D);
            target.getWorld().playSound(target.getLocation(), Sound.EXPLODE, 0.6F, 0.9F);
            for (Entity e : target.getWorld().getEntities()) {
              if (((e instanceof LivingEntity))
                  && (e.getEntityId() != getPlayer().getPlayer().getEntityId())
                  && (e.getLocation().distanceSquared(target.getLocation()) <= r * r)) {
                EntityDamageByEntityEvent event =
                    new EntityDamageByEntityEvent(
                        getPlayer().getPlayer(), e, DamageCause.CUSTOM, getDamage());
                Bukkit.getPluginManager().callEvent(event);
              }
            }
          }
        },
        1L * Math.round(v.length()));

    return true;
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }
    if (WaterSpout.isBending(event.getPlayer())
        || AirSpout.getPlayers().contains(event.getPlayer())) {
      Vector vel = new Vector();
      vel.setX(event.getTo().getX() - event.getFrom().getX());
      vel.setY(event.getTo().getY() - event.getFrom().getY());
      vel.setZ(event.getTo().getZ() - event.getFrom().getZ());
      // You now know the old velocity. Set to match recommended velocity
      double currspeed = vel.length();
      double maxspeed = .15;
      if (currspeed > maxspeed) {
        vel = vel.normalize().multiply(maxspeed * 0.9);
        event.getPlayer().setVelocity(vel);
      }
    }
    if (Bloodbending.isBloodbended(player)) {
      double distance1, distance2;
      Location loc = Bloodbending.getBloodbendingLocation(player);
      distance1 = event.getFrom().distance(loc);
      distance2 = event.getTo().distance(loc);
      if (distance2 > distance1) {
        player.setVelocity(new Vector(0, 0, 0));
      }
    }

    if (Dash.isDashing(player)) {
      Vector dir = event.getTo().clone().subtract(event.getFrom()).toVector();
      Dash d = Dash.getDash(player);
      d.setDirection(dir);
    }
  }
  public void onRun() {
    Location location = getLocation();
    // Lines
    int mL = RandomUtils.random.nextInt(maxLines - 2) + 2;
    for (int m = 0; m < mL * 2; m++) {
      double x = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
      double y = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
      double z = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
      if (direction == Direction.DOWN) y = RandomUtils.random.nextInt(max * 2 - max) + max;
      else if (direction == Direction.UP)
        y = RandomUtils.random.nextInt(max * (-1) - max * (-2)) + max * (-2);
      Location target = location.clone().subtract(x, y, z);
      if (target == null) {
        cancel();
        return;
      }
      Vector link = target.toVector().subtract(location.toVector());
      float length = (float) link.length();
      link.normalize();

      float ratio = length / lineParticles;
      Vector v = link.multiply(ratio);
      Location loc = location.clone().subtract(v);
      for (int i = 0; i < lineParticles; i++) {
        loc.add(v);
        display(lineParticle, loc, lineColor);
      }
    }

    // Sphere
    for (int i = 0; i < sphereParticles; i++) {
      Vector vector = RandomUtils.getRandomVector().multiply(sphereRadius);
      location.add(vector);
      display(sphereParticle, location, sphereColor);
      location.subtract(vector);
    }
  }
 public Velocity getVelocity() {
   Vector v = e.getVelocity();
   return new Velocity(v.length(), v.getX(), v.getY(), v.getZ());
 }