diff --git a/.github/README.MD b/.github/README.MD index b39eb8f..17aa190 100644 --- a/.github/README.MD +++ b/.github/README.MD @@ -1,21 +1,13 @@ -# AntiHaxerman -> An open-sourced anti-cheat solution for servers and for people to learn from. - -## Join MAC (Minecraft Anti-Cheat Community) -https://discord.gg/SAuj458nzM +# antihaxerman +> An open-sourced anti-cheat solution for people to learn from. +## Join the [Minecraft AntiCheat Community](https://discord.gg/SAuj458nzM) ## About Keep in mind I coded this all whilst drunk as hell so you never know what you might find. - Tecnio -This is a project mostly designed for people to be able to learn and take code from to use on their projects. - -## Warning - -This project is intentionally nerfed in order to teach people not to mess up on whilst providing them the ground works of -a nice and robust anti-cheat base that they can work off of. - -This by itself will work stably for the most part, but do not expect it to detect everything and by no means is it flawless. +This is a project mostly designed for people to be able to learn and take code from to use on their projects and is +nerfed by design. It is not representative of what are the best practices. ## Getting Started @@ -24,10 +16,10 @@ This by itself will work stably for the most part, but do not expect it to detec ### Installation 1. Clone the repository\ -`git clone https://github.com/Tecnio/AntiHaxerman.git` +`git clone https://github.com/Tecnio/antihaxerman.git` 2. CD into the folder\ -`cd AntiHaxerman` +`cd antihaxerman` 3. Compile with Gradle - Windows: `./gradlew.bat build` @@ -44,15 +36,4 @@ Supported server/Spigot forks are listed below, the rest are not guaranteed to w - Paper - TacoSpigot -Make sure to be running a 1.8.8 server. - -## Contributing - -If you find any issues or want to contribute to this open-source project, please feel free to do so. Any bug fixes or additions are more than welcome. Your help and ideas are greatly appreciated! - -## Developers -- https://github.com/Tecnio (Tecnio) -- https://github.com/TheRealShitDev (aSwitch) -- https://github.com/gbomexify (Mexify) -- https://github.com/incognitolol (RNOIncognito) -- https://github.com/Cyanade (Cyanade) +Make sure to be running a 1.8.8 server. \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6fc491a..d2f1612 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -# Created by .ignore support plugin (hsz.mobi) ### Java template # Compiled class file *.class diff --git a/build.gradle.kts b/build.gradle.kts index 6e267e9..101d111 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,11 @@ plugins { java - id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.gradleup.shadow") version "8.3.5" + id("io.freefair.lombok") version "8.11" } group = "me.tecnio" -version = "4.0.2" +version = "4.0.3" java { toolchain { @@ -26,19 +27,16 @@ repositories { dependencies { compileOnly("org.github.spigot:1.8.8:1.8.8") - compileOnly("org.projectlombok:lombok:1.18.32") - - annotationProcessor("org.projectlombok:lombok:1.18.32") implementation("com.github.artemisac.artemis-packet-api:api:2.0.0-beta-3") implementation("com.github.artemisac.artemis-packet-api:spigot:2.0.0-beta-3") - implementation("org.atteo.classindex:classindex:3.13") implementation("co.aikar:acf-paper:0.5.1-SNAPSHOT") - implementation("org.bstats:bstats-bukkit:3.0.2") + implementation("org.bstats:bstats-bukkit:3.1.0") } tasks.shadowJar { archiveFileName = "AntiHaxerman.jar" + minimize() relocate("org.atteo.classindex", "me.tecnio.ahm.libs.classindex") diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23..cea7a79 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 1aa94a4..f3b75f3 100644 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 25da30d..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/src/main/java/me/tecnio/ahm/AHM.java b/src/main/java/me/tecnio/ahm/AntiHaxerman.java similarity index 95% rename from src/main/java/me/tecnio/ahm/AHM.java rename to src/main/java/me/tecnio/ahm/AntiHaxerman.java index 9b96698..faf78f5 100644 --- a/src/main/java/me/tecnio/ahm/AHM.java +++ b/src/main/java/me/tecnio/ahm/AntiHaxerman.java @@ -24,7 +24,7 @@ import java.util.logging.Logger; @Getter -public enum AHM { +public enum AntiHaxerman { INSTANCE; @@ -67,7 +67,6 @@ public void end() { terminateManagers(); } - private void registerMetrics() { System.setProperty("bstats.relocatecheck", "false"); new Metrics(this.plugin, 11350); @@ -82,8 +81,10 @@ private void registerManagers() { } private void registerConfiguration() { - get(ConfigManager.class).generate(); - get(ConfigManager.class).load(); + final ConfigManager config = get(ConfigManager.class); + + config.generate(); + config.load(); } private void registerListeners() { @@ -115,7 +116,7 @@ private void terminateManagers() { this.configManager = null; } - public static AHM get() { + public static AntiHaxerman get() { return INSTANCE; } diff --git a/src/main/java/me/tecnio/ahm/AHMPlugin.java b/src/main/java/me/tecnio/ahm/AntiHaxermanPlugin.java similarity index 55% rename from src/main/java/me/tecnio/ahm/AHMPlugin.java rename to src/main/java/me/tecnio/ahm/AntiHaxermanPlugin.java index 4b8e4f6..7b51682 100644 --- a/src/main/java/me/tecnio/ahm/AHMPlugin.java +++ b/src/main/java/me/tecnio/ahm/AntiHaxermanPlugin.java @@ -2,15 +2,15 @@ import org.bukkit.plugin.java.JavaPlugin; -public final class AHMPlugin extends JavaPlugin { +public final class AntiHaxermanPlugin extends JavaPlugin { @Override public void onEnable() { - AHM.INSTANCE.start(this); + AntiHaxerman.INSTANCE.start(this); } @Override public void onDisable() { - AHM.INSTANCE.end(); + AntiHaxerman.INSTANCE.end(); } } diff --git a/src/main/java/me/tecnio/ahm/alert/AlertManager.java b/src/main/java/me/tecnio/ahm/alert/AlertManager.java index 1b42078..b726942 100644 --- a/src/main/java/me/tecnio/ahm/alert/AlertManager.java +++ b/src/main/java/me/tecnio/ahm/alert/AlertManager.java @@ -1,7 +1,7 @@ package me.tecnio.ahm.alert; import lombok.Getter; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.alert.alert.AlertHandler; import me.tecnio.ahm.alert.alert.AlertHandlerFactory; import me.tecnio.ahm.alert.punish.PunishmentHandler; @@ -24,7 +24,7 @@ public class AlertManager { private final AlertHandler alertHandler = new AlertHandlerFactory().build(); private final PunishmentHandler punishmentHandler = new PunishmentHandlerFactory() - .setTesting(AHM.TEST_MODE) + .setTesting(AntiHaxerman.TEST_MODE) .build(); public boolean toggleAlerts(final PlayerData data) { @@ -40,8 +40,4 @@ public void handleAlert(final Check check, final String debug) { public void handlePunishment(final Check check) { this.punishmentHandler.punish(check); } - - public enum ToggleAlertType { - ADD, REMOVE - } } diff --git a/src/main/java/me/tecnio/ahm/alert/punish/PunishmentHandlerFactory.java b/src/main/java/me/tecnio/ahm/alert/punish/PunishmentHandlerFactory.java index 5a49d46..ef0cf46 100644 --- a/src/main/java/me/tecnio/ahm/alert/punish/PunishmentHandlerFactory.java +++ b/src/main/java/me/tecnio/ahm/alert/punish/PunishmentHandlerFactory.java @@ -16,6 +16,8 @@ public PunishmentHandlerFactory setTesting(final boolean testing) { @Override public PunishmentHandler build() { - return this.testing ? new TestingPunishmentHandler() : new ProductionPunishmentHandler(); + return this.testing + ? new TestingPunishmentHandler() + : new ProductionPunishmentHandler(); } } diff --git a/src/main/java/me/tecnio/ahm/alert/punish/impl/ProductionPunishmentHandler.java b/src/main/java/me/tecnio/ahm/alert/punish/impl/ProductionPunishmentHandler.java index 1bd8f8e..23d10e9 100644 --- a/src/main/java/me/tecnio/ahm/alert/punish/impl/ProductionPunishmentHandler.java +++ b/src/main/java/me/tecnio/ahm/alert/punish/impl/ProductionPunishmentHandler.java @@ -1,6 +1,6 @@ package me.tecnio.ahm.alert.punish.impl; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.alert.punish.PunishmentHandler; import me.tecnio.ahm.check.Check; import org.bukkit.Bukkit; @@ -17,7 +17,7 @@ public void punish(final Check check) { } private void execute(final String command) { - Bukkit.getScheduler().runTask(AHM.get().getPlugin(), + Bukkit.getScheduler().runTask(AntiHaxerman.get().getPlugin(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)); } } diff --git a/src/main/java/me/tecnio/ahm/check/Check.java b/src/main/java/me/tecnio/ahm/check/Check.java index 97246f2..c11809f 100644 --- a/src/main/java/me/tecnio/ahm/check/Check.java +++ b/src/main/java/me/tecnio/ahm/check/Check.java @@ -2,7 +2,7 @@ import lombok.Getter; import lombok.Setter; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.alert.AlertManager; import me.tecnio.ahm.check.api.Buffer; import me.tecnio.ahm.check.api.annotations.CheckManifest; @@ -11,14 +11,12 @@ import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.exempt.ExemptType; import me.tecnio.ahm.util.string.ChatUtil; -import org.atteo.classindex.IndexSubclasses; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.List; @Getter -@IndexSubclasses public abstract class Check { protected final PlayerData data; @@ -57,11 +55,11 @@ public Check(final PlayerData data) { this.buffer = new Buffer(this.info.maxBuffer()); } else { this.info = null; - throw new IllegalStateException("The CheckManifest annotation has not been added on " + this.getClass().getName()); + throw new IllegalStateException("CheckManifest has not been added to " + this.getClass().getName()); } final String name = this.name + "." + this.type; - final ConfigManager config = AHM.get(ConfigManager.class); + final ConfigManager config = AntiHaxerman.get(ConfigManager.class); this.enabled = config.getEnabledMap().get(name); this.punishing = config.getPunishMap().get(name); @@ -74,12 +72,12 @@ protected final void fail() { } protected final void fail(final String debug) { - ++this.violations; + final AlertManager alertManager = AntiHaxerman.get(AlertManager.class); - AHM.get(AlertManager.class).handleAlert(this, debug); + alertManager.handleAlert(this, debug); - if (this.violations >= this.maxVl) { - AHM.get(AlertManager.class).handlePunishment(this); + if (++this.violations >= this.maxVl) { + alertManager.handlePunishment(this); } } @@ -92,10 +90,7 @@ protected final boolean isExempt(final ExemptType... exemptTypes) { } protected final void debug(final Object object, final Object... objects) { - data.getPlayer().sendMessage(ChatUtil.translate(String.format("&6AntiHaxerman Debug &8> " + ChatColor.WHITE + object.toString(), objects))); - } - - protected boolean canClick() { - return !data.getActionTracker().isPlacing(); + data.getPlayer().sendMessage(ChatUtil.translate( + String.format("&6AntiHaxerman Debug &8> " + ChatColor.WHITE + object.toString(), objects))); } } diff --git a/src/main/java/me/tecnio/ahm/check/api/CheckManager.java b/src/main/java/me/tecnio/ahm/check/api/CheckManager.java index 0b71014..5ee8bff 100644 --- a/src/main/java/me/tecnio/ahm/check/api/CheckManager.java +++ b/src/main/java/me/tecnio/ahm/check/api/CheckManager.java @@ -3,12 +3,31 @@ import lombok.Getter; import lombok.SneakyThrows; import me.tecnio.ahm.check.Check; -import me.tecnio.ahm.check.api.annotations.Disabled; +import me.tecnio.ahm.check.impl.aim.AimA; +import me.tecnio.ahm.check.impl.aim.AimB; +import me.tecnio.ahm.check.impl.aura.AuraA; +import me.tecnio.ahm.check.impl.aura.AuraB; +import me.tecnio.ahm.check.impl.aura.AuraC; +import me.tecnio.ahm.check.impl.autoclicker.AutoClickerA; +import me.tecnio.ahm.check.impl.flight.FlightA; +import me.tecnio.ahm.check.impl.flight.FlightB; +import me.tecnio.ahm.check.impl.flight.FlightC; +import me.tecnio.ahm.check.impl.flight.FlightD; +import me.tecnio.ahm.check.impl.groundspoof.GroundSpoofA; +import me.tecnio.ahm.check.impl.hitbox.HitboxA; +import me.tecnio.ahm.check.impl.interact.InteractA; +import me.tecnio.ahm.check.impl.interact.InteractB; +import me.tecnio.ahm.check.impl.interact.InteractC; +import me.tecnio.ahm.check.impl.protocol.*; +import me.tecnio.ahm.check.impl.scaffold.ScaffoldA; +import me.tecnio.ahm.check.impl.speed.SpeedA; +import me.tecnio.ahm.check.impl.speed.SpeedB; +import me.tecnio.ahm.check.impl.timer.TimerA; +import me.tecnio.ahm.check.impl.velocity.VelocityA; +import me.tecnio.ahm.check.impl.velocity.VelocityB; +import me.tecnio.ahm.check.impl.velocity.VelocityC; import me.tecnio.ahm.data.PlayerData; -import org.atteo.classindex.ClassIndex; -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; @@ -16,27 +35,57 @@ public final class CheckManager { private final List> checks = new ArrayList<>(); - private final List> constructors = new ArrayList<>(); public CheckManager() { - ClassIndex.getSubclasses(Check.class, Check.class.getClassLoader()).forEach(clazz -> { - try { - if (!Modifier.isAbstract(clazz.getModifiers()) && !clazz.isAnnotationPresent(Disabled.class)) { - this.checks.add(clazz); - this.constructors.add(clazz.getConstructor(PlayerData.class)); - } - } catch (final Exception ex) { - ex.printStackTrace(); - } - }); + this.checks.add(AimA.class); + this.checks.add(AimB.class); + + this.checks.add(AuraA.class); + this.checks.add(AuraB.class); + this.checks.add(AuraC.class); + + this.checks.add(AutoClickerA.class); + + this.checks.add(FlightA.class); + this.checks.add(FlightB.class); + this.checks.add(FlightC.class); + this.checks.add(FlightD.class); + + this.checks.add(GroundSpoofA.class); + + this.checks.add(HitboxA.class); + + this.checks.add(InteractA.class); + this.checks.add(InteractB.class); + this.checks.add(InteractC.class); + + this.checks.add(ProtocolA.class); + this.checks.add(ProtocolB.class); + this.checks.add(ProtocolC.class); + this.checks.add(ProtocolD.class); + this.checks.add(ProtocolE.class); + this.checks.add(ProtocolF.class); + this.checks.add(ProtocolG.class); + this.checks.add(ProtocolH.class); + + this.checks.add(ScaffoldA.class); + + this.checks.add(SpeedA.class); + this.checks.add(SpeedB.class); + + this.checks.add(TimerA.class); + + this.checks.add(VelocityA.class); + this.checks.add(VelocityB.class); + this.checks.add(VelocityC.class); } @SneakyThrows public List loadChecks(final PlayerData data) { final List checkList = new ArrayList<>(); - for (final Constructor constructor : this.constructors) { - checkList.add((Check) constructor.newInstance(data)); + for (final Class check : this.checks) { + checkList.add((Check) check.getConstructor(PlayerData.class).newInstance(data)); } return checkList; diff --git a/src/main/java/me/tecnio/ahm/check/impl/aim/AimA.java b/src/main/java/me/tecnio/ahm/check/impl/aim/AimA.java index 4fc5a6c..1b14263 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/aim/AimA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/aim/AimA.java @@ -7,9 +7,6 @@ import me.tecnio.ahm.exempt.ExemptType; import me.tecnio.ahm.update.RotationUpdate; -/** - * Check to detect rotations with rounding flaws. - */ @CheckManifest(name = "Aim", type = "A", description = "Detects rotations with rounding flaws.") public final class AimA extends Check implements RotationCheck { @@ -19,27 +16,21 @@ public AimA(final PlayerData data) { @Override public void handle(final RotationUpdate update) { - // If the player is exempt from aim-related or teleportation-related checks, exit the method. if (this.isExempt(ExemptType.AIM, ExemptType.TELEPORT)) return; - // Calculate the constant based on sensitivity to be used for calculations. final float constant = data.getRotationTracker().getSensitivity() / 142.0F; - // Get the pitch and yaw values from the update. final float pitch = update.getPitch(); final float yaw = update.getYaw(); - // Calculate the modulo of pitch and yaw with respect to the constant. final float moduloPitch = Math.abs(pitch % constant); final float moduloYaw = Math.abs(yaw % constant); - // If both moduloPitch and moduloYaw are zero, increase the buffer count. if (moduloPitch == 0.0D && moduloYaw == 0.0D) { if (this.buffer.increase() > 30) { this.fail("mP: " + moduloPitch); } } else { - // If at least one of the modulos is not zero, decrease the buffer by 0.05. this.buffer.decreaseBy(0.05D); } } diff --git a/src/main/java/me/tecnio/ahm/check/impl/aim/AimB.java b/src/main/java/me/tecnio/ahm/check/impl/aim/AimB.java index 718cb81..3bf0152 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/aim/AimB.java +++ b/src/main/java/me/tecnio/ahm/check/impl/aim/AimB.java @@ -19,31 +19,23 @@ public AimB(final PlayerData data) { @Override public void handle(final RotationUpdate update) { - // If the player is exempt from aim-related checks, exit the method. if (this.isExempt(ExemptType.AIM)) return; - // Get the changes in yaw and pitch from the update. final float deltaYaw = update.getDeltaYaw(); final float deltaPitch = update.getDeltaPitch(); - // If either the change in yaw or pitch is too small, exit the method as we can't do the math - // as we require both yaw and the pitch to be moving in order to get the highest GCD between them. if (deltaYaw < 1.0F || deltaPitch < 1.0F) return; - // Get the divisor values for the x and y axes from the rotation tracker. final float divisorX = data.getRotationTracker().getDivisorX(); final float divisorY = data.getRotationTracker().getDivisorY(); - // Find the maximum divisor value between the x and y axes. final float divisorMax = Math.max(divisorX, divisorY); - // If the maximum divisor is below a certain threshold, increase the buffer count. if (divisorMax < 0.0078125F) { if (this.buffer.increaseBy(0.3D) > 8) { this.fail("dM: " + divisorMax); } } else { - // If the maximum divisor is not too small, decrease the buffer by 0.1. this.buffer.decreaseBy(0.1D); } } diff --git a/src/main/java/me/tecnio/ahm/check/impl/aura/AuraB.java b/src/main/java/me/tecnio/ahm/check/impl/aura/AuraB.java index 65ba16b..1a4777e 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/aura/AuraB.java +++ b/src/main/java/me/tecnio/ahm/check/impl/aura/AuraB.java @@ -8,9 +8,6 @@ import me.tecnio.ahm.update.PositionUpdate; import org.bukkit.entity.Player; -/** - * Check to detect keep-sprint behavior, commonly used in aura-like cheats. - */ @CheckManifest(name = "Aura", type = "B", description = "Detects keep-sprint.") public final class AuraB extends Check implements PositionCheck { @@ -20,26 +17,29 @@ public AuraB(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - // Skip processing if the attack timer hasn't passed or the target is not a player. if (data.getActionTracker().getAttackTimer().hasPassed(1) || !(data.getActionTracker().getTarget() instanceof Player)) return; - // Check for exemption conditions. - final boolean exempt = this.isExempt(ExemptType.VEHICLE, ExemptType.CHUNK, ExemptType.FLIGHT, ExemptType.RETARD, - ExemptType.PISTON, ExemptType.SLIME, ExemptType.LIQUID, ExemptType.TELEPORTED_RECENTLY); + final boolean exempt = this.isExempt( + ExemptType.VEHICLE, + ExemptType.CHUNK, + ExemptType.FLIGHT, + ExemptType.SLOW, + ExemptType.PISTON, + ExemptType.SLIME, + ExemptType.LIQUID, + ExemptType.TELEPORTED_RECENTLY + ); - // Check for invalid conditions: sprinting without hit slowdown, sprinting, and being on the ground. final boolean invalid = !data.getEmulationTracker().isHitSlowdown() && data.getEmulationTracker().isSprint() && data.getPositionTracker().isOnGround(); if (invalid && !exempt) { - // Trigger a violation if the conditions are met and the buffer threshold is exceeded. if (this.buffer.increase() > 3) { this.fail(); } } else { - // Decrease the buffer if the conditions are not met. this.buffer.decreaseBy(0.1D); } } diff --git a/src/main/java/me/tecnio/ahm/check/impl/aura/AuraC.java b/src/main/java/me/tecnio/ahm/check/impl/aura/AuraC.java index 30edeae..5df8021 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/aura/AuraC.java +++ b/src/main/java/me/tecnio/ahm/check/impl/aura/AuraC.java @@ -25,7 +25,9 @@ public void handle(final GPacket packet) { if (packet instanceof PacketPlayClientUseEntity) { final GPacketPlayClientUseEntity wrapper = ((GPacketPlayClientUseEntity) packet); - if (wrapper.getType() == PlayerEnums.UseType.ATTACK && !this.swung) this.fail(); + if (wrapper.getType() == PlayerEnums.UseType.ATTACK && !this.swung) { + this.fail(); + } } else if (packet instanceof PacketPlayClientArmAnimation) { diff --git a/src/main/java/me/tecnio/ahm/check/impl/autoclicker/AutoClickerA.java b/src/main/java/me/tecnio/ahm/check/impl/autoclicker/AutoClickerA.java index c52fcd7..87dbf4f 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/autoclicker/AutoClickerA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/autoclicker/AutoClickerA.java @@ -19,19 +19,20 @@ public AutoClickerA(final PlayerData data) { @Override public void handle(final GPacket packet) { - if (packet instanceof GPacketPlayClientArmAnimation) { - if (this.canClick()) { - ++this.cps; - } - } - - else if (packet instanceof PacketPlayClientFlying) { + if (packet instanceof PacketPlayClientFlying) { if (++this.movements >= 20) { - if (this.cps > 20 && this.canClick()) { + if (this.cps > 20 && !data.getActionTracker().isPlacing()) { this.fail("C: %s", this.cps); } - this.cps = this.movements = 0; + this.cps = 0; + this.movements = 0; + } + } + + else if (packet instanceof GPacketPlayClientArmAnimation) { + if (!data.getActionTracker().isPlacing()) { + ++this.cps; } } } diff --git a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightA.java b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightA.java index 47a1ef9..3cd4c38 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightA.java @@ -19,7 +19,6 @@ public FlightA(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - // Retrieve relevant data for analysis final boolean velocity = data.getVelocityTracker().getTicksSinceVelocity() == 1; final boolean lastVelocity = data.getVelocityTracker().isLastTickVelocity(); @@ -65,22 +64,27 @@ public void handle(final PositionUpdate update) { } } - // 0.03 can happen for multiple ticks but I rather doubt it's gonna be anything over 0.03 tbh. - final double threshold = this.isExempt(ExemptType.RETARD) ? 0.03D : 1e-06D; + final double threshold = this.isExempt(ExemptType.SLOW) ? 0.03D : 1e-06D; - // Check for invalid conditions: significant difference between observed and predicted Y, not on ground, and previous tick not on ground. final boolean invalid = distance > threshold && !ground && !lastGround; - final boolean exempt = this.isExempt(ExemptType.CLIMBABLE, ExemptType.PISTON, ExemptType.SLIME, - ExemptType.VEHICLE, ExemptType.FLIGHT, ExemptType.TELEPORT, ExemptType.UNDER_BLOCK, ExemptType.WEB, ExemptType.LIQUID, - ExemptType.TELEPORTED_RECENTLY); + final boolean exempt = this.isExempt( + ExemptType.CLIMBABLE, + ExemptType.PISTON, + ExemptType.SLIME, + ExemptType.VEHICLE, + ExemptType.FLIGHT, + ExemptType.TELEPORT, + ExemptType.UNDER_BLOCK, + ExemptType.WEB, + ExemptType.LIQUID, + ExemptType.TELEPORTED_RECENTLY + ); if (invalid && !exempt) { - // Trigger a violation if the conditions are met and the buffer threshold is exceeded. if (this.buffer.increase() > 2) { this.fail("oY: %s", Math.abs(deltaY - predicted)); } } else { - // Decrease the buffer if the conditions are not met. this.buffer.decreaseBy(0.01D); } } diff --git a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightB.java b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightB.java index a06691a..b5f8199 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightB.java +++ b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightB.java @@ -20,29 +20,33 @@ public FlightB(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - // The ground states of the current and last tick in order to detect if the player has jumped or gained velocity. final boolean onGround = update.isOnGround(); final boolean lastOnGround = update.isLastOnGround(); - // The current motion upwards in order to be compared to the expected later on. final double deltaY = update.getDeltaY(); - // Calculate expected jump motion based on block placement ticks and potion effects final double modifierJump = data.getAttributeTracker().getPotionLevel(PotionEffectType.JUMP) * 0.1F; final double expectedJumpMotion = 0.42F + modifierJump; - // This is the 0.03 compensated threshold that should prevent falses related to 0.03. - final double threshold = (this.isExempt(ExemptType.RETARD) ? 0.03D : 0.0) + 1.0E-6; - - // Check exemption conditions - final boolean exempt = this.isExempt(ExemptType.VEHICLE, ExemptType.CLIMBABLE, ExemptType.VELOCITY, ExemptType.PISTON, - ExemptType.LIQUID, ExemptType.TELEPORT, ExemptType.WEB, ExemptType.BOAT, ExemptType.FLIGHT, ExemptType.SLIME, - ExemptType.WALL, ExemptType.UNDER_BLOCK, ExemptType.CHUNK); - - // Check for invalid jump motion + final double threshold = (this.isExempt(ExemptType.SLOW) ? 0.03D : 0.0) + 1.0E-6; + final boolean invalid = Math.abs(deltaY - expectedJumpMotion) > threshold && deltaY >= 0; - - // Checking for first "air tick" could be spoofed but they better jump this high if they spoof so idc + final boolean exempt = this.isExempt( + ExemptType.VEHICLE, + ExemptType.CLIMBABLE, + ExemptType.VELOCITY, + ExemptType.PISTON, + ExemptType.LIQUID, + ExemptType.TELEPORT, + ExemptType.WEB, + ExemptType.BOAT, + ExemptType.FLIGHT, + ExemptType.SLIME, + ExemptType.WALL, + ExemptType.UNDER_BLOCK, + ExemptType.CHUNK + ); + if (!onGround && lastOnGround && invalid && !exempt) { this.fail("dY: %s", deltaY); } diff --git a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightC.java b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightC.java index 39c0c20..f32bfcd 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightC.java +++ b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightC.java @@ -8,9 +8,6 @@ import me.tecnio.ahm.update.PositionUpdate; import org.bukkit.potion.PotionEffectType; -/** - * Check to detect invalid step motion that may indicate flight cheats. - */ @CheckManifest(name = "Flight", type = "C", description = "Checks for invalid step motion.") public class FlightC extends Check implements PositionCheck { @@ -22,18 +19,20 @@ public FlightC(final PlayerData data) { public void handle(final PositionUpdate update) { final boolean ground = update.isOnGround(); - // Calculate modified jump motion with potion effects final double modifierJump = data.getAttributeTracker().getPotionLevel(PotionEffectType.JUMP) * 0.1F; final double deltaY = update.getDeltaY() - modifierJump; - // Check exemption conditions - final boolean exempt = this.isExempt(ExemptType.VEHICLE, ExemptType.VELOCITY, ExemptType.PISTON, - ExemptType.TELEPORT, ExemptType.BOAT, ExemptType.FLIGHT, ExemptType.SLIME, ExemptType.CHUNK); + final boolean exempt = this.isExempt( + ExemptType.VEHICLE, + ExemptType.VELOCITY, + ExemptType.PISTON, + ExemptType.TELEPORT, + ExemptType.BOAT, + ExemptType.FLIGHT, + ExemptType.SLIME, + ExemptType.CHUNK + ); - /* - * Check if their instant motion is more than possible while still on ground. - * We use 0.6f to avoid false positives from fences/walls with carpets on top. - */ if (deltaY > 0.6f && ground && !exempt) { this.fail("dY: %s", deltaY); } diff --git a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightD.java b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightD.java index 189de4d..ac85bb4 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/flight/FlightD.java +++ b/src/main/java/me/tecnio/ahm/check/impl/flight/FlightD.java @@ -8,9 +8,6 @@ import me.tecnio.ahm.exempt.ExemptType; import me.tecnio.ahm.update.PositionUpdate; -/** - * Check to detect invalid fall motion that may indicate flight cheats. - */ @CheckManifest(name = "Flight", type = "D", description = "Checks for invalid fall motion.", state = CheckState.EXPERIMENTAL) public class FlightD extends Check implements PositionCheck { @@ -20,25 +17,33 @@ public FlightD(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - /* - * The main idea here is that when players start to fall, their motion cannot be higher than their previous motion - * unless they are cheating. We check for this by comparing the current motion with the previous motion while the - * player is in the air. - */ final double deltaY = update.getDeltaY(); final double lastDeltaY = update.getLastDeltaY(); final boolean ground = update.isOnGround(); final boolean lastOnGround = update.isLastOnGround(); - final boolean exempt = this.isExempt(ExemptType.VEHICLE, ExemptType.VELOCITY, ExemptType.PISTON, - ExemptType.CLIMBABLE, ExemptType.TELEPORT, ExemptType.BOAT, ExemptType.TELEPORTED_RECENTLY, - ExemptType.UNDER_BLOCK, ExemptType.WEB, ExemptType.FLIGHT, ExemptType.SLIME, ExemptType.CHUNK, - ExemptType.LIQUID, ExemptType.JOIN); - final boolean startedFalling = deltaY <= 0.2 && !ground; - if (!ground && !lastOnGround && !exempt && deltaY >= lastDeltaY && startedFalling) { + final boolean invalid = !ground && !lastOnGround && deltaY >= lastDeltaY && startedFalling; + final boolean exempt = this.isExempt( + ExemptType.VEHICLE, + ExemptType.VELOCITY, + ExemptType.PISTON, + ExemptType.CLIMBABLE, + ExemptType.TELEPORT, + ExemptType.BOAT, + ExemptType.TELEPORTED_RECENTLY, + ExemptType.UNDER_BLOCK, + ExemptType.WEB, + ExemptType.FLIGHT, + ExemptType.SLIME, + ExemptType.CHUNK, + ExemptType.LIQUID, + ExemptType.JOIN + ); + + if (invalid && !exempt) { if (this.buffer.increase() > 2) { this.fail("invalid fall motion"); } diff --git a/src/main/java/me/tecnio/ahm/check/impl/groundspoof/GroundSpoofA.java b/src/main/java/me/tecnio/ahm/check/impl/groundspoof/GroundSpoofA.java index e8c7a0d..8085d5e 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/groundspoof/GroundSpoofA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/groundspoof/GroundSpoofA.java @@ -16,7 +16,8 @@ public GroundSpoofA(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - if (this.isExempt(ExemptType.CHUNK, ExemptType.CLIMBABLE, ExemptType.SLIME, ExemptType.BOAT, ExemptType.RETARD)) return; + if (this.isExempt(ExemptType.CHUNK, ExemptType.CLIMBABLE, + ExemptType.SLIME, ExemptType.BOAT, ExemptType.SLOW)) return; final boolean ground = data.getPositionTracker().isOnGround(); final boolean mathGround = data.getPositionTracker().getY() % 0.015625D == 0.0D; diff --git a/src/main/java/me/tecnio/ahm/check/impl/hitbox/HitboxA.java b/src/main/java/me/tecnio/ahm/check/impl/hitbox/HitboxA.java index dde6b1a..e348906 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/hitbox/HitboxA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/hitbox/HitboxA.java @@ -32,52 +32,39 @@ public HitboxA(final PlayerData data) { @Override public void handle(final GPacket packet) { if (packet instanceof PacketPlayClientFlying && this.target != null) { - // As we are brute forcing some possibilities, we just need to see if any of them intersected; boolean intersection = false; - // These are the tracked positions of the target that was attacked; final double targetX = this.target.getPosX(); final double targetY = this.target.getPosY(); final double targetZ = this.target.getPosZ(); - // As we are going to ray-cast we need to create an appropriately sized bounding box for the target. AxisAlignedBB boundingBox = new AxisAlignedBB( targetX - 0.4F, targetY - 0.1F, targetZ - 0.4F, targetX + 0.4F, targetY + 1.9F, targetZ + 0.4F ); - // Because of something called 0.03 we sometimes get uncertainty in the position of the attacker. - // To handle this we can just add a 0.03 block leniency on the targets bounding box. - // Not a perfect solution but a valid one for sure. - if (this.isExempt(ExemptType.RETARD)) boundingBox = boundingBox.expand(0.03, 0.03, 0.03); + if (this.isExempt(ExemptType.SLOW)) boundingBox = boundingBox.expand(0.03, 0.03, 0.03); - // On 1.8.9, the rotations of the player is a tick behind but very popular mods like OptiFine fix this problem, - // and therefore we have to handle them as well. for (final boolean rotation : BOOLEANS) { - // This is for the sneaking status of the player, because the latest sneaking position doesn't work - // and I can't be asked to find the proper sneaking state of the player, we are brute forcing it. for (final boolean sneak : BOOLEANS) { - // These are the yaw and pitch of the player. For the explanation of this read the rotation iterations comment. - final float yaw = rotation ? data.getRotationTracker().getYaw() : data.getRotationTracker().getLastYaw(); - final float pitch = rotation ? data.getRotationTracker().getPitch() : data.getRotationTracker().getLastPitch(); + final float yaw = rotation + ? data.getRotationTracker().getYaw() + : data.getRotationTracker().getLastYaw(); + final float pitch = data.getRotationTracker().getPitch(); - // This is where we do the actual ray-casting. final MovingObjectPosition result = this.rayCast(yaw, pitch, sneak, boundingBox); - // Here, if we have an intersection we set the intersection variable to true, if else it stays false. intersection |= result != null && result.hitVec != null; } } final Player target = (Player) data.getActionTracker().getTarget(); - // These are some scenarios the check wouldn't work and instead of properly handling it, we are returning - // because who actually gives a fuck about these scenarios. final boolean exempt = data.getPlayer().getGameMode() == GameMode.CREATIVE - || target.isInsideVehicle() || target.isSleeping(); + || target.isInsideVehicle() + || target.isSleeping(); if (!intersection && !exempt) { - // This check does need some buffer as it's not flawless but the concept is there, ready to be expanded on. if (this.buffer.increase() > 2) { this.fail(); } @@ -92,7 +79,8 @@ else if (packet instanceof PacketPlayClientUseEntity) { final GPacketPlayClientUseEntity wrapper = ((GPacketPlayClientUseEntity) packet); if (wrapper.getType() == PlayerEnums.UseType.ATTACK) { - this.target = data.getEntityTracker().getTrackerMap().getOrDefault(wrapper.getEntityId(), null); + this.target = data.getEntityTracker().getTrackerMap() + .get(wrapper.getEntityId()); } } } @@ -111,7 +99,6 @@ private MovingObjectPosition rayCast(final float yaw, final float pitch, final b return bb.calculateIntercept(vec3, vec32); } - // better not be using fastmath my guy private Vec3 getVectorForRotation(final float pitch, final float yaw) { final float f = MathHelper.cos(-yaw * 0.017453292F - (float) Math.PI); final float f1 = MathHelper.sin(-yaw * 0.017453292F - (float) Math.PI); diff --git a/src/main/java/me/tecnio/ahm/check/impl/interact/InteractC.java b/src/main/java/me/tecnio/ahm/check/impl/interact/InteractC.java index 70aeb45..c8c40b8 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/interact/InteractC.java +++ b/src/main/java/me/tecnio/ahm/check/impl/interact/InteractC.java @@ -11,6 +11,7 @@ @CheckManifest(name = "Interact", type = "C", description = "Checks for baritone rotations") public class InteractC extends Check implements PacketCheck { + public InteractC(PlayerData data) { super(data); } diff --git a/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolA.java b/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolA.java index 66189ff..787c15d 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolA.java @@ -16,9 +16,11 @@ public ProtocolA(final PlayerData data) { @Override public void handle(final RotationUpdate update) { + if (this.isExempt(ExemptType.TELEPORT)) return; + final float pitch = Math.abs(update.getPitch()); - if (pitch > 90.0F && !this.isExempt(ExemptType.TELEPORT)) { + if (pitch > 90.0F) { this.fail("p: " + pitch); } } diff --git a/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolC.java b/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolC.java index a861124..4df38f3 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolC.java +++ b/src/main/java/me/tecnio/ahm/check/impl/protocol/ProtocolC.java @@ -23,10 +23,10 @@ public void handle(final GPacket packet) { if (packet instanceof GPacketPlayClientUseEntity) { final GPacketPlayClientUseEntity wrapper = ((GPacketPlayClientUseEntity) packet); - if (wrapper.getType() == PlayerEnums.UseType.ATTACK) { - if (++this.streak > 2) { - this.fail(); - } + if (wrapper.getType() != PlayerEnums.UseType.ATTACK) return; + + if (++this.streak > 2) { + this.fail(); } } else if (packet instanceof GPacketPlayClientArmAnimation) { this.streak = 0; diff --git a/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedA.java b/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedA.java index 5173ebb..61fd023 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedA.java @@ -35,37 +35,36 @@ public void handle(final PositionUpdate update) { float friction = 0.91F; if (lastOnGround) friction *= data.getPositionTracker().getSlipperiness(); - // Create a limit for the maximum offset. We assume they are sprinting why not. double movementSpeed = PlayerUtil.getAttributeSpeed(data, true); - // Apply air and ground math depending on the current scenario. if (lastOnGround) { - // Apply ground movement math. movementSpeed *= 0.16277136F / (friction * friction * friction); - // If the player might have jumped compensate for it. This may or may not be abusable (It is - Mexify YW BTW). if (!onGround && deltaY >= 0.0D) { movementSpeed += 0.2D; } } else { - // If the player is in air get the max sprint speed. movementSpeed = (float) ((double) 0.02F + (double) 0.02F * 0.3D); } - // Compensate for velocity. if (data.getVelocityTracker().getTicksSinceVelocity() == 1) { this.motionX = data.getVelocityTracker().getVelocity().getX(); this.motionZ = data.getVelocityTracker().getVelocity().getZ(); } - // Create a ratio for acceleration final double acceleration = (deltaXZ - (MathUtil.hypot(this.motionX, this.motionZ))) / movementSpeed; - final boolean exempt = this.isExempt(ExemptType.TELEPORTED_RECENTLY, ExemptType.PISTON, ExemptType.EXPLOSION, - ExemptType.FLIGHT, ExemptType.CHUNK, ExemptType.RETARD, ExemptType.VEHICLE, ExemptType.LIQUID); - - // Checks if acceleration is impossible and also checks if the player is not moving slow final boolean invalid = acceleration > 1.0D + 1.0E-6 && deltaXZ > 0.2D; + final boolean exempt = this.isExempt( + ExemptType.TELEPORTED_RECENTLY, + ExemptType.PISTON, + ExemptType.EXPLOSION, + ExemptType.FLIGHT, + ExemptType.CHUNK, + ExemptType.SLOW, + ExemptType.VEHICLE, + ExemptType.LIQUID + ); if (invalid && !exempt) { final boolean certain = data.getVelocityTracker().getTicksSinceVelocity() > 2; @@ -78,11 +77,9 @@ public void handle(final PositionUpdate update) { this.buffer.decreaseBy(0.02D); } - // Update motion values this.motionX = deltaX * friction; this.motionZ = deltaZ * friction; - // Low motion if (Math.abs(this.motionX) < 0.005D) this.motionX = 0.0D; if (Math.abs(this.motionZ) < 0.005D) this.motionZ = 0.0D; } diff --git a/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedB.java b/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedB.java index 735a090..e08c9e4 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedB.java +++ b/src/main/java/me/tecnio/ahm/check/impl/speed/SpeedB.java @@ -21,22 +21,28 @@ public SpeedB(final PlayerData data) { public void handle(final PositionUpdate update) { if (!update.isPosition()) return; - // Get the smallest outcome final double smallest = data.getEmulationTracker().getDistance(); - // This value will determine a compensated value for 0.03 occurring final double compensation = 0.03D * data.getPositionTracker().getDelayedFlyingTicks(); - /* - * We use this in order to set our max offset value this checks if a player is retarded(AKA 0.03 MOST LIKELY OCCURRED) - * if so we compensate for it to prevent false positives, if not we don't have to worry about aids affecting. - */ - final double max = data.getExemptTracker().isExempt(ExemptType.RETARD) ? compensation : 1.0E-14D; + final double max = data.getExemptTracker().isExempt(ExemptType.SLOW) ? compensation : 1.0E-14D; final boolean invalid = smallest > max; - final boolean exempt = this.isExempt(ExemptType.JOIN, ExemptType.TELEPORTED_RECENTLY, ExemptType.PISTON, - ExemptType.FLIGHT, ExemptType.LIQUID, ExemptType.SLIME, ExemptType.VEHICLE, ExemptType.CHUNK, - ExemptType.CLIMBABLE, ExemptType.SOUL_SAND, ExemptType.WEB, ExemptType.ICE, ExemptType.WALL, - ExemptType.STEP, ExemptType.SNEAK_EDGE + final boolean exempt = this.isExempt( + ExemptType.JOIN, + ExemptType.TELEPORTED_RECENTLY, + ExemptType.PISTON, + ExemptType.FLIGHT, + ExemptType.LIQUID, + ExemptType.SLIME, + ExemptType.VEHICLE, + ExemptType.CHUNK, + ExemptType.CLIMBABLE, + ExemptType.SOUL_SAND, + ExemptType.WEB, + ExemptType.ICE, + ExemptType.WALL, + ExemptType.STEP, + ExemptType.SNEAK_EDGE ); if (invalid && !exempt) { diff --git a/src/main/java/me/tecnio/ahm/check/impl/timer/TimerA.java b/src/main/java/me/tecnio/ahm/check/impl/timer/TimerA.java index 7a9d4b2..5b452d9 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/timer/TimerA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/timer/TimerA.java @@ -28,7 +28,6 @@ public void handle(final GPacket packet) { final long delay = packet.getTimestamp() - this.lastFlying; - // Update allowance using balance system this.allowance += 50L; this.allowance -= delay; diff --git a/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityA.java b/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityA.java index 9d5c4e3..680aa51 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityA.java +++ b/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityA.java @@ -7,9 +7,6 @@ import me.tecnio.ahm.exempt.ExemptType; import me.tecnio.ahm.update.PositionUpdate; -/** - * Check to detect any horizontal velocity modification. - */ @CheckManifest(name = "Velocity", type = "A", description = "Detects for any horizontal velocity modification.") public final class VelocityA extends Check implements PositionCheck { @@ -19,21 +16,31 @@ public VelocityA(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - // Check if recent velocity update if (data.getVelocityTracker().getTicksSinceVelocity() > 8) return; - // Calculate the distance and compensation for delayed flying ticks final double distance = data.getEmulationTracker().getDistance(); final double compensation = 0.03D * data.getPositionTracker().getDelayedFlyingTicks(); - // Check if the distance is invalid and handle exemptions - final boolean invalid = distance > (this.isExempt(ExemptType.RETARD) ? compensation : 1.0E-07); - final boolean exempt = this.isExempt(ExemptType.JOIN, ExemptType.TELEPORTED_RECENTLY, ExemptType.PISTON, - ExemptType.FLIGHT, ExemptType.LIQUID, ExemptType.SLIME, ExemptType.VEHICLE, ExemptType.CHUNK, - ExemptType.CLIMBABLE, ExemptType.SOUL_SAND, ExemptType.WEB, ExemptType.ICE, ExemptType.RETARD, - ExemptType.WALL, ExemptType.STEP, ExemptType.GHOST_WALL); + final boolean invalid = distance > (this.isExempt(ExemptType.SLOW) ? compensation : 1.0E-07); + final boolean exempt = this.isExempt( + ExemptType.JOIN, + ExemptType.TELEPORTED_RECENTLY, + ExemptType.PISTON, + ExemptType.FLIGHT, + ExemptType.LIQUID, + ExemptType.SLIME, + ExemptType.VEHICLE, + ExemptType.CHUNK, + ExemptType.CLIMBABLE, + ExemptType.SOUL_SAND, + ExemptType.WEB, + ExemptType.ICE, + ExemptType.SLOW, + ExemptType.WALL, + ExemptType.STEP, + ExemptType.GHOST_WALL + ); - // Check if invalid and increase buffer, or decrease buffer if valid if (invalid && !exempt) { if (this.buffer.increase() > 3) { this.fail("o: " + distance); diff --git a/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityB.java b/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityB.java index 86b72da..780cf05 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityB.java +++ b/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityB.java @@ -8,9 +8,6 @@ import me.tecnio.ahm.update.PositionUpdate; import org.bukkit.potion.PotionEffectType; -/** - * Check to detect vertical velocity modifications. - */ @CheckManifest(name = "Velocity", type = "B", description = "Checks for vertical velocity modifications.") public final class VelocityB extends Check implements PositionCheck { @@ -20,36 +17,40 @@ public VelocityB(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - // Check if recent velocity update if (data.getVelocityTracker().getTicksSinceVelocity() != 1) return; - // Calculate expected jump motion final float expectedJumpMotion = 0.42F + (data.getAttributeTracker().getPotionLevel(PotionEffectType.JUMP) * 0.1F); - // Get delta Y and velocity Y final double deltaY = data.getPositionTracker().getDeltaY(); final double velocityY = data.getVelocityTracker().getVelocity().getY(); - // Calculate offsets final double offset = Math.abs(deltaY - velocityY); final double jumpOffset = Math.abs(deltaY - expectedJumpMotion); - // Calculate compensation and maximum threshold final double compensation = 0.03D * data.getPositionTracker().getDelayedFlyingTicks(); - final double max = (this.isExempt(ExemptType.RETARD) ? compensation : 1.0E-08); + final double max = (this.isExempt(ExemptType.SLOW) ? compensation : 1.0E-08); - // Check primary and secondary conditions for invalidity final boolean primary = offset > max && jumpOffset > 1.0E-08; final boolean secondary = offset > max && jumpOffset > max && data.getEmulationTracker().isJump(); - // Check for invalid vertical velocity modification final boolean invalid = (primary || secondary) && velocityY > 0.05; - final boolean exempt = this.isExempt(ExemptType.JOIN, ExemptType.TELEPORTED_RECENTLY, ExemptType.PISTON, - ExemptType.FLIGHT, ExemptType.LIQUID, ExemptType.SLIME, ExemptType.VEHICLE, ExemptType.CHUNK, - ExemptType.CLIMBABLE, ExemptType.SOUL_SAND, ExemptType.WEB, ExemptType.ICE, ExemptType.UNDER_BLOCK, - ExemptType.STEP); + final boolean exempt = this.isExempt( + ExemptType.JOIN, + ExemptType.TELEPORTED_RECENTLY, + ExemptType.PISTON, + ExemptType.FLIGHT, + ExemptType.LIQUID, + ExemptType.SLIME, + ExemptType.VEHICLE, + ExemptType.CHUNK, + ExemptType.CLIMBABLE, + ExemptType.SOUL_SAND, + ExemptType.WEB, + ExemptType.ICE, + ExemptType.UNDER_BLOCK, + ExemptType.STEP + ); - // Check if invalid and increase buffer, or decrease buffer if valid if (invalid && !exempt) { if (this.buffer.increase() > 2) { this.fail(); diff --git a/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityC.java b/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityC.java index 11ca44c..fb9eabb 100644 --- a/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityC.java +++ b/src/main/java/me/tecnio/ahm/check/impl/velocity/VelocityC.java @@ -7,9 +7,6 @@ import me.tecnio.ahm.exempt.ExemptType; import me.tecnio.ahm.update.PositionUpdate; -/** - * Check to detect vertical velocity modifications. - */ @CheckManifest(name = "Velocity", type = "C", description = "Checks for vertical velocity modifications.") public final class VelocityC extends Check implements PositionCheck { @@ -21,25 +18,32 @@ public VelocityC(final PlayerData data) { @Override public void handle(final PositionUpdate update) { - // Check if recent velocity update if (data.getVelocityTracker().getTicksSinceVelocity() > 3) return; - // If first tick after velocity update, store the initial velocity if (data.getVelocityTracker().getTicksSinceVelocity() == 1) { this.velocity = data.getVelocityTracker().getVelocity().getY(); } - // Get delta Y and calculate percentage change in Y velocity final double deltaY = data.getPositionTracker().getDeltaY(); - final float percentage = (float) (deltaY / this.velocity); + final double percentage = deltaY / this.velocity; + + final boolean exempt = this.isExempt( + ExemptType.JOIN, + ExemptType.TELEPORTED_RECENTLY, + ExemptType.PISTON, + ExemptType.FLIGHT, + ExemptType.LIQUID, + ExemptType.SLIME, + ExemptType.VEHICLE, + ExemptType.CHUNK, + ExemptType.CLIMBABLE, + ExemptType.SOUL_SAND, + ExemptType.WEB, + ExemptType.ICE, + ExemptType.UNDER_BLOCK, + ExemptType.STEP + ) || update.isOnGround(); - // Check exemptions - final boolean exempt = this.isExempt(ExemptType.JOIN, ExemptType.TELEPORTED_RECENTLY, ExemptType.PISTON, - ExemptType.FLIGHT, ExemptType.LIQUID, ExemptType.SLIME, ExemptType.VEHICLE, ExemptType.CHUNK, - ExemptType.CLIMBABLE, ExemptType.SOUL_SAND, ExemptType.WEB, ExemptType.ICE, ExemptType.UNDER_BLOCK, - ExemptType.STEP) || update.isOnGround(); - - // Check if percentage change is less than 1 and velocity is positive, and increase buffer if invalid if (percentage < 1 && this.velocity > 0 && !exempt) { if (this.buffer.increase() > 7) { this.fail("p: %s", (percentage * 100)); @@ -48,7 +52,6 @@ public void handle(final PositionUpdate update) { this.buffer.decreaseBy(0.125); } - // Update and decay the velocity this.velocity -= 0.08D; this.velocity *= 0.9800000190734863D; diff --git a/src/main/java/me/tecnio/ahm/command/AHMCommand.java b/src/main/java/me/tecnio/ahm/command/AntiHaxermanCommand.java similarity index 84% rename from src/main/java/me/tecnio/ahm/command/AHMCommand.java rename to src/main/java/me/tecnio/ahm/command/AntiHaxermanCommand.java index a0bfa99..044ac06 100644 --- a/src/main/java/me/tecnio/ahm/command/AHMCommand.java +++ b/src/main/java/me/tecnio/ahm/command/AntiHaxermanCommand.java @@ -10,7 +10,7 @@ import java.util.List; @Getter -public class AHMCommand extends BaseCommand { +public class AntiHaxermanCommand extends BaseCommand { public void sendLineBreak(final CommandSender sender) { sender.sendMessage(ChatUtil.translate("&7&m-------------------------------------------------")); @@ -29,7 +29,8 @@ public void sendMessage(final Player sender, final String message) { } @Override - public List tabComplete(final CommandIssuer issuer, final String commandLabel, final String[] args, final boolean isAsync) throws IllegalArgumentException { + public List tabComplete(final CommandIssuer issuer, final String commandLabel, + final String[] args, final boolean isAsync) throws IllegalArgumentException { return super.tabComplete(issuer, commandLabel, args, isAsync); } } diff --git a/src/main/java/me/tecnio/ahm/command/impl/AlertsCommand.java b/src/main/java/me/tecnio/ahm/command/impl/AlertsCommand.java index 263a5f8..e2fb578 100644 --- a/src/main/java/me/tecnio/ahm/command/impl/AlertsCommand.java +++ b/src/main/java/me/tecnio/ahm/command/impl/AlertsCommand.java @@ -4,9 +4,9 @@ import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Subcommand; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.alert.AlertManager; -import me.tecnio.ahm.command.AHMCommand; +import me.tecnio.ahm.command.AntiHaxermanCommand; import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.data.PlayerDataManager; import me.tecnio.ahm.util.string.ChatUtil; @@ -14,7 +14,7 @@ import org.bukkit.entity.Player; @CommandAlias("ahm") -public class AlertsCommand extends AHMCommand { +public class AlertsCommand extends AntiHaxermanCommand { @Subcommand("alerts") @Description("Toggles your anti-cheat alerts") @@ -26,9 +26,9 @@ public void onCommand(final CommandSender sender) { } final Player player = ((Player) sender).getPlayer(); - final PlayerData data = AHM.get(PlayerDataManager.class).getPlayerData(player.getUniqueId()); + final PlayerData data = AntiHaxerman.get(PlayerDataManager.class).get(player.getUniqueId()); - if (AHM.get(AlertManager.class).toggleAlerts(data)) { + if (AntiHaxerman.get(AlertManager.class).toggleAlerts(data)) { player.sendMessage(ChatUtil.translate("&aYou are now viewing alerts!")); } else { player.sendMessage(ChatUtil.translate("&cYou are no longer viewing alerts!")); diff --git a/src/main/java/me/tecnio/ahm/command/impl/ChecksCommand.java b/src/main/java/me/tecnio/ahm/command/impl/ChecksCommand.java index bb799b3..231d932 100644 --- a/src/main/java/me/tecnio/ahm/command/impl/ChecksCommand.java +++ b/src/main/java/me/tecnio/ahm/command/impl/ChecksCommand.java @@ -2,13 +2,16 @@ import co.aikar.commands.annotation.*; import co.aikar.commands.bukkit.contexts.OnlinePlayer; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.check.Check; -import me.tecnio.ahm.command.AHMCommand; +import me.tecnio.ahm.command.AntiHaxermanCommand; import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.data.PlayerDataManager; import me.tecnio.ahm.util.string.ChatUtil; -import net.md_5.bungee.api.chat.*; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -16,14 +19,14 @@ import java.util.List; @CommandAlias("ahm") -public class ChecksCommand extends AHMCommand { +public class ChecksCommand extends AntiHaxermanCommand { @Subcommand("checks") @Description("View enabled checks for player") @CommandPermission("ahm.checks") public void onCommand(final CommandSender sender, @Name("target") final OnlinePlayer onlinePlayer) { final Player player = onlinePlayer.getPlayer(); - final PlayerData data = AHM.get(PlayerDataManager.class).getPlayerData(player.getUniqueId()); + final PlayerData data = AntiHaxerman.get(PlayerDataManager.class).get(player.getUniqueId()); sendLineBreak(sender); sendMessage(sender, "&cChecks for &f" + player.getName() + "&c:"); diff --git a/src/main/java/me/tecnio/ahm/command/impl/DefaultCommand.java b/src/main/java/me/tecnio/ahm/command/impl/DefaultCommand.java index 5485d85..ae5f33d 100644 --- a/src/main/java/me/tecnio/ahm/command/impl/DefaultCommand.java +++ b/src/main/java/me/tecnio/ahm/command/impl/DefaultCommand.java @@ -2,11 +2,11 @@ import co.aikar.commands.CommandHelp; import co.aikar.commands.annotation.*; -import me.tecnio.ahm.command.AHMCommand; +import me.tecnio.ahm.command.AntiHaxermanCommand; import org.bukkit.command.CommandSender; @CommandAlias("ahm") -public class DefaultCommand extends AHMCommand { +public class DefaultCommand extends AntiHaxermanCommand { @HelpCommand @Description("AntiHaxerman help command") @@ -17,8 +17,8 @@ public void onHelp(final CommandSender sender, final CommandHelp commandHelp) { sendMessage(sender, "&cAntiHaxerman commands:"); - // whoever coded this fix this monstrosity. or ur fired - commandHelp.getHelpEntries().forEach(command -> sendMessage(sender, " &f- &c" + command.getCommandPrefix() + command.getCommand() + " &7" + command.getParameterSyntax() + " &8- &c" + command.getDescription())); + commandHelp.getHelpEntries().forEach(command -> sendMessage(sender, " &f- &c" + command.getCommandPrefix() + + command.getCommand() + " &7" + command.getParameterSyntax() + " &8- &c" + command.getDescription())); sendMessage(sender, String.format("&7Total of &c%s &7commands.", commandHelp.getHelpEntries().size())); sendLineBreak(sender); diff --git a/src/main/java/me/tecnio/ahm/command/impl/InfoCommand.java b/src/main/java/me/tecnio/ahm/command/impl/InfoCommand.java index 9f571f7..4b6f91e 100644 --- a/src/main/java/me/tecnio/ahm/command/impl/InfoCommand.java +++ b/src/main/java/me/tecnio/ahm/command/impl/InfoCommand.java @@ -2,8 +2,8 @@ import co.aikar.commands.annotation.*; import co.aikar.commands.bukkit.contexts.OnlinePlayer; -import me.tecnio.ahm.AHM; -import me.tecnio.ahm.command.AHMCommand; +import me.tecnio.ahm.AntiHaxerman; +import me.tecnio.ahm.command.AntiHaxermanCommand; import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.data.PlayerDataManager; import org.bukkit.command.CommandSender; @@ -14,17 +14,19 @@ import java.util.List; @CommandAlias("ahm") -public class InfoCommand extends AHMCommand { +public class InfoCommand extends AntiHaxermanCommand { @Subcommand("info") @Description("View information about a player") @CommandPermission("ahm.info") public void onCommand(final CommandSender sender, @Name("target") final OnlinePlayer onlinePlayer) { final Player player = onlinePlayer.getPlayer(); - final PlayerData data = AHM.get(PlayerDataManager.class).getPlayerData(player.getUniqueId()); + final PlayerData data = AntiHaxerman.get(PlayerDataManager.class).get(player.getUniqueId()); - final String lastTransaction = new SimpleDateFormat("hh:mm:ss:ms aaa").format(data.getConnectionTracker().getLastTransaction()); - final String lastEntity = data.getActionTracker().getTarget() == null ? "None" : data.getActionTracker().getTarget().getName(); + final String lastTransaction = new SimpleDateFormat("hh:mm:ss:ms aaa") + .format(data.getConnectionTracker().getLastTransaction()); + final String lastEntity = data.getActionTracker().getTarget() == null + ? "None" : data.getActionTracker().getTarget().getName(); final List message = Arrays.asList( "&cInformation for &f" + player.getName() + "&c:", diff --git a/src/main/java/me/tecnio/ahm/config/ConfigManager.java b/src/main/java/me/tecnio/ahm/config/ConfigManager.java index cca93bb..cb0a1e7 100644 --- a/src/main/java/me/tecnio/ahm/config/ConfigManager.java +++ b/src/main/java/me/tecnio/ahm/config/ConfigManager.java @@ -3,7 +3,7 @@ import com.google.common.collect.Maps; import lombok.Getter; import lombok.SneakyThrows; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.check.api.CheckManager; import me.tecnio.ahm.check.api.annotations.CheckManifest; import org.bukkit.configuration.file.FileConfiguration; @@ -24,16 +24,12 @@ public final class ConfigManager { @SneakyThrows public void generate() { - final JavaPlugin plugin = AHM.get().getPlugin(); + final JavaPlugin plugin = AntiHaxerman.get().getPlugin(); final FileConfiguration config = plugin.getConfig(); - final List> checks = AHM.get(CheckManager.class).getChecks(); + final List> checks = AntiHaxerman.get(CheckManager.class).getChecks(); plugin.saveDefaultConfig(); - /* - * Simple config generation, no need to make it more complicated and it is quite - * easy to navigate, this also allows us to have the default values saved on temp - */ for (final Class check : checks) { final CheckManifest info = check.getAnnotation(CheckManifest.class); @@ -61,20 +57,16 @@ public void generate() { write(commands, Collections.singletonList("ban %player% Cheating")); } - /* - * Make sure to make the config changes before this point, otherwise - * they will only be saved on temp and it wont function properly - */ plugin.saveConfig(); plugin.reloadConfig(); } @SneakyThrows public void load() { - final JavaPlugin plugin = AHM.get().getPlugin(); + final JavaPlugin plugin = AntiHaxerman.get().getPlugin(); final FileConfiguration config = plugin.getConfig(); - final List> checks = AHM.get(CheckManager.class).getChecks(); + final List> checks = AntiHaxerman.get(CheckManager.class).getChecks(); plugin.saveDefaultConfig(); @@ -102,7 +94,7 @@ public void load() { } private void write(final String header, final Object value) { - final JavaPlugin plugin = AHM.get().getPlugin(); + final JavaPlugin plugin = AntiHaxerman.get().getPlugin(); if (plugin.getConfig().contains(header)) return; diff --git a/src/main/java/me/tecnio/ahm/data/PlayerData.java b/src/main/java/me/tecnio/ahm/data/PlayerData.java index fa3012b..bbd83b8 100644 --- a/src/main/java/me/tecnio/ahm/data/PlayerData.java +++ b/src/main/java/me/tecnio/ahm/data/PlayerData.java @@ -4,7 +4,7 @@ import cc.ghast.packet.PacketAPI; import lombok.Getter; import lombok.Setter; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.alert.AlertManager; import me.tecnio.ahm.check.Check; import me.tecnio.ahm.check.api.CheckManager; @@ -80,7 +80,7 @@ public PlayerData(final Player player) { }; this.exemptTracker = new ExemptTracker(this); - this.checks = AHM.get(CheckManager.class).loadChecks(this); + this.checks = AntiHaxerman.get(CheckManager.class).loadChecks(this); this.packetChecks = this.checks.stream().filter(check -> check instanceof PacketCheck) .map(check -> ((PacketCheck) check)).collect(Collectors.toList()); @@ -89,11 +89,11 @@ public PlayerData(final Player player) { this.rotationChecks = this.checks.stream().filter(check -> check instanceof RotationCheck) .map(check -> ((RotationCheck) check)).collect(Collectors.toList()); - if (this.player.hasPermission("ahm.alerts")) AHM.get(AlertManager.class).toggleAlerts(this); + if (this.player.hasPermission("ahm.alerts")) AntiHaxerman.get(AlertManager.class).toggleAlerts(this); } public void terminate() { - AHM.get(AlertManager.class).getPlayers().remove(this); + AntiHaxerman.get(AlertManager.class).getPlayers().remove(this); } public void updateTicks() { @@ -105,7 +105,7 @@ public void haram() { } public void haram(final String reason) { - Bukkit.getScheduler().runTask(AHM.get().getPlugin(), () -> this.player.kickPlayer(reason)); + Bukkit.getScheduler().runTask(AntiHaxerman.get().getPlugin(), () -> this.player.kickPlayer(reason)); } public void send(final GPacket packet) { diff --git a/src/main/java/me/tecnio/ahm/data/PlayerDataManager.java b/src/main/java/me/tecnio/ahm/data/PlayerDataManager.java index a983ea9..51e061d 100644 --- a/src/main/java/me/tecnio/ahm/data/PlayerDataManager.java +++ b/src/main/java/me/tecnio/ahm/data/PlayerDataManager.java @@ -2,22 +2,20 @@ import org.bukkit.entity.Player; -import java.util.Collection; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; public final class PlayerDataManager { - // skidded from OG AHM... W private final Map playerDataMap = new ConcurrentHashMap<>(); - public PlayerData getPlayerData(final UUID uuid) { - return playerDataMap.getOrDefault(uuid, null); + public PlayerData get(final UUID uuid) { + return this.playerDataMap.get(uuid); } public void add(final Player player) { - playerDataMap.put(player.getUniqueId(), new PlayerData(player)); + this.playerDataMap.put(player.getUniqueId(), new PlayerData(player)); } public boolean has(final Player player) { @@ -25,10 +23,6 @@ public boolean has(final Player player) { } public void remove(final Player player) { - playerDataMap.remove(player.getUniqueId()); - } - - public Collection getAllData() { - return playerDataMap.values(); + this.playerDataMap.remove(player.getUniqueId()); } } \ No newline at end of file diff --git a/src/main/java/me/tecnio/ahm/data/tracker/impl/ConnectionTracker.java b/src/main/java/me/tecnio/ahm/data/tracker/impl/ConnectionTracker.java index 7f37570..263d377 100644 --- a/src/main/java/me/tecnio/ahm/data/tracker/impl/ConnectionTracker.java +++ b/src/main/java/me/tecnio/ahm/data/tracker/impl/ConnectionTracker.java @@ -10,24 +10,25 @@ import lombok.Getter; import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.data.tracker.Tracker; -import me.tecnio.ahm.util.type.EvictingMap; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; @Getter public final class ConnectionTracker extends Tracker { - private final EvictingMap keepAliveMap = new EvictingMap<>(800); - private final EvictingMap transactionMap = new EvictingMap<>(800); + private final Map keepAliveMap = new HashMap<>(); + private final Map transactionMap = new HashMap<>(); - private final EvictingMap confirmationMap = new EvictingMap<>(800); + private final Map confirmationMap = new HashMap<>(); private int transactionPing, keepAlivePing; private short transactionId = Short.MIN_VALUE; - private int keepAliveId = Short.MIN_VALUE; private long lastFlying, flyingDelay; - private long lastKeepAlive = System.currentTimeMillis(), lastTransaction = System.currentTimeMillis(); + private long lastKeepAlive = System.currentTimeMillis(), + lastTransaction = System.currentTimeMillis(); private int ticksSinceLag; @@ -45,17 +46,19 @@ public void handle(final GPacket packet) { final GPacketPlayServerTransaction wrapper = ((GPacketPlayServerTransaction) packet); this.transactionMap.put(wrapper.getActionNumber(), packet.getTimestamp()); - } else if (packet instanceof PacketPlayClientKeepAlive) { + } + + else if (packet instanceof PacketPlayClientKeepAlive) { final PacketPlayClientKeepAlive wrapper = ((PacketPlayClientKeepAlive) packet); this.keepAliveMap.computeIfPresent(wrapper.getId(), (id, time) -> { this.keepAlivePing = (int) (packet.getTimestamp() - time); this.lastKeepAlive = packet.getTimestamp(); - this.keepAliveMap.remove(wrapper.getId()); - return time; }); + + this.keepAliveMap.remove(wrapper.getId()); } else if (packet instanceof PacketPlayClientTransaction) { final PacketPlayClientTransaction wrapper = ((PacketPlayClientTransaction) packet); @@ -63,20 +66,24 @@ public void handle(final GPacket packet) { this.transactionPing = (int) (packet.getTimestamp() - time); this.lastTransaction = packet.getTimestamp(); - this.transactionMap.remove(wrapper.getActionNumber()); - return time; }); + this.transactionMap.remove(wrapper.getActionNumber()); + Optional.ofNullable(this.confirmationMap.remove(wrapper.getActionNumber())) .ifPresent(Runnable::run); - } else if (packet instanceof PacketPlayClientFlying) { + } + + else if (packet instanceof PacketPlayClientFlying) { final long now = packet.getTimestamp(); this.flyingDelay = now - this.lastFlying; this.lastFlying = now; - if (this.flyingDelay < 30 || this.flyingDelay > 70) this.ticksSinceLag = 0; + if (this.flyingDelay < 30 || this.flyingDelay > 70) { + this.ticksSinceLag = 0; + } } } diff --git a/src/main/java/me/tecnio/ahm/data/tracker/impl/GhostBlockTracker.java b/src/main/java/me/tecnio/ahm/data/tracker/impl/GhostBlockTracker.java index 72d40ae..5140589 100644 --- a/src/main/java/me/tecnio/ahm/data/tracker/impl/GhostBlockTracker.java +++ b/src/main/java/me/tecnio/ahm/data/tracker/impl/GhostBlockTracker.java @@ -41,7 +41,7 @@ public void handle(final GPacket packet) { for (final BlockPosition position : this.blockMap.keySet()) { final boolean x = Math.floor(data.getPositionTracker().getX()) == position.getX(); // TODO: 9/7/23 fix artemis packet api insaneness - final boolean y = /*Math.floor(data.getPositionTracker().getY() - 0.03D) == position.getY()*/ true; + final boolean y = true; final boolean z = Math.floor(data.getPositionTracker().getZ()) == position.getZ(); legit |= x && y && z; diff --git a/src/main/java/me/tecnio/ahm/data/tracker/impl/PositionTracker.java b/src/main/java/me/tecnio/ahm/data/tracker/impl/PositionTracker.java index f523ca1..d56a660 100644 --- a/src/main/java/me/tecnio/ahm/data/tracker/impl/PositionTracker.java +++ b/src/main/java/me/tecnio/ahm/data/tracker/impl/PositionTracker.java @@ -14,13 +14,14 @@ import me.tecnio.ahm.util.mcp.MathHelper; import me.tecnio.ahm.util.player.Teleport; import me.tecnio.ahm.util.player.TickTimer; -import me.tecnio.ahm.util.type.EvictingList; import me.tecnio.ahm.util.world.BlockUtil; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.EntityType; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.Set; import java.util.function.Predicate; @@ -65,7 +66,7 @@ public final class PositionTracker extends Tracker { private boolean boat; - private final EvictingList teleportQueue = new EvictingList<>(800); + private final Deque teleportQueue = new ArrayDeque<>(); private boolean teleported; private final TickTimer ticksSinceTeleport = new TickTimer(this.data); @@ -133,7 +134,7 @@ public void handle(final GPacket packet) { if (!(wrapper.isPos() && wrapper.isLook() && !wrapper.isOnGround())) break teleport; - if (this.teleportQueue.size() != 0) { + if (!this.teleportQueue.isEmpty()) { final Teleport teleport = this.teleportQueue.peek(); final Set flags = teleport.getFlags(); @@ -156,7 +157,7 @@ public void handle(final GPacket packet) { data.setTicks(data.getTicks() - 1); - this.teleportQueue.poll(); + this.teleportQueue.removeFirst(); } } } diff --git a/src/main/java/me/tecnio/ahm/exempt/ExemptType.java b/src/main/java/me/tecnio/ahm/exempt/ExemptType.java index b8ee2bc..b3ce32a 100644 --- a/src/main/java/me/tecnio/ahm/exempt/ExemptType.java +++ b/src/main/java/me/tecnio/ahm/exempt/ExemptType.java @@ -24,41 +24,54 @@ public enum ExemptType { VELOCITY(data -> data.getVelocityTracker().getTicksSinceVelocity() == 1), - RETARD(data -> !data.getPositionTracker().isLastPosition() || !data.getPositionTracker().isLastLastPosition()), + SLOW(data -> !data.getPositionTracker().isLastPosition() + || !data.getPositionTracker().isLastLastPosition()), LIQUID(data -> data.getPositionTracker().isWater() || data.getPositionTracker().isLastWater() || data.getPositionTracker().isLava() || data.getPositionTracker().isLastLava()), - WEB(data -> data.getPositionTracker().isWeb() || data.getPositionTracker().isLastWeb()), + WEB(data -> data.getPositionTracker().isWeb() + || data.getPositionTracker().isLastWeb()), - CLIMBABLE(data -> data.getPositionTracker().isClimbable() || data.getPositionTracker().isLastClimbable()), + CLIMBABLE(data -> data.getPositionTracker().isClimbable() + || data.getPositionTracker().isLastClimbable()), - UNDER_BLOCK(data -> data.getPositionTracker().isUnderBlock() || data.getPositionTracker().isLastUnderBlock()), + UNDER_BLOCK(data -> data.getPositionTracker().isUnderBlock() + || data.getPositionTracker().isLastUnderBlock()), - PISTON(data -> data.getPositionTracker().isPiston() || data.getPositionTracker().isLastPiston()), + PISTON(data -> data.getPositionTracker().isPiston() + || data.getPositionTracker().isLastPiston()), BOAT(data -> data.getPositionTracker().isBoat()), - SLIME(data -> data.getPositionTracker().isSlime() || data.getPositionTracker().isLastSlime()), + SLIME(data -> data.getPositionTracker().isSlime() + || data.getPositionTracker().isLastSlime()), - SOUL_SAND(data -> data.getPositionTracker().isSoulSand() || data.getPositionTracker().isLastSoulSand()), + SOUL_SAND(data -> data.getPositionTracker().isSoulSand() + || data.getPositionTracker().isLastSoulSand()), - ICE(data -> data.getPositionTracker().isIce() || data.getPositionTracker().isLastIce()), + ICE(data -> data.getPositionTracker().isIce() + || data.getPositionTracker().isLastIce()), - WALL(data -> data.getPositionTracker().isWall() || data.getPositionTracker().isLastWall()), + WALL(data -> data.getPositionTracker().isWall() + || data.getPositionTracker().isLastWall()), - STEP(data -> data.getPositionTracker().isFucked() || data.getPositionTracker().isLastFucked()), + STEP(data -> data.getPositionTracker().isFucked() + || data.getPositionTracker().isLastFucked()), AIM(data -> data.getActionTracker().getAttackTimer().hasPassed(3) || data.getPositionTracker().getTicksSinceTeleport().hasNotPassed(2)), EXPLOSION(data -> data.getVelocityTracker().getTicksSinceExplosion() < 2), - FLIGHT(data -> data.getPlayer().getAllowFlight() || data.getPlayer().isFlying()), + FLIGHT(data -> data.getPlayer().getAllowFlight() + || data.getPlayer().isFlying()), - SNEAK_EDGE(data -> data.getActionTracker().isSneaking() && data.getPositionTracker().isLastOnGround() && data.getPositionTracker().isAirBelow()), + SNEAK_EDGE(data -> data.getActionTracker().isSneaking() + && data.getPositionTracker().isLastOnGround() + && data.getPositionTracker().isAirBelow()), GHOST_WALL(data -> data.getPositionTracker().isMathCollision()); diff --git a/src/main/java/me/tecnio/ahm/listener/bukkit/RegistrationListener.java b/src/main/java/me/tecnio/ahm/listener/bukkit/RegistrationListener.java index e998ad6..b1de360 100644 --- a/src/main/java/me/tecnio/ahm/listener/bukkit/RegistrationListener.java +++ b/src/main/java/me/tecnio/ahm/listener/bukkit/RegistrationListener.java @@ -1,6 +1,6 @@ package me.tecnio.ahm.listener.bukkit; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.data.PlayerDataManager; import org.bukkit.event.EventHandler; @@ -13,17 +13,17 @@ public final class RegistrationListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(final PlayerJoinEvent event) { - AHM.get(PlayerDataManager.class).add(event.getPlayer()); + AntiHaxerman.get(PlayerDataManager.class).add(event.getPlayer()); } @EventHandler(priority = EventPriority.LOWEST) public void onPlayerLeave(final PlayerQuitEvent event) { - final PlayerData data = AHM.get(PlayerDataManager.class).getPlayerData(event.getPlayer().getUniqueId()); + final PlayerDataManager dataManager = AntiHaxerman.get(PlayerDataManager.class); + final PlayerData data = dataManager.get(event.getPlayer().getUniqueId()); if (data == null) return; data.terminate(); - - AHM.get(PlayerDataManager.class).remove(event.getPlayer()); + dataManager.remove(event.getPlayer()); } } diff --git a/src/main/java/me/tecnio/ahm/listener/network/NetworkFilter.java b/src/main/java/me/tecnio/ahm/listener/network/NetworkFilter.java new file mode 100644 index 0000000..0b7591a --- /dev/null +++ b/src/main/java/me/tecnio/ahm/listener/network/NetworkFilter.java @@ -0,0 +1,50 @@ +package me.tecnio.ahm.listener.network; + +import cc.ghast.packet.wrapper.packet.play.client.*; +import cc.ghast.packet.wrapper.packet.play.server.*; + +import java.util.Arrays; +import java.util.HashSet; + +public final class NetworkFilter { + + private final HashSet> filters = new HashSet<>(); + + public NetworkFilter() { + this.filters.addAll(Arrays.asList( + GPacketPlayClientFlying.class, + GPacketPlayClientPosition.class, + GPacketPlayClientPositionLook.class, + GPacketPlayClientLook.class, + GPacketPlayClientUseEntity.class, + GPacketPlayClientKeepAlive.class, + GPacketPlayServerKeepAlive.class, + GPacketPlayClientTransaction.class, + GPacketPlayServerTransaction.class, + GPacketPlayServerEntity.class, + GPacketPlayServerEntity.GPacketPlayServerEntityLook.class, + GPacketPlayServerEntity.GPacketPlayServerRelEntityMove.class, + GPacketPlayServerEntity.GPacketPlayServerRelEntityMoveLook.class, + GPacketPlayServerEntityTeleport.class, + GPacketPlayServerSpawnNamedEntity.class, + GPacketPlayServerEntityDestroy.class, + GPacketPlayClientBlockPlace.class, + GPacketPlayClientArmAnimation.class, + GPacketPlayClientBlockDig.class, + GPacketPlayClientHeldItemSlot.class, + GPacketPlayServerPosition.class, + GPacketPlayServerBlockChange.class, + GPacketPlayServerBlockChangeMulti.class, + GPacketPlayClientEntityAction.class, + GPacketPlayServerEntityEffect.class, + GPacketPlayServerEntityEffectRemove.class, + GPacketPlayServerUpdateAttributes.class, + GPacketPlayServerEntityVelocity.class, + GPacketPlayClientBlockDig.class + )); + } + + public boolean isAllowed(final Class clazz) { + return this.filters.contains(clazz); + } +} diff --git a/src/main/java/me/tecnio/ahm/listener/network/NetworkListener.java b/src/main/java/me/tecnio/ahm/listener/network/NetworkListener.java index 87c38ce..2691d45 100644 --- a/src/main/java/me/tecnio/ahm/listener/network/NetworkListener.java +++ b/src/main/java/me/tecnio/ahm/listener/network/NetworkListener.java @@ -5,45 +5,26 @@ import ac.artemis.packet.spigot.wrappers.GPacket; import ac.artemis.packet.wrapper.Packet; import ac.artemis.packet.wrapper.PacketClient; -import cc.ghast.packet.wrapper.packet.play.client.*; -import cc.ghast.packet.wrapper.packet.play.server.*; -import me.tecnio.ahm.AHM; +import me.tecnio.ahm.AntiHaxerman; import me.tecnio.ahm.data.PlayerData; import me.tecnio.ahm.data.PlayerDataManager; -import java.util.Arrays; -import java.util.HashSet; - public final class NetworkListener implements PacketListener { - private final HashSet> allowedPackets = new HashSet<>(); - - public NetworkListener() { - // I know this shit's ugly, but I really don't give a shit. - this.allowedPackets.addAll(Arrays.asList(GPacketPlayClientFlying.class, GPacketPlayClientPosition.class, - GPacketPlayClientPositionLook.class, GPacketPlayClientLook.class, GPacketPlayClientUseEntity.class, - GPacketPlayClientKeepAlive.class, GPacketPlayServerKeepAlive.class, GPacketPlayClientTransaction.class, - GPacketPlayServerTransaction.class, GPacketPlayServerEntity.class, GPacketPlayServerEntity.GPacketPlayServerEntityLook.class, - GPacketPlayServerEntity.GPacketPlayServerRelEntityMove.class, GPacketPlayServerEntity.GPacketPlayServerRelEntityMoveLook.class, - GPacketPlayServerEntityTeleport.class, GPacketPlayServerSpawnNamedEntity.class, GPacketPlayServerEntityDestroy.class, - GPacketPlayClientBlockPlace.class, GPacketPlayClientArmAnimation.class, GPacketPlayClientBlockDig.class, - GPacketPlayClientHeldItemSlot.class, GPacketPlayServerPosition.class, GPacketPlayServerBlockChange.class, - GPacketPlayServerBlockChangeMulti.class, GPacketPlayClientEntityAction.class, GPacketPlayServerEntityEffect.class, - GPacketPlayServerEntityEffectRemove.class, GPacketPlayServerUpdateAttributes.class, GPacketPlayServerEntityVelocity.class, - GPacketPlayClientBlockDig.class - )); - } + private final NetworkFilter filter = new NetworkFilter(); @Override public void onPacket(final Profile profile, final Packet packet) { - if (profile == null || !this.allowedPackets.contains(packet.getClass())) return; + if (profile == null || !this.filter.isAllowed(packet.getClass())) return; + + final PlayerData data = AntiHaxerman.get(PlayerDataManager.class).get(profile.getUuid()); - final PlayerData data = AHM.get(PlayerDataManager.class).getPlayerData(profile.getUuid()); + if (data == null) return; - if (data != null) { - // TODO: 4/9/2023 switch to ahm executor - if (packet instanceof PacketClient) data.getIncomingPacketProcessor().handle((GPacket) packet); - else data.getOutgoingPacketProcessor().handle((GPacket) packet); + if (packet instanceof PacketClient) { + data.getIncomingPacketProcessor().handle((GPacket) packet); + } else { + data.getOutgoingPacketProcessor().handle((GPacket) packet); } } } diff --git a/src/main/java/me/tecnio/ahm/util/player/PlayerUtil.java b/src/main/java/me/tecnio/ahm/util/player/PlayerUtil.java index 1f9c154..363d2a5 100644 --- a/src/main/java/me/tecnio/ahm/util/player/PlayerUtil.java +++ b/src/main/java/me/tecnio/ahm/util/player/PlayerUtil.java @@ -3,15 +3,8 @@ import cc.ghast.packet.wrapper.packet.play.server.GPacketPlayServerUpdateAttributes; import lombok.experimental.UtilityClass; import me.tecnio.ahm.data.PlayerData; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; import org.bukkit.potion.PotionEffectType; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - @UtilityClass public final class PlayerUtil { @@ -29,65 +22,15 @@ public float getAttributeSpeed(PlayerData data, boolean sprinting) { } if (data.getAttributeTracker().getPotionLevel(PotionEffectType.SPEED) > 0) { - attributeSpeed += data.getAttributeTracker().getPotionLevel(PotionEffectType.SPEED) * 0.20000000298023224D * attributeSpeed; + attributeSpeed += data.getAttributeTracker() + .getPotionLevel(PotionEffectType.SPEED) * 0.20000000298023224D * attributeSpeed; } if (data.getAttributeTracker().getPotionLevel(PotionEffectType.SLOW) > 0) { - attributeSpeed += data.getAttributeTracker().getPotionLevel(PotionEffectType.SLOW) * -0.15000000596046448D * attributeSpeed; + attributeSpeed += data.getAttributeTracker() + .getPotionLevel(PotionEffectType.SLOW) * -0.15000000596046448D * attributeSpeed; } return (float) attributeSpeed; } - - /** - * Bukkit's getNearbyEntities method looks for all entities in all chunks - * This is a lighter method and can also be used Asynchronously since we won't load any chunks - * - * @param location The location to scan for nearby entities - * @param radius The radius to expand - * @return The entities within that radius - * @author Nik - */ - public List getEntitiesWithinRadius(final Location location, final double radius) { - try { - final double expander = 16.0D; - - final double x = location.getX(); - final double z = location.getZ(); - - final int minX = (int) Math.floor((x - radius) / expander); - final int maxX = (int) Math.floor((x + radius) / expander); - - final int minZ = (int) Math.floor((z - radius) / expander); - final int maxZ = (int) Math.floor((z + radius) / expander); - - final World world = location.getWorld(); - - final List entities = new LinkedList<>(); - - for (int xVal = minX; xVal <= maxX; xVal++) { - - for (int zVal = minZ; zVal <= maxZ; zVal++) { - - if (!world.isChunkLoaded(xVal, zVal)) continue; - - for (final Entity entity : world.getChunkAt(xVal, zVal).getEntities()) { - //We have to do this due to stupidness - if (entity == null) break; - - //Make sure the entity is within the radius specified - if (entity.getLocation().distanceSquared(location) > radius * radius) continue; - - entities.add(entity); - } - } - } - - return entities; - } catch (final Throwable t) { - // I know stfu - } - - return new ArrayList<>(); - } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 2160230..620fff8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: AntiHaxerman -version: 4.0.2 -main: me.tecnio.ahm.AHMPlugin +version: 4.0.3 +main: me.tecnio.ahm.AntiHaxermanPlugin authors: [Tecnio, Incognito, aSwitch, Mexify, Cyanade] description: An open-sourced anti-cheat solution. load: STARTUP \ No newline at end of file