mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-03 06:28:52 +00:00
Drop 1.8 support, improve IllegalInteract, drop rules engine for java 16, more refactoring
This commit is contained in:
1 parent
71a9c9a9c7
commit
a1f7a0cf7f
24 files changed
+632
-622
No files matched your search
@@ -21,11 +21,13 @@ package com.rammelkast.anticheatreloaded.check.player;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
|
||||
import com.rammelkast.anticheatreloaded.check.CheckResult;
|
||||
@@ -36,12 +38,12 @@ import com.rammelkast.anticheatreloaded.util.User;
|
||||
import com.rammelkast.anticheatreloaded.util.Utilities;
|
||||
import com.rammelkast.anticheatreloaded.util.VersionUtil;
|
||||
|
||||
public class IllegalInteract {
|
||||
public final class IllegalInteract {
|
||||
|
||||
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
|
||||
|
||||
public static CheckResult performCheck(Player player, Event event) {
|
||||
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
public static CheckResult performCheck(final Player player, final Event event) {
|
||||
final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
if (event instanceof BlockPlaceEvent && checksConfig.isSubcheckEnabled(CheckType.ILLEGAL_INTERACT, "place")) {
|
||||
return checkBlockPlace(player, (BlockPlaceEvent) event);
|
||||
} else if (event instanceof BlockBreakEvent
|
||||
@@ -54,10 +56,11 @@ public class IllegalInteract {
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static CheckResult checkInteract(Player player, PlayerInteractEvent event) {
|
||||
User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
|
||||
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
double distance = player.getEyeLocation().toVector().distance(event.getClickedBlock().getLocation().toVector());
|
||||
private static CheckResult checkInteract(final Player player, final PlayerInteractEvent event) {
|
||||
final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
|
||||
final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
final double distance = player.getEyeLocation().toVector()
|
||||
.distance(event.getClickedBlock().getLocation().toVector());
|
||||
double maxDistance = player.getGameMode() == GameMode.CREATIVE
|
||||
? checksConfig.getDouble(CheckType.ILLEGAL_INTERACT, "interact", "creativeRange")
|
||||
: checksConfig.getDouble(CheckType.ILLEGAL_INTERACT, "interact", "survivalRange");
|
||||
@@ -74,25 +77,31 @@ public class IllegalInteract {
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static CheckResult checkBlockBreak(Player player, BlockBreakEvent event) {
|
||||
private static CheckResult checkBlockBreak(final Player player, final BlockBreakEvent event) {
|
||||
if (!isValidTarget(player, event.getBlock())) {
|
||||
return new CheckResult(CheckResult.Result.FAILED, "Break", "tried to break a block which was out of view");
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static CheckResult checkBlockPlace(Player player, BlockPlaceEvent event) {
|
||||
if (event.getBlock().getType().isSolid() && !isValidTarget(player, event.getBlock())) {
|
||||
return new CheckResult(CheckResult.Result.FAILED, "Place", "tried to place a block out of their view");
|
||||
private static CheckResult checkBlockPlace(final Player player, final BlockPlaceEvent event) {
|
||||
final BlockFace face = event.getBlock().getFace(event.getBlockAgainst());
|
||||
final Vector vector = new Vector(face.getModX(), face.getModY(), face.getModZ());
|
||||
if (event.getBlock().getType().isSolid()
|
||||
&& player.getLocation().getDirection().angle(vector) > Math.toRadians(90)) {
|
||||
return new CheckResult(CheckResult.Result.FAILED, "Place",
|
||||
"tried to place a block out of their view (angle="
|
||||
+ Utilities.roundFloat(player.getLocation().getDirection().angle(vector), 1)
|
||||
+ ", max=90.0");
|
||||
}
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static boolean isValidTarget(Player player, Block block) {
|
||||
Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
double distance = player.getGameMode() == GameMode.CREATIVE ? 6.0
|
||||
private static boolean isValidTarget(final Player player, final Block block) {
|
||||
final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
|
||||
final double distance = player.getGameMode() == GameMode.CREATIVE ? 6.0
|
||||
: player.getLocation().getDirection().getY() > 0.9 ? 6.0 : 5.5;
|
||||
Block targetBlock = VersionUtil.getTargetBlock(player, ((int) Math.ceil(distance)));
|
||||
final Block targetBlock = VersionUtil.getTargetBlock(player, ((int) Math.ceil(distance)));
|
||||
if (targetBlock == null) {
|
||||
// TODO better check here
|
||||
return true;
|
||||
@@ -108,10 +117,10 @@ public class IllegalInteract {
|
||||
return true;
|
||||
}
|
||||
|
||||
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));
|
||||
final Location eyeLocation = player.getEyeLocation();
|
||||
final double yawDifference = KillAuraCheck.calculateYawDifference(eyeLocation, block.getLocation());
|
||||
final double playerYaw = player.getEyeLocation().getYaw();
|
||||
final double angleDifference = Math.abs(180 - Math.abs(Math.abs(yawDifference - playerYaw) - 180));
|
||||
if (Math.round(angleDifference) > checksConfig.getInteger(CheckType.ILLEGAL_INTERACT, "maxAngleDifference")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user