mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-26 18:37:59 +01:00
Use a defensive method for yaw difference for the angle check.
This commit is contained in:
parent
7f17420606
commit
05c7699937
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
|
||||
/*
|
||||
@ -71,6 +72,7 @@ public class Angle extends Check {
|
||||
|
||||
// Browse the locations of the map.
|
||||
long previousTime = 0L;
|
||||
// TODO: Don't store locations, but yaws ?
|
||||
Location previousLocation = null;
|
||||
for (final long time : data.angleHits.descendingKeySet()) {
|
||||
final Location location = data.angleHits.get(time);
|
||||
@ -82,7 +84,7 @@ public class Angle extends Check {
|
||||
// Calculate the time elapsed between the two hits.
|
||||
deltaTime += previousTime - time;
|
||||
// Calculate the difference of the yaw between the two locations.
|
||||
final float dYaw = (previousLocation.getYaw() - location.getYaw()) % 180;
|
||||
final float dYaw = CheckUtils.yawDiff(previousLocation.getYaw(), location.getYaw());
|
||||
deltaYaw += Math.abs(dYaw);
|
||||
}
|
||||
// Remember the current time and location.
|
||||
|
@ -16,7 +16,7 @@ import org.bukkit.util.Vector;
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
|
||||
/**
|
||||
* Random auxiliary gear, some might have general quality.
|
||||
* Random auxiliary gear, some might have general quality. Contents are likely to get moved to other classes.
|
||||
*/
|
||||
public class CheckUtils {
|
||||
|
||||
@ -319,6 +319,23 @@ public class CheckUtils {
|
||||
else return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Yaw (angle in grad) difference. This ensures inputs are interpreted correctly (for 360 degree offsets).
|
||||
* @param fromYaw
|
||||
* @param toYaw
|
||||
* @return Angle difference to get from fromYaw to toYaw. Result is in [-180, 180].
|
||||
*/
|
||||
public static final float yawDiff(float fromYaw, float toYaw){
|
||||
if (fromYaw <= -360f) fromYaw = -((-fromYaw) % 360f);
|
||||
else if (fromYaw >= 360f) fromYaw = fromYaw % 360f;
|
||||
if (toYaw <= -360f) toYaw = -((-toYaw) % 360f);
|
||||
else if (toYaw >= 360f) toYaw = toYaw % 360f;
|
||||
float yawDiff = toYaw - fromYaw;
|
||||
if (yawDiff < -180f) yawDiff += 360f;
|
||||
else if (yawDiff > 180f) yawDiff -= 360f;
|
||||
return yawDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use instead: LogUtil.logSevere
|
||||
* @param msg
|
||||
|
Loading…
Reference in New Issue
Block a user