Skip to content

Commit

Permalink
Update ExprYawPitch.java
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth committed Mar 19, 2024
1 parent f7e859e commit 6c2fdb4
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main/java/ch/njol/skript/expressions/ExprYawPitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"set pitch of player to -90 # Makes the player look upwards, Paper 1.19+ only",
"add 180 to yaw of target of player # Makes the target look behind themselves"
})
@Since("2.0, 2.2-dev28 (vector yaw/pitch), INSERT VERSION (changers)")
@RequiredPlugins("Paper 1.19+ (change player yaw/pitch)")
@Since("2.0, 2.2-dev28 (vector yaw/pitch), INSERT VERSION (entity changers)")
@RequiredPlugins("Paper 1.19+ (player changers)")
public class ExprYawPitch extends SimplePropertyExpression<Object, Number> {

static {
Expand Down Expand Up @@ -88,15 +88,15 @@ public Number convert(Object object) {
} else if (object instanceof Vector) {
Vector vector = (Vector) object;
return usesYaw
? normalizeYaw(VectorMath.getYaw(vector))
: VectorMath.getPitch(vector);
? VectorMath.skriptYaw((VectorMath.getYaw(vector)))
: VectorMath.skriptPitch(VectorMath.getPitch(vector));
}
return null;
}

@Override
public Class<?>[] acceptChange(ChangeMode mode) {
if (getExpr().getReturnType().isAssignableFrom(Player.class) && !SUPPORTS_PLAYERS)
if (Player.class.isAssignableFrom(getExpr().getReturnType()) && !SUPPORTS_PLAYERS)
return null;

switch (mode) {
Expand Down Expand Up @@ -196,15 +196,9 @@ private void changeForVector(Vector vector, float value, ChangeMode mode) {
float yaw = VectorMath.getYaw(vector);
float pitch = VectorMath.getPitch(vector);
switch (mode) {
case SET:
if (usesYaw) {
yaw = value;
} else {
pitch = value;
}
break;
case REMOVE:
value = -value;
// $FALL-THROUGH$
case ADD:
if (usesYaw) {
yaw += value;
Expand All @@ -213,8 +207,14 @@ private void changeForVector(Vector vector, float value, ChangeMode mode) {
pitch -= value;
}
break;
case SET:
if (usesYaw)
yaw = VectorMath.fromSkriptYaw(value);
else
pitch = VectorMath.fromSkriptPitch(value);
}
VectorMath.copyVector(vector, VectorMath.fromYawAndPitch(yaw, pitch).multiply(vector.length()));
Vector newVector = VectorMath.fromYawAndPitch(yaw, pitch).multiply(vector.length());
VectorMath.copyVector(vector, newVector);
}

private static float normalizeYaw(float yaw) {
Expand Down

0 comments on commit 6c2fdb4

Please sign in to comment.