mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-14 02:31:26 +01:00
More cleanup for SurvivalFly.
* Further split off rather seldom triggering code parts into methods. * Accounting does not manipulate the accumulator anymore. * Remove some unused parameters form signature(s). * Method renaming. * Comment cleanups. (Expect more with time...)
This commit is contained in:
parent
fb30a84f5e
commit
65ee38bf9a
@ -340,7 +340,7 @@ public class SurvivalFly extends Check {
|
|||||||
|
|
||||||
if (!resetFrom && !resetTo){
|
if (!resetFrom && !resetTo){
|
||||||
// "On-air" checks (vertical)
|
// "On-air" checks (vertical)
|
||||||
vDistanceAboveLimit = Math.max(vDistanceAboveLimit, verticalAccounting(now, from, to, hDistance, yDistance, data, cc));
|
vDistanceAboveLimit = Math.max(vDistanceAboveLimit, inAirChecks(now, from, to, hDistance, yDistance, data, cc));
|
||||||
}
|
}
|
||||||
|
|
||||||
final double result = (Math.max(hDistanceAboveLimit, 0D) + Math.max(vDistanceAboveLimit, 0D)) * 100D;
|
final double result = (Math.max(hDistanceAboveLimit, 0D) + Math.max(vDistanceAboveLimit, 0D)) * 100D;
|
||||||
@ -551,8 +551,7 @@ public class SurvivalFly extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First split-off. Not strictly accounting only, actually.<br>
|
* Extended in-air checks for vertical move: y-direction changes and accounting.
|
||||||
* In-air checks.
|
|
||||||
*
|
*
|
||||||
* @param now
|
* @param now
|
||||||
* @param yDistance
|
* @param yDistance
|
||||||
@ -560,58 +559,14 @@ public class SurvivalFly extends Check {
|
|||||||
* @param cc
|
* @param cc
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private double verticalAccounting(final long now, final PlayerLocation from, final PlayerLocation to, final double hDistance, final double yDistance, final MovingData data, final MovingConfig cc) {
|
private double inAirChecks(final long now, final PlayerLocation from, final PlayerLocation to, final double hDistance, final double yDistance, final MovingData data, final MovingConfig cc) {
|
||||||
double vDistanceAboveLimit = 0;
|
double vDistanceAboveLimit = 0;
|
||||||
|
|
||||||
// y direction change detection.
|
// y direction change detection.
|
||||||
// TODO: Consider using accounting for y-change detection.
|
// TODO: Consider using accounting for y-change detection. <- Nope :).
|
||||||
boolean yDirChange = data.sfLastYDist != Double.MAX_VALUE && data.sfLastYDist != yDistance && (yDistance <= 0 && data.sfLastYDist >= 0 || yDistance >= 0 && data.sfLastYDist <= 0 );
|
final boolean yDirChange = data.sfLastYDist != Double.MAX_VALUE && data.sfLastYDist != yDistance && (yDistance <= 0 && data.sfLastYDist >= 0 || yDistance >= 0 && data.sfLastYDist <= 0 );
|
||||||
if (yDirChange){
|
if (yDirChange){
|
||||||
// TODO: account for velocity,
|
vDistanceAboveLimit = yDirChange(from, to, yDistance, vDistanceAboveLimit, data);
|
||||||
if (yDistance > 0){
|
|
||||||
// Increase
|
|
||||||
if (data.toWasReset){
|
|
||||||
tags.add("ychinc");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Moving upwards after falling without having touched the ground.
|
|
||||||
if (data.verticalFreedom <= 0.001 && data.bunnyhopDelay < 9 && !(data.fromWasReset && data.sfLastYDist == 0D)){
|
|
||||||
// TODO: adjust limit for bunny-hop.
|
|
||||||
vDistanceAboveLimit = Math.max(vDistanceAboveLimit, Math.abs(yDistance));
|
|
||||||
tags.add("ychincfly");
|
|
||||||
}
|
|
||||||
else tags.add("ychincair");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// Decrease
|
|
||||||
tags.add("ychdec");
|
|
||||||
// Detect low jumping.
|
|
||||||
if (!data.sfNoLowJump && !data.sfDirty && data.mediumLiftOff == MediumLiftOff.GROUND){
|
|
||||||
final double setBackYDistance = to.getY() - data.getSetBackY();
|
|
||||||
if (setBackYDistance > 0.0){
|
|
||||||
// Only count it if the player has actually been jumping (higher than setback).
|
|
||||||
final Player player = from.getPlayer();
|
|
||||||
// Estimate of minimal jump height.
|
|
||||||
double estimate = 1.15;
|
|
||||||
if (data.jumpAmplifier > 0){
|
|
||||||
// TODO: Could skip this.
|
|
||||||
estimate += 0.5 * getJumpAmplifier(player);
|
|
||||||
}
|
|
||||||
if (setBackYDistance < estimate){
|
|
||||||
// Low jump, further check if there might have been a reason for low jumping.
|
|
||||||
final long flags = BlockProperties.F_GROUND | BlockProperties.F_SOLID;
|
|
||||||
if ((BlockProperties.getBlockFlags(from.getTypeIdAbove()) & flags) == 0){
|
|
||||||
// Check block above that too (if high enough).
|
|
||||||
final int refY = Location.locToBlock(from.getY() + 0.5);
|
|
||||||
if (refY == from.getBlockY() || (BlockProperties.getBlockFlags(from.getTypeId(from.getBlockX(), refY, from.getBlockZ())) & flags) == 0){
|
|
||||||
tags.add("lowjump");
|
|
||||||
data.sfLowJump = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // (Low jump.)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accounting support.
|
// Accounting support.
|
||||||
@ -626,7 +581,8 @@ public class SurvivalFly extends Check {
|
|||||||
else if (data.verticalFreedom <= 0.001D) {
|
else if (data.verticalFreedom <= 0.001D) {
|
||||||
// Here yDistance can be negative and positive (!).
|
// Here yDistance can be negative and positive (!).
|
||||||
if (yDistance != 0D){
|
if (yDistance != 0D){
|
||||||
final double accAboveLimit = verticalAccounting(now, from, to, yDistance, data.vDistAcc ,tags, "vacc");
|
data.vDistAcc.add((float) yDistance);
|
||||||
|
final double accAboveLimit = verticalAccounting(yDistance, data.vDistAcc ,tags, "vacc");
|
||||||
if (accAboveLimit > vDistanceAboveLimit){
|
if (accAboveLimit > vDistanceAboveLimit){
|
||||||
vDistanceAboveLimit = accAboveLimit;
|
vDistanceAboveLimit = accAboveLimit;
|
||||||
}
|
}
|
||||||
@ -641,9 +597,10 @@ public class SurvivalFly extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of values, demanding that with time the values decrease.<br>
|
* Demand that with time the values decrease.<br>
|
||||||
* The ActionFrequency objects have 3 buckets, bucket 1 is checked against
|
* The ActionAccumulator instance must have 3 buckets, bucket 1 is checked against
|
||||||
* bucket 2, 0 is ignored. [Vertical accounting.]
|
* bucket 2, 0 is ignored. [Vertical accounting: applies to both falling and jumping]<br>
|
||||||
|
* NOTE: This just checks and adds to tags, no change to acc.
|
||||||
*
|
*
|
||||||
* @param now
|
* @param now
|
||||||
* @param yDistance
|
* @param yDistance
|
||||||
@ -651,19 +608,16 @@ public class SurvivalFly extends Check {
|
|||||||
* @param count
|
* @param count
|
||||||
* @param tags
|
* @param tags
|
||||||
* @param tag
|
* @param tag
|
||||||
* @return absolute difference on violation.;
|
* @return absolute difference on violation.
|
||||||
*/
|
*/
|
||||||
// private static final double verticalAccounting(final long now, final double value, final ActionFrequency sum, final ActionFrequency count, final ArrayList<String> tags, String tag)
|
private static final double verticalAccounting(final double yDistance, final ActionAccumulator acc, final ArrayList<String> tags, final String tag)
|
||||||
private static final double verticalAccounting(final long now, final PlayerLocation from, final PlayerLocation to, final double yDistance, final ActionAccumulator acc, final ArrayList<String> tags, final String tag)
|
|
||||||
{
|
{
|
||||||
// sum.add(now, (float) value);
|
// TODO: Add on-eq-return parameter <- still?
|
||||||
// count.add(now, 1f);
|
|
||||||
acc.add((float) yDistance);
|
|
||||||
// TODO: Add on-eq-return parameter
|
|
||||||
// if (count.bucketScore(2) > 0 && count.bucketScore(1) > 0) {
|
|
||||||
final int i1, i2;
|
|
||||||
// TODO: distinguish near-ground moves somehow ?
|
// TODO: distinguish near-ground moves somehow ?
|
||||||
// if (acc.bucketCount(0) == acc.bucketCapacity()){
|
// Determine which buckets to check:
|
||||||
|
final int i1, i2;
|
||||||
|
// TODO: use 1st vs. 2nd whenever possible (!) (logics might need idstinguish falling from other ?...).
|
||||||
|
// if (acc.bucketCount(0) == acc.bucketCapacity() &&){
|
||||||
// i1 = 0;
|
// i1 = 0;
|
||||||
// i2 = 1;
|
// i2 = 1;
|
||||||
// }
|
// }
|
||||||
@ -671,28 +625,24 @@ public class SurvivalFly extends Check {
|
|||||||
i1 = 1;
|
i1 = 1;
|
||||||
i2 = 2;
|
i2 = 2;
|
||||||
// }
|
// }
|
||||||
|
// TODO: Do count int first bucket on some occasions.
|
||||||
if (acc.bucketCount(i1) > 0 && acc.bucketCount(i2) > 0) {
|
if (acc.bucketCount(i1) > 0 && acc.bucketCount(i2) > 0) {
|
||||||
// final float sc1 = sum.bucketScore(1);
|
|
||||||
// final float sc2 = sum.bucketScore(2);
|
|
||||||
final float sc1 = acc.bucketScore(i1);
|
final float sc1 = acc.bucketScore(i1);
|
||||||
final float sc2 = acc.bucketScore(i2);
|
final float sc2 = acc.bucketScore(i2);
|
||||||
final double diff = sc1 - sc2;
|
final double diff = sc1 - sc2;
|
||||||
final double aDiff = Math.abs(diff);
|
final double aDiff = Math.abs(diff);
|
||||||
// TODO: Relate this to the fall distance !
|
// TODO: Relate this to the fall distance !
|
||||||
if (diff > 0 || yDistance > -1.1 && aDiff <= 0.07) { // TODO: sharpen later (force speed gain while falling).
|
// TODO: sharpen later (force speed gain while falling).
|
||||||
if (yDistance < -1.1 && (aDiff < Math.abs(yDistance) || sc2 < - 10)){
|
if (diff > 0.0 || yDistance > -1.1 && aDiff <= 0.07) {
|
||||||
// High falling speeds are somewhat ok.
|
if (yDistance < -1.1 && (aDiff < Math.abs(yDistance) || sc2 < - 10.0f)){
|
||||||
|
// High falling speeds may pass.
|
||||||
tags.add(tag + "grace");
|
tags.add(tag + "grace");
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
// else if (value < 0 && aDiff < 0.27 && sc1 * sc2 > 0.0 && Math.abs(sc1) > 0.27 && (BlockProperties.isGround(from.getTypeIdBelow()) || BlockProperties.isGround(to.getTypeIdBelow()) || from.isOnGround(0.6, 0.4, 0))){
|
|
||||||
// // TODO: This part is a temporary workaround for sprinting down block-stairs (around sc1*sc2).
|
|
||||||
// // TODO: This works partly only.
|
|
||||||
// tags.add(tag + "tempgrace");
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
tags.add(tag);
|
tags.add(tag);
|
||||||
if (diff < 0 ){
|
if (diff < 0.0 ){
|
||||||
|
// Note: aDiff should be <= 0.07 here.
|
||||||
|
// TODO: Does this high violation make sense?
|
||||||
return 1.3 - aDiff;
|
return 1.3 - aDiff;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -701,13 +651,69 @@ public class SurvivalFly extends Check {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: return Float.MAX_VALUE if no violation ?
|
// TODO: return Float.MAX_VALUE if no violation ?
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After-failure checks for horizontal velocity.
|
* Check on change of y direction.
|
||||||
|
* @param yDistance
|
||||||
|
* @param vDistanceAboveLimit
|
||||||
|
* @return vDistanceAboveLimit
|
||||||
|
*/
|
||||||
|
private double yDirChange(final PlayerLocation from, final PlayerLocation to, final double yDistance, double vDistanceAboveLimit, final MovingData data) {
|
||||||
|
// TODO: account for velocity,
|
||||||
|
if (yDistance > 0){
|
||||||
|
// Increase
|
||||||
|
if (data.toWasReset){
|
||||||
|
tags.add("ychinc");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Moving upwards after falling without having touched the ground.
|
||||||
|
if (data.verticalFreedom <= 0.001 && data.bunnyhopDelay < 9 && !(data.fromWasReset && data.sfLastYDist == 0D)){
|
||||||
|
// TODO: adjust limit for bunny-hop.
|
||||||
|
vDistanceAboveLimit = Math.max(vDistanceAboveLimit, Math.abs(yDistance));
|
||||||
|
tags.add("ychincfly");
|
||||||
|
}
|
||||||
|
else tags.add("ychincair");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Decrease
|
||||||
|
tags.add("ychdec");
|
||||||
|
// Detect low jumping.
|
||||||
|
if (!data.sfNoLowJump && !data.sfDirty && data.mediumLiftOff == MediumLiftOff.GROUND){
|
||||||
|
final double setBackYDistance = to.getY() - data.getSetBackY();
|
||||||
|
if (setBackYDistance > 0.0){
|
||||||
|
// Only count it if the player has actually been jumping (higher than setback).
|
||||||
|
final Player player = from.getPlayer();
|
||||||
|
// Estimate of minimal jump height.
|
||||||
|
double estimate = 1.15;
|
||||||
|
if (data.jumpAmplifier > 0){
|
||||||
|
// TODO: Could skip this.
|
||||||
|
estimate += 0.5 * getJumpAmplifier(player);
|
||||||
|
}
|
||||||
|
if (setBackYDistance < estimate){
|
||||||
|
// Low jump, further check if there might have been a reason for low jumping.
|
||||||
|
final long flags = BlockProperties.F_GROUND | BlockProperties.F_SOLID;
|
||||||
|
if ((BlockProperties.getBlockFlags(from.getTypeIdAbove()) & flags) == 0){
|
||||||
|
// Check block above that too (if high enough).
|
||||||
|
final int refY = Location.locToBlock(from.getY() + 0.5);
|
||||||
|
if (refY == from.getBlockY() || (BlockProperties.getBlockFlags(from.getTypeId(from.getBlockX(), refY, from.getBlockZ())) & flags) == 0){
|
||||||
|
tags.add("lowjump");
|
||||||
|
data.sfLowJump = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // (Low jump.)
|
||||||
|
}
|
||||||
|
return vDistanceAboveLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After-failure checks for horizontal distance.
|
||||||
*
|
*
|
||||||
* buffers and velocity, also recheck with permissions, if needed.
|
* buffers and velocity, also re-check hDist with permissions, if needed.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param from
|
* @param from
|
||||||
@ -809,6 +815,15 @@ public class SurvivalFly extends Check {
|
|||||||
return new double[]{hAllowedDistance, hDistanceAboveLimit, hFreedom};
|
return new double[]{hAllowedDistance, hDistanceAboveLimit, hFreedom};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inside liquids vertical speed checking.
|
||||||
|
* @param from
|
||||||
|
* @param to
|
||||||
|
* @param toOnGround
|
||||||
|
* @param yDistance
|
||||||
|
* @param data
|
||||||
|
* @return vAllowedDistance, vDistanceAboveLimit
|
||||||
|
*/
|
||||||
private double[] vDistLiquid(final PlayerLocation from, final PlayerLocation to, final boolean toOnGround, final double yDistance, final MovingData data) {
|
private double[] vDistLiquid(final PlayerLocation from, final PlayerLocation to, final boolean toOnGround, final double yDistance, final MovingData data) {
|
||||||
double vAllowedDistance = 0.0;
|
double vAllowedDistance = 0.0;
|
||||||
double vDistanceAboveLimit = 0.0;
|
double vDistanceAboveLimit = 0.0;
|
||||||
@ -837,6 +852,15 @@ public class SurvivalFly extends Check {
|
|||||||
return new double[]{vAllowedDistance, vDistanceAboveLimit};
|
return new double[]{vAllowedDistance, vDistanceAboveLimit};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On-climbable vertical distance checking.
|
||||||
|
* @param from
|
||||||
|
* @param fromOnGround
|
||||||
|
* @param toOnGround
|
||||||
|
* @param yDistance
|
||||||
|
* @param data
|
||||||
|
* @return vDistanceAboveLimit
|
||||||
|
*/
|
||||||
private double vDistClimbable(final PlayerLocation from, final boolean fromOnGround, final boolean toOnGround, final double yDistance, final MovingData data) {
|
private double vDistClimbable(final PlayerLocation from, final boolean fromOnGround, final boolean toOnGround, final double yDistance, final MovingData data) {
|
||||||
double vDistanceAboveLimit = 0.0;
|
double vDistanceAboveLimit = 0.0;
|
||||||
data.sfNoLowJump = true;
|
data.sfNoLowJump = true;
|
||||||
@ -866,6 +890,19 @@ public class SurvivalFly extends Check {
|
|||||||
return vDistanceAboveLimit;
|
return vDistanceAboveLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In-web vertical distance checking.
|
||||||
|
* @param player
|
||||||
|
* @param from
|
||||||
|
* @param to
|
||||||
|
* @param toOnGround
|
||||||
|
* @param hDistanceAboveLimit
|
||||||
|
* @param yDistance
|
||||||
|
* @param now
|
||||||
|
* @param data
|
||||||
|
* @param cc
|
||||||
|
* @return vAllowedDistance, vDistanceAboveLimit
|
||||||
|
*/
|
||||||
private double[] vDistWeb(final Player player, final PlayerLocation from, final PlayerLocation to, final boolean toOnGround, final double hDistanceAboveLimit, final double yDistance, final long now, final MovingData data, final MovingConfig cc) {
|
private double[] vDistWeb(final Player player, final PlayerLocation from, final PlayerLocation to, final boolean toOnGround, final double hDistanceAboveLimit, final double yDistance, final long now, final MovingData data, final MovingConfig cc) {
|
||||||
double vAllowedDistance = 0.0;
|
double vAllowedDistance = 0.0;
|
||||||
double vDistanceAboveLimit = 0.0;
|
double vDistanceAboveLimit = 0.0;
|
||||||
|
Loading…
Reference in New Issue
Block a user