mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-03 22:37:44 +01:00
Allow feeding yawrate violations to improbable check. Rename methods for
yawRate.
This commit is contained in:
parent
985a273286
commit
bb24ecaa93
@ -18,8 +18,8 @@ public class Combined {
|
||||
* @param worldName
|
||||
* @return
|
||||
*/
|
||||
public static final boolean checkYaw(final Player player, final float yaw, final long now, final String worldName){
|
||||
return checkYaw(player, yaw, now, worldName, CombinedData.getData(player));
|
||||
public static final boolean checkYawRate(final Player player, final float yaw, final long now, final String worldName){
|
||||
return checkYawRate(player, yaw, now, worldName, CombinedData.getData(player));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,8 +29,8 @@ public class Combined {
|
||||
* @param now
|
||||
* @param worldName
|
||||
*/
|
||||
public static final void feedYaw(final Player player, final float yaw, final long now, final String worldName){
|
||||
feedYaw(player, yaw, now, worldName, CombinedData.getData(player));
|
||||
public static final void feedYawRate(final Player player, final float yaw, final long now, final String worldName){
|
||||
feedYawRate(player, yaw, now, worldName, CombinedData.getData(player));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +41,7 @@ public class Combined {
|
||||
* @param worldName
|
||||
* @param data
|
||||
*/
|
||||
private static final void feedYaw(final Player player, final float yaw, final long now, final String worldName, final CombinedData data) {
|
||||
private static final void feedYawRate(final Player player, final float yaw, final long now, final String worldName, final CombinedData data) {
|
||||
// Reset on world change or timeout.
|
||||
if (now - data.lastYawTime > 999 || !worldName.equals(data.lastWorld)){
|
||||
data.lastYaw = yaw;
|
||||
@ -70,20 +70,25 @@ public class Combined {
|
||||
* @param worldName
|
||||
* @return
|
||||
*/
|
||||
private static final boolean checkYaw(Player player, float yaw, long now, final String worldName, final CombinedData data) {
|
||||
private static final boolean checkYawRate(Player player, float yaw, long now, final String worldName, final CombinedData data) {
|
||||
|
||||
feedYaw(player, yaw, now, worldName, data);
|
||||
feedYawRate(player, yaw, now, worldName, data);
|
||||
|
||||
final CombinedConfig cc = CombinedConfig.getConfig(player);
|
||||
|
||||
// Angle diff per second
|
||||
final float total = Math.max(data.yawFreq.getScore(1f), data.yawFreq.getScore(0) * 3f);
|
||||
final float threshold = cc.lastYawRate;
|
||||
final float threshold = cc.yawRate;
|
||||
boolean cancel = false;
|
||||
if (total > threshold){
|
||||
// Add time
|
||||
data.timeFreeze = Math.max(data.timeFreeze, now + (long) ((total - threshold) / threshold * 1000f));
|
||||
final float amount = ((total - threshold) / threshold * 1000f);
|
||||
data.timeFreeze = Math.max(data.timeFreeze, now + (long) amount);
|
||||
if (cc.yawRateImprobable && Improbable.check(player, 5f * amount / 1000f, now))
|
||||
cancel = true;
|
||||
}
|
||||
return now < data.timeFreeze;
|
||||
if (now < data.timeFreeze) cancel = true;
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,10 +100,10 @@ public class Combined {
|
||||
* @param yawRateCheck If to actually check the yaw rate, or just feed.
|
||||
* @return
|
||||
*/
|
||||
public static final boolean checkYaw(final Player player, final float yaw, final long now, final String worldName, final boolean yawRateCheck) {
|
||||
if (yawRateCheck) return checkYaw(player, yaw, now, worldName);
|
||||
public static final boolean checkYawRate(final Player player, final float yaw, final long now, final String worldName, final boolean yawRateCheck) {
|
||||
if (yawRateCheck) return checkYawRate(player, yaw, now, worldName);
|
||||
else {
|
||||
feedYaw(player, yaw, now, worldName);
|
||||
feedYawRate(player, yaw, now, worldName);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -43,14 +43,16 @@ public class CombinedConfig extends ACheckConfig {
|
||||
public final ActionList improbableActions;
|
||||
|
||||
// Last yaw tracking
|
||||
public final float lastYawRate;
|
||||
public final float yawRate;
|
||||
public final boolean yawRateImprobable;
|
||||
|
||||
public CombinedConfig(final ConfigFile config) {
|
||||
improbableCheck = config.getBoolean(ConfPaths.COMBINED_IMPROBABLE_CHECK, false);
|
||||
improbableLevel = (float) config.getDouble(ConfPaths.COMBINED_IMPROBABLE_LEVEL, 300);
|
||||
improbableActions = config.getActionList(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, Permissions.COMBINED_IMPROBABLE);
|
||||
|
||||
lastYawRate = config.getInt(ConfPaths.COMBINED_YAWRATE_RATE);
|
||||
yawRate = config.getInt(ConfPaths.COMBINED_YAWRATE_RATE);
|
||||
yawRateImprobable = config.getBoolean(ConfPaths.COMBINED_YAWRATE_IMPROBABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,7 +41,7 @@ public class CombinedListener implements Listener {
|
||||
// Just add the yaw to the list.
|
||||
final Location loc = player.getLocation();
|
||||
final String worldName = loc.getWorld().getName();
|
||||
Combined.feedYaw(player, loc.getYaw(), System.currentTimeMillis(), worldName);
|
||||
Combined.feedYawRate(player, loc.getYaw(), System.currentTimeMillis(), worldName);
|
||||
}
|
||||
|
||||
// (possibly other types of events, but these combine with fighting).
|
||||
|
@ -119,7 +119,7 @@ public class FightListener implements Listener {
|
||||
final boolean worldChanged = !worldName.equals(data.lastWorld);
|
||||
|
||||
// Improbable yaw:
|
||||
if (Combined.checkYaw(player, player.getLocation().getYaw(), now, worldName, cc.yawRateCheck)){
|
||||
if (Combined.checkYawRate(player, player.getLocation().getYaw(), now, worldName, cc.yawRateCheck)){
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
|
@ -303,6 +303,7 @@ public abstract class ConfPaths {
|
||||
|
||||
private static final String COMBINED_YAWRATE = COMBINED + "yawrate.";
|
||||
public static final String COMBINED_YAWRATE_RATE = COMBINED_YAWRATE + "rate";
|
||||
public static final String COMBINED_YAWRATE_IMPROBABLE = COMBINED_YAWRATE + "improbable";
|
||||
|
||||
/*
|
||||
* 888'Y88 ,e, 888 d8
|
||||
|
@ -228,7 +228,8 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.COMBINED_IMPROBABLE_FASTBREAK_CHECK, false);
|
||||
set(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, "cancel log:improbable:2:8:if");
|
||||
|
||||
set(ConfPaths.COMBINED_YAWRATE_RATE , "380");
|
||||
set(ConfPaths.COMBINED_YAWRATE_RATE , 380);
|
||||
set(ConfPaths.COMBINED_YAWRATE_IMPROBABLE, true);
|
||||
|
||||
/*
|
||||
* 888'Y88 ,e, 888 d8
|
||||
|
Loading…
Reference in New Issue
Block a user