This commit is contained in:
Rammelkast committed 2021-09-15 09:58:59 +02:00
1 parent a1f7a0cf7f
commit 5f1dc37679
4 files changed
+82 -12

No files matched your search

@@ -20,7 +20,9 @@ package com.rammelkast.anticheatreloaded.check.movement;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
@@ -44,14 +46,15 @@ public final class SpeedCheck {
return backend.isMovingExempt(player) || backend.justVelocity(player) || VersionUtil.isFlying(player);
}
public static CheckResult checkXZSpeed(final Player player, final double x, final double z, final Location movingTowards) {
public static CheckResult checkXZSpeed(final Player player, final double x, final double z,
final Location movingTowards) {
final Backend backend = AntiCheatReloaded.getManager().getBackend();
if (isSpeedExempt(player, backend) || player.getVehicle() != null || Utilities.isInWater(player)) {
return PASS;
}
final MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getMovementManager();
final MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager()
.getUser(player.getUniqueId()).getMovementManager();
// Riptiding exemption
if (movementManager.riptideTicks > 0) {
return PASS;
@@ -108,6 +111,12 @@ public final class SpeedCheck {
predict += slimeIncrement;
}
// Adjust for soul speed
final ItemStack boots = player.getInventory().getBoots();
if (boots != null && movementManager.soilInfluenceTicks > 0 && VersionUtil.isSoulSpeed(boots)) {
predict += boots.getEnchantmentLevel(Enchantment.SOUL_SPEED) * 0.05D;
}
// Adjust for speed effects
if (movementManager.hasSpeedEffect) {
predict += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.05D;
@@ -124,7 +133,8 @@ public final class SpeedCheck {
}
// Adjust for custom walking speed
final double walkSpeedMultiplier = checksConfig.getDouble(CheckType.SPEED, "airSpeed", "walkSpeedMultiplier"); // Default 1.4
final 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
@@ -188,6 +198,12 @@ public final class SpeedCheck {
limit *= 1.08D;
}
// Adjust for soul speed
final ItemStack boots = player.getInventory().getBoots();
if (boots != null && movementManager.soilInfluenceTicks > 0 && VersionUtil.isSoulSpeed(boots)) {
limit += boots.getEnchantmentLevel(Enchantment.SOUL_SPEED) * 0.025D;
}
// Adjust for speed effects
if (player.hasPotionEffect(PotionEffectType.SPEED)) {
limit += VersionUtil.getPotionLevel(player, PotionEffectType.SPEED) * 0.0225D;
@@ -218,7 +234,8 @@ public final class SpeedCheck {
// Works against YPorts and mini jumps
if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "jumpBehaviour") && movementManager.touchedGroundThisTick
&& !boxedIn && movementManager.slimeInfluenceTicks <= 10 && !Utilities.isNearHalfblock(movingTowards)
&& !Utilities.isNearHalfblock(movingTowards.clone().subtract(0, 0.51, 0)) && !Utilities.couldBeOnBoat(player, 0.8d, false)) {
&& !Utilities.isNearHalfblock(movingTowards.clone().subtract(0, 0.51, 0))
&& !Utilities.couldBeOnBoat(player, 0.8d, false)) {
// This happens naturally
if (movementManager.airTicksBeforeGrounded == movementManager.groundTicks) {
final double minimumDistXZ = checksConfig.getDouble(CheckType.SPEED, "jumpBehaviour", "minimumDistXZ"); // Default
@@ -232,7 +249,8 @@ public final class SpeedCheck {
// GroundSpeed
if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "groundSpeed") && movementManager.groundTicks > 1) {
final double initialLimit = checksConfig.getDouble(CheckType.SPEED, "groundSpeed", "initialLimit"); // Default 0.34
final 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) {
@@ -328,8 +346,8 @@ public final class SpeedCheck {
return PASS;
}
final MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getMovementManager();
final MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager()
.getUser(player.getUniqueId()).getMovementManager();
// Riptiding exemption
if (movementManager.riptideTicks > 0) {
return PASS;
@@ -357,13 +375,13 @@ public final class SpeedCheck {
return PASS;
}
private static double getMaxAcceptableMotionY(final Player player, final boolean nearBed, final boolean couldBeOnBoat,
final boolean fromClimbable, final boolean halfMovement, final Checks checksConfig) {
private static double getMaxAcceptableMotionY(final Player player, final boolean nearBed,
final boolean couldBeOnBoat, final boolean fromClimbable, final boolean halfMovement,
final Checks checksConfig) {
// TODO config for these values
// TODO something funky vanilla stuff going on with 0.42, like 0.445.., check
// this..
double base = couldBeOnBoat ? 0.600000025
: (nearBed ? 0.5625 : ((halfMovement) ? 0.6 : 0.42));
double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : ((halfMovement) ? 0.6 : 0.42));
if (fromClimbable) {
base += checksConfig.getDouble(CheckType.SPEED, "verticalSpeed", "climbableCompensation"); // Default 0.04
}
@@ -41,6 +41,8 @@ public final class MovementManager {
public int iceInfluenceTicks = 0;
// Ticks influenced by slime
public int slimeInfluenceTicks = 0;
// Ticks influenced by soil
public int soilInfluenceTicks = 0;
// Y motion of the movement
public double motionY;
// Previous Y motion of the movement
@@ -163,6 +165,14 @@ public final class MovementManager {
}
}
if (Utilities.couldBeOnSoil(to)) {
this.soilInfluenceTicks = 6;
} else {
if (this.soilInfluenceTicks > 0) {
this.soilInfluenceTicks--;
}
}
if (VersionUtil.isGliding(player)) {
this.elytraEffectTicks = 30;
} else {
@@ -270,6 +270,41 @@ public final class Utilities {
|| isSlime(location.getBlock().getRelative(BlockFace.SOUTH_WEST));
}
/**
* Determine whether a player could be standing on soil
*
* @param location the location to check
* @return true if the player could be standing on soil
*/
public static boolean couldBeOnSoil(Location location) {
return isNearSoil(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D,
location.getBlockZ()))
|| isNearSoil(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.51D,
location.getBlockZ()));
}
/**
* Determine whether a block is a type of soil
*
* @param block block to check
* @return true if block is a type of soil
*/
public static boolean isSoil(Block block) {
Material type = block.getType();
return type.equals(XMaterial.SOUL_SOIL.parseMaterial()) || type.equals(XMaterial.SOUL_SAND.parseMaterial());
}
public static boolean isNearSoil(Location location) {
return isSoil(location.getBlock()) || isSoil(location.getBlock().getRelative(BlockFace.NORTH))
|| isSoil(location.getBlock().getRelative(BlockFace.SOUTH))
|| isSoil(location.getBlock().getRelative(BlockFace.EAST))
|| isSoil(location.getBlock().getRelative(BlockFace.WEST))
|| isSoil(location.getBlock().getRelative(BlockFace.NORTH_EAST))
|| isSoil(location.getBlock().getRelative(BlockFace.NORTH_WEST))
|| isSoil(location.getBlock().getRelative(BlockFace.SOUTH_EAST))
|| isSoil(location.getBlock().getRelative(BlockFace.SOUTH_WEST));
}
/**
* Determine whether a player is fully submerged in water
*
@@ -77,6 +77,13 @@ public class VersionUtil {
return player.getInventory().getBoots().containsEnchantment(Enchantment.FROST_WALKER);
}
public static boolean isSoulSpeed(final ItemStack boots) {
if (!CURRENT_VERSION.isAtLeast(MinecraftVersion.NETHER_UPDATE)) {
return false;
}
return boots.containsEnchantment(Enchantment.SOUL_SPEED);
}
public static ItemStack getItemInHand(final Player player) {
return player.getInventory().getItemInMainHand();
}