Moved speed check to its own class

This commit is contained in:
Rammelkast committed 2016-11-12 10:49:12 +01:00
1 parent 7e2c636ca6
commit ef771cec86
4 files changed
+85 -72

No files matched your search

@@ -43,6 +43,7 @@ import net.gravitydevelopment.anticheat.check.combat.VelocityCheck;
import net.gravitydevelopment.anticheat.check.movement.BlinkCheck;
import net.gravitydevelopment.anticheat.check.movement.FlightCheck;
import net.gravitydevelopment.anticheat.check.movement.GlideCheck;
import net.gravitydevelopment.anticheat.check.movement.SpeedCheck;
import net.gravitydevelopment.anticheat.check.movement.WaterWalkCheck;
import net.gravitydevelopment.anticheat.check.movement.YAxisCheck;
import net.gravitydevelopment.anticheat.config.Configuration;
@@ -60,7 +61,6 @@ public class Backend {
private Map<String, Integer> chatLevel = new HashMap<String, Integer>();
private Map<String, Integer> commandLevel = new HashMap<String, Integer>();
private Map<String, Integer> nofallViolation = new HashMap<String, Integer>();
private Map<String, Integer> speedViolation = new HashMap<String, Integer>();
private Map<String, Integer> fastBreakViolation = new HashMap<String, Integer>();
private Map<String, Integer> fastBreaks = new HashMap<String, Integer>();
private Map<String, Boolean> blockBreakHolder = new HashMap<String, Boolean>();
@@ -172,6 +172,7 @@ public class Backend {
lastFallPacket.remove(pN);
GlideCheck.lastYDelta.remove(pN);
GlideCheck.glideBuffer.remove(pN);
SpeedCheck.speedViolation.remove(player.getUniqueId());
}
public CheckResult checkFastBow(Player player, float force) {
@@ -289,56 +290,6 @@ public class Backend {
return PASS;
}
public CheckResult checkXZSpeed(Player player, double x, double z) {
if (!isSpeedExempt(player) && player.getVehicle() == null) {
String reason = "";
double max = magic.XZ_SPEED_MAX();
if (player.getLocation().getBlock().getType() == Material.SOUL_SAND) {
if (player.isSprinting()) {
reason = "on soulsand while sprinting ";
max = magic.XZ_SPEED_MAX_SOULSAND_SPRINT();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
reason = "on soulsand with speed potion ";
max = magic.XZ_SPEED_MAX_SOULSAND_POTION();
} else {
reason = "on soulsand ";
max = magic.XZ_SPEED_MAX_SOULSAND();
}
} else if (player.isFlying()) {
reason = "while flying ";
max = magic.XZ_SPEED_MAX_FLY();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
if (player.isSprinting()) {
reason = "with speed potion while sprinting ";
max = magic.XZ_SPEED_MAX_POTION_SPRINT();
} else {
reason = "with speed potion ";
max = magic.XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
reason = "while sprinting ";
max = magic.XZ_SPEED_MAX_SPRINT();
}
float speed = player.getWalkSpeed();
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
if (x > max || z > max) {
int num = this.incrementOld(player, speedViolation, magic.SPEED_MAX());
if (num >= magic.SPEED_MAX()) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + "'s speed was too high " + reason + num + " times in a row (max=" + magic.SPEED_MAX() + ", speed=" + (x > z ? x : z) + ", max speed=" + max + ")");
} else {
return PASS;
}
} else {
speedViolation.put(player.getName(), 0);
return PASS;
}
} else {
return PASS;
}
}
public CheckResult checkSneak(Player player, double x, double z) {
if (player.isSneaking() && !player.isFlying() && !isMovingExempt(player) && !player.isInsideVehicle()) {
double i = x > magic.XZ_SPEED_MAX_SNEAK() ? x : z > magic.XZ_SPEED_MAX_SNEAK() ? z : -1;
@@ -848,10 +799,6 @@ public class Backend {
return isAscending.contains(player.getName());
}
public boolean isSpeedExempt(Player player) {
return isMovingExempt(player) || justVelocity(player) || VersionUtil.isFlying(player);
}
private boolean isDoing(Player player, Map<String, Long> map, double max) {
if (map.containsKey(player.getName())) {
if (max != -1) {
@@ -0,0 +1,79 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.VersionUtil;
public class SpeedCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<UUID, Integer> speedViolation = new HashMap<UUID, Integer>();
public static boolean isSpeedExempt(Player player) {
return AntiCheat.getManager().getBackend().isMovingExempt(player)
|| AntiCheat.getManager().getBackend().justVelocity(player) || VersionUtil.isFlying(player);
}
public static CheckResult checkXZSpeed(Player player, double x, double z) {
if (!isSpeedExempt(player) && player.getVehicle() == null) {
String reason = "";
double max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX();
if (player.getLocation().getBlock().getType() == Material.SOUL_SAND) {
if (player.isSprinting()) {
reason = "on soulsand while sprinting ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_SPRINT();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
reason = "on soulsand with speed potion ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_POTION();
} else {
reason = "on soulsand ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND();
}
} else if (player.isFlying()) {
reason = "while flying ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_FLY();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
if (player.isSprinting()) {
reason = "with speed potion while sprinting ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION_SPRINT();
} else {
reason = "with speed potion ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
reason = "while sprinting ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT();
}
float speed = player.getWalkSpeed();
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
if (x > max || z > max) {
int num = AntiCheat.getManager().getBackend().increment(player, speedViolation,
AntiCheat.getManager().getBackend().getMagic().SPEED_MAX());
if (num >= AntiCheat.getManager().getBackend().getMagic().SPEED_MAX()) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + "'s speed was too high " + reason + num + " times in a row (max="
+ AntiCheat.getManager().getBackend().getMagic().SPEED_MAX() + ", speed="
+ (x > z ? x : z) + ", max speed=" + max + ")");
} else {
return PASS;
}
} else {
speedViolation.put(player.getUniqueId(), 0);
return PASS;
}
} else {
return PASS;
}
}
}