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

The following examples show how to use org.bukkit.entity.Player#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: GrapplingHookListener.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private void handleGrapplingHook(Arrow arrow) {
    if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player) {
        Player p = (Player) arrow.getShooter();
        GrapplingHookEntity hook = activeHooks.get(p.getUniqueId());

        if (hook != null) {
            Location target = arrow.getLocation();
            hook.drop(target);

            Vector velocity = new Vector(0.0, 0.2, 0.0);

            if (p.getLocation().distance(target) < 3.0) {
                if (target.getY() <= p.getLocation().getY()) {
                    velocity = target.toVector().subtract(p.getLocation().toVector());
                }
            }
            else {
                Location l = p.getLocation();
                l.setY(l.getY() + 0.5);
                p.teleport(l);

                double g = -0.08;
                double d = target.distance(l);
                double t = d;
                double vX = (1.0 + 0.08 * t) * (target.getX() - l.getX()) / t;
                double vY = (1.0 + 0.04 * t) * (target.getY() - l.getY()) / t - 0.5D * g * t;
                double vZ = (1.0 + 0.08 * t) * (target.getZ() - l.getZ()) / t;

                velocity = p.getVelocity();
                velocity.setX(vX);
                velocity.setY(vY);
                velocity.setZ(vZ);
            }

            p.setVelocity(velocity);

            hook.remove();
            Slimefun.runSync(() -> activeHooks.remove(p.getUniqueId()), 20L);
        }
    }
}