mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-02 14:38:45 +00:00
Update to 1.16, migrate config and more movement changes
This commit is contained in:
1 parent
20635a2acb
commit
add3fe5eae
27 files changed
+986
-692
No files matched your search
@@ -44,9 +44,7 @@ import com.rammelkast.anticheatreloaded.check.movement.AimbotCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.ElytraCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.FlightCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.GlideCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.movement.YAxisCheck;
|
||||
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
|
||||
import com.rammelkast.anticheatreloaded.config.Configuration;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Lang;
|
||||
@@ -59,6 +57,7 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
public class Backend {
|
||||
public Map<UUID, Long> velocitized = new HashMap<UUID, Long>();
|
||||
private Map<UUID, Long> levitatingEnd = new HashMap<UUID, Long>();
|
||||
private List<UUID> isAscending = new ArrayList<UUID>();
|
||||
private Map<UUID, Integer> chatLevel = new HashMap<UUID, Integer>();
|
||||
private Map<UUID, Integer> commandLevel = new HashMap<UUID, Integer>();
|
||||
@@ -80,7 +79,7 @@ public class Backend {
|
||||
private Map<UUID, Long> instantBreakExempt = new HashMap<UUID, Long>();
|
||||
private Map<UUID, Long> sprinted = new HashMap<UUID, Long>();
|
||||
private Map<UUID, Long> brokenBlock = new HashMap<UUID, Long>();
|
||||
private Map<UUID, Long> placedBlock = new HashMap<UUID, Long>();
|
||||
public Map<UUID, Long> placedBlock = new HashMap<UUID, Long>();
|
||||
private Map<UUID, Long> blockTime = new HashMap<UUID, Long>();
|
||||
private Map<UUID, Integer> blocksDropped = new HashMap<UUID, Integer>();
|
||||
private Map<UUID, Long> lastInventoryTime = new HashMap<UUID, Long>();
|
||||
@@ -158,6 +157,7 @@ public class Backend {
|
||||
lastFallPacket.remove(uuid);
|
||||
fastSneakViolations.remove(uuid);
|
||||
lastSneak.remove(uuid);
|
||||
levitatingEnd.remove(uuid);
|
||||
AimbotCheck.LAST_DELTA_YAW.remove(uuid);
|
||||
VelocityCheck.VIOLATIONS.remove(uuid);
|
||||
MorePacketsCheck.LAST_PACKET_TIME.remove(uuid);
|
||||
@@ -169,10 +169,6 @@ public class Backend {
|
||||
ElytraCheck.JUMP_Y_VALUE.remove(uuid);
|
||||
KillAuraCheck.ANGLE_FLAGS.remove(uuid);
|
||||
FlightCheck.MOVING_EXEMPT.remove(uuid);
|
||||
YAxisCheck.Y_AXIS_VIOLATIONS.remove(uuid);
|
||||
YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(uuid);
|
||||
YAxisCheck.LAST_Y_COORD_CACHE.remove(uuid);
|
||||
YAxisCheck.LAST_Y_TIME.remove(uuid);
|
||||
WaterWalkCheck.IS_IN_WATER.remove(uuid);
|
||||
WaterWalkCheck.IS_IN_WATER_CACHE.remove(uuid);
|
||||
WaterWalkCheck.WATER_ASCENSION_VIOLATIONS.remove(uuid);
|
||||
@@ -472,7 +468,7 @@ public class Backend {
|
||||
if (lastBlockPlaced.get(uuid) > 0 && math < magic.FASTPLACE_MAXVIOLATIONTIME()) {
|
||||
lastBlockPlaced.put(uuid, time);
|
||||
return new CheckResult(CheckResult.Result.FAILED, "placed blocks too fast "
|
||||
+ fastBreakViolation.get(uuid) + " times in a row (max=" + violations + ")");
|
||||
+ fastPlaceViolation.get(uuid) + " times in a row (max=" + violations + ")");
|
||||
} else if (lastBlockPlaced.get(uuid) > 0 && math > magic.FASTPLACE_MAXVIOLATIONTIME()) {
|
||||
fastPlaceViolation.put(uuid, 0);
|
||||
}
|
||||
@@ -548,7 +544,9 @@ public class Backend {
|
||||
if (Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.BASIC_LATIN
|
||||
&& Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.LATIN_1_SUPPLEMENT
|
||||
&& Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.LATIN_EXTENDED_A
|
||||
&& Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.GENERAL_PUNCTUATION) {
|
||||
&& Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.GENERAL_PUNCTUATION
|
||||
&& Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.CYRILLIC
|
||||
&& Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.CYRILLIC_EXTENDED_A) {
|
||||
return new CheckResult(CheckResult.Result.FAILED, "Unicode chat is not allowed.");
|
||||
}
|
||||
}
|
||||
@@ -678,16 +676,6 @@ public class Backend {
|
||||
sprinted.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public boolean isHoveringOverWaterAfterViolation(Player player) {
|
||||
if (WaterWalkCheck.WATER_SPEED_VIOLATIONS.containsKey(player.getUniqueId())) {
|
||||
if (WaterWalkCheck.WATER_SPEED_VIOLATIONS.get(player.getUniqueId()) >= magic.WATER_SPEED_VIOLATION_MAX()
|
||||
&& Utilities.isHoveringOverWater(player.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void logBlockBreak(final Player player) {
|
||||
brokenBlock.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
@@ -700,11 +688,21 @@ public class Backend {
|
||||
velocitized.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void logLevitating(final Player player, final int duration) {
|
||||
levitatingEnd.put(player.getUniqueId(), System.currentTimeMillis() + (duration * 1000L));
|
||||
}
|
||||
|
||||
public boolean justVelocity(Player player) {
|
||||
return (velocitized.containsKey(player.getUniqueId())
|
||||
? (System.currentTimeMillis() - velocitized.get(player.getUniqueId())) < magic.VELOCITY_CHECKTIME()
|
||||
: false);
|
||||
}
|
||||
|
||||
public boolean justLevitated(Player player) {
|
||||
return (levitatingEnd.containsKey(player.getUniqueId())
|
||||
? (System.currentTimeMillis() - levitatingEnd.get(player.getUniqueId())) < magic.VELOCITY_CHECKTIME()
|
||||
: false);
|
||||
}
|
||||
|
||||
public boolean extendVelocityTime(final Player player) {
|
||||
if (velocitytrack.containsKey(player.getUniqueId())) {
|
||||
@@ -765,15 +763,9 @@ public class Backend {
|
||||
}
|
||||
|
||||
public void logTeleport(final Player player) {
|
||||
// TODO check this
|
||||
//FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME());
|
||||
|
||||
manager.getUserManager().getUser(player.getUniqueId()).getMovementManager().lastTeleport = System.currentTimeMillis();
|
||||
/* Data for fly/speed should be reset */
|
||||
nofallViolation.remove(player.getUniqueId());
|
||||
YAxisCheck.Y_AXIS_VIOLATIONS.remove(player.getUniqueId());
|
||||
YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(player.getUniqueId());
|
||||
YAxisCheck.LAST_Y_COORD_CACHE.remove(player.getUniqueId());
|
||||
YAxisCheck.LAST_Y_TIME.remove(player.getUniqueId());
|
||||
GlideCheck.LAST_FALL_DISTANCE.remove(player.getUniqueId());
|
||||
GlideCheck.LAST_MOTION_Y.remove(player.getUniqueId());
|
||||
GlideCheck.VIOLATIONS.remove(player.getUniqueId());
|
||||
|
||||
@@ -36,47 +36,50 @@ import java.util.UUID;
|
||||
*/
|
||||
|
||||
public enum CheckType {
|
||||
FLIGHT(Permission.CHECK_FLIGHT),
|
||||
ELYTRAFLY(Permission.CHECK_FLIGHT),
|
||||
WATER_WALK(Permission.CHECK_WATERWALK),
|
||||
NO_SWING(Permission.CHECK_NOSWING),
|
||||
FAST_BREAK(Permission.CHECK_FASTBREAK),
|
||||
FAST_PLACE(Permission.CHECK_FASTPLACE),
|
||||
CHAT_SPAM(Permission.CHECK_CHATSPAM),
|
||||
COMMAND_SPAM(Permission.CHECK_COMMANDSPAM),
|
||||
SPRINT(Permission.CHECK_SPRINT),
|
||||
SNEAK(Permission.CHECK_SNEAK),
|
||||
SPEED(Permission.CHECK_SPEED),
|
||||
VCLIP(Permission.CHECK_VCLIP),
|
||||
SPIDER(Permission.CHECK_SPIDER),
|
||||
NOFALL(Permission.CHECK_NOFALL),
|
||||
FAST_BOW(Permission.CHECK_FASTBOW),
|
||||
FAST_EAT(Permission.CHECK_FASTEAT),
|
||||
FAST_HEAL(Permission.CHECK_FASTHEAL),
|
||||
KILLAURA(Permission.CHECK_KILLAURA),
|
||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL),
|
||||
MOREPACKETS(Permission.CHECK_MOREPACKETS),
|
||||
BADPACKETS(Permission.CHECK_BADPACKETS),
|
||||
VELOCITY(Permission.CHECK_VELOCITY),
|
||||
CRITICALS(Permission.CHECK_CRITICALS),
|
||||
CHAT_UNICODE(Permission.CHECK_UNICODE),
|
||||
ILLEGAL_INTERACT(Permission.CHECK_ILLEGALINTERACT),
|
||||
FASTLADDER(Permission.CHECK_FASTLADDER),
|
||||
AIMBOT(Permission.CHECK_AIMBOT);
|
||||
FLIGHT(Permission.CHECK_FLIGHT, "Flight"),
|
||||
ELYTRAFLY(Permission.CHECK_FLIGHT, "ElytraFly"),
|
||||
WATER_WALK(Permission.CHECK_WATERWALK, "WaterWalk"),
|
||||
NO_SWING(Permission.CHECK_NOSWING, "NoSwing"),
|
||||
FAST_BREAK(Permission.CHECK_FASTBREAK, "FastBreak"),
|
||||
FAST_PLACE(Permission.CHECK_FASTPLACE, "FastPlace"),
|
||||
CHAT_SPAM(Permission.CHECK_CHATSPAM, "ChatSpam"),
|
||||
COMMAND_SPAM(Permission.CHECK_COMMANDSPAM, "CommandSpam"),
|
||||
SPRINT(Permission.CHECK_SPRINT, "Sprint"),
|
||||
SNEAK(Permission.CHECK_SNEAK, "Sneak"),
|
||||
SPEED(Permission.CHECK_SPEED, "Speed"),
|
||||
VCLIP(Permission.CHECK_VCLIP, "vClip"),
|
||||
SPIDER(Permission.CHECK_SPIDER, "Spider"),
|
||||
NOFALL(Permission.CHECK_NOFALL, "NoFall"),
|
||||
FAST_BOW(Permission.CHECK_FASTBOW, "FastBow"),
|
||||
FAST_EAT(Permission.CHECK_FASTEAT, "FastEat"),
|
||||
FAST_HEAL(Permission.CHECK_FASTHEAL, "FastHeal"),
|
||||
KILLAURA(Permission.CHECK_KILLAURA, "KillAura"),
|
||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE, "FastProjectile"),
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM, "ItemSpam"),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY, "FastInventory"),
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL, "AutoTool"),
|
||||
MOREPACKETS(Permission.CHECK_MOREPACKETS, "MorePackets"),
|
||||
BADPACKETS(Permission.CHECK_BADPACKETS, "BadPackets"),
|
||||
VELOCITY(Permission.CHECK_VELOCITY, "Velocity"),
|
||||
CRITICALS(Permission.CHECK_CRITICALS, "Criticals"),
|
||||
CHAT_UNICODE(Permission.CHECK_UNICODE, "ChatUnicode"),
|
||||
ILLEGAL_INTERACT(Permission.CHECK_ILLEGALINTERACT, "IllegalInteract"),
|
||||
FASTLADDER(Permission.CHECK_FASTLADDER, "FastLadder"),
|
||||
AIMBOT(Permission.CHECK_AIMBOT, "Aimbot");
|
||||
|
||||
private final Permission permission;
|
||||
private final String displayName;
|
||||
private final Map<UUID, Integer> level = new HashMap<UUID, Integer>();
|
||||
|
||||
/**
|
||||
* Initialize a CheckType
|
||||
*
|
||||
* @param perm Permission that applies to this check
|
||||
* @param permission Permission that applies to this check
|
||||
* @peram displayName The chat display name
|
||||
*/
|
||||
private CheckType(Permission perm) {
|
||||
this.permission = perm;
|
||||
private CheckType(Permission permission, String displayName) {
|
||||
this.permission = permission;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,23 +125,9 @@ public enum CheckType {
|
||||
/**
|
||||
* Get the reference name of a check
|
||||
*
|
||||
* @param type Type of check
|
||||
* @return reference name
|
||||
*/
|
||||
public static String getName(CheckType type) {
|
||||
if (type.name().contains("_")) {
|
||||
String[] split = type.name().toLowerCase().split("_");
|
||||
String name = "";
|
||||
for (String part : split) {
|
||||
char[] chars = part.toCharArray();
|
||||
chars[0] = Character.toUpperCase(chars[0]);
|
||||
name += new String(chars);
|
||||
}
|
||||
return name;
|
||||
} else {
|
||||
char[] chars = type.name().toLowerCase().toCharArray();
|
||||
chars[0] = Character.toUpperCase(chars[0]);
|
||||
return new String(chars);
|
||||
}
|
||||
public String getName() {
|
||||
return this.displayName;
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,12 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
import com.rammelkast.anticheatreloaded.util.MovementManager;
|
||||
import com.rammelkast.anticheatreloaded.util.User;
|
||||
|
||||
public class KillAuraCheck {
|
||||
@@ -104,4 +106,5 @@ public class KillAuraCheck {
|
||||
clonedFrom.setDirection(targetVector.subtract(startVector));
|
||||
return clonedFrom.getYaw();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class AimbotCheck {
|
||||
if (backend.isMovingExempt(player)) {
|
||||
return PASS;
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
float dYaw = Math.abs(event.getTo().getYaw() - event.getFrom().getYaw());
|
||||
float dPitch = Math.abs(event.getTo().getPitch() - event.getFrom().getPitch());
|
||||
@@ -56,9 +57,8 @@ public class AimbotCheck {
|
||||
LAST_DELTA_YAW.put(uuid, dYaw);
|
||||
|
||||
float absoluteYawDifference = Math.abs(dYaw - lastDeltaYaw);
|
||||
if (absoluteYawDifference < 1E-8 && dYaw > 30 && dYaw < 355) {
|
||||
if (absoluteYawDifference < 1E-8 && dYaw > 30 && dYaw < 355)
|
||||
return new CheckResult(CheckResult.Result.FAILED, "repeated yaw difference (dYaw=" + dYaw + ")");
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,18 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckType;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Checks;
|
||||
import com.rammelkast.anticheatreloaded.util.Distance;
|
||||
import com.rammelkast.anticheatreloaded.util.MovementManager;
|
||||
import com.rammelkast.anticheatreloaded.util.User;
|
||||
import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
/**
|
||||
@@ -37,7 +43,7 @@ public class FlightCheck {
|
||||
|
||||
public static final Map<UUID, Long> MOVING_EXEMPT = new HashMap<UUID, Long>();
|
||||
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
|
||||
|
||||
|
||||
public static CheckResult runCheck(Player player, Distance distance) {
|
||||
if (distance.getYDifference() >= AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()
|
||||
|| VersionUtil.isFlying(player)) {
|
||||
@@ -46,8 +52,79 @@ public class FlightCheck {
|
||||
return PASS;
|
||||
}
|
||||
|
||||
MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
|
||||
.getMovementManager();
|
||||
User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
|
||||
MovementManager movementManager = user.getMovementManager();
|
||||
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
|
||||
if (Utilities.isNearWater(player) || movementManager.halfMovement
|
||||
|| Utilities.isClimbableBlock(distance.getFrom().getBlock())
|
||||
|| Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN))
|
||||
|| Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.UP)))
|
||||
return PASS;
|
||||
|
||||
int minAirTicks = 13;
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP) ) {
|
||||
minAirTicks += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 3;
|
||||
}
|
||||
|
||||
if (movementManager.halfMovementHistoryCounter > 25)
|
||||
minAirTicks += 5;
|
||||
|
||||
// Start AirFlight
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airFlight") && movementManager.airTicks > minAirTicks) {
|
||||
// Config default base is 1200ms
|
||||
// Ping clamped to max. 1000 to prevent spoofing for an advantage
|
||||
int blockPlaceAccountingTime = (int) (checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForBlockPlacement") + (0.25 * (user.getPing() > 1000 ? 1000 : user.getPing())));
|
||||
// Config default account is 250ms
|
||||
if (AntiCheatReloaded.getPlugin().getTPS() < 18.0)
|
||||
blockPlaceAccountingTime += checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForTpsDrops");
|
||||
long lastPlacedBlock = AntiCheatReloaded.getManager().getBackend().placedBlock
|
||||
.containsKey(player.getUniqueId())
|
||||
? AntiCheatReloaded.getManager().getBackend().placedBlock.get(player.getUniqueId())
|
||||
: (blockPlaceAccountingTime + 1);
|
||||
double maxMotionY = System.currentTimeMillis() - lastPlacedBlock > blockPlaceAccountingTime ? 0 : 0.42;
|
||||
if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0)
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"tried to fly on the Y-axis (mY=" + movementManager.motionY + ", max=" + maxMotionY + ")");
|
||||
|
||||
if (Math.abs(movementManager.motionY - movementManager.lastMotionY) < 0.01
|
||||
&& !Utilities.couldBeOnBoat(player)
|
||||
&& (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForTeleports"))
|
||||
&& !VersionUtil.isSlowFalling(player))
|
||||
return new CheckResult(CheckResult.Result.FAILED, "had too little Y dropoff (diff="
|
||||
+ Math.abs(movementManager.motionY - movementManager.lastMotionY) + ")");
|
||||
}
|
||||
// End AirFlight
|
||||
|
||||
// Start AirClimb
|
||||
// TODO two hardcoded values here shouldn't be there, temp against false positive
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airClimb") && movementManager.lastMotionY > 0
|
||||
&& movementManager.motionY > 0 && movementManager.airTicks == 2
|
||||
&& Math.round(movementManager.lastMotionY * 1000) != 420
|
||||
&& !(Math.round(movementManager.motionY * 1000) == 333 && Math.round(movementManager.lastMotionY * 1000) != 333)
|
||||
&& !AntiCheatReloaded.getManager().getBackend().justVelocity(player)
|
||||
&& !player.hasPotionEffect(PotionEffectType.JUMP)
|
||||
&& (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports")))
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"tried to climb air (mY=" + movementManager.motionY + ")");
|
||||
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airClimb") && movementManager.motionY > 0.42
|
||||
&& movementManager.airTicks > 2 && !AntiCheatReloaded.getManager().getBackend().justVelocity(player)
|
||||
&& !player.hasPotionEffect(PotionEffectType.JUMP)
|
||||
&& (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports")))
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"tried to climb air (mY=" + movementManager.motionY + ", at=" + movementManager.airTicks + ")");
|
||||
// End AirClimb
|
||||
|
||||
// Start GroundFlight
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "groundFlight") && movementManager.onGround
|
||||
&& Utilities.cantStandAt(distance.getTo().getBlock().getRelative(BlockFace.DOWN))
|
||||
&& Utilities.cantStandAt(distance.getFrom().getBlock().getRelative(BlockFace.DOWN))
|
||||
&& movementManager.groundTicks > 2) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"faked ground to fly (mY=" + movementManager.motionY + ", gt=" + movementManager.groundTicks + ")");
|
||||
}
|
||||
// End GroundFlight
|
||||
|
||||
return PASS;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
package com.rammelkast.anticheatreloaded.check.movement;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -32,6 +30,7 @@ import org.bukkit.entity.Player;
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
import com.rammelkast.anticheatreloaded.util.Distance;
|
||||
import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
public class GlideCheck {
|
||||
@@ -78,13 +77,11 @@ public class GlideCheck {
|
||||
.getGoodLocation(prev));
|
||||
}
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"type=glide, desc_amount=" + new BigDecimal(motionY).setScale(2, RoundingMode.HALF_UP) + ")");
|
||||
"had gliding behaviour (amt=" + Utilities.roundDouble(motionY, 5) + ")");
|
||||
} else {
|
||||
VIOLATIONS.put(player.getUniqueId(), violations + 1);
|
||||
return PASS;
|
||||
}
|
||||
} else {
|
||||
// TODO redo this
|
||||
}
|
||||
LAST_MOTION_Y.put(player.getUniqueId(), distance.getYDifference());
|
||||
LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance());
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* AntiCheatReloaded for Bukkit and Spigot.
|
||||
* Copyright (c) 2012-2015 AntiCheat Team
|
||||
* Copyright (c) 2016-2020 Rammelkast
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rammelkast.anticheatreloaded.check.movement;
|
||||
|
||||
public class NoSlowdownCheck {
|
||||
|
||||
}
|
||||
@@ -26,6 +26,8 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.Backend;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckType;
|
||||
import com.rammelkast.anticheatreloaded.config.providers.Checks;
|
||||
import com.rammelkast.anticheatreloaded.util.Distance;
|
||||
import com.rammelkast.anticheatreloaded.util.MovementManager;
|
||||
import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
@@ -33,18 +35,6 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
/**
|
||||
* @author Rammelkast
|
||||
*
|
||||
* Features:
|
||||
* + AirSpeed A
|
||||
* + AirAcceleration A
|
||||
* + JumpBehaviour A
|
||||
* + VerticalSpeed
|
||||
*
|
||||
* Planned:
|
||||
* + GroundSpeed A
|
||||
* + GroundAcceleration A
|
||||
* + AirSpeed B
|
||||
* + JumpBehaviour B
|
||||
*/
|
||||
public class SpeedCheck {
|
||||
|
||||
@@ -56,27 +46,30 @@ public class SpeedCheck {
|
||||
|
||||
public static CheckResult checkXZSpeed(Player player, double x, double z, Location movingTowards) {
|
||||
Backend backend = AntiCheatReloaded.getManager().getBackend();
|
||||
if (isSpeedExempt(player, backend) || player.getVehicle() != null)
|
||||
if (isSpeedExempt(player, backend) || player.getVehicle() != null || Utilities.isInWater(player))
|
||||
return PASS;
|
||||
|
||||
MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
|
||||
.getMovementManager();
|
||||
double distanceXZ = Math.sqrt(x * x + z * z);
|
||||
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
double distanceXZ = movementManager.distanceXZ;
|
||||
boolean boxedIn = movementManager.topSolid && movementManager.bottomSolid;
|
||||
|
||||
// AirSpeed A
|
||||
if (movementManager.airTicks > 1) {
|
||||
double multiplier = 0.9808305131D;
|
||||
double predict = 0.3597320645 * Math.pow(multiplier, movementManager.airTicks + 1);
|
||||
double limit = 0.03075D;
|
||||
// AirSpeed
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "airSpeed") && movementManager.airTicks > 1 && movementManager.elytraEffectTicks <= 0) {
|
||||
double multiplier = 0.985D;
|
||||
double predict = 0.36 * Math.pow(multiplier, movementManager.airTicks + 1);
|
||||
double limit = checksConfig.getDouble(CheckType.SPEED, "airSpeed", "baseLimit"); // Default 0.03125
|
||||
// Adjust for ice
|
||||
if (movementManager.iceInfluenceTicks > 0) {
|
||||
double iceIncrement = 0.02 * Math.pow(1.0375, movementManager.iceInfluenceTicks);
|
||||
double iceIncrement = 0.025 * Math.pow(1.038, movementManager.iceInfluenceTicks);
|
||||
// Clamp to max value
|
||||
if (iceIncrement > 0.18D)
|
||||
iceIncrement = 0.18D;
|
||||
if (boxedIn)
|
||||
iceIncrement += 0.5D;
|
||||
if (!Utilities.couldBeOnIce(movingTowards))
|
||||
iceIncrement *= 2.5D;
|
||||
predict += iceIncrement;
|
||||
}
|
||||
// Adjust for slime
|
||||
@@ -89,85 +82,108 @@ public class SpeedCheck {
|
||||
}
|
||||
// Adjust for speed effects
|
||||
if (player.hasPotionEffect(PotionEffectType.SPEED))
|
||||
predict += player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() * 0.05D;
|
||||
predict += (player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() + 1) * 0.05D;
|
||||
// Adjust for jump boost effects
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP))
|
||||
predict += (player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.05D;
|
||||
// Adjust for custom walking speed
|
||||
predict += 1.4D * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1);
|
||||
double walkSpeedMultiplier = checksConfig.getDouble(CheckType.SPEED, "airSpeed", "walkSpeedMultiplier"); // Default 1.4
|
||||
predict += walkSpeedMultiplier * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1);
|
||||
// Slabs sometimes allow for a slight boost after jump
|
||||
if (movementManager.halfMovementHistoryCounter > 0)
|
||||
predict *= 2.125D;
|
||||
if (Utilities.couldBeOnHalfblock(movingTowards) && movementManager.halfMovementHistoryCounter == 0)
|
||||
predict *= 1.25D;
|
||||
// Boats sometimes give a false positive
|
||||
if (Utilities.couldBeOnBoat(player, 0.5))
|
||||
predict *= 1.25D;
|
||||
// Strafing in air when nearing terminal velocity gives false positives
|
||||
// This fixes the issue but gives hackers some leniency which means we need another check for this
|
||||
double deltaMotionY = movementManager.motionY - movementManager.lastMotionY;
|
||||
if (deltaMotionY < 0 && deltaMotionY >= -0.06)
|
||||
predict *= 1.5D;
|
||||
// Players can move faster in air with slow falling
|
||||
if (VersionUtil.isSlowFalling(player))
|
||||
predict *= 1.25D;
|
||||
|
||||
if (distanceXZ - predict > limit) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"moved too fast in air (speed=" + distanceXZ + ", limit=" + predict + ")");
|
||||
}
|
||||
}
|
||||
|
||||
// AirAcceleration A
|
||||
// AirAcceleration
|
||||
// As of right now, this falses sometimes, dont know why
|
||||
if (movementManager.airTicks > 1 && movementManager.iceInfluenceTicks <= 0 && movementManager.slimeInfluenceTicks <= 0) {
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "airAcceleration") && movementManager.airTicks > 1
|
||||
&& movementManager.iceInfluenceTicks <= 0 && movementManager.slimeInfluenceTicks <= 0
|
||||
&& movementManager.elytraEffectTicks <= 0) {
|
||||
double initialAcceleration = movementManager.acceleration;
|
||||
double limit = 0.3725D;
|
||||
double limit = checksConfig.getDouble(CheckType.SPEED, "airAcceleration", "baseLimit"); // Default 0.3725
|
||||
// Adjust for speed effects
|
||||
if (player.hasPotionEffect(PotionEffectType.SPEED) )
|
||||
limit += player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() * 0.0225D;
|
||||
if (player.hasPotionEffect(PotionEffectType.SPEED))
|
||||
limit += (player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() + 1) * 0.0225D;
|
||||
// Adjust for slabs
|
||||
if (movementManager.halfMovementHistoryCounter > 15)
|
||||
limit *= 2.0D;
|
||||
// Adjust for custom walking speed
|
||||
limit += 1.4D * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1);
|
||||
double walkSpeedMultiplier = checksConfig.getDouble(CheckType.SPEED, "airAcceleration", "walkSpeedMultiplier"); // Default 1.4
|
||||
limit += walkSpeedMultiplier * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1);
|
||||
// Boats sometimes give a false positive
|
||||
if (Utilities.couldBeOnBoat(player))
|
||||
limit *= 1.25D;
|
||||
if (initialAcceleration > limit) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"exceeded acceleration limits (acceleration=" + initialAcceleration + ", max=" + limit + ")");
|
||||
}
|
||||
}
|
||||
|
||||
// JumpBehaviour A
|
||||
// JumpBehaviour
|
||||
// Works against YPorts and mini jumps
|
||||
if (movementManager.touchedGroundThisTick && !boxedIn && movementManager.slimeInfluenceTicks <= 10) {
|
||||
// This happens naturally as well when walking next to walls
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "jumpBehaviour") && movementManager.touchedGroundThisTick
|
||||
&& !boxedIn && movementManager.slimeInfluenceTicks <= 10) {
|
||||
// This happens naturally
|
||||
if (movementManager.airTicksBeforeGrounded == movementManager.groundTicks) {
|
||||
boolean movingFreely = Utilities.cantStandClose(movingTowards.getBlock())
|
||||
&& Utilities.cantStandFar(movingTowards.getBlock());
|
||||
// TODO calculation for distanceXZ value
|
||||
if (movingFreely && distanceXZ >= 0.42) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"had unexpected jumping behaviour");
|
||||
double minimumDistXZ = checksConfig.getDouble(CheckType.SPEED, "jumpBehaviour", "minimumDistXZ"); // Default 0.42
|
||||
if (distanceXZ >= minimumDistXZ) {
|
||||
return new CheckResult(CheckResult.Result.FAILED, "had unexpected jumping behaviour");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GroundSpeed A
|
||||
if (movementManager.groundTicks > 1) {
|
||||
double limit = 0.34 - 0.0055 * Math.min(9, movementManager.groundTicks);
|
||||
if (movementManager.groundTicks < 5)
|
||||
limit += 0.1D;
|
||||
if (!Utilities.cantStandAtExp(movingTowards.clone().add(0, 0.51, 0))
|
||||
|| !Utilities.cantStandAtExp(movingTowards.clone().add(0, 0.11, 0)))
|
||||
limit *= 2.2D;
|
||||
if (movementManager.halfMovementHistoryCounter > 8)
|
||||
limit += 0.2D;
|
||||
if (movementManager.iceInfluenceTicks >= 55) {
|
||||
if (!Utilities.isIce(movingTowards.getBlock().getRelative(BlockFace.DOWN)))
|
||||
limit += 0.75D;
|
||||
else {
|
||||
if (movementManager.topSolid && movementManager.bottomSolid)
|
||||
limit *= 2.5D;
|
||||
else
|
||||
limit += 0.03D;
|
||||
}
|
||||
}
|
||||
if (Utilities.isNearBed(movingTowards) || Utilities.couldBeOnHalfblock(movingTowards)
|
||||
|| Utilities.isNearBed(movingTowards.clone().add(0, -0.5, 0)))
|
||||
limit *= 2.0D;
|
||||
if (Utilities.couldBeOnBoat(player))
|
||||
limit += 0.2D;
|
||||
if (movementManager.signInfluenceTicks > 0)
|
||||
limit += 0.08D;
|
||||
if (distanceXZ - limit > 0) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ")");
|
||||
}
|
||||
// GroundSpeed
|
||||
if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "groundSpeed") && movementManager.groundTicks > 1) {
|
||||
double initialLimit = checksConfig.getDouble(CheckType.SPEED, "groundSpeed", "initialLimit"); // Default 0.34
|
||||
double limit = initialLimit - 0.0055 * Math.min(9, movementManager.groundTicks);
|
||||
// Leniency when moving back on ground
|
||||
if (movementManager.groundTicks < 5)
|
||||
limit += 0.1D;
|
||||
// Slab leniency
|
||||
if (movementManager.halfMovementHistoryCounter > 8)
|
||||
limit += 0.2D;
|
||||
// Adjust for speed effects
|
||||
if (player.hasPotionEffect(PotionEffectType.SPEED))
|
||||
limit += (player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() + 1) * 0.06D;
|
||||
if (movementManager.iceInfluenceTicks >= 50) {
|
||||
// When moving off ice
|
||||
if (!Utilities.couldBeOnIce(movingTowards))
|
||||
limit *= 2.5D;
|
||||
else {
|
||||
// When boxed in and spamming space for boost
|
||||
if (movementManager.topSolid && movementManager.bottomSolid)
|
||||
limit *= 3.0D;
|
||||
else
|
||||
limit *= 1.25D;
|
||||
}
|
||||
}
|
||||
if (Utilities.isNearBed(movingTowards) || Utilities.couldBeOnHalfblock(movingTowards)
|
||||
|| Utilities.isNearBed(movingTowards.clone().add(0, -0.5, 0)))
|
||||
limit *= 2.0D;
|
||||
if (Utilities.couldBeOnBoat(player))
|
||||
limit += 0.2D;
|
||||
if (distanceXZ - limit > 0) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ")");
|
||||
}
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
@@ -176,6 +192,10 @@ public class SpeedCheck {
|
||||
Backend backend = AntiCheatReloaded.getManager().getBackend();
|
||||
MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
|
||||
.getMovementManager();
|
||||
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
if (!checksConfig.isSubcheckEnabled(CheckType.SPEED, "verticalSpeed"))
|
||||
return PASS;
|
||||
|
||||
if (player.isInsideVehicle() || player.isSleeping()
|
||||
|| backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_TIME()) || VersionUtil.isFlying(player)
|
||||
|| VersionUtil.isRiptiding(player)) {
|
||||
@@ -184,21 +204,20 @@ public class SpeedCheck {
|
||||
|
||||
double maxMotionY = getMaxAcceptableMotionY(player, Utilities.isNearBed(distance.getTo()),
|
||||
Utilities.couldBeOnBoat(player), Utilities.isClimbableBlock(distance.getFrom().getBlock())
|
||||
|| Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN)));
|
||||
if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0
|
||||
&& !movementManager.halfMovement) {
|
||||
|| Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN)), movementManager.halfMovement, checksConfig);
|
||||
if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0) {
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"exceeded vertical speed limit (mY=" + movementManager.motionY + ", max=" + maxMotionY + ")");
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static double getMaxAcceptableMotionY(Player player, boolean nearBed, boolean couldBeOnBoat, boolean fromClimbable) {
|
||||
double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : 0.42);
|
||||
private static double getMaxAcceptableMotionY(Player player, boolean nearBed, boolean couldBeOnBoat, boolean fromClimbable, boolean halfMovement, Checks checksConfig) {
|
||||
double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : (halfMovement ? 0.6 : 0.42));
|
||||
if (fromClimbable)
|
||||
base += 0.04;
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP) ) {
|
||||
base += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 0.15D;
|
||||
base += checksConfig.getDouble(CheckType.SPEED, "verticalSpeed", "climbableCompensation"); // Default 0.04
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
base += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 0.2D;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
/**
|
||||
* This check should be replaced It works, but not great
|
||||
* TODO recode
|
||||
*/
|
||||
public class WaterWalkCheck {
|
||||
|
||||
@@ -57,13 +57,14 @@ public class WaterWalkCheck {
|
||||
if (IS_IN_WATER_CACHE.contains(uuid)) {
|
||||
if (player.getNearbyEntities(1, 1, 1).isEmpty()) {
|
||||
boolean violation;
|
||||
if (!Utilities.sprintFly(player)) {
|
||||
/*if (!Utilities.sprintFly(player)) {
|
||||
violation = x > backend.getMagic().XZ_SPEED_MAX_WATER()
|
||||
|| z > backend.getMagic().XZ_SPEED_MAX_WATER();
|
||||
} else {
|
||||
violation = x > backend.getMagic().XZ_SPEED_MAX_WATER_SPRINT()
|
||||
|| z > backend.getMagic().XZ_SPEED_MAX_WATER_SPRINT();
|
||||
}
|
||||
}*/
|
||||
violation = false;
|
||||
if (!violation && !Utilities.isFullyInWater(player.getLocation())
|
||||
&& Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D
|
||||
&& !block.getType().equals(Utilities.LILY_PAD)) {
|
||||
@@ -72,7 +73,7 @@ public class WaterWalkCheck {
|
||||
if (violation) {
|
||||
if (WATER_SPEED_VIOLATIONS.containsKey(uuid)) {
|
||||
int v = WATER_SPEED_VIOLATIONS.get(uuid);
|
||||
if (v >= backend.getMagic().WATER_SPEED_VIOLATION_MAX()) {
|
||||
if (v >= 8) {
|
||||
WATER_SPEED_VIOLATIONS.put(uuid, 0);
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"stood on water " + v + " times (can't stand on " + block.getType()
|
||||
@@ -99,7 +100,7 @@ public class WaterWalkCheck {
|
||||
|| y == 0.04999999999999982)) {
|
||||
if (WATER_ASCENSION_VIOLATIONS.containsKey(uuid)) {
|
||||
int v = WATER_ASCENSION_VIOLATIONS.get(uuid);
|
||||
if (v >= backend.getMagic().WATER_ASCENSION_VIOLATION_MAX()) {
|
||||
if (v >= 8) {
|
||||
WATER_ASCENSION_VIOLATIONS.put(uuid, 0);
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"stood on water " + v + " times (can't stand on " + block.getType() + " or "
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* AntiCheatReloaded for Bukkit and Spigot.
|
||||
* Copyright (c) 2012-2015 AntiCheat Team
|
||||
* Copyright (c) 2016-2020 Rammelkast
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rammelkast.anticheatreloaded.check.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
import com.rammelkast.anticheatreloaded.util.Distance;
|
||||
import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
public class YAxisCheck {
|
||||
|
||||
public static final Map<UUID, Double> LAST_Y_COORD_CACHE = new HashMap<UUID, Double>();
|
||||
public static final Map<UUID, Long> LAST_Y_TIME = new HashMap<UUID, Long>();
|
||||
public static final Map<UUID, Integer> Y_AXIS_VIOLATIONS = new HashMap<UUID, Integer>();
|
||||
public static final Map<UUID, Long> LAST_Y_AXIS_VIOLATION = new HashMap<UUID, Long>();
|
||||
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
|
||||
|
||||
private static boolean hasJumpPotion(Player player) {
|
||||
return player.hasPotionEffect(PotionEffectType.JUMP);
|
||||
}
|
||||
|
||||
public static CheckResult runCheck(Player player, Distance distance) {
|
||||
if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()
|
||||
|| distance.getYDifference() < 0 || VersionUtil.isFlying(player)) {
|
||||
return PASS;
|
||||
}
|
||||
if (!FlightCheck.isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock())
|
||||
&& !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock())
|
||||
&& !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player)
|
||||
&& !isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock())
|
||||
&& !isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) {
|
||||
double y1 = player.getLocation().getY();
|
||||
UUID uuid = player.getUniqueId();
|
||||
// Fix Y axis spam.
|
||||
if (!LAST_Y_COORD_CACHE.containsKey(uuid) || !LAST_Y_TIME.containsKey(uuid)
|
||||
|| !LAST_Y_AXIS_VIOLATION.containsKey(uuid)) {
|
||||
LAST_Y_COORD_CACHE.put(uuid, y1);
|
||||
Y_AXIS_VIOLATIONS.put(uuid, 0);
|
||||
LAST_Y_AXIS_VIOLATION.put(uuid, 0L);
|
||||
LAST_Y_TIME.put(uuid, System.currentTimeMillis());
|
||||
} else {
|
||||
if (y1 > LAST_Y_COORD_CACHE.get(uuid)
|
||||
&& Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic()
|
||||
.Y_MAXVIOLATIONS()
|
||||
&& (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) < AntiCheatReloaded
|
||||
.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
|
||||
Location g = player.getLocation();
|
||||
Y_AXIS_VIOLATIONS.put(uuid, Y_AXIS_VIOLATIONS.get(uuid) + 1);
|
||||
LAST_Y_AXIS_VIOLATION.put(uuid, System.currentTimeMillis());
|
||||
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
|
||||
g.setY(LAST_Y_COORD_CACHE.get(uuid));
|
||||
if (g.getBlock().getType() == Material.AIR) {
|
||||
player.teleport(g);
|
||||
}
|
||||
}
|
||||
return new CheckResult(CheckResult.Result.FAILED,
|
||||
"tried to fly on y-axis " + Y_AXIS_VIOLATIONS.get(uuid) + " times (max="
|
||||
+ AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")");
|
||||
} else {
|
||||
if (Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic()
|
||||
.Y_MAXVIOLATIONS()
|
||||
&& (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) > AntiCheatReloaded
|
||||
.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
|
||||
Y_AXIS_VIOLATIONS.put(uuid, 0);
|
||||
LAST_Y_AXIS_VIOLATION.put(uuid, 0L);
|
||||
}
|
||||
}
|
||||
long i = System.currentTimeMillis() - LAST_Y_TIME.get(uuid);
|
||||
double diff = AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF()
|
||||
+ ((Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) || Utilities.isStair(player.getLocation().add(0, -0.5, 0).getBlock())) ? 0.5 : 0.0);
|
||||
if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > diff
|
||||
&& i < AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME()) {
|
||||
Location g = player.getLocation();
|
||||
Y_AXIS_VIOLATIONS.put(uuid, Y_AXIS_VIOLATIONS.get(uuid) + 1);
|
||||
LAST_Y_AXIS_VIOLATION.put(uuid, System.currentTimeMillis());
|
||||
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
|
||||
g.setY(LAST_Y_COORD_CACHE.get(uuid));
|
||||
if (g.getBlock().getType() == Material.AIR) {
|
||||
player.teleport(g);
|
||||
}
|
||||
}
|
||||
return new CheckResult(CheckResult.Result.FAILED, "tried to fly on y-axis in " + i + " ms (min="
|
||||
+ AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME() + ")");
|
||||
} else {
|
||||
if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > AntiCheatReloaded.getManager().getBackend().getMagic()
|
||||
.Y_MAXDIFF() + 1
|
||||
|| (System.currentTimeMillis() - LAST_Y_TIME.get(uuid)) > AntiCheatReloaded.getManager()
|
||||
.getBackend().getMagic().Y_TIME()) {
|
||||
LAST_Y_TIME.put(uuid, System.currentTimeMillis());
|
||||
LAST_Y_COORD_CACHE.put(uuid, y1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fix Y axis spam
|
||||
return PASS;
|
||||
}
|
||||
|
||||
public static boolean isMoveUpBlock(Block block) {
|
||||
return Utilities.isStair(block);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user