mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Moved speed check to its own class
This commit is contained in:
1 parent
7e2c636ca6
commit
ef771cec86
4 files changed
+85
-72
No files matched your search
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.gravitydevelopment.anticheat</groupId>
|
||||
<artifactId>AntiCheat</artifactId>
|
||||
<version>1.4.0-ALPHA</version>
|
||||
<version>1.5.0-ALPHA</version>
|
||||
<name>AntiCheatReloaded</name>
|
||||
<url>https://rammelkast.com</url>
|
||||
<properties>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package net.gravitydevelopment.anticheat.event;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -58,6 +57,7 @@ import net.gravitydevelopment.anticheat.check.CheckType;
|
||||
import net.gravitydevelopment.anticheat.check.combat.KillAuraCheck;
|
||||
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.util.Distance;
|
||||
@@ -154,7 +154,7 @@ public class PlayerListener extends EventListener {
|
||||
if (getCheckManager().willCheck(player, CheckType.FLY)) {
|
||||
if (getBackend().justVelocity(player) && getBackend().extendVelocityTime(player)) {
|
||||
event.setCancelled(!silentMode());
|
||||
return; // don't log it lol.
|
||||
return;
|
||||
}
|
||||
getBackend().logVelocity(player);
|
||||
}
|
||||
@@ -223,7 +223,6 @@ public class PlayerListener extends EventListener {
|
||||
Player player = event.getPlayer();
|
||||
PlayerInventory inv = player.getInventory();
|
||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
// TODO: offhand (1.9)
|
||||
Material m = inv.getItemInHand().getType();
|
||||
if (m == Material.BOW) {
|
||||
getBackend().logBowWindUp(player);
|
||||
@@ -389,7 +388,7 @@ public class PlayerListener extends EventListener {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
CheckResult result = getBackend().checkXZSpeed(player, x, z);
|
||||
CheckResult result = SpeedCheck.checkXZSpeed(player, x, z);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
@@ -397,18 +396,6 @@ public class PlayerListener extends EventListener {
|
||||
log(result.getMessage(), player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
/*if ((event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ())) {
|
||||
result = backend.checkTimer(player);
|
||||
if(result.failed()) {
|
||||
if (!config.silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log("tried to alter their timer.", player, CheckType.SPEED);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
TODO
|
||||
*/
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.WATER_WALK)) {
|
||||
CheckResult result = WaterWalkCheck.runCheck(player, x, y, z);
|
||||
|
||||
Reference in new issue
Block a user