Sort of fixed badly broken and untested GhostHand check, added update messaging.

Check will still need to be improved, but seems to work without false positives for now.
This commit is contained in:
Rammelkast committed 2020-03-30 22:55:18 +02:00
1 parent e89a6cfd88
commit 2ba98f9f9c
8 files changed
+50 -41

No files matched your search

@@ -33,7 +33,6 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.potion.PotionEffectType;
@@ -48,6 +47,7 @@ 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.player.GhosthandCheck;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.providers.Lang;
import com.rammelkast.anticheatreloaded.config.providers.Magic;
@@ -333,13 +333,6 @@ public class Backend {
}
}
public CheckResult checkSprintStill(Player player, Location from, Location to) {
/*if(!isMovingExempt(player) && player.isSprinting() && from.getX() == to.getX() && from.getZ() == to.getZ()) {
return new CheckResult(Result.FAILED, player.getName()+" sprinted while standing still (xyz = "+(int)from.getX()+","+(int)from.getY()+","+(int)from.getZ()+")");
}*/
return PASS;
}
public CheckResult checkVClip(Player player, Distance distance) {
double from = Math.round(distance.fromY());
double to = Math.round(distance.toY());
@@ -45,14 +45,14 @@ public class KillAuraCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static void listenPackets() {
AntiCheatReloaded.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
/*AntiCheatReloaded.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
ListenerPriority.LOWEST, new PacketType[] { PacketType.Play.Client.POSITION_LOOK }) {
@Override
public void onPacketReceiving(PacketEvent e) {
Player player = e.getPlayer();
PacketContainer packet = e.getPacket();
}
});
});*/
}
public static CheckResult checkAngle(Player player, EntityDamageEvent event) {
@@ -83,7 +83,7 @@ public class KillAuraCheck {
return PASS;
}
private static double calculateYawDifference(Location from, Location to) {
public static double calculateYawDifference(Location from, Location to) {
Location clonedFrom = from.clone();
Vector startVector = clonedFrom.toVector();
Vector targetVector = to.toVector();
@@ -19,9 +19,8 @@
package com.rammelkast.anticheatreloaded.check.player;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@@ -30,6 +29,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck;
import com.rammelkast.anticheatreloaded.config.providers.Magic;
import com.rammelkast.anticheatreloaded.util.Utilities;
@@ -47,7 +47,7 @@ public class GhosthandCheck {
}
private static CheckResult checkBlockBreak(Player player, BlockBreakEvent event) {
if (!isValidBreakTarget(player, event.getBlock())) {
if (!isValidTarget(player, event.getBlock())) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " tried to break a block which was out of view");
}
@@ -55,41 +55,44 @@ public class GhosthandCheck {
}
private static CheckResult checkBlockPlace(Player player, BlockPlaceEvent event) {
if (!isValidPlaceTarget(player, event.getBlock())) {
if (!isValidTarget(player, event.getBlock())) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " tried to place a block out of their view");
}
return PASS;
}
private static boolean isValidPlaceTarget(Player player, Block block) {
private static boolean isValidTarget(Player player, Block block) {
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
double distance =
player.getGameMode() == GameMode.CREATIVE ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: player.getLocation().getDirection().getY() > 0.9 ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: magic.BLOCK_MAX_DISTANCE();
Block targetBlock = player.getTargetBlockExact((int) Math.ceil(distance));
if (targetBlock == null) {
return false;
}
if (Utilities.isClimbableBlock(targetBlock)) {
if (targetBlock.getLocation().distance(player.getLocation()) <= distance) {
return true;
}
}
return targetBlock.equals(block) || targetBlock.getLocation().distance(block.getLocation()) <= 1.51;
}
private static boolean isValidBreakTarget(Player player, Block block) {
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
double distance =
player.getGameMode() == GameMode.CREATIVE ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: player.getLocation().getDirection().getY() > 0.9 ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: magic.BLOCK_MAX_DISTANCE();
List<Block> targetBlocks = player.getLastTwoTargetBlocks(null, (int) Math.ceil(distance));
for (Block target : targetBlocks) {
if (Utilities.isClimbableBlock(target)) {
return true;
}
if (targetBlock.equals(block)) {
return true;
}
return targetBlocks.contains(block);
Location eyeLocation = player.getEyeLocation();
double yawDifference = KillAuraCheck.calculateYawDifference(eyeLocation, block.getLocation());
double playerYaw = player.getEyeLocation().getYaw();
double angleDifference = Math.abs(180 - Math.abs(Math.abs(yawDifference - playerYaw) - 180));
if (Math.round(angleDifference) > magic.GHOSTHAND_MAX_ANGLE_DIFFERENCE()) {
return false;
}
return true;
}
}