Replaced broken reach check, continued work on movement check update

This commit is contained in:
Rammelkast committed 2020-06-13 14:49:35 +02:00
1 parent 636f94b408
commit 20635a2acb
15 files changed
+295 -203

No files matched your search

@@ -31,13 +31,40 @@ import org.bukkit.util.Vector;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.User;
public class KillAuraCheck {
// Angle check
public static final Map<UUID, Integer> ANGLE_FLAGS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult checkReach(Player player, Entity target) {
if (!(target instanceof LivingEntity))
return PASS;
// TODO add configs for everything here
User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
double allowedReach = target.getVelocity().length() < 0.08 ? 3.6D : 4.0D;
// Lag compensation
allowedReach += user.getPing() * 0.0025D;
if (user.isLagging())
allowedReach += 0.2D;
if (target instanceof Player) {
User targetUser = AntiCheatReloaded.getManager().getUserManager().getUser(target.getUniqueId());
allowedReach += targetUser.getPing()
* 0.0025D;
if (targetUser.isLagging())
allowedReach += 0.2D;
}
// Velocity compensation
allowedReach += Math.abs(target.getVelocity().length()) * 1.2D;
double reachedDistance = ((LivingEntity)target).getLocation().toVector().distance(player.getLocation().toVector());
if (reachedDistance > allowedReach)
return new CheckResult(CheckResult.Result.FAILED,
"reached too far (distance=" + reachedDistance + ", max=" + allowedReach + ")");
return PASS;
}
public static CheckResult checkAngle(Player player, EntityDamageEvent event) {
UUID uuid = player.getUniqueId();
Entity entity = event.getEntity();
@@ -49,24 +76,27 @@ public class KillAuraCheck {
double playerYaw = player.getEyeLocation().getYaw();
double angleDifference = Math.abs(180 - Math.abs(Math.abs(yawDifference - playerYaw) - 180));
if (Math.round(angleDifference) > AntiCheatReloaded.getManager().getConfiguration().getMagic().KILLAURA_MAX_ANGLE_DIFFERENCE()) {
if (Math.round(angleDifference) > AntiCheatReloaded.getManager().getConfiguration().getMagic()
.KILLAURA_MAX_ANGLE_DIFFERENCE()) {
if (!ANGLE_FLAGS.containsKey(uuid)) {
ANGLE_FLAGS.put(uuid, 1);
return PASS;
}
int flags = ANGLE_FLAGS.get(uuid);
if (flags >= AntiCheatReloaded.getManager().getConfiguration().getMagic().KILLAURA_MAX_ANGLE_VIOLATIONS()) {
if (flags >= AntiCheatReloaded.getManager().getConfiguration().getMagic()
.KILLAURA_MAX_ANGLE_VIOLATIONS()) {
ANGLE_FLAGS.remove(uuid);
return new CheckResult(CheckResult.Result.FAILED, "tried to attack from an illegal angle (angle=" + Math.round(angleDifference) + ")");
return new CheckResult(CheckResult.Result.FAILED,
"tried to attack from an illegal angle (angle=" + Math.round(angleDifference) + ")");
}
ANGLE_FLAGS.put(uuid, flags + 1);
}
}
return PASS;
}
public static double calculateYawDifference(Location from, Location to) {
Location clonedFrom = from.clone();
Vector startVector = clonedFrom.toVector();