Move NoFall check out of backend

This commit is contained in:
Rammelkast committed 2022-01-01 13:09:02 +01:00
1 parent 83d9705886
commit 67e6f0df62
7 files changed
+103 -112

No files matched your search

@@ -75,7 +75,6 @@ public final class AntiCheatReloaded extends JavaPlugin {
private static boolean verbose;
private double tps = -1;
private String symbiosisMetric = "None";
@Override
public void onLoad() {
@@ -165,7 +164,6 @@ public final class AntiCheatReloaded extends JavaPlugin {
getServer().getScheduler().runTaskLater(this, new Runnable() {
@Override
public void run() {
checkForSymbiosis();
try {
final Metrics metrics = new Metrics(AntiCheatReloaded.this, 202);
metrics.addCustomChart(new SingleLineChart("cheaters_kicked", new Callable<Integer>() {
@@ -189,12 +187,6 @@ public final class AntiCheatReloaded extends JavaPlugin {
return VersionUtil.getVersion();
}
}));
metrics.addCustomChart(new SimplePie("symbiosis", new Callable<String>() {
@Override
public String call() throws Exception {
return symbiosisMetric;
}
}));
metrics.addCustomChart(new SimplePie("floodgate_enabled", new Callable<String>() {
@Override
public String call() throws Exception {
@@ -312,56 +304,6 @@ public final class AntiCheatReloaded extends JavaPlugin {
this.playersKicked++;
}
/**
* Creates metric that checks for anti-cheat symbiosis I use this to see if
* AntiCheatReloaded is actively being used together with other anti-cheats, so
* I can account for that.
*/
protected void checkForSymbiosis() {
if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "NoCheatPlus";
} else {
this.symbiosisMetric += ", NoCheatPlus";
}
}
if (Bukkit.getPluginManager().getPlugin("Matrix") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "Matrix";
} else {
this.symbiosisMetric += ", Matrix";
}
}
if (Bukkit.getPluginManager().getPlugin("AAC") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "AAC";
} else {
this.symbiosisMetric += ", AAC";
}
}
if (Bukkit.getPluginManager().getPlugin("Spartan") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "Spartan";
} else {
this.symbiosisMetric += ", Spartan";
}
}
if (Bukkit.getPluginManager().getPlugin("Negativity") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "Negativity";
} else {
this.symbiosisMetric += ", Negativity";
}
}
if (Bukkit.getPluginManager().getPlugin("SoaromaSAC") != null) {
if (this.symbiosisMetric.equals("None")) {
this.symbiosisMetric = "SoaromaSAC";
} else {
this.symbiosisMetric += ", SoaromaSAC";
}
}
}
public static void sendToMainThread(final Runnable runnable) {
Bukkit.getScheduler().runTask(AntiCheatReloaded.getPlugin(), runnable);
}
@@ -26,7 +26,6 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.potion.PotionEffectType;
@@ -39,6 +38,7 @@ import com.rammelkast.anticheatreloaded.check.movement.ElytraCheck;
import com.rammelkast.anticheatreloaded.check.movement.FlightCheck;
import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck;
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
import com.rammelkast.anticheatreloaded.check.player.NoFallCheck;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.providers.Checks;
import com.rammelkast.anticheatreloaded.config.providers.Lang;
@@ -47,7 +47,6 @@ import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class Backend {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
@@ -57,7 +56,6 @@ public class Backend {
private final Map<UUID, Long> levitatingEnd = new HashMap<UUID, Long>();
private final Map<UUID, Integer> chatLevel = new HashMap<UUID, Integer>();
private final Map<UUID, Integer> commandLevel = new HashMap<UUID, Integer>();
private final Map<UUID, Integer> nofallViolation = new HashMap<UUID, Integer>();
private final Map<UUID, Integer> fastPlaceViolation = new HashMap<UUID, Integer>();
private final Map<UUID, Long> lastBlockPlaced = new HashMap<UUID, Long>();
private final Map<UUID, Long> lastBlockPlaceTime = new HashMap<UUID, Long>();
@@ -105,7 +103,6 @@ public class Backend {
startEat.remove(uuid);
lastHeal.remove(uuid);
sprinted.remove(uuid);
nofallViolation.remove(uuid);
fastPlaceViolation.remove(uuid);
lastBlockPlaced.remove(uuid);
lastBlockPlaceTime.remove(uuid);
@@ -124,6 +121,7 @@ public class Backend {
fastSneakViolations.remove(uuid);
lastSneak.remove(uuid);
levitatingEnd.remove(uuid);
NoFallCheck.VIOLATIONS.remove(uuid);
VelocityCheck.VIOLATIONS.remove(uuid);
MorePacketsCheck.LAST_PACKET_TIME.remove(uuid);
MorePacketsCheck.PACKET_BALANCE.remove(uuid);
@@ -211,40 +209,6 @@ public class Backend {
}
}
public CheckResult checkNoFall(final Player player, final double y) {
final UUID uuid = player.getUniqueId();
if (player.getGameMode() != GameMode.CREATIVE && !player.isInsideVehicle() && !player.isSleeping()
&& !isMovingExempt(player) && !justPlaced(player) && !Utilities.isNearWater(player)
&& !Utilities.isInWeb(player) && !player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR")
&& !VersionUtil.isSlowFalling(player)
&& !Utilities
.isNearShulkerBox(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation())
&& !Utilities.isNearClimbable(player)
&& !Utilities.isNearWater(player.getLocation().clone().subtract(0, 1.5, 0))) {
if (player.getFallDistance() == 0) {
if (nofallViolation.get(uuid) == null) {
nofallViolation.put(uuid, 1);
} else {
nofallViolation.put(uuid, nofallViolation.get(player.getUniqueId()) + 1);
}
int i = nofallViolation.get(uuid);
int vlBeforeFlag = checksConfig.getInteger(CheckType.NOFALL, "vlBeforeFlag");
if (i >= vlBeforeFlag) {
nofallViolation.put(player.getUniqueId(), 1);
return new CheckResult(CheckResult.Result.FAILED,
"tried to avoid fall damage (" + i + " times in a row, max=" + vlBeforeFlag + ")");
} else {
return PASS;
}
} else {
nofallViolation.put(uuid, 0);
return PASS;
}
}
return PASS;
}
public CheckResult checkSneakToggle(final Player player) {
final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
final long lastSneak = this.lastSneak.getOrDefault(player.getUniqueId(), (long) 0);
@@ -534,7 +498,7 @@ public class Backend {
manager.getUserManager().getUser(player.getUniqueId()).getMovementManager().lastTeleport = System
.currentTimeMillis();
/* Data for fly/speed should be reset */
nofallViolation.remove(player.getUniqueId());
NoFallCheck.VIOLATIONS.remove(player.getUniqueId());
ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId());
}
@@ -31,7 +31,8 @@ import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.Utilities;
/*
* In development - expect issues
* TODO redo (again)
* Just go for a basic GCD check and implement optifine detection
*/
public final class AimbotCheck {
@@ -0,0 +1,79 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2022 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.player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.GameMode;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
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.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public final class NoFallCheck {
public static final Map<UUID, Integer> VIOLATIONS = new HashMap<>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult performCheck(final Player player, final double motionY) {
final UUID uuid = player.getUniqueId();
final Backend backend = AntiCheatReloaded.getManager().getBackend();
final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
if (player.getGameMode() != GameMode.CREATIVE && !player.isInsideVehicle() && !player.isSleeping()
&& !backend.isMovingExempt(player) && !backend.justPlaced(player) && !Utilities.isNearWater(player)
&& !Utilities.isInWeb(player) && !player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR")
&& !VersionUtil.isSlowFalling(player)
&& !Utilities
.isNearShulkerBox(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation())
&& !Utilities.isNearClimbable(player)
&& !Utilities.isNearWater(player.getLocation().clone().subtract(0, 1.5, 0))) {
if (player.getFallDistance() == 0.0) {
if (VIOLATIONS.get(uuid) == null) {
VIOLATIONS.put(uuid, 1);
} else {
VIOLATIONS.put(uuid, VIOLATIONS.get(player.getUniqueId()) + 1);
}
final int violations = VIOLATIONS.get(uuid);
final int vlBeforeFlag = checksConfig.getInteger(CheckType.NOFALL, "vlBeforeFlag");
if (violations >= vlBeforeFlag) {
VIOLATIONS.put(player.getUniqueId(), 1);
return new CheckResult(CheckResult.Result.FAILED,
"tried to avoid fall damage (" + violations + " times in a row, max=" + vlBeforeFlag + ")");
} else {
return PASS;
}
} else {
VIOLATIONS.put(uuid, 0);
return PASS;
}
}
return PASS;
}
}
@@ -42,6 +42,7 @@ public class CommandReload extends CommandBase {
@Override
protected void execute(CommandSender cs, String[] args) {
CONFIG.load();
cs.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + "The configuration was reloaded");
cs.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> "
+ ChatColor.GRAY + "The configuration was reloaded");
}
}
@@ -72,6 +72,7 @@ import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck;
import com.rammelkast.anticheatreloaded.check.movement.StrafeCheck;
import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck;
import com.rammelkast.anticheatreloaded.check.player.IllegalInteract;
import com.rammelkast.anticheatreloaded.check.player.NoFallCheck;
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.Permission;
@@ -82,7 +83,7 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil;
public final class PlayerListener extends EventListener {
private static final AntiCheatManager MANAGER = AntiCheatReloaded.getManager();
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
final Player player = event.getPlayer();
@@ -184,18 +185,18 @@ public final class PlayerListener extends EventListener {
if (!user.getMovementManager().onGround) {
return;
}
final double motionY = velocity.getY();
user.getMovementManager().velocityExpectedMotionY = motionY;
// End part of Velocity check
MANAGER.addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(final AsyncPlayerChatEvent event) {
final Player player = event.getPlayer();
if (getCheckManager().willCheck(player, CheckType.CHAT_SPAM)) {
final CheckResult result = getBackend().checkChatSpam(player, event.getMessage());
if (result.failed()) {
@@ -252,7 +253,8 @@ public final class PlayerListener extends EventListener {
}).get();
getUserManager().removeUser(user);
} catch (final InterruptedException | ExecutionException exception) {
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to destroy user object async", exception);
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to destroy user object async",
exception);
return;
}
@@ -290,7 +292,8 @@ public final class PlayerListener extends EventListener {
final Player player = event.getPlayer();
final PlayerInventory inv = player.getInventory();
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
final ItemStack itemInHand = ((event.getHand() == EquipmentSlot.HAND) ? inv.getItemInMainHand() : inv.getItemInOffHand());
final ItemStack itemInHand = ((event.getHand() == EquipmentSlot.HAND) ? inv.getItemInMainHand()
: inv.getItemInOffHand());
if (itemInHand.getType() == Material.BOW) {
getBackend().logBowWindUp(player);
@@ -372,10 +375,11 @@ public final class PlayerListener extends EventListener {
}).get();
getUserManager().addUser(user);
} catch (final InterruptedException | ExecutionException exception) {
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to create user object async", exception);
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to create user object async",
exception);
return;
}
MANAGER.addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
if (player.hasPermission("anticheat.admin") && !AntiCheatReloaded.getUpdateManager().isLatest()) {
@@ -427,7 +431,8 @@ public final class PlayerListener extends EventListener {
}
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP)
&& event.getFrom().getY() > event.getTo().getY()) {
final CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo()));
final CheckResult result = getBackend().checkVClip(player,
new Distance(event.getFrom(), event.getTo()));
if (result.failed()) {
if (!silentMode()) {
int data = result.getData() > 3 ? 3 : result.getData();
@@ -447,7 +452,7 @@ public final class PlayerListener extends EventListener {
&& getCheckManager().willCheck(player, CheckType.FLIGHT)
&& !Utilities.isClimbableBlock(player.getLocation().getBlock())
&& event.getFrom().getY() > event.getTo().getY()) {
final CheckResult result = getBackend().checkNoFall(player, y);
final CheckResult result = NoFallCheck.performCheck(player, y);
if (result.failed()) {
if (!silentMode()) {
event.setTo(user.getGoodLocation(from.clone()));
@@ -36,10 +36,9 @@ import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* <p/>
* The manager that AntiCheat will check with to see if it should watch certain checks and certain players.
* The manager that AntiCheatReloaded will check with to see if it should watch
* certain checks and certain players.
*/
public final class CheckManager {
private final AntiCheatManager manager;