Allow feeding yawrate violations to improbable check. Rename methods for

yawRate.
This commit is contained in:
asofold 2012-09-18 17:53:30 +02:00
parent 985a273286
commit bb24ecaa93
6 changed files with 27 additions and 18 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -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).

View File

@ -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;
}

View File

@ -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

View File

@ -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