diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java index 7efb5a56..99a2ccb3 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java @@ -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. diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java index 0b387042..a82b72df 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/utilities/CheckUtils.java @@ -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