package de.slikey.effectlib.util;

import org.bukkit.util.Vector;

public final class VectorUtils {

    private VectorUtils() {
    }

    public static final Vector rotateAroundAxisX(Vector v, double angle) {
        double y, z, cos, sin;
        cos = Math.cos(angle);
        sin = Math.sin(angle);
        y = v.getY() * cos - v.getZ() * sin;
        z = v.getY() * sin + v.getZ() * cos;
        return v.setY(y).setZ(z);
    }

    public static final Vector rotateAroundAxisY(Vector v, double angle) {
        double x, z, cos, sin;
        cos = Math.cos(angle);
        sin = Math.sin(angle);
        x = v.getX() * cos + v.getZ() * sin;
        z = v.getX() * -sin + v.getZ() * cos;
        return v.setX(x).setZ(z);
    }

    public static final Vector rotateAroundAxisZ(Vector v, double angle) {
        double x, y, cos, sin;
        cos = Math.cos(angle);
        sin = Math.sin(angle);
        x = v.getX() * cos - v.getY() * sin;
        y = v.getX() * sin + v.getY() * cos;
        return v.setX(x).setY(y);
    }

    public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) {
        // double x = v.getX(), y = v.getY(), z = v.getZ();
        // double cosX = Math.cos(angleX), sinX = Math.sin(angleX), cosY =
        // Math.cos(angleY), sinY = Math.sin(angleY), cosZ = Math.cos(angleZ),
        // sinZ = Math.sin(angleZ);
        // double nx, ny, nz;
        // nx = (x * cosY + z * sinY) * (x * cosZ - y * sinZ);
        // ny = (y * cosX - z * sinX) * (x * sinZ + y * cosZ);
        // nz = (y * sinX + z * cosX) * (-x * sinY + z * cosY);
        // return v.setX(nx).setY(ny).setZ(nz);
        // Having some strange behavior up there.. Have to look in it later. TODO
        rotateAroundAxisX(v, angleX);
        rotateAroundAxisY(v, angleY);
        rotateAroundAxisZ(v, angleZ);
        return v;
    }

    public static final double angleToXAxis(Vector vector) {
        return Math.atan2(vector.getX(), vector.getY());
    }

}

@@ -1859,32 +1859,885 @@
 eturn v;%0A    %7D%0A%0A
+    /**%0A     * This handles non-unit vectors, with yaw and pitch instead of X,Y,Z angles.%0A     *%0A     * Thanks to SexyToad!%0A     *%0A     * @param v%0A     * @param yaw%0A     * @param pitch%0A     * @return%0A     */%0A    public static final Vector rotateVector(Vector v, double yaw, double pitch) %7B%0A        double length;%0A        yaw = Math.toRadians(-1 * (yaw + 90));%0A        pitch = Math.toRadians(-pitch);%0A        double x;%0A        double y;%0A        double z;%0A%0A        double cosYaw = Math.cos(yaw);%0A        double cosPitch = Math.sin(yaw);%0A        double sinYaw = Math.cos(pitch);%0A        double sinPitch = Math.cos(pitch);%0A%0A        length = v.length();%0A        x = length * cosYaw * sinPitch;%0A        y = length * sinYaw * sinPitch;%0A        z = length * cosPitch;%0A%0A        Vector adjustedVector = new Vector(x, y, z);%0A%0A        return adjustedVector;%0A    %7D%0A%0A
     public stati
@@ -2844,11 +2844,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Add yaw/pitch based rotateVector method (thanks to SexyToad!)