Java Code Examples for org.bukkit.entity.Entity#getVelocity()

The following examples show how to use org.bukkit.entity.Entity#getVelocity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Scout.java    From AnnihilationPro with MIT License 6 votes vote down vote up
private void pullEntityToLocation(Entity e, Location loc)
{
	Location entityLoc = e.getLocation();

	entityLoc.setY(entityLoc.getY() + 0.5D);
	e.teleport(entityLoc);

	double g = -0.08D;
	double d = loc.distance(entityLoc);
	double t = d;
	double v_x = (1.0D + 0.07000000000000001D * t)
			* (loc.getX() - entityLoc.getX()) / t;
	double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t
			- 0.5D * g * t;
	double v_z = (1.0D + 0.07000000000000001D * t)
			* (loc.getZ() - entityLoc.getZ()) / t;

	Vector v = e.getVelocity();
	v.setX(v_x);
	v.setY(v_y);
	v.setZ(v_z);
	e.setVelocity(v);

	//addNoFall(e, 100);
}
 
Example 2
Source File: SentinelUtilities.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Gets the velocity for an entity. Uses a special tracker for players (since velocity doesn't network properly).
 */
public static Vector getVelocity(Entity entity) {
    if (entity instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(entity)) {
        return VelocityTracker.getVelocityFor((Player) entity);
    }
    return entity.getVelocity();
}
 
Example 3
Source File: ChunkListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevent FireWorks from loading chunks
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
    if (!Settings.IMP.TICK_LIMITER.FIREWORKS_LOAD_CHUNKS) {
        Chunk chunk = event.getChunk();
        Entity[] entities = chunk.getEntities();
        World world = chunk.getWorld();

        Exception e = new Exception();
        int start = 14;
        int end = 22;
        int depth = Math.min(end, getDepth(e));

        for (int frame = start; frame < depth; frame++) {
            StackTraceElement elem = getElement(e, frame);
            if (elem == null) return;
            String className = elem.getClassName();
            int len = className.length();
            if (className != null) {
                if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) {
                    for (Entity ent : world.getEntities()) {
                        if (ent.getType() == EntityType.FIREWORK) {
                            Vector velocity = ent.getVelocity();
                            double vertical = Math.abs(velocity.getY());
                            if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) {
                                Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation());
                                ent.remove();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: JumpEffect.java    From EffectLib with MIT License 5 votes vote down vote up
@Override
public void onRun() {
    Entity entity = getEntity();
    if (entity == null) {
        cancel();
        return;
    }
    Vector v = entity.getVelocity();
    v.setY(v.getY() + power);
    entity.setVelocity(v);
}
 
Example 5
Source File: ModifyBowProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
  Entity projectile = event.getDamager();
  if (projectile.hasMetadata("customProjectile")) {

    // If the custom projectile replaced an arrow, recreate some effects specific to arrows
    if (projectile.hasMetadata("damage")) {
      boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
      int knockback = projectile.getMetadata("knockback").get(0).asInt();
      double damage = projectile.getMetadata("damage").get(0).asDouble();
      double speed = projectile.getVelocity().length();

      // Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
      int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
      if (critical) {
        finalDamage += match.getRandom().nextInt(finalDamage / 2 + 2);
      }
      event.setDamage(finalDamage);

      // Flame arrows - target burns for 5 seconds always
      if (projectile.getFireTicks() > 0) {
        event.getEntity().setFireTicks(100);
      }

      // Reproduce the knockback calculation for punch bows
      if (knockback > 0) {
        Vector projectileVelocity = projectile.getVelocity();
        double horizontalSpeed =
            Math.sqrt(
                projectileVelocity.getX() * projectileVelocity.getX()
                    + projectileVelocity.getZ() * projectileVelocity.getZ());
        Vector velocity = event.getEntity().getVelocity();
        velocity.setX(
            velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
        velocity.setY(velocity.getY() + 0.1);
        velocity.setZ(
            velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
        event.getEntity().setVelocity(velocity);
      }

      // If the projectile is not an arrow, play an impact sound.
      if (event.getEntity() instanceof Player
          && (projectile instanceof Projectile && !(projectile instanceof Arrow))) {
        Projectile customProjectile = (Projectile) projectile;
        if (customProjectile.getShooter() instanceof Player) {
          Player bukkitShooter = (Player) customProjectile.getShooter();
          MatchPlayer shooter = match.getPlayer(bukkitShooter);
          if (shooter != null && event.getEntity() != null) {
            shooter.playSound(PROJECTILE_SOUND);
          }
        }
      }
    }

    // Apply any potion effects attached to the projectile
    if (event.getEntity() instanceof LivingEntity) {
      for (PotionEffect potionEffect : this.potionEffects) {
        ((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
      }
    }
  }
}
 
Example 6
Source File: ModifyBowProjectileMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
    Entity projectile = event.getDamager();
    if(projectile.hasMetadata("customProjectile")) {

        // If the custom projectile replaced an arrow, recreate some effects specific to arrows
        if(projectile.hasMetadata("damage")) {
            boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
            int knockback = projectile.getMetadata("knockback").get(0).asInt();
            double damage = projectile.getMetadata("damage").get(0).asDouble();
            double speed = projectile.getVelocity().length();

            // Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
            int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
            if(critical) {
                finalDamage += random.nextInt(finalDamage / 2 + 2);
            }
            event.setDamage(finalDamage);

            // Flame arrows - target burns for 5 seconds always
            if(projectile.getFireTicks() > 0) {
                event.getEntity().setFireTicks(100);
            }

            // Reproduce the knockback calculation for punch bows
            if(knockback > 0) {
                Vector projectileVelocity = projectile.getVelocity();
                double horizontalSpeed = Math.sqrt(projectileVelocity.getX() * projectileVelocity.getX() +
                                                   projectileVelocity.getZ() * projectileVelocity.getZ());
                Vector velocity = event.getEntity().getVelocity();
                velocity.setX(velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
                velocity.setY(velocity.getY() + 0.1);
                velocity.setZ(velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
                event.getEntity().setVelocity(velocity);
            }
        }

        // Apply any potion effects attached to the projectile
        if(event.getEntity() instanceof LivingEntity) {
            for(PotionEffect potionEffect : this.potionEffects) {
                ((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
            }
        }
    }
}
 
Example 7
Source File: ExprVelocity.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
@Nullable
public Vector convert(Entity e) {
	return e.getVelocity();
}
 
Example 8
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityDamageEvent(EntityDamageEvent e) {

    Entity damaged = e.getEntity();

    if (damaged instanceof Player) {

        CEventHandler.handleEvent((Player) damaged, e, damageNature);

        if (damaged.hasMetadata("ce.springs")) {
            e.setCancelled(true);
            Vector vel = damaged.getVelocity();
            vel.setY((vel.getY() * -0.75) > 1 ? vel.getY() * -0.75 : 0);
            damaged.setVelocity(vel);
        }

    }

}