From 2c6a1e0296c0299349a9fa30cd0ec8ba080bc73c Mon Sep 17 00:00:00 2001 From: "thatonecoder (formerly Coccocoa's Helper)" <157546848+Coccocoahelper@users.noreply.github.com> Date: Fri, 17 May 2024 13:53:54 +0100 Subject: [PATCH] Major cleanup --- .../main/java/dev/brighten/api/KauriAPI.java | 2 +- .../brighten/api/handlers/ExemptHandler.java | 4 +- .../dev/brighten/api/wrappers/Wrapper.java | 4 +- .../anticheat/check/impl/combat/aim/AimA.java | 6 +- .../anticheat/check/impl/combat/aim/AimB.java | 6 +- .../anticheat/check/impl/combat/aim/AimC.java | 6 +- .../anticheat/check/impl/combat/aim/AimD.java | 6 +- .../anticheat/check/impl/combat/aim/AimE.java | 12 +- .../anticheat/check/impl/combat/aim/AimF.java | 2 +- .../anticheat/check/impl/combat/aim/AimG.java | 8 +- .../impl/combat/autoclicker/AutoclickerA.java | 8 +- .../impl/combat/autoclicker/AutoclickerB.java | 10 +- .../impl/combat/autoclicker/AutoclickerC.java | 14 +- .../impl/combat/autoclicker/AutoclickerD.java | 2 +- .../impl/combat/autoclicker/AutoclickerE.java | 16 +- .../impl/combat/autoclicker/AutoclickerF.java | 4 +- .../impl/combat/autoclicker/AutoclickerG.java | 6 +- .../impl/combat/autoclicker/AutoclickerH.java | 6 +- .../impl/combat/autoclicker/AutoclickerI.java | 8 +- .../impl/combat/autoclicker/AutoclickerJ.java | 6 +- .../check/impl/combat/hitbox/Hitboxes.java | 10 +- .../check/impl/combat/hitbox/ReachA.java | 2 +- .../check/impl/combat/killaura/KillauraA.java | 18 +-- .../check/impl/combat/killaura/KillauraB.java | 8 +- .../check/impl/combat/killaura/KillauraD.java | 2 +- .../check/impl/combat/killaura/KillauraE.java | 2 +- .../check/impl/combat/killaura/KillauraF.java | 10 +- .../check/impl/combat/killaura/KillauraG.java | 2 +- .../check/impl/combat/killaura/KillauraH.java | 8 +- .../check/impl/misc/HealthSpoof.java | 8 +- .../check/impl/movement/fly/FlyA.java | 16 +- .../check/impl/movement/fly/FlyB.java | 12 +- .../check/impl/movement/fly/FlyC.java | 2 +- .../check/impl/movement/fly/FlyD.java | 2 +- .../check/impl/movement/fly/FlyE.java | 8 +- .../check/impl/movement/fly/FlyF.java | 12 +- .../check/impl/movement/fly/FlyG.java | 14 +- .../check/impl/movement/fly/FlyH.java | 8 +- .../check/impl/movement/fly/FlyI.java | 4 +- .../check/impl/movement/general/Blink.java | 4 +- .../impl/movement/general/FastLadder.java | 8 +- .../impl/movement/general/OmniSprint.java | 18 +-- .../check/impl/movement/general/Phase.java | 30 ++-- .../check/impl/movement/inv/InventoryA.java | 6 +- .../check/impl/movement/inv/InventoryB.java | 6 +- .../check/impl/movement/inv/InventoryC.java | 8 +- .../check/impl/movement/nofall/NoFallA.java | 10 +- .../check/impl/movement/nofall/NoFallB.java | 18 +-- .../check/impl/movement/speed/SpeedA.java | 30 ++-- .../check/impl/movement/speed/SpeedB.java | 12 +- .../check/impl/movement/speed/SpeedC.java | 12 +- .../check/impl/movement/speed/SpeedD.java | 18 +-- .../impl/movement/velocity/VelocityA.java | 12 +- .../impl/movement/velocity/VelocityB.java | 26 ++-- .../impl/movement/velocity/VelocityC.java | 16 +- .../impl/packet/badpacket/BadPacketsA.java | 6 +- .../impl/packet/badpacket/BadPacketsB.java | 6 +- .../impl/packet/badpacket/BadPacketsC.java | 8 +- .../impl/packet/badpacket/BadPacketsD.java | 14 +- .../impl/packet/badpacket/BadPacketsE.java | 4 +- .../impl/packet/badpacket/BadPacketsG.java | 6 +- .../impl/packet/badpacket/BadPacketsH.java | 8 +- .../impl/packet/badpacket/BadPacketsI.java | 2 +- .../impl/packet/badpacket/BadPacketsK.java | 6 +- .../impl/packet/badpacket/BadPacketsM.java | 2 +- .../impl/packet/badpacket/BadPacketsN.java | 10 +- .../check/impl/packet/exploits/BookCrash.java | 18 +-- .../impl/packet/exploits/BookEnchant.java | 4 +- .../check/impl/packet/exploits/BookOp.java | 2 +- .../impl/packet/exploits/CreativeCrash.java | 14 +- .../check/impl/packet/exploits/Infinity.java | 2 +- .../check/impl/packet/exploits/LargeMove.java | 22 +-- .../impl/packet/exploits/Log4JPatch.java | 2 +- .../impl/packet/exploits/PacketSpam.java | 14 +- .../check/impl/packet/exploits/SignCrash.java | 2 +- .../check/impl/packet/exploits/SignOp.java | 2 +- .../impl/packet/exploits/WindowCrash.java | 6 +- .../check/impl/packet/timer/TimerA.java | 12 +- .../check/impl/world/block/BlockA.java | 6 +- .../check/impl/world/block/BlockB.java | 18 +-- .../check/impl/world/block/BlockC.java | 10 +- .../check/impl/world/block/BlockG.java | 6 +- .../check/impl/world/hand/HandA.java | 8 +- .../check/impl/world/hand/HandB.java | 6 +- .../check/impl/world/hand/HandC.java | 4 +- .../check/impl/world/hand/HandD.java | 4 +- .../check/impl/world/hand/HandE.java | 6 +- .../java/dev/brighten/anticheat/Kauri.java | 16 +- .../brighten/anticheat/check/api/Check.java | 56 +++---- .../anticheat/commands/AlertsCommand.java | 8 +- .../anticheat/commands/BungeeCommand.java | 4 +- .../anticheat/commands/KauriCommand.java | 50 +++---- .../anticheat/commands/LogCommand.java | 26 ++-- .../anticheat/commands/MenuCommand.java | 12 +- .../brighten/anticheat/data/ObjectData.java | 20 +-- .../data/classes/BlockInformation.java | 74 +++++----- .../anticheat/data/classes/CheckManager.java | 54 +++---- .../data/classes/PredictionService.java | 26 ++-- .../anticheat/data/classes/WrappedCheck.java | 6 +- .../anticheat/discord/DiscordAPI.java | 18 +-- .../listeners/BukkitCheckListeners.java | 38 ++--- .../anticheat/listeners/BungeeListener.java | 6 +- .../anticheat/listeners/CancelListeners.java | 40 ++--- .../generalChecks/BukkitListener.java | 26 ++-- .../listeners/generalChecks/ChatCheck.java | 10 +- .../listeners/generalChecks/LagCheck.java | 6 +- .../anticheat/logs/LoggerManager.java | 4 +- .../logs/data/impl/FlatfileStorage.java | 34 ++--- .../logs/data/impl/MongoStorage.java | 38 ++--- .../logs/data/impl/MySQLStorage.java | 28 ++-- .../anticheat/logs/data/sql/MySQL.java | 6 +- .../dev/brighten/anticheat/menu/LogsGUI.java | 10 +- .../anticheat/menu/PlayerInformationGUI.java | 6 +- .../anticheat/processing/ClickProcessor.java | 8 +- .../processing/EntityLocationProcessor.java | 22 +-- .../processing/MovementProcessor.java | 72 ++++----- .../anticheat/processing/PacketProcessor.java | 138 +++++++++--------- .../anticheat/processing/PotionProcessor.java | 6 +- .../keepalive/KeepaliveProcessor.java | 14 +- .../processing/thread/ThreadHandler.java | 4 +- .../anticheat/utils/CollisionHandler.java | 22 +-- .../anticheat/utils/EntityLocation.java | 2 +- .../dev/brighten/anticheat/utils/Helper.java | 8 +- .../brighten/anticheat/utils/MiscUtils.java | 54 +++---- .../anticheat/utils/MovementUtils.java | 12 +- .../brighten/anticheat/utils/Pastebin.java | 2 +- .../anticheat/utils/SimpleAverage.java | 4 +- .../brighten/anticheat/utils/StringUtils.java | 2 +- .../dev/brighten/anticheat/utils/Verbose.java | 2 +- .../anticheat/utils/menu/MenuListener.java | 4 +- .../utils/menu/type/impl/PagedMenu.java | 2 +- .../anticheat/utils/mojang/MojangAPI.java | 10 +- .../utils/timer/impl/AtlasTimer.java | 2 +- .../utils/timer/impl/MillisTimer.java | 2 +- .../utils/timer/impl/PlayerTimer.java | 2 +- .../anticheat/utils/timer/impl/TickTimer.java | 2 +- 136 files changed, 887 insertions(+), 889 deletions(-) diff --git a/API/src/main/java/dev/brighten/api/KauriAPI.java b/API/src/main/java/dev/brighten/api/KauriAPI.java index 02197b7ad..eb06ab266 100644 --- a/API/src/main/java/dev/brighten/api/KauriAPI.java +++ b/API/src/main/java/dev/brighten/api/KauriAPI.java @@ -43,7 +43,7 @@ public void unregisterEvents(Plugin plugin) { public void registerEvent(Plugin plugin, KauriEvent event) { registeredEvents.compute(plugin.getName(), (key, list) -> { - if(list == null) { + if (list == null) { list = new ArrayList<>(); } diff --git a/API/src/main/java/dev/brighten/api/handlers/ExemptHandler.java b/API/src/main/java/dev/brighten/api/handlers/ExemptHandler.java index 5a4323de2..fa9e3aea4 100644 --- a/API/src/main/java/dev/brighten/api/handlers/ExemptHandler.java +++ b/API/src/main/java/dev/brighten/api/handlers/ExemptHandler.java @@ -54,7 +54,7 @@ public AtomicBoolean addExemption(UUID uuid, long timeLater, TimeUnit unitLater, @Deprecated public boolean isExempt(UUID uuid, KauriCheck... checks) { - if(!exemptions.containsKey(uuid)) return false; + if (!exemptions.containsKey(uuid)) return false; return isExempt(uuid, Arrays.stream(checks).map(KauriCheck::getCheckType).toArray(CheckType[]::new)); } @@ -72,7 +72,7 @@ public Exemption getExemption(UUID uuid) { } public Optional getPlayerExemption(UUID uuid) { - if(!exemptions.containsKey(uuid)) return Optional.empty(); + if (!exemptions.containsKey(uuid)) return Optional.empty(); return Optional.of(exemptions.get(uuid)); } diff --git a/API/src/main/java/dev/brighten/api/wrappers/Wrapper.java b/API/src/main/java/dev/brighten/api/wrappers/Wrapper.java index 49014970b..e2b1e23a2 100644 --- a/API/src/main/java/dev/brighten/api/wrappers/Wrapper.java +++ b/API/src/main/java/dev/brighten/api/wrappers/Wrapper.java @@ -30,7 +30,7 @@ public T fetchField(String fieldName) { assert object != null; return cachedFields.compute(wrappedClass.getParent().getName() + ";;;" + fieldName, (key, field) -> { - if(field != null) return field; + if (field != null) return field; return wrappedClass.getFieldByName(fieldName); }).get(object); @@ -42,7 +42,7 @@ public T fetchMethod(String methodName, Object... parameters) { return cachedMethods.compute(wrappedClass.getParent().getName() + ";;;" + methodName + ";;;" + Arrays.stream(parameters).map(ob -> ob.getClass().getSimpleName()) .collect(Collectors.joining(",")), (key, field) -> { - if(field != null) return field; + if (field != null) return field; return wrappedClass.getMethod(methodName); }).invoke(object, parameters); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimA.java index 6e274ea09..d7e4fb6ef 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimA.java @@ -13,14 +13,14 @@ public class AimA extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isLook()) { + if (packet.isLook()) { float yawAccel = MathUtils.getDelta(data.playerInfo.lDeltaYaw, data.playerInfo.deltaYaw); float pitchAccel = MathUtils.getDelta(data.playerInfo.lDeltaPitch, data.playerInfo.deltaPitch); - if(yawAccel < 1E-3 && pitchAccel < 1E-4 + if (yawAccel < 1E-3 && pitchAccel < 1E-4 && (data.playerInfo.deltaPitch > 0 || yawAccel > 0) && (data.moveProcessor.deltaX > 2 || data.moveProcessor.deltaY > 2)) { - if(vl++ > 20) { + if (vl++ > 20) { flag("yawAccel=%s pitchAccel=%s", yawAccel, pitchAccel); } } else vl-= vl > 0 ? 2 : 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimB.java index 8b7b2efc8..546a4b058 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimB.java @@ -2,7 +2,6 @@ import cc.funkemunky.api.tinyprotocol.packet.in.WrappedInFlyingPacket; import cc.funkemunky.api.utils.Color; -import cc.funkemunky.api.utils.MathUtils; import dev.brighten.anticheat.check.api.Check; import dev.brighten.anticheat.check.api.CheckInfo; import dev.brighten.anticheat.check.api.Packet; @@ -24,13 +23,12 @@ public class AimB extends Check { public void process(WrappedInFlyingPacket packet) { if (!packet.isLook()) return; - float sensitivity = data.moveProcessor.sensitivityMcp; final float deltaYaw = Math.abs(data.playerInfo.deltaYaw), deltaPitch = Math.abs(data.playerInfo.deltaPitch); final float deltaX = deltaYaw / data.moveProcessor.yawMode, deltaY = deltaPitch / data.moveProcessor.pitchMode; - if(data.moveProcessor.yawGcdList.size() < 40) + if (data.moveProcessor.yawGcdList.size() < 40) return; final double gridX = getGrid(data.moveProcessor.yawGcdList), @@ -43,7 +41,7 @@ public void process(WrappedInFlyingPacket packet) { debug("sensitivity instability: mcp=%.4f, cx=%.4f, cy=%.4f, dx=%.1f, dy=%.1f", data.moveProcessor.sensitivityMcp, data.moveProcessor.currentSensX, data.moveProcessor.currentSensY, deltaX, deltaY); - if(buffer > 0) buffer--; + if (buffer > 0) buffer--; return; } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimC.java index 5c9b85de4..513128a80 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimC.java @@ -13,16 +13,16 @@ public class AimC extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isLook() && data.moveProcessor.deltaX > 0) { + if (packet.isLook() && data.moveProcessor.deltaX > 0) { float deltaYaw = MathUtils.getAngleDelta(data.playerInfo.to.yaw, data.playerInfo.from.yaw); - if(deltaYaw > 320 + if (deltaYaw > 320 && data.playerInfo.lDeltaYaw > 0 && data.moveProcessor.sensitivityX < 0.65 && data.playerInfo.lDeltaYaw < 30 && data.playerInfo.lastTeleportTimer.isPassed(1) && !data.playerInfo.doingTeleport) { vl++; - if(vl > 1) { + if (vl > 1) { flag("yaw=%.3f", deltaYaw); } } else vl-= vl > 0 ? 0.005 : 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimD.java index b159b0eb0..2f5511cae 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimD.java @@ -15,12 +15,12 @@ public class AimD extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isLook() && Math.abs(data.playerInfo.deltaPitch) >= 0.5f) { + if (packet.isLook() && Math.abs(data.playerInfo.deltaPitch) >= 0.5f) { float shit1 = data.playerInfo.deltaPitch % 0.1f, shit2 = data.playerInfo.deltaPitch % 0.05f; - if(data.playerInfo.deltaPitch > 0 && Math.abs(data.playerInfo.deltaPitch) < 100 + if (data.playerInfo.deltaPitch > 0 && Math.abs(data.playerInfo.deltaPitch) < 100 && (shit1 == 0 || shit2 == 0 || data.playerInfo.deltaPitch % 1f == 0)) { - if(verbose.add(1) > 10) { + if (verbose.add(1) > 10) { vl++; flag("deltaPitch=%s trimmed=%s vb=%s", data.playerInfo.deltaPitch, data.playerInfo.deltaPitch, verbose.value()); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimE.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimE.java index 764bc9f07..dd3002353 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimE.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimE.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Optional; -@CheckInfo(name = "Aim (G)", description = "Statistical aim analysis", +@CheckInfo(name = "Aim (E)", description = "Statistical aim analysis", checkType = CheckType.AIM, punishVL = 20, executable = true) public class AimE extends Check { @@ -23,12 +23,12 @@ public class AimE extends Check { @Packet public void onUse(WrappedInUseEntityPacket packet) { - if(packet.getAction() != WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK + if (packet.getAction() != WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK || data.target == null) return; Optional opLoc = data.entityLocationProcessor.getEntityLocation(data.target); - if(!opLoc.isPresent()) return; + if (!opLoc.isPresent()) return; final EntityLocation eloc = opLoc.get(); @@ -41,8 +41,8 @@ public void onUse(WrappedInUseEntityPacket packet) { targetLocation.toLocation(data.getPlayer().getWorld())); // Running the TypeG detection itself - if(offset[0] == 0D) { - if(data.playerInfo.deltaYaw > 0.2 && ++abuffer > 5) { + if (offset[0] == 0D) { + if (data.playerInfo.deltaYaw > 0.2 && ++abuffer > 5) { vl++; abuffer = 5; flag("t=a y=%.2f dy=%.3f", offset[1], data.playerInfo.deltaYaw); @@ -53,7 +53,7 @@ public void onUse(WrappedInUseEntityPacket packet) { yawOffsets.add(offset[0]); pitchOffsets.add(offset[1]); - if(yawOffsets.size() < 8 || pitchOffsets.size() < 8) return; + if (yawOffsets.size() < 8 || pitchOffsets.size() < 8) return; debug("po=%.1f yo=%.1f", offset[1], offset[0]); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimF.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimF.java index b4b21fd8f..9b271475b 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimF.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimF.java @@ -7,7 +7,7 @@ import dev.brighten.api.check.CheckType; import dev.brighten.api.check.DevStage; -@CheckInfo(name = "Aim (H)", description = "checks for large headsnaps.", +@CheckInfo(name = "Aim (F)", description = "checks for large headsnaps.", devStage = DevStage.BETA, checkType = CheckType.AIM, vlToFlag = 9) public class AimF extends Check { private double lastHorizontalDistance; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimG.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimG.java index 2038b680b..fd43e5221 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimG.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/aim/AimG.java @@ -6,7 +6,7 @@ import dev.brighten.anticheat.check.api.Packet; import dev.brighten.api.check.CheckType; -@CheckInfo(name = "Aim (I)", description = "Checks for weird pitch values that are near impossible to accomplish", +@CheckInfo(name = "Aim (G)", description = "Checks for weird pitch values that are near impossible to accomplish", checkType = CheckType.AIM, executable = true, punishVL = 12) public class AimG extends Check { @@ -14,13 +14,13 @@ public class AimG extends Check { private int buffer; @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(!packet.isLook()) return; + if (!packet.isLook()) return; final double pitch = data.playerInfo.to.pitch, lpitch = data.playerInfo.from.pitch; - if(pitch == lpitch && pitch == 0 && !data.playerInfo.inVehicle + if (pitch == lpitch && pitch == 0 && !data.playerInfo.inVehicle && data.playerInfo.lastTeleportTimer.isPassed(1) && data.moveProcessor.deltaX > 12) { - if(++buffer > 3) { + if (++buffer > 3) { vl++; flag("deltaX=%s buffer=%s", data.moveProcessor.deltaX, buffer); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerA.java index 8185f8881..c557f465a 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerA.java @@ -23,9 +23,9 @@ public class AutoclickerA extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { flyingTicks++; - if(flyingTicks >= 20) { - if(cps > cpsToFlag) { - if(cps > cpsToBan) vl++; + if (flyingTicks >= 20) { + if (cps > cpsToFlag) { + if (cps > cpsToBan) vl++; flag("cps=%s", cps); } debug("cps=%s", cps); @@ -36,7 +36,7 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { @Packet public void onArmAnimation(WrappedInArmAnimationPacket packet) { - if(!data.playerInfo.breakingBlock + if (!data.playerInfo.breakingBlock && data.playerInfo.lastBrokenBlock.isPassed(5) && data.playerInfo.lastBlockDigPacket.isPassed(1) && data.playerInfo.lastBlockPlacePacket.isPassed(1)) diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerB.java index e043916ee..91883d504 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerB.java @@ -23,11 +23,11 @@ public class AutoclickerB extends Check { @Packet public void onBlockPlace(WrappedInBlockPlacePacket packet, int currentTick) { - if(data.playerInfo.breakingBlock || data.getPlayer().getItemInHand().getType().isBlock()) return; + if (data.playerInfo.breakingBlock || data.getPlayer().getItemInHand().getType().isBlock()) return; int deltaPlace = currentTick - lastPlace; tickDeltas.add(deltaPlace); - if(tickDeltas.size() > 8) { + if (tickDeltas.size() > 8) { int max = -10000000, min = Integer.MAX_VALUE; double average = 0; int range, total = 0; @@ -43,12 +43,12 @@ public void onBlockPlace(WrappedInBlockPlacePacket packet, int currentTick) { average/= total; range = max - min; - if(average < 3 && range <= 1) { - if(++buffer > 12) { + if (average < 3 && range <= 1) { + if (++buffer > 12) { vl++; flag("range=%s", range); } - } else if(vl > 0) buffer-= 0.5f; + } else if (vl > 0) buffer-= 0.5f; debug("range=%s average=%.1f vl=%.1f", range, average, vl); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerC.java index f52af8699..dc9c7b56d 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerC.java @@ -26,7 +26,7 @@ public class AutoclickerC extends Check { @Packet public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { - if(data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock) return; + if (data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock) return; cps = 1000D / (timeStamp - lastArm); lastArm = timeStamp; armTicks++; @@ -34,11 +34,11 @@ public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(blocked) { - if(armTicks > 0) { - if(armTicks == 1 && cps > 3) { - if(cps > 7) verbose.add(); - if(verbose.value() > 15) { + if (blocked) { + if (armTicks > 0) { + if (armTicks == 1 && cps > 3) { + if (cps > 7) verbose.add(); + if (verbose.value() > 15) { flag("arm=%s cps=%.3f lagging=%s", armTicks, cps, data.lagInfo.lagging); } @@ -52,7 +52,7 @@ public void onFlying(WrappedInFlyingPacket packet) { @Packet public void onPlace(WrappedInBlockPlacePacket packet) { - if(packet.getItemStack() == null || !packet.getItemStack().getType().name().contains("SWORD")) return; + if (packet.getItemStack() == null || !packet.getItemStack().getType().name().contains("SWORD")) return; blocked = true; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerD.java index cb59bf64b..7197faed2 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerD.java @@ -19,7 +19,7 @@ public class AutoclickerD extends Check { @Packet public void onClick(WrappedInArmAnimationPacket packet, long timeStamp) { - if(!data.playerInfo.breakingBlock + if (!data.playerInfo.breakingBlock && !data.playerInfo.lookingAtBlock && data.playerInfo.lastBrokenBlock.isPassed(5) && data.playerInfo.lastBlockDigPacket.isPassed(1) diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerE.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerE.java index 96f39e624..40009e3a2 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerE.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerE.java @@ -16,7 +16,7 @@ public class AutoclickerE extends Check { private float buffer; @Packet public void onClick(WrappedInArmAnimationPacket packet) { - if(data.playerInfo.breakingBlock + if (data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock || data.clickProcessor.isNotReady() || data.playerInfo.lastBrokenBlock.isNotPassed(5) @@ -28,38 +28,38 @@ public void onClick(WrappedInArmAnimationPacket packet) { TagsBuilder tags = new TagsBuilder(); - if(data.clickProcessor.getOutliers() == 0 + if (data.clickProcessor.getOutliers() == 0 && data.clickProcessor.getMean() < 2.5) { tags.addTag("outliers"); buffer++; } - if(data.clickProcessor.getStd() < 0.5 && data.clickProcessor.getOutliers() <= 1) { + if (data.clickProcessor.getStd() < 0.5 && data.clickProcessor.getOutliers() <= 1) { buffer+= 0.75; tags.addTag("deviation"); } - if(data.clickProcessor.getKurtosis() < 0 + if (data.clickProcessor.getKurtosis() < 0 && (data.clickProcessor.getOutliers() <= 1 || skewness < 0.1) && data.clickProcessor.getMean() < 2.5) { buffer+= 0.45f; tags.addTag("kurtosis"); } - if(skewness < 0.15 && data.clickProcessor.getMean() < 2.5) { + if (skewness < 0.15 && data.clickProcessor.getMean() < 2.5) { buffer+= 0.45f; tags.addTag("skew"); } - if(tags.getSize() > 0) { - if(buffer > 30) { + if (tags.getSize() > 0) { + if (buffer > 30) { vl++; buffer = 28; flag("tags=%s k=%.2f o=%s sk=%.2f a=%.1f", tags.build(), data.clickProcessor.getKurtosis(), data.clickProcessor.getOutliers(), data.clickProcessor.getSkewness(), data.clickProcessor.getMean()); } - } else if(buffer > 0) buffer-= 0.75f; + } else if (buffer > 0) buffer-= 0.75f; debug("tags=%s mean=%.2f skew=%.2f kurt=%.2f std=%.3f outliers=%s buffer=%.1f", (tags.getSize() > 0 ? Color.Green : "") +tags.build() + Color.Gray, data.clickProcessor.getMean(), diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerF.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerF.java index e172204d9..09159c30a 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerF.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerF.java @@ -31,7 +31,7 @@ public class AutoclickerF extends Check { public void onFlying(WrappedInTransactionPacket packet) { val optional = Kauri.INSTANCE.keepaliveProcessor.getKeepById(packet.getAction()); - if(optional.isPresent()) { + if (optional.isPresent()) { flying++; } } @@ -43,7 +43,7 @@ public void onUse(WrappedInUseEntityPacket packet, int current) { @Packet public void onArm(WrappedInArmAnimationPacket packet, int current) { - if(data.playerInfo.breakingBlock + if (data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock || data.playerInfo.lastBrokenBlock.isNotPassed(5) || data.playerInfo.lastBlockDigPacket.isNotPassed(1) diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerG.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerG.java index 23ed37bd8..2a374cc6d 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerG.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerG.java @@ -16,7 +16,7 @@ public class AutoclickerG extends Check { float buffer; @Packet public void check(WrappedInArmAnimationPacket packet) { - if(data.playerInfo.breakingBlock + if (data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock || data.clickProcessor.isNotReady() || data.playerInfo.lastBrokenBlock.isNotPassed(5) @@ -26,8 +26,8 @@ public void check(WrappedInArmAnimationPacket packet) { int low = data.clickProcessor.getLowOutliers(), high = data.clickProcessor.getHighOutliers(); double cpsAvg = 20L / Math.max(0.0001, data.clickProcessor.getMean()); //I used long for 1000 since long is 64 bit with double. - if((low + high) == 0 && data.clickProcessor.getMean() < 2.52) { - if((buffer < 20 ? ++buffer : buffer) > 6) { + if ((low + high) == 0 && data.clickProcessor.getMean() < 2.52) { + if ((buffer < 20 ? ++buffer : buffer) > 6) { vl++; flag(20 * 30, "buffer=%.1f avgCps=%.1f std=%.2f low=%s high=%s", buffer, cpsAvg, diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerH.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerH.java index 22f631c22..580253310 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerH.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerH.java @@ -19,7 +19,7 @@ public class AutoclickerH extends Check { @Packet public void onArm(WrappedInArmAnimationPacket packet) { - if(data.playerInfo.breakingBlock + if (data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock || data.clickProcessor.isNotReady() || data.playerInfo.lastBrokenBlock.isNotPassed(5) @@ -28,11 +28,11 @@ public void onArm(WrappedInArmAnimationPacket packet) { return; long range = data.clickProcessor.getMax() - data.clickProcessor.getMin(); - if(data.clickProcessor.getStd() < 0.3 + if (data.clickProcessor.getStd() < 0.3 && data.clickProcessor.getMean() < 3 && range > 3) { buffer++; - } else if(buffer > 0) buffer-= 0.25f; + } else if (buffer > 0) buffer-= 0.25f; debug("std=%.2f mean=%.1f range=%s buffer.1", data.clickProcessor.getStd(), data.clickProcessor.getMean(), range, buffer); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerI.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerI.java index 296565ed7..8118e5ab3 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerI.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerI.java @@ -21,12 +21,12 @@ public class AutoclickerI extends Check { public void use(WrappedInArmAnimationPacket packet, long now) { long delta = now - lastFlying; - if(delta < 10 && now - lastArm > 30 && data.lagInfo.lastPacketDrop.isPassed(1)) { - if(++buffer > 6) { + if (delta < 10 && now - lastArm > 30 && data.lagInfo.lastPacketDrop.isPassed(1)) { + if (++buffer > 6) { vl++; flag("delta=%s buffer=%s", delta, buffer); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; debug("delta=%s buffer=%s", delta, buffer); lastArm = now; @@ -34,7 +34,7 @@ public void use(WrappedInArmAnimationPacket packet, long now) { @Packet public void flying(WrappedInFlyingPacket packet, long now) { - if(data.playerInfo.lastTeleportTimer.isPassed(0) && now - lastFlying > 30) + if (data.playerInfo.lastTeleportTimer.isPassed(0) && now - lastFlying > 30) lastFlying = now; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerJ.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerJ.java index bb76ffb1e..15a5e6d29 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerJ.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/autoclicker/AutoclickerJ.java @@ -19,7 +19,7 @@ public class AutoclickerJ extends Check { @Packet public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { - if(data.playerInfo.breakingBlock + if (data.playerInfo.breakingBlock || data.playerInfo.lookingAtBlock || data.clickProcessor.isNotReady() || data.playerInfo.lastBrokenBlock.isNotPassed(5) @@ -28,11 +28,11 @@ public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { return; double skew = Math.abs(data.clickProcessor.getSkewness()); - if(data.clickProcessor.getKurtosis() < 0 + if (data.clickProcessor.getKurtosis() < 0 && data.clickProcessor.getMean() < 3 && skew < 0.15 && (data.clickProcessor.getZeros() <= 1 || data.clickProcessor.getMean() <= 1)) { - if(buffer++ > 40) { + if (buffer++ > 40) { vl++; flag(20 * 40, "k=%.4f avg=%.3f s=%.3f v=%.3f b=%.1f zeros=%s", data.clickProcessor.getKurtosis(), data.clickProcessor.getMean(), diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/Hitboxes.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/Hitboxes.java index f5eef9ec2..fac329acf 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/Hitboxes.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/Hitboxes.java @@ -33,10 +33,10 @@ public class Hitboxes extends Check { @Packet public void onUse(WrappedInUseEntityPacket packet, long now) { - if(packet.getAction() != WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK) return; + if (packet.getAction() != WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK) return; Hitboxes: { - if(data.playerInfo.creative + if (data.playerInfo.creative || data.targetPastLocation.previousLocations.size() < 10 || data.playerInfo.inVehicle || data.target == null @@ -65,14 +65,14 @@ public void onUse(WrappedInUseEntityPacket packet, long now) { intersecFrom = vanillaBox.rayTrace(forigin.toVector(), MathUtils.getDirection(forigin), 10); - if(intersectTo != null || intersecFrom != null) { - if(buffer > 0) buffer-= 0.2; + if (intersectTo != null || intersecFrom != null) { + if (buffer > 0) buffer-= 0.2; debug("hit: %.1f", buffer); return; } } - if(now - data.lagInfo.lastClientTrans < 150L + if (now - data.lagInfo.lastClientTrans < 150L && data.lagInfo.lastPingDrop.isPassed(5) && ++buffer > 5) { vl++; flag(""); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/ReachA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/ReachA.java index a4a8e3bc2..1d4dd5fbe 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/ReachA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/hitbox/ReachA.java @@ -57,7 +57,7 @@ public void onUse(WrappedInUseEntityPacket packet) { double current = MiscUtils.getDistanceWithoutRoot(torigin, copy); //If the calculated distance is smaller, we want to set it until we reach the smallest distance - if(distance > current) { + if (distance > current) { distance = current; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraA.java index 1840da6e3..818235f78 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraA.java @@ -25,12 +25,12 @@ public class KillauraA extends Check { @Packet public void onUse(WrappedInUseEntityPacket packet) { - if(data.target == null + if (data.target == null || packet.getAction() != WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK) return; //We can't run this check if we have no block boxes to check! - if(data.getLookingAtBoxes().size() == 0) { + if (data.getLookingAtBoxes().size() == 0) { debug("No block boxes to look at"); buffer = 0; //Resetting buffer return; @@ -39,7 +39,7 @@ public void onUse(WrappedInUseEntityPacket packet) { //Get a single target box. SimpleCollisionBox targetBox = (SimpleCollisionBox) EntityData.getEntityBox(data.target.getLocation(), data.target); - if(targetBox == null) return; + if (targetBox == null) return; KLocation origin = data.playerInfo.to.clone(); @@ -49,7 +49,7 @@ public void onUse(WrappedInUseEntityPacket packet) { Vector targetPoint = ray.collisionPoint(targetBox); //If the ray isn't collided, we might as well not run this check. Just a simple boxes on array check - if(targetPoint == null) return; + if (targetPoint == null) return; double dist = origin.toVector().distanceSquared(targetPoint); @@ -57,10 +57,10 @@ public void onUse(WrappedInUseEntityPacket packet) { synchronized (data.getLookingAtBoxes()) { for (CollisionBox lookingAtBox : data.getLookingAtBoxes()) { - if((lookingAtBox instanceof SimpleCollisionBox)) { + if ((lookingAtBox instanceof SimpleCollisionBox)) { SimpleCollisionBox box = (SimpleCollisionBox) lookingAtBox; - if(box.xMin % 1 != 0 || box.yMin % 1 != 0 || box.zMin % 1 != 0 + if (box.xMin % 1 != 0 || box.yMin % 1 != 0 || box.zMin % 1 != 0 || box.xMax % 1 != 0 || box.yMax % 1 != 0 || box.zMax % 1 != 0) continue; @@ -73,12 +73,12 @@ public void onUse(WrappedInUseEntityPacket packet) { } } - if(rayCollidedOnBlock) { - if(++buffer > 2) { + if (rayCollidedOnBlock) { + if (++buffer > 2) { vl++; flag("b=%s s=%s", buffer, data.getLookingAtBoxes().size()); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; } debug("b=%s collides=%s", buffer, rayCollidedOnBlock); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraB.java index 5177abc4f..ec716dfd8 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraB.java @@ -19,17 +19,17 @@ public class KillauraB extends Check { @Packet public void use(WrappedInUseEntityPacket packet, long current) { - if(current - lastFlying < 10 && data.lagInfo.lastPacketDrop.isPassed(1)) { - if(++buffer > 7) { + if (current - lastFlying < 10 && data.lagInfo.lastPacketDrop.isPassed(1)) { + if (++buffer > 7) { vl++; flag("delta=%s", current - lastFlying); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; } @Packet public void flying(WrappedInFlyingPacket packet, long current) { - if(data.playerInfo.lastTeleportTimer.isPassed(0)) + if (data.playerInfo.lastTeleportTimer.isPassed(0)) lastFlying = current; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraD.java index f765f8ffc..f0bee614b 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraD.java @@ -13,7 +13,7 @@ public class KillauraD extends Check { @Packet public void onPacket(WrappedInFlyingPacket packet) { - if((packet.isPos() || packet.isLook()) + if ((packet.isPos() || packet.isLook()) && data.playerInfo.lastWindowClick.isNotPassed(3) && data.playerInfo.lastAttack.isNotPassed(1) && data.playerInfo.inventoryOpen) { diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraE.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraE.java index 743852fa8..ffc9f7687 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraE.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraE.java @@ -38,7 +38,7 @@ public void onFlying(WrappedInFlyingPacket packet) { @Packet public void onBlock(WrappedInBlockPlacePacket packet) { - if(attacks && !interacts) { + if (attacks && !interacts) { vl++; flag(10, "attacked=true interacted=false"); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraF.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraF.java index 4d1ecf235..e05ad2bae 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraF.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraF.java @@ -21,7 +21,7 @@ public class KillauraF extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(attack && data.playerInfo.sprinting) { + if (attack && data.playerInfo.sprinting) { double px = data.playerInfo.lDeltaX, pz = data.playerInfo.lDeltaZ; px*= 0.6; @@ -33,14 +33,14 @@ public void onFlying(WrappedInFlyingPacket packet) { double deltaYes = Math.abs(deltaXZ - pxz), deltaNo = Math.abs(deltaXZ - noxz); - if(deltaYes > 0.0049 && deltaNo < 0.0001 && data.target != null + if (deltaYes > 0.0049 && deltaNo < 0.0001 && data.target != null && data.target.getType().equals(EntityType.PLAYER)) { - if(++buffer > 5) { + if (++buffer > 5) { vl++; flag("dy=%.3f dn=%.3f dxz=%.2f noxz=%.2f", deltaYes, deltaNo, data.playerInfo.deltaXZ, noxz); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; debug("(%s) dxz=%.3f pxz=%.3f noxz=%.3f dYes=%.3f dNo=%.3f", buffer, data.playerInfo.deltaXZ, pxz, noxz, deltaYes, deltaNo); @@ -50,7 +50,7 @@ public void onFlying(WrappedInFlyingPacket packet) { @Packet public void onUse(WrappedInUseEntityPacket packet) { - if(packet.getAction() == WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK + if (packet.getAction() == WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK && packet.getEntity() instanceof Player) { attack = true; } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraG.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraG.java index 593a91f16..4bd84bf37 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraG.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraG.java @@ -20,7 +20,7 @@ public class KillauraG extends Check { @Packet public void onUse(WrappedInUseEntityPacket packet) { - if(packet.getAction() == WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK + if (packet.getAction() == WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK && sent && data.playerInfo.lastFlyingTimer.isNotPassed(1)) { vl++; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraH.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraH.java index 95c3eef8b..e78b4e58e 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraH.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/combat/killaura/KillauraH.java @@ -22,13 +22,13 @@ public void onUse(WrappedInUseEntityPacket packet) { @Packet public void onArm(WrappedInArmAnimationPacket packet) { - if(data.playerInfo.deltaXZ > 0.21 && data.target != null + if (data.playerInfo.deltaXZ > 0.21 && data.target != null && MathUtils.getDelta(data.target.getVelocity().getY(), -0.078) > 0.001) validAmount++; - if(++arm >= 14) { + if (++arm >= 14) { float ratio = useEntity / (float)arm; - if(ratio > 0.99f) { - if(validAmount > 6 && ++buffer > 4) { + if (ratio > 0.99f) { + if (validAmount > 6 && ++buffer > 4) { vl++; flag("r=%.1f%% b=%s", ratio * 100f, buffer); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/misc/HealthSpoof.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/misc/HealthSpoof.java index bca3f91a3..0b73d79a8 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/misc/HealthSpoof.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/misc/HealthSpoof.java @@ -29,17 +29,17 @@ public class HealthSpoof extends Check { @Packet public boolean onMetadata(WrappedOutEntityMetadata packet) { - if(packet.getEntityId() == data.getPlayer().getEntityId()) return true; + if (packet.getEntityId() == data.getPlayer().getEntityId()) return true; val wobjects = packet.getWatchableObjects() .stream().map(WrappedWatchableObject::new) .collect(Collectors.toList()); val optional = wobjects.stream().filter(wobj -> wobj.getDataValueId() == 6).findFirst(); - if(optional.isPresent()) { + if (optional.isPresent()) { val object = optional.get(); - if(object.getWatchedObject() instanceof Float + if (object.getWatchedObject() instanceof Float && ((float)object.getWatchedObject()) != 1.f) { //debug List strings = new ArrayList<>(); @@ -56,7 +56,7 @@ public boolean onMetadata(WrappedOutEntityMetadata packet) { for (int i = 0; i < wobjects.size(); i++) { val wobj = wobjects.get(i); - if(!newer) wobj.setPacket(wobj.getFirstInt(), + if (!newer) wobj.setPacket(wobj.getFirstInt(), wobj.getDataValueId(), wobj.getWatchedObject()); else wobj.setPacket(wobj.getDataWatcherObject(), wobj.getWatchedObject()); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyA.java index b695ed7aa..56d727f17 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyA.java @@ -21,13 +21,13 @@ public class FlyA extends Check { private static double mult = 0.98f; @Packet public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { - if(packet.isPos() && (data.playerInfo.deltaXZ > 0 || data.playerInfo.deltaY != 0)) { + if (packet.isPos() && (data.playerInfo.deltaXZ > 0 || data.playerInfo.deltaY != 0)) { /* We check if the player is in ground, since theoretically the y should be zero. */ double lDeltaY = data.playerInfo.lClientGround ? 0 : data.playerInfo.lDeltaY; boolean onGround = data.playerInfo.clientGround; double predicted = onGround ? lDeltaY : (lDeltaY - 0.08) * mult; - if(data.playerInfo.lClientGround && !onGround && data.playerInfo.deltaY > 0) { + if (data.playerInfo.lClientGround && !onGround && data.playerInfo.deltaY > 0) { predicted = MovementUtils.getJumpHeight(data); } @@ -35,22 +35,22 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { If it is, it won't send any position packet. Usually this only occurs when the magnitude of motionY is less than 0.005 and it rounds it to 0. The easiest way I found to produce this oddity is by putting myself in a corner and just jumping. */ - if(Math.abs(predicted) < 0.005 + if (Math.abs(predicted) < 0.005 && ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_9)) { predicted = 0; } - if(timeStamp - lastPos > 60L) { + if (timeStamp - lastPos > 60L) { double toCheck = (predicted - 0.08) * mult; - if(Math.abs(data.playerInfo.deltaY - toCheck) < Math.abs(data.playerInfo.deltaY - predicted)) + if (Math.abs(data.playerInfo.deltaY - toCheck) < Math.abs(data.playerInfo.deltaY - predicted)) predicted = toCheck; } double deltaPredict = MathUtils.getDelta(data.playerInfo.deltaY, predicted); boolean flagged = false; - if(!data.playerInfo.flightCancel + if (!data.playerInfo.flightCancel && !data.blockInfo.fenceNear && data.playerInfo.lastBlockPlace.isPassed(1) && data.playerInfo.lastVelocity.isPassed(3) @@ -60,13 +60,13 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { && data.playerInfo.blockAboveTimer.isPassed(5) && deltaPredict > 0.016) { flagged = true; - if(++buffer > 5) { + if (++buffer > 5) { ++vl; flag("dY=%.3f p=%.3f dx=%.3f", data.playerInfo.deltaY, predicted, data.playerInfo.deltaXZ); fixMovementBugs(); - if(buffer > 6) buffer = 6; + if (buffer > 6) buffer = 6; } } else buffer-= buffer > 0 ? 0.25f : 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyB.java index 6a0fc14ee..de65b22b8 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyB.java @@ -20,7 +20,7 @@ public class FlyB extends Check { @Packet public void onVelocity(WrappedOutVelocityPacket packet) { - if(packet.getId() == data.getPlayer().getEntityId()) { + if (packet.getId() == data.getPlayer().getEntityId()) { velocityY = MovementUtils.getTotalHeight(data.playerVersion, (float)packet.getY()); } } @@ -39,25 +39,25 @@ public void onFlying(WrappedInFlyingPacket packet) { } - if(data.playerInfo.serverGround || data.playerInfo.clientGround + if (data.playerInfo.serverGround || data.playerInfo.clientGround || data.playerInfo.lastGhostCollision.isNotPassed(1)) { vertical = 0; pistonBelow = data.blockInfo.pistonNear && data.playerInfo.slimeTimer.isNotPassed(20); limit = MovementUtils.getTotalHeight(data.playerVersion, MovementUtils.getJumpHeight(data)); - if(data.playerInfo.lastVelocity.isPassed(3)) velocityY = 0; + if (data.playerInfo.lastVelocity.isPassed(3)) velocityY = 0; - if(data.playerInfo.wasOnSlime && data.playerInfo.clientGround) { + if (data.playerInfo.wasOnSlime && data.playerInfo.clientGround) { slimeY = MovementUtils.getTotalHeight(data.playerVersion, (float)Math.abs(data.playerInfo.lDeltaY)); debug("SLIME: sy=%.2f dy=%.2f", slimeY, data.playerInfo.lDeltaY); - } else if(data.playerInfo.slimeTimer.isPassed(4)) slimeY = 0; + } else if (data.playerInfo.slimeTimer.isPassed(4)) slimeY = 0; } else { vertical += data.playerInfo.deltaY; double limit = (this.limit + slimeY + velocityY) * 1.6; - if(vertical > limit && !pistonBelow) { + if (vertical > limit && !pistonBelow) { vl++; flag("%.3f>-%.3f", vertical, limit); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyC.java index 69a00d4d3..eea225c6c 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyC.java @@ -33,7 +33,7 @@ public void onPacket(WrappedInFlyingPacket packet) { flag("deltaY=%.4f maxHeight=%.4f", data.playerInfo.deltaY, data.playerInfo.jumpHeight); fixMovementBugs(); - } else if(vl > 0) vl-= 0.01f; + } else if (vl > 0) vl-= 0.01f; debug("deltaY=%s above=%s", data.playerInfo.deltaY, data.playerInfo.blockAboveTimer.getPassed()); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyD.java index c8c8160ff..131daaacc 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyD.java @@ -28,7 +28,7 @@ public void onFlying(WrappedInFlyingPacket packet) { ) return; - if(data.playerInfo.deltaY > data.playerInfo.lDeltaY) { + if (data.playerInfo.deltaY > data.playerInfo.lDeltaY) { vl++; flag("dy=%.2f ldy=%.2f", data.playerInfo.deltaY, data.playerInfo.lDeltaY); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyE.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyE.java index 0f449fcdf..93ecc8736 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyE.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyE.java @@ -16,20 +16,20 @@ public class FlyE extends Check { private int buffer; @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(!packet.isPos() || data.playerInfo.flightCancel || data.excuseNextFlying) return; + if (!packet.isPos() || data.playerInfo.flightCancel || data.excuseNextFlying) return; double accel = Math.abs(data.playerInfo.deltaY - data.playerInfo.lDeltaY); - if(accel < 0.01 && Math.abs(data.playerInfo.deltaY) < 1.5 + if (accel < 0.01 && Math.abs(data.playerInfo.deltaY) < 1.5 && data.playerInfo.lastTeleportTimer.isPassed(2) && data.playerInfo.lastRespawnTimer.isPassed(20) && !data.playerInfo.clientGround && !data.playerInfo.lClientGround) { buffer+= 4; - if(buffer > 15) { + if (buffer > 15) { vl++; flag("accel=%s deltaY=%.3f buffer=%s", accel, data.playerInfo.deltaY, buffer); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyF.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyF.java index 0e9711ced..69166081e 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyF.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyF.java @@ -17,32 +17,32 @@ public class FlyF extends Check { private double slimeY = 0; @Packet public void onPacket(WrappedInFlyingPacket packet) { - if(data.playerInfo.deltaXZ == 0 && data.playerInfo.deltaY == 0) return; + if (data.playerInfo.deltaXZ == 0 && data.playerInfo.deltaY == 0) return; double max = Math.max((data.playerInfo.clientGround && data.playerInfo.serverGround) ? 0.6001 : 0.5001, (data.playerInfo.lastVelocity.isNotPassed(20) ? Math.max(data.playerInfo.velocityY, data.playerInfo.jumpHeight) : data.playerInfo.jumpHeight) + 0.001); - if(data.playerInfo.lastHalfBlock.isNotPassed(20) + if (data.playerInfo.lastHalfBlock.isNotPassed(20) || data.blockInfo.collidesHorizontally) max = Math.max(0.5625, max); - if(data.playerInfo.wasOnSlime && data.playerInfo.clientGround && data.playerInfo.nearGround) { + if (data.playerInfo.wasOnSlime && data.playerInfo.clientGround && data.playerInfo.nearGround) { //Fixes false when jumping onto slime from a large height slimeY = MovementUtils.getTotalHeight(data.playerVersion, (float)Math.abs(data.playerInfo.lDeltaY)); max = Math.max(max, slimeY); debug("SLIME: sy=%.2f", slimeY); - } else if(data.playerInfo.wasOnSlime && data.playerInfo.airTicks > 2) { + } else if (data.playerInfo.wasOnSlime && data.playerInfo.airTicks > 2) { slimeY-= 0.08f; slimeY*= 0.98f; debug("SLIME ACCEL: sy=%.2f", slimeY); max = Math.max(max, slimeY); - } else if(!data.playerInfo.wasOnSlime && slimeY != 0) { + } else if (!data.playerInfo.wasOnSlime && slimeY != 0) { slimeY = 0; } - if(data.playerInfo.deltaY > max + if (data.playerInfo.deltaY > max && !data.blockInfo.roseBush && data.playerInfo.lastVelocity.isPassed(2) && !data.playerInfo.doingVelocity diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyG.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyG.java index cd88d1282..8d33a4650 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyG.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyG.java @@ -16,7 +16,7 @@ public class FlyG extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(!packet.isPos() + if (!packet.isPos() || data.playerInfo.canUseElytra || data.playerInfo.doingBlockUpdate) return; @@ -26,17 +26,17 @@ public void onFlying(WrappedInFlyingPacket packet) { TagsBuilder tags = new TagsBuilder(); double max = data.playerInfo.jumpHeight; - if(toGround) { - if(!fromGround) { - if(data.playerInfo.lDeltaY > 0 && data.playerInfo.lastFenceBelow.isPassed(4) + if (toGround) { + if (!fromGround) { + if (data.playerInfo.lDeltaY > 0 && data.playerInfo.lastFenceBelow.isPassed(4) && data.playerInfo.blockAboveTimer.isPassed(2)) { tags.addTag("INVALID_LANDING"); max = 0; } } else { - if(data.blockInfo.onSlab || data.blockInfo.onStairs) + if (data.blockInfo.onSlab || data.blockInfo.onStairs) max = 0.5; - else if(data.blockInfo.onHalfBlock || data.blockInfo.miscNear) + else if (data.blockInfo.onHalfBlock || data.blockInfo.miscNear) max = 0.5625; tags.addTag("GROUND_STEP"); @@ -44,7 +44,7 @@ else if(data.blockInfo.onHalfBlock || data.blockInfo.miscNear) } } - if(data.playerInfo.deltaY > max && tags.getSize() > 0 + if (data.playerInfo.deltaY > max && tags.getSize() > 0 && data.playerInfo.lastEntityCollision.isPassed(1) && !data.playerInfo.flightCancel) { vl++; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyH.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyH.java index 6331a87e3..e70934e84 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyH.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyH.java @@ -18,7 +18,7 @@ public class FlyH extends Check { //Electrum is sexy if he was of age. @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(data.playerInfo.lastVelocity.isNotPassed(20) + if (data.playerInfo.lastVelocity.isNotPassed(20) || !data.playerInfo.checkMovement || data.playerInfo.canFly || data.playerInfo.doingBlockUpdate @@ -31,16 +31,16 @@ public void onFlying(WrappedInFlyingPacket packet) { final double ldeltaY = data.playerInfo.lDeltaY, deltaY = data.playerInfo.deltaY; - if(Math.abs(deltaY + ldeltaY) < 0.05 + if (Math.abs(deltaY + ldeltaY) < 0.05 && data.playerInfo.lastHalfBlock.isPassed(2) && data.playerInfo.slimeTimer.isPassed(5) && Math.abs(deltaY) > 0.2) { buffer+=15; - if(buffer > 20) { + if (buffer > 20) { vl++; flag("dy=%.1f ldy=%.1f t=same", deltaY, ldeltaY); buffer = 20; //Making sure the buffer doesn't go too high } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyI.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyI.java index ab6f35db1..d1beb40cb 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyI.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/fly/FlyI.java @@ -22,7 +22,7 @@ public class FlyI extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(!packet.isPos() + if (!packet.isPos() || data.playerInfo.generalCancel || (data.playerInfo.serverGround || (data.playerInfo.clientGround && data.playerInfo.groundTicks < 3)) @@ -37,7 +37,7 @@ public void onFlying(WrappedInFlyingPacket packet) { debug("Resetting buffer"); } - if(++buffer > 6) { + if (++buffer > 6) { vl++; flag("b=%s a=%s", buffer, data.playerInfo.airTicks); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Blink.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Blink.java index 0142e7af6..3508f803e 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Blink.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Blink.java @@ -15,9 +15,9 @@ public class Blink extends Check { private int buffer = 0; @Packet public void onTrans(WrappedInTransactionPacket packet) { - if(data.playerInfo.lastFlyingTimer.isPassed( + if (data.playerInfo.lastFlyingTimer.isPassed( (data.playerVersion.isAbove(ProtocolVersion.V1_8_9) ? 40 : 25) + data.lagInfo.transPing)) { - if(++buffer > 2) { + if (++buffer > 2) { vl++; flag(40, "%s", data.playerInfo.lastFlyingTimer.getPassed()); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/FastLadder.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/FastLadder.java index d8eaa2114..931baa1fa 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/FastLadder.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/FastLadder.java @@ -25,13 +25,13 @@ public void setData(ObjectData data) { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isPos() + if (packet.isPos() && data.playerInfo.lastVelocity.isPassed(10) && data.blockInfo.onClimbable && !data.playerInfo.generalCancel) { - if(data.playerInfo.jumped) lastJump.reset(); - if(data.playerInfo.deltaY > (lastJump.isNotPassed() ? data.playerInfo.jumpHeight : 0.144)) { - if((vl+=(data.playerInfo.deltaY > data.playerInfo.jumpHeight * 1.5 ? 10 : 1)) > 8) { + if (data.playerInfo.jumped) lastJump.reset(); + if (data.playerInfo.deltaY > (lastJump.isNotPassed() ? data.playerInfo.jumpHeight : 0.144)) { + if ((vl+=(data.playerInfo.deltaY > data.playerInfo.jumpHeight * 1.5 ? 10 : 1)) > 8) { flag("deltaY=" + data.playerInfo.deltaY); } } else vl-= vl > 0 ? 0.5f : 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/OmniSprint.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/OmniSprint.java index 17c569886..6935adc43 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/OmniSprint.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/OmniSprint.java @@ -19,22 +19,22 @@ public class OmniSprint extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(Math.abs(data.predictionService.motionYaw) > 95 || data.predictionService.key.contains("W")) return; + if (Math.abs(data.predictionService.motionYaw) > 95 || data.predictionService.key.contains("W")) return; double angle = Math.abs( MiscUtils.getAngle(data.playerInfo.to, data.playerInfo.from)); - if(angle < 100 || (data.playerInfo.lastEntityCollision.isNotPassed(4) + if (angle < 100 || (data.playerInfo.lastEntityCollision.isNotPassed(4) && data.playerVersion.isOrAbove(ProtocolVersion.V1_9))) return; omniSprint: { - if(!data.playerInfo.sprinting || !data.playerInfo.serverGround) break omniSprint; + if (!data.playerInfo.sprinting || !data.playerInfo.serverGround) break omniSprint; - if(data.playerInfo.deltaXZ > 0.2 + if (data.playerInfo.deltaXZ > 0.2 && data.playerInfo.lastAttack.isPassed(2) && !data.playerInfo.doingVelocity && !data.playerInfo.generalCancel && data.playerInfo.lastVelocity.isPassed(20)) { - if(++sprintBuffer > 3) { + if (++sprintBuffer > 3) { vl++; flag("type=SPRINT a=%.1f b=%s", data.predictionService.motionYaw, sprintBuffer); } @@ -42,19 +42,19 @@ public void onFlying(WrappedInFlyingPacket packet) { } invalidMove: { - if(data.playerInfo.groundTicks < 9 || !data.playerInfo.serverGround || data.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) break invalidMove; + if (data.playerInfo.groundTicks < 9 || !data.playerInfo.serverGround || data.getPlayer().getGameMode().equals(GameMode.SPECTATOR)) break invalidMove; double base = .235; int speed = data.potionProcessor.getEffectByType(PotionEffectType.SPEED) .map(ef -> ef.getAmplifier() + 1).orElse(0); - if(speed > 0) + if (speed > 0) base *= 1.2 * speed; - if(data.playerInfo.deltaXZ > base + if (data.playerInfo.deltaXZ > base && data.playerInfo.lastVelocity.isPassed(20) && data.playerInfo.lastTeleportTimer.isPassed(1)) { - if(++invalidBuffer > 6) { + if (++invalidBuffer > 6) { vl+= 0.25f; flag("type=INVALID sprint=%s a=%.1f b=%s delta=%.6f>-%.6f", data.playerInfo.sprinting, data.predictionService.motionYaw, invalidBuffer, diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Phase.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Phase.java index a2dc48195..53d3f3fc5 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Phase.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/general/Phase.java @@ -47,7 +47,7 @@ public class Phase extends Check { allowedMaterials.add(XMaterial.VINE.parseMaterial()); allowedMaterials.add(XMaterial.CAKE.parseMaterial()); - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_14)) { + if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_14)) { allowedMaterials.add(XMaterial.SCAFFOLDING.parseMaterial()); } } @@ -63,7 +63,7 @@ public Phase() { @Packet public void onFlying(WrappedInFlyingPacket packet, long now) { - if(!packet.isPos() || now - data.creation < 800L || ((now - data.playerInfo.lastRespawn < 500L + if (!packet.isPos() || now - data.creation < 800L || ((now - data.playerInfo.lastRespawn < 500L || data.playerInfo.moveTicks == 0) && lastFlag.isPassed(12)) || data.playerInfo.creative || data.playerInfo.canFly) { return; @@ -86,9 +86,9 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { newb = Helper.blockCollisions(blocks, toUpdate); for (Block block : newb) { - if(!current.contains(block)) { + if (!current.contains(block)) { Material type = block.getType(); - if(Materials.checkFlag(type, Materials.SOLID) + if (Materials.checkFlag(type, Materials.SOLID) && !allowedMaterials.contains(type) && !Materials.checkFlag(type, Materials.STAIRS)) { tags.addTag("INTO_BLOCK"); @@ -101,7 +101,7 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { } phaseThru: { - if(playerBox.isIntersected(toUpdate)) break phaseThru; + if (playerBox.isIntersected(toUpdate)) break phaseThru; Vector to = data.playerInfo.to.toVector(), from = data.playerInfo.from.toVector(); @@ -115,17 +115,17 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { for (Block block : blocks) { Material type = block.getType(); - if(!Materials.checkFlag(type, Materials.SOLID) + if (!Materials.checkFlag(type, Materials.SOLID) || allowedMaterials.contains(type) || Materials.checkFlag(type, Materials.STAIRS)) continue; CollisionBox box = BlockData.getData(type).getBox(block, data.playerVersion); - if(box instanceof SimpleCollisionBox) { + if (box instanceof SimpleCollisionBox) { Tuple result = new Tuple<>(0., 0.); boolean intersected = RayCollision.intersect(ray, (SimpleCollisionBox) box); - if(intersected && result.one <= dist) { + if (intersected && result.one <= dist) { vl++; tags.addTag("THROUGH_BLOCK"); tags.addTag("material=" + type); @@ -142,13 +142,13 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { Tuple result = new Tuple<>(0., 0.); boolean intersected = RayCollision.intersect(ray, sbox); - if(intersected && result.one <= dist) { + if (intersected && result.one <= dist) { flagged = true; break; } } - if(flagged) { + if (flagged) { vl++; tags.addTag("THROUGH_BLOCK"); tags.addTag("material=" + type); @@ -158,18 +158,18 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { } } - if(tags.getSize() > 0) { - if(flagIntoChat) + if (tags.getSize() > 0) { + if (flagIntoChat) flag("tags=%s", tags.build()); - if(fromWhereShitAintBad == null) fromWhereShitAintBad = data.playerInfo.from; + if (fromWhereShitAintBad == null) fromWhereShitAintBad = data.playerInfo.from; final Location finalSetbackLocation = fromWhereShitAintBad.toLocation(data.getPlayer().getWorld()); - if(finalSetbackLocation != null) { + if (finalSetbackLocation != null) { RunUtils.task(() -> data.getPlayer().teleport(finalSetbackLocation)); } lastFlag.reset(); - } else if(lastFlag.isPassed(5) && !data.blockInfo.collidesHorizontally) + } else if (lastFlag.isPassed(5) && !data.blockInfo.collidesHorizontally) fromWhereShitAintBad = data.playerInfo.from; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryA.java index cb2bd10d8..a7d119bb6 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryA.java @@ -22,8 +22,8 @@ public void setData(ObjectData data) { @Packet public void onWindow(WrappedInWindowClickPacket packet) { - if(data.playerInfo.lastFlyingTimer.isPassed(2)) moveStreak = 0; - if(moveStreak > 5 && data.playerInfo.lastVelocity.isPassed(20)) { + if (data.playerInfo.lastFlyingTimer.isPassed(2)) moveStreak = 0; + if (moveStreak > 5 && data.playerInfo.lastVelocity.isPassed(20)) { vl++; flag("slot=%s clickType=%s ms=%s o=%s", packet.getSlot(), packet.getAction().name(), moveStreak, data.playerInfo.inventoryOpen); @@ -32,7 +32,7 @@ public void onWindow(WrappedInWindowClickPacket packet) { @Packet public void onFlyng(WrappedInFlyingPacket packet) { - if(packet.isPos() + if (packet.isPos() && data.playerInfo.deltaXZ > 0 && data.playerInfo.liquidTimer.isPassed(2) && data.playerInfo.climbTimer.isPassed(3) diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryB.java index 3592b6183..9d16f5677 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryB.java @@ -21,7 +21,7 @@ public class InventoryB extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isPos() + if (packet.isPos() && data.playerInfo.inventoryOpen && !data.playerInfo.flying && !data.blockInfo.inLava @@ -30,11 +30,11 @@ public void onFlying(WrappedInFlyingPacket packet) { && !data.blockInfo.collidesHorizontally && data.playerInfo.deltaXZ > 0.1 && (data.predictionService.strafe != 0 || data.predictionService.forward != 0)) { - if(verbose++ > 10) { + if (verbose++ > 10) { vl++; flag("key=[%s], dxz=%s", data.predictionService.key, MathUtils.round(data.playerInfo.deltaXZ, 2)); - if(cancellable) TinyProtocolHandler.sendPacket(packet.getPlayer(), + if (cancellable) TinyProtocolHandler.sendPacket(packet.getPlayer(), new WrappedOutCloseWindowPacket(data.playerInfo.inventoryId).getObject()); } } else verbose = 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryC.java index 829120bd4..d4280e564 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/inv/InventoryC.java @@ -15,17 +15,17 @@ public class InventoryC extends Check { @Packet public void use(WrappedInWindowClickPacket packet, long current) { - if(current - lastFlying < 10) { + if (current - lastFlying < 10) { vl++; - if(vl > 11) { + if (vl > 11) { flag("delta=%s", current - lastFlying); } - } else if(vl > 0) vl--; + } else if (vl > 0) vl--; } @Packet public void flying(WrappedInFlyingPacket packet, long current) { - if(data.playerInfo.lastTeleportTimer.isPassed(0)) + if (data.playerInfo.lastTeleportTimer.isPassed(0)) lastFlying = current; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallA.java index 382eb4d1e..0de14f7f3 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallA.java @@ -28,14 +28,14 @@ public void onPacket(WrappedInFlyingPacket packet) { || !packet.isPos() || (data.playerInfo.deltaXZ == 0 && data.playerInfo.deltaY == 0) || (data.blockInfo.inWater /* && Todo: T1 */)) { - if(buffer > 0) buffer-= 0.5f; + if (buffer > 0) buffer-= 0.5f; return; } boolean onGround = packet.isGround(); boolean flag = false; - if(onGround) { + if (onGround) { flag = Math.abs(data.playerInfo.deltaY) > 0.0051 // Precautionary since it causes falses with onGround = false && data.playerInfo.slimeTimer.isPassed(2) @@ -55,12 +55,12 @@ public void onPacket(WrappedInFlyingPacket packet) { && data.playerInfo.slimeTimer.isPassed(2); } - if(flag) { - if(++buffer > 1) { + if (flag) { + if (++buffer > 1) { vl++; flag("g=%s;dy=%.4f;ldy=%.4f", onGround, data.playerInfo.deltaY, data.playerInfo.lDeltaY); } - } else if(buffer > 0) buffer-= 0.25f; + } else if (buffer > 0) buffer-= 0.25f; debug("[%.1f] g=%s;dy=%.4f;ldy=%.4f", buffer, onGround, data.playerInfo.deltaY, data.playerInfo.lDeltaY); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallB.java index ec0967e66..7961d1d10 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/nofall/NoFallB.java @@ -18,7 +18,7 @@ public class NoFallB extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet, long timestamp) { - if(data.playerInfo.doingTeleport + if (data.playerInfo.doingTeleport || data.playerInfo.lastTeleportTimer.isNotPassed(3) || data.playerInfo.moveTicks < 2 || data.playerInfo.canFly @@ -28,13 +28,13 @@ public void onFlying(WrappedInFlyingPacket packet, long timestamp) { || data.playerInfo.climbTimer.isNotPassed(3) || timestamp - data.creation < 2000L) { //Subtracting buffers - if(groundBuffer > 0) groundBuffer--; - if(airBuffer > 0) airBuffer--; + if (groundBuffer > 0) groundBuffer--; + if (airBuffer > 0) airBuffer--; return; // If we are waiting for them to teleport, don't check. } // If they are saying they are on the ground - if(data.playerInfo.clientGround + if (data.playerInfo.clientGround && !data.playerInfo.doingBlockUpdate && !data.playerInfo.serverGround && data.playerInfo.vehicleTimer.isPassed(20) @@ -45,29 +45,29 @@ public void onFlying(WrappedInFlyingPacket packet, long timestamp) { && data.playerInfo.lastGhostCollision.isPassed(6)) { groundBuffer+= 2; - if(groundBuffer > 14) { + if (groundBuffer > 14) { vl++; groundBuffer = 14; flag(200, "T=SPOOF_GROUND dy=%.2f y=%.1f", data.playerInfo.deltaY, data.playerInfo.to.y); } fixMovementBugs(); - } else if(groundBuffer > 0) groundBuffer--; + } else if (groundBuffer > 0) groundBuffer--; final boolean dground = Math.abs(data.playerInfo.to.y) % divisor < 1E-4 && data.playerInfo.nearGround; // If they are saying they are on the ground - if(!data.playerInfo.clientGround + if (!data.playerInfo.clientGround && !data.blockInfo.inWeb // Their bounding box is on the ground && data.playerInfo.vehicleTimer.isPassed(20) && ((data.playerInfo.serverGround || data.blockInfo.blocksBelow) && dground && !data.blockInfo.onHalfBlock) && data.playerInfo.lastTeleportTimer.isPassed(2)) { - if((airBuffer +=10) > 30) { + if ((airBuffer +=10) > 30) { vl++; flag(200, "T=SPOOF_AIR dy=%.2f y=%.1f", data.playerInfo.deltaY, data.playerInfo.to.y); } - } else if(airBuffer > 0) airBuffer -= 4; + } else if (airBuffer > 0) airBuffer -= 4; debug("c=%s s=%s bbelow=%s dg=%s dy=%s", data.playerInfo.clientGround, data.playerInfo.serverGround, data.blockInfo.blocksBelow, dground, data.playerInfo.deltaY); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedA.java index 63c9bf9c0..07821901f 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedA.java @@ -23,7 +23,7 @@ public class SpeedA extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(data.excuseNextFlying) return; + if (data.excuseNextFlying) return; checkProccesing: { if (!packet.isPos()) @@ -36,11 +36,11 @@ public void onFlying(WrappedInFlyingPacket packet) { moveFactor+= moveFactor * 0.3f; - if(data.potionProcessor.hasPotionEffect(PotionEffectType.SPEED)) + if (data.potionProcessor.hasPotionEffect(PotionEffectType.SPEED)) moveFactor += (PlayerUtils.getPotionEffectLevel(data.getPlayer(), PotionEffectType.SPEED) * (0.20000000298023224D)) * moveFactor; - if(data.potionProcessor.hasPotionEffect(PotionEffectType.SLOW)) + if (data.potionProcessor.hasPotionEffect(PotionEffectType.SLOW)) moveFactor += (PlayerUtils.getPotionEffectLevel(data.getPlayer(), PotionEffectType.SLOW) * (-0.15000000596046448D)) * moveFactor; @@ -59,22 +59,22 @@ public void onFlying(WrappedInFlyingPacket packet) { moveFactor = 0.026f; } - if(data.blockInfo.inWater) { + if (data.blockInfo.inWater) { tags.addTag("water"); drag = data.getClientVersion().isOrAbove(ProtocolVersion.V1_13) ? 0.9f : 0.8f; moveFactor = 0.034; - if(data.playerInfo.liquidTimer.getResetStreak() < 3) { + if (data.playerInfo.liquidTimer.getResetStreak() < 3) { tags.addTag("water-enter"); moveFactor*= 1.35; } - } else if(data.playerInfo.liquidTimer.isNotPassed(3)) { + } else if (data.playerInfo.liquidTimer.isNotPassed(3)) { moveFactor*= 1.35; tags.addTag("water-leave"); } - if(data.playerInfo.lastTeleportTimer.isNotPassed(6) + if (data.playerInfo.lastTeleportTimer.isNotPassed(6) || data.playerInfo.lastRespawnTimer.isNotPassed(6)) { tags.addTag("teleport"); moveFactor+= 0.1; @@ -82,25 +82,25 @@ public void onFlying(WrappedInFlyingPacket packet) { } //In 1.9+, entity collisions add acceleration to their movement. - if(data.playerInfo.lastEntityCollision.isNotPassed(2)) { + if (data.playerInfo.lastEntityCollision.isNotPassed(2)) { tags.addTag("entity-collision"); moveFactor+= 0.05; } //Pistons have the ability to move players 1 whole block - if(data.blockInfo.pistonNear) { + if (data.blockInfo.pistonNear) { tags.addTag("piston"); moveFactor+= 1; } - if(data.blockInfo.inWeb + if (data.blockInfo.inWeb //Ensuring they aren't just entering or leaving web && data.playerInfo.webTimer.getResetStreak() > 1) { tags.addTag("web"); moveFactor*= 0.4; } - if(data.blockInfo.onSoulSand && data.playerInfo.lClientGround + if (data.blockInfo.onSoulSand && data.playerInfo.lClientGround //Ensuring the player is actually standing on the block and recieving slow && packet.getY() % (1) == 0.875) { tags.addTag("soulsand"); @@ -115,19 +115,19 @@ public void onFlying(WrappedInFlyingPacket packet) { && data.playerInfo.lastVelocity.isPassed(2) && data.playerInfo.liquidTimer.isPassed(2) && !data.playerInfo.generalCancel) { - if(++buffer > 2) { + if (++buffer > 2) { vl++; flag("p=%.1f%% dxz=%.3f a/g=%s,%s aimove=%.3f tags=%s", ratio, data.playerInfo.deltaXZ, data.playerInfo.airTicks, data.playerInfo.groundTicks, data.predictionService.aiMoveSpeed, tags.build()); buffer = Math.min(5, buffer); //Preventing runaway flagging - } else if(ratio > 250) { + } else if (ratio > 250) { cancelAction(CancelType.MOVEMENT); debug("Cancelled user movement: %.1f", ratio); } - if(buffer >= 2) + if (buffer >= 2) fixMovementBugs(); - } else if(buffer > 0) buffer-= 0.2f; + } else if (buffer > 0) buffer-= 0.2f; debug("ratio=%.1f tags=%s tp=%s buffer=%.1f", ratio, tags.build(), data.playerInfo.liquidTimer.getPassed(), buffer); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedB.java index cbd3f3f12..2f4762726 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedB.java @@ -15,22 +15,22 @@ public class SpeedB extends Check { private float verbose; @Packet public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { - if(data.playerInfo.deltaXZ > 0 + if (data.playerInfo.deltaXZ > 0 && !data.excuseNextFlying && !data.playerInfo.generalCancel) { - if(data.playerInfo.airTicks > 2 && !data.playerInfo.lClientGround && !data.playerInfo.clientGround) { + if (data.playerInfo.airTicks > 2 && !data.playerInfo.lClientGround && !data.playerInfo.clientGround) { double accelX = data.playerInfo.deltaX - data.playerInfo.lDeltaX; double accelZ = data.playerInfo.deltaZ - data.playerInfo.lDeltaZ; double hypot = (accelX * accelX) + (accelZ * accelZ); - if(hypot > 0.01 //0.1*0.1 + if (hypot > 0.01 //0.1*0.1 && !data.blockInfo.blocksNear && data.playerInfo.lastVelocity.isPassed(8) && !data.blockInfo.inLiquid && data.playerInfo.lastHalfBlock.isPassed(10) && (accelX > -0.0049 || accelZ > -0.0049) //0.07*0.07 && data.playerInfo.lastBlockPlace.isPassed(7)) { - if(verbose++ > 2) { + if (verbose++ > 2) { vl++; flag("x=%.3f z=%.3f", accelX, accelZ); @@ -38,7 +38,7 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { } else verbose-= verbose > 0 ? 0.2f : 0; debug("x=" + accelX + " z=" + accelZ + " vl=" + verbose); - } else if(verbose > 0) verbose-= 0.1f; - } else if(verbose > 0) verbose-= 0.05f; + } else if (verbose > 0) verbose-= 0.1f; + } else if (verbose > 0) verbose-= 0.05f; } } \ No newline at end of file diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedC.java index b8fd5f7c6..b409e562a 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedC.java @@ -17,11 +17,11 @@ public class SpeedC extends Check { @Packet public void onPacket(WrappedInFlyingPacket packet) { - if(!packet.isPos() + if (!packet.isPos() || data.playerInfo.generalCancel || data.playerInfo.canUseElytra || data.playerInfo.lastVelocity.isNotPassed(25)) { - if(data.playerInfo.generalCancel)verbose.subtract(); + if (data.playerInfo.generalCancel)verbose.subtract(); return; } @@ -37,13 +37,13 @@ public void onPacket(WrappedInFlyingPacket packet) { : 0; baseSpeed+= data.playerInfo.wasOnSlime ? 0.1 : 0; - if(data.playerInfo.lastBlockPlace.isNotPassed(10)) + if (data.playerInfo.lastBlockPlace.isNotPassed(10)) baseSpeed+= 0.2; - if(data.playerInfo.baseSpeed < 0.2) return; + if (data.playerInfo.baseSpeed < 0.2) return; - if(data.playerInfo.deltaXZ > baseSpeed) { - if(verbose.add(data.playerInfo.deltaXZ - baseSpeed > 0.45f ? 4 : 1) > 25 + if (data.playerInfo.deltaXZ > baseSpeed) { + if (verbose.add(data.playerInfo.deltaXZ - baseSpeed > 0.45f ? 4 : 1) > 25 || data.playerInfo.deltaXZ - baseSpeed > 0.45f) { vl++; flag("%s>-%s", diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedD.java index c0664a79c..16f0ab882 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/speed/SpeedD.java @@ -16,7 +16,7 @@ public class SpeedD extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet, long now) { - if(!packet.isPos() || now - data.creation < 800L || now - data.playerInfo.lastRespawn < 500L + if (!packet.isPos() || now - data.creation < 800L || now - data.playerInfo.lastRespawn < 500L || data.playerInfo.lastTeleportTimer.isPassed(1) || data.playerInfo.canUseElytra || data.playerInfo.doingTeleport ||data.playerInfo.canFly || data.playerInfo.creative @@ -24,25 +24,25 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { double threshold = data.potionProcessor.hasPotionEffect(PotionEffectType.JUMP) ? 0.62 : 0.5; - if(data.blockInfo.pistonNear) threshold = 0.95; - else if(data.playerInfo.blockAboveTimer.isNotPassed(20)) { + if (data.blockInfo.pistonNear) threshold = 0.95; + else if (data.playerInfo.blockAboveTimer.isNotPassed(20)) { //TODO Fix under block falses threshold = 0.8; - if(data.playerInfo.iceTimer.isNotPassed(20)) threshold+= 0.4; + if (data.playerInfo.iceTimer.isNotPassed(20)) threshold+= 0.4; } - else if(data.playerInfo.jumped) threshold = 0.68; - else if(data.playerInfo.iceTimer.isNotPassed(4)) threshold = 0.6; + else if (data.playerInfo.jumped) threshold = 0.68; + else if (data.playerInfo.iceTimer.isNotPassed(4)) threshold = 0.6; - if(data.playerInfo.lastVelocity.isNotPassed(20)) + if (data.playerInfo.lastVelocity.isNotPassed(20)) threshold = Math.max(threshold, data.playerInfo.velocityXZ + 0.3); Optional speed = data.potionProcessor.getEffectByType(PotionEffectType.SPEED); - if(speed.isPresent()) { + if (speed.isPresent()) { threshold*= 1.2 * (speed.get().getAmplifier() + 1); } - if(data.playerInfo.deltaXZ > threshold) { + if (data.playerInfo.deltaXZ > threshold) { vl++; flag(80, "%.3f>-%.3f", data.playerInfo.deltaXZ, threshold); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityA.java index 44bd91619..7079f23e5 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityA.java @@ -21,17 +21,17 @@ public class VelocityA extends Check { public void onFlying(WrappedInFlyingPacket packet) { //Player just jumped into the air - if(data.playerInfo.cva) { - if(data.playerInfo.velocityY > 0.1) + if (data.playerInfo.cva) { + if (data.playerInfo.velocityY > 0.1) vY = data.playerInfo.velocityY; data.playerInfo.cva = false; - } else if(data.playerInfo.doingBlockUpdate) { + } else if (data.playerInfo.doingBlockUpdate) { vY = 0; return; } //If any of these conditions aren't met, we don't want to make checking for vertical velocity. - if(vY > 0 + if (vY > 0 && !data.playerInfo.generalCancel && data.playerInfo.worldLoaded && data.playerInfo.lastTeleportTimer.isPassed(2) @@ -44,7 +44,7 @@ public void onFlying(WrappedInFlyingPacket packet) { if ((pct < 99.999 || pct > 400) && !data.playerInfo.lastBlockPlace.isNotPassed(5) && !data.blockInfo.blocksAbove) { - if(++buffer > 15) { + if (++buffer > 15) { vl++; flag("pct=%.1f%% buffer=%.1f", pct, buffer); } @@ -54,7 +54,7 @@ public void onFlying(WrappedInFlyingPacket packet) { vY*= 0.98; //If any of these conditions are met, we might as well stop checking for velocity. - if(vY < 0.005 //While this is a 1.8.9 and below only thing, we might as well stop checking. + if (vY < 0.005 //While this is a 1.8.9 and below only thing, we might as well stop checking. || data.playerInfo.lastVelocity.isPassed(7) || data.blockInfo.collidesHorizontally || data.blockInfo.collidesVertically) vY = 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityB.java index 8e82fc560..5a4973e15 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityB.java @@ -28,7 +28,7 @@ public class VelocityB extends Check { @Packet public void onUseEntity(WrappedInUseEntityPacket packet) { - if(!useEntity + if (!useEntity && packet.getAction().equals(WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK)) { useEntity = true; } @@ -36,20 +36,20 @@ public void onUseEntity(WrappedInUseEntityPacket packet) { @Packet public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { - if(data.playerInfo.cvc) { + if (data.playerInfo.cvc) { pvZ = data.playerInfo.velocityZ; pvX = data.playerInfo.velocityX; data.playerInfo.cvc = false; ticks = 0; } - if((pvX != 0 || pvZ != 0) && (data.playerInfo.deltaX != 0 + if ((pvX != 0 || pvZ != 0) && (data.playerInfo.deltaX != 0 || data.playerInfo.deltaY != 0 || data.playerInfo.deltaZ != 0)) { boolean found = false; double drag = 0.91; - if(data.blockInfo.blocksNear + if (data.blockInfo.blocksNear || data.blockInfo.blocksAbove || data.blockInfo.inLiquid || data.playerInfo.creative @@ -58,16 +58,16 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { pvX = pvZ = 0; buffer-= buffer > 0 ? 1 : 0; return; - } else if(data.playerInfo.doingBlockUpdate) { + } else if (data.playerInfo.doingBlockUpdate) { pvX = pvZ = 0; return; } - if(data.playerInfo.lClientGround) { + if (data.playerInfo.lClientGround) { drag*= data.blockInfo.fromFriction; } - if(useEntity && (sprint || (data.getPlayer().getItemInHand() != null + if (useEntity && (sprint || (data.getPlayer().getItemInHand() != null && data.getPlayer().getItemInHand().containsEnchantment(Enchantment.KNOCKBACK)))) { pvX*= 0.6; pvZ*= 0.6; @@ -117,7 +117,7 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { return (deltaX * deltaX + deltaZ * deltaZ); })); - if(!velocity.isPresent()) { + if (!velocity.isPresent()) { double s2 = data.predictionService.strafe; double f2 = data.predictionService.forward; @@ -138,13 +138,13 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { double ratioX = data.playerInfo.deltaX / pvX, ratioZ = data.playerInfo.deltaZ / pvZ; double ratio = (Math.abs(ratioX) + Math.abs(ratioZ)) / 2; - if((ratio < 0.85 || ratio > 3) && pvX != 0 + if ((ratio < 0.85 || ratio > 3) && pvX != 0 && pvZ != 0 && timeStamp - data.creation > 3000L && data.playerInfo.lastTeleportTimer.isPassed(1) && !data.getPlayer().getItemInHand().getType().isEdible() && !data.blockInfo.blocksNear) { - if(data.playerInfo.lastUseItem.isPassed(2) && ++buffer > 30) { + if (data.playerInfo.lastUseItem.isPassed(2) && ++buffer > 30) { vl++; flag("pct=%.2f buffer=%.1f forward=%.2f strafe=%.2f", ratio * 100, buffer, moveStrafe, moveForward); @@ -160,13 +160,13 @@ public void onFlying(WrappedInFlyingPacket packet, long timeStamp) { pvX *= drag; pvZ *= drag; - if(++ticks > 6) { + if (++ticks > 6) { ticks = 0; pvX = pvZ = 0; } - if(Math.abs(pvX) < 0.005) pvX = 0; - if(Math.abs(pvZ) < 0.005) pvZ = 0; + if (Math.abs(pvX) < 0.005) pvX = 0; + if (Math.abs(pvZ) < 0.005) pvZ = 0; } sprint = data.playerInfo.sprinting; useEntity = false; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityC.java index 0772bb691..6ffd4e986 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/movement/velocity/VelocityC.java @@ -29,7 +29,7 @@ public class VelocityC extends Check { @Packet public void onVelocity(WrappedOutVelocityPacket packet) { - if(packet.getId() == data.getPlayer().getEntityId() && packet.getY() > 0.1) { + if (packet.getId() == data.getPlayer().getEntityId() && packet.getY() > 0.1) { data.runKeepaliveAction(ka -> { synchronized (velocityY) { velocityY.add(new Velocity(packet.getY())); @@ -41,15 +41,15 @@ public void onVelocity(WrappedOutVelocityPacket packet) { @Packet public void onFlying(WrappedInFlyingPacket packet, long now) { - if(velocityY.size() == 0) return; + if (velocityY.size() == 0) return; var toRemove = velocityY.stream() .filter(t -> Math.abs(data.playerInfo.deltaY - t.getVelocity()) < 0.001) .collect(Collectors.toList()); - if(toRemove.size() > 0) { + if (toRemove.size() > 0) { - if(buffer > 0) buffer--; + if (buffer > 0) buffer--; debug("Reset velocity: dy=%.4f b=%s", data.playerInfo.deltaY, buffer); @@ -62,7 +62,7 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { } //All potential causes of false positives - if(data.playerInfo.doingBlockUpdate + if (data.playerInfo.doingBlockUpdate || data.playerInfo.webTimer.isNotPassed(3) || data.playerInfo.liquidTimer.isNotPassed(3) || data.playerInfo.slimeTimer.isNotPassed(2) @@ -76,14 +76,14 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { toRemove = velocityY.stream().filter(t -> now - t.getTimestamp() > 4000L) .collect(Collectors.toList()); - if(toRemove.size() > 0) { + if (toRemove.size() > 0) { for (Velocity v : toRemove) { velocityY.remove(v); } toRemove.clear(); - } else if(velocityY.size() > 0 && lastVelocity.isPassed(2000L)) { - if(++buffer > 2) { + } else if (velocityY.size() > 0 && lastVelocity.isPassed(2000L)) { + if (++buffer > 2) { vl++; flag("lv=%s s=%s", lastVelocity.getPassed(), velocityY.size()); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsA.java index 7677c4641..c38fa3783 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsA.java @@ -19,9 +19,9 @@ public class BadPacketsA extends Check { @Packet public void onDig(WrappedInBlockDigPacket packet, long timeStamp) { - if(timeStamp - lastBlockPlace < 5 && !data.lagInfo.lagging + if (timeStamp - lastBlockPlace < 5 && !data.lagInfo.lagging && data.lagInfo.lastPacketDrop.isPassed(5)) { - if(vl++ > 4) { + if (vl++ > 4) { flag("unblocked and blocked in same tick."); } } else vl-= vl > 0 ? 0.5 : 0; @@ -29,7 +29,7 @@ public void onDig(WrappedInBlockDigPacket packet, long timeStamp) { @Packet public void onPlace(WrappedInBlockPlacePacket packet, long timeStamp) { - if(packet.getPlayer().getItemInHand() != null + if (packet.getPlayer().getItemInHand() != null && BlockUtils.isTool(packet.getPlayer().getItemInHand())) lastBlockPlace = timeStamp; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsB.java index a3910ad96..12c82f35f 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsB.java @@ -17,10 +17,10 @@ public class BadPacketsB extends Check { private MaxInteger ticks = new MaxInteger(Integer.MAX_VALUE); @Packet public void onPlace(WrappedInEntityActionPacket action, long timeStamp) { - if(action.getAction().name().contains("SNEAK")) { - if(timeStamp - lastSneak <= 10) { + if (action.getAction().name().contains("SNEAK")) { + if (timeStamp - lastSneak <= 10) { ticks.add(); - if(ticks.value() > 80) { + if (ticks.value() > 80) { vl++; flag("ticks=%s", ticks.value()); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsC.java index fbdacaf31..17f594e53 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsC.java @@ -18,17 +18,17 @@ public class BadPacketsC extends Check { @Packet public void use(WrappedInHeldItemSlotPacket packet, long current) { - if(current - lastFlying < 10 && data.lagInfo.lastPacketDrop.isPassed(2)) { - if(++buffer > 11) { + if (current - lastFlying < 10 && data.lagInfo.lastPacketDrop.isPassed(2)) { + if (++buffer > 11) { vl++; flag("delta=%s", current - lastFlying); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; } @Packet public void flying(WrappedInFlyingPacket packet, long current) { - if(data.playerInfo.lastTeleportTimer.isPassed(0)) + if (data.playerInfo.lastTeleportTimer.isPassed(0)) lastFlying = current; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsD.java index 17e6fb51b..09355f97b 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsD.java @@ -22,25 +22,25 @@ public class BadPacketsD extends Check { @Packet public void server(WrappedOutAbilitiesPacket packet) { - if(packet.isAllowedFlight()) { + if (packet.isAllowedFlight()) { serverAllowed = true; - } else if(!clientAllowed) { + } else if (!clientAllowed) { serverAllowed = false; } } @Packet public void client(WrappedInAbilitiesPacket packet) { - if(packet.isAllowedFlight()) { + if (packet.isAllowedFlight()) { clientAllowed = true; - } else if(!serverAllowed) { + } else if (!serverAllowed) { clientAllowed = false; } } @Packet public void flying(WrappedInFlyingPacket packet, long timeStamp) { - if(timeStamp - data.creation < 1000L) { + if (timeStamp - data.creation < 1000L) { serverAllowed = data.getPlayer().getAllowFlight(); clientAllowed = data.getPlayer().getAllowFlight(); RunUtils.task(() -> { @@ -49,8 +49,8 @@ public void flying(WrappedInFlyingPacket packet, long timeStamp) { data.getPlayer().setGameMode(GameMode.SURVIVAL); }, Kauri.INSTANCE); } else { - if(!serverAllowed && clientAllowed) { - if(vl++ > 1) { + if (!serverAllowed && clientAllowed) { + if (vl++ > 1) { flag("server=" + serverAllowed + " client=" + clientAllowed); RunUtils.task(() -> { data.getPlayer().setFlying(false); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsE.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsE.java index 4d971b2b8..01cc65e09 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsE.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsE.java @@ -20,8 +20,8 @@ public class BadPacketsE extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet, long now) { - if(!packet.isPos()) { - if(++noPosTicks > 1 + if (!packet.isPos()) { + if (++noPosTicks > 1 && now - data.creation > 2000L && data.playerInfo.lastTeleportTimer.isPassed(2) && lastGround != packet.isGround() diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsG.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsG.java index 09393d843..5edddb0d7 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsG.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsG.java @@ -15,11 +15,11 @@ public class BadPacketsG extends Check { private int verbose; @Packet public void onPacket(WrappedInBlockDigPacket packet, long timeStamp) { - if(packet.getAction().equals(WrappedInBlockDigPacket.EnumPlayerDigType.DROP_ITEM)) { + if (packet.getAction().equals(WrappedInBlockDigPacket.EnumPlayerDigType.DROP_ITEM)) { long delta = timeStamp - lastItemDrop; - if(delta < 35) { - if(verbose++ > 5) { + if (delta < 35) { + if (verbose++ > 5) { vl++; flag("delta=" + delta); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsH.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsH.java index f9e54c3d4..504814aa0 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsH.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsH.java @@ -17,12 +17,12 @@ public class BadPacketsH extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet, long now ) { - if(data.playerInfo.creative || data.playerInfo.inVehicle) return; + if (data.playerInfo.creative || data.playerInfo.inVehicle) return; - if(!packet.isPos() && packet.isLook()) { - if(data.playerInfo.from.yaw == data.playerInfo.to.yaw + if (!packet.isPos() && packet.isLook()) { + if (data.playerInfo.from.yaw == data.playerInfo.to.yaw && data.playerInfo.from.pitch == data.playerInfo.to.pitch) { - if(!exempt && data.playerInfo.lastTeleportTimer.isPassed(1) + if (!exempt && data.playerInfo.lastTeleportTimer.isPassed(1) && data.playerInfo.vehicleTimer.isPassed(1) && now - data.creation > 5000L && data.playerInfo.lastRespawnTimer.isPassed(10)) { diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsI.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsI.java index 761155d8f..5e02a5486 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsI.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsI.java @@ -14,7 +14,7 @@ public class BadPacketsI extends Check { @Packet public void onFlying(WrappedInAbilitiesPacket packet) { - if(packet.isFlying() && !packet.isAllowedFlight() + if (packet.isFlying() && !packet.isAllowedFlight() && !packet.getPlayer().getAllowFlight() && !data.lagInfo.lagging) { vl+= 2; flag("isFlying=" + packet.isFlying() + " allowed=" + packet.isAllowedFlight()); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsK.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsK.java index 1b7e50550..a27724d6f 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsK.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsK.java @@ -14,12 +14,12 @@ public class BadPacketsK extends Check { @Packet public void onHeld(WrappedInHeldItemSlotPacket packet) { - if(lastSlot != -1 && lastSlot == packet.getSlot() && data.lagInfo.lastPacketDrop.isPassed(2)) { - if(++buffer > 3) { + if (lastSlot != -1 && lastSlot == packet.getSlot() && data.lagInfo.lastPacketDrop.isPassed(2)) { + if (++buffer > 3) { vl++; flag("current=%s;last=%s", packet.getSlot(), lastSlot); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; debug("slot=%s lastslot=%s", packet.getSlot(), lastSlot); lastSlot = packet.getSlot(); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsM.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsM.java index cd0ec0328..e39a14ecc 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsM.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsM.java @@ -13,7 +13,7 @@ public class BadPacketsM extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isLook() && Math.abs(packet.getPitch()) > 90) { + if (packet.isLook() && Math.abs(packet.getPitch()) > 90) { vl++; flag("pitch=%s", MathUtils.round(packet.getPitch(), 2)); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsN.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsN.java index fd5c2a908..de38acb79 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsN.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/badpacket/BadPacketsN.java @@ -45,7 +45,7 @@ public BadPacketsN() { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(lastSentTrans.isNotPassed(300L) + if (lastSentTrans.isNotPassed(300L) && ++flying > 305 + (data.lagInfo.ping / 50.) && Kauri.INSTANCE.tps.getAverage() > 19.6 && lastKeepAlive.isNotPassed(4000L)) { @@ -58,21 +58,21 @@ public void onFlying(WrappedInFlyingPacket packet) { @Event public void onEvent(PlayerMoveEvent event) { - if(flying > 10) { + if (flying > 10) { event.setCancelled(true); } } @Event public void onEvent(EntityDamageByEntityEvent event) { - if(flying > 10) { + if (flying > 10) { event.setCancelled(true); } } @Event public void onEvent(PlayerInteractEvent event) { - if(flying > 10) { + if (flying > 10) { event.setCancelled(true); } } @@ -94,7 +94,7 @@ public void onOutTrans(WrappedOutTransaction packet) { @Packet public void onTransaction(WrappedInTransactionPacket packet, long now) { - if(packet.getId() != 0) return; + if (packet.getId() != 0) return; val response = Kauri.INSTANCE.keepaliveProcessor.getKeepById(packet.getAction()); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookCrash.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookCrash.java index 98e5df61a..675b90f8a 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookCrash.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookCrash.java @@ -23,15 +23,15 @@ public class BookCrash extends Check { @Packet public void blockPlace(WrappedInBlockPlacePacket packet) { - if(packet.getItemStack() != null && packet.getItemStack().getType().name().contains("BOOK")) { + if (packet.getItemStack() != null && packet.getItemStack().getType().name().contains("BOOK")) { sentCount++; } } @Packet public void inTransaction(WrappedInTransactionPacket packet) { - if(++checkCount > 5) { - if(sentCount > 6) { + if (++checkCount > 5) { + if (sentCount > 6) { vl++; flag("book crasher"); RunUtils.task(() -> packet.getPlayer().kickPlayer("Please, do not spam")); @@ -44,8 +44,8 @@ public void inTransaction(WrappedInTransactionPacket packet) { private int pageCount = 0; @Packet public boolean onBook(WrappedInCustomPayload payload) { - if(payload.getTag().equals("MC|BSign") || payload.getTag().equals("MC|BEdit") || payload.getTag().equals("MC|BOpen")) { - if(!data.getPlayer().getItemInHand().getType().equals(BOOK)) { + if (payload.getTag().equals("MC|BSign") || payload.getTag().equals("MC|BEdit") || payload.getTag().equals("MC|BOpen")) { + if (!data.getPlayer().getItemInHand().getType().equals(BOOK)) { vl++; flag("Item in hand is not book"); return true; @@ -56,16 +56,16 @@ public boolean onBook(WrappedInCustomPayload payload) { BookMeta meta = (BookMeta) book.getItemMeta(); - if(meta.getPages().size() > 50) { + if (meta.getPages().size() > 50) { vl++; flag("%s>-50", meta.getPages().size()); return true; } else { for (String page : meta.getPages()) { - if(page.length() > 400 && ++ pageCount > 2) { + if (page.length() > 400 && ++ pageCount > 2) { vl++; flag("Too large of length"); - if(vl > 2) closePlayerChannel(); + if (vl > 2) closePlayerChannel(); pageCount = 0; return true; } @@ -73,7 +73,7 @@ public boolean onBook(WrappedInCustomPayload payload) { pageCount = 0; } } - } else if(payload.getData().length == 0) { + } else if (payload.getData().length == 0) { debug("Sent empty payload"); return true; } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookEnchant.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookEnchant.java index 0d75a4a89..baef64eb3 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookEnchant.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookEnchant.java @@ -14,11 +14,11 @@ public class BookEnchant extends Check { @Event public void onEvent(PlayerInteractEvent event) { - if(event.getItem() == null) return; + if (event.getItem() == null) return; val type = event.getItem().getType(); - if(type.name().contains("BOOK") && !type.name().contains("ENCHANT") + if (type.name().contains("BOOK") && !type.name().contains("ENCHANT") && event.getItem().getEnchantments().size() > 0) { for (Enchantment enchantment : event.getItem().getEnchantments().keySet()) { event.getItem().removeEnchantment(enchantment); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookOp.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookOp.java index 7c3f8a525..c5ca04414 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookOp.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/BookOp.java @@ -15,7 +15,7 @@ public void onEvent(PlayerEditBookEvent event) { val optional = event.getNewBookMeta().getPages().stream() .filter(string -> string.toLowerCase().contains("run_command")) .findFirst(); - if(optional.isPresent()) { + if (optional.isPresent()) { vl++; flag("line=" + optional.get()); event.setCancelled(true); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/CreativeCrash.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/CreativeCrash.java index 520d2c1ef..f44e8cff5 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/CreativeCrash.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/CreativeCrash.java @@ -45,7 +45,7 @@ public boolean onEvent(WrappedInSetCreativeSlotPacket packet) { boolean flagged = false; CREATIVE: { - if(packet.getPlayer().getGameMode().equals(GameMode.CREATIVE)) break CREATIVE; + if (packet.getPlayer().getGameMode().equals(GameMode.CREATIVE)) break CREATIVE; if (!packet.getPlayer().getGameMode().equals(GameMode.CREATIVE)) { vl++; @@ -56,10 +56,10 @@ public boolean onEvent(WrappedInSetCreativeSlotPacket packet) { } BOOK_PAGES: { - if(packet.itemStack == null + if (packet.itemStack == null || !packet.itemStack.getType().name().contains("BOOK")) break BOOK_PAGES; - if(packet.itemStack.getItemMeta() instanceof BookMeta) { + if (packet.itemStack.getItemMeta() instanceof BookMeta) { BookMeta meta = (BookMeta) packet.itemStack.getItemMeta(); int pages = meta.getPages().size(); @@ -71,7 +71,7 @@ public boolean onEvent(WrappedInSetCreativeSlotPacket packet) { } } } - if(flagged) { + if (flagged) { if (cancelPacket) return true; if (closeChannel) @@ -80,14 +80,14 @@ public boolean onEvent(WrappedInSetCreativeSlotPacket packet) { } } IMPOSSIBLE_ITEM: { - if(!impossibleItemCreate || packet.itemStack == null) break IMPOSSIBLE_ITEM; + if (!impossibleItemCreate || packet.itemStack == null) break IMPOSSIBLE_ITEM; boolean flagged = false; ENCHANT_SIZE: { int size = packet.itemStack.getEnchantments().size(); - if(size <= maxEnchantSize) break ENCHANT_SIZE; + if (size <= maxEnchantSize) break ENCHANT_SIZE; vl++; flag("category=%s type=%s reason=%s", @@ -96,7 +96,7 @@ public boolean onEvent(WrappedInSetCreativeSlotPacket packet) { flagged = true; } - if(flagged) return true; + if (flagged) return true; } return false; } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Infinity.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Infinity.java index 364b295da..61b1950ab 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Infinity.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Infinity.java @@ -12,7 +12,7 @@ public class Infinity extends Check { @Packet public boolean onFlying(WrappedInFlyingPacket packet) { - if(Double.isInfinite(packet.getX()) || Double.isInfinite(packet.getY()) || Double.isInfinite(packet.getZ())) { + if (Double.isInfinite(packet.getX()) || Double.isInfinite(packet.getY()) || Double.isInfinite(packet.getZ())) { vl++; flag("sent infinite position"); closePlayerChannel(); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/LargeMove.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/LargeMove.java index f2e37f6da..3cf8621da 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/LargeMove.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/LargeMove.java @@ -47,38 +47,38 @@ public boolean onPacket(WrappedInFlyingPacket packet, long timeStamp) { boolean cancel = false; detection: { - if(packet.isPos()) { + if (packet.isPos()) { Vector to = new Vector(packet.getX(), packet.getY(), packet.getZ()); - if(data.playerInfo.lastTeleportTimer.isPassed(4) + if (data.playerInfo.lastTeleportTimer.isPassed(4) && data.playerInfo.checkMovement && teleportIds.size() == 0 && from != null) { double distance, deltaY = to.getY() - from.getY(); double deltaXZ = to.clone().setY(0).distance(from.clone().setY(0)); - if(deltaY > -0.0981 && deltaY < -0.0979 && deltaXZ < 1) break detection; + if (deltaY > -0.0981 && deltaY < -0.0979 && deltaXZ < 1) break detection; distance = to.distance(from); - if(Math.abs(to.getY()) > 1000) { + if (Math.abs(to.getY()) > 1000) { vl++; flag("type=%s y=%s", 1, to.getY()); - if(cancelPacket) { + if (cancelPacket) { cancel = true; } - if(closeChannel) + if (closeChannel) closePlayerChannel(); - else if(bukkitKick) RunUtils.task(() -> packet.getPlayer().kickPlayer(bukkitKickMessage)); - } else if(distance > 100) { + else if (bukkitKick) RunUtils.task(() -> packet.getPlayer().kickPlayer(bukkitKickMessage)); + } else if (distance > 100) { vl++; flag("type=%s dist=%.2f", 2, distance); - if(cancelPacket) { + if (cancelPacket) { cancel = true; } - if(closeChannel) + if (closeChannel) closePlayerChannel(); - else if(bukkitKick) RunUtils.task(() -> packet.getPlayer().kickPlayer(bukkitKickMessage)); + else if (bukkitKick) RunUtils.task(() -> packet.getPlayer().kickPlayer(bukkitKickMessage)); } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Log4JPatch.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Log4JPatch.java index 432d0e881..5ce875870 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Log4JPatch.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/Log4JPatch.java @@ -16,7 +16,7 @@ public class Log4JPatch extends Check { @Packet public boolean onChat(WrappedInChatPacket packet) { Matcher matcher = pattern.matcher(packet.getMessage()); - if(matcher.matches()) { + if (matcher.matches()) { vl++; flag("Tried to use JNDI exploit"); return true; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/PacketSpam.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/PacketSpam.java index 258e197ae..1d66ef2e3 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/PacketSpam.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/PacketSpam.java @@ -64,7 +64,7 @@ public void onPosition(WrappedOutPositionPacket packet, long timeStamp) { @Event public boolean onReceive(PacketInfo event) { - if(whitelistedPackets.contains(event.getType()) + if (whitelistedPackets.contains(event.getType()) || PacketProcessor.outgoingPackets.contains(event.getType()) || event.getTimestamp() - data.creation < 1000) return false; @@ -73,19 +73,19 @@ public boolean onReceive(PacketInfo event) { new PacketTicks(0, event.getTimestamp())); boolean cancelled = false; - if(event.getTimestamp() - packets.lastReset <= 200) { + if (event.getTimestamp() - packets.lastReset <= 200) { int thresholdBase = event.getType().equals(Packet.Client.CUSTOM_PAYLOAD) ? payloadThresholdBase : generalThresholdBase; - if(++packets.ticks > thresholdBase) { + if (++packets.ticks > thresholdBase) { vl++; flag(true, "ticks=" + packets.ticks + " packet=" + event.getType()); - if(packets.ticks > thresholdBase * 2) { - if(disconnectChannel) + if (packets.ticks > thresholdBase * 2) { + if (disconnectChannel) closePlayerChannel(); else kickPlayer(event.getPlayer()); } cancelled = true; - } else if(packets.ticks > 5) { + } else if (packets.ticks > 5) { debug("type=%s ticks=%s", event.getType(), packets.ticks); } } else { @@ -97,7 +97,7 @@ public boolean onReceive(PacketInfo event) { } private static void kickPlayer(Player player) { - if(Atlas.getInstance().getBungeeManager().isBungee()) { + if (Atlas.getInstance().getBungeeManager().isBungee()) { BungeeAPI.kickPlayer(player.getUniqueId(), "Too many packets"); } else RunUtils.task(() -> player.kickPlayer("Too many packets")); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignCrash.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignCrash.java index 3aab25c1c..b8ce9b392 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignCrash.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignCrash.java @@ -20,7 +20,7 @@ public void onSignChange(SignChangeEvent event) { val optional = Arrays.stream(event.getLines()) .filter(s -> s.length() > 100).findFirst(); - if(optional.isPresent()) { + if (optional.isPresent()) { vl++; flag("length=%s", optional.get().length()); event.setCancelled(true); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignOp.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignOp.java index 7e1675f7b..a11c8b98d 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignOp.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/SignOp.java @@ -18,7 +18,7 @@ public void onSign(SignChangeEvent event) { val optional = Arrays.stream(event.getLines()) .filter(string -> string.toLowerCase().contains("run_command")) .findFirst(); - if(optional.isPresent()) { + if (optional.isPresent()) { vl++; flag("line=%s", optional.get()); event.setCancelled(true); diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/WindowCrash.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/WindowCrash.java index ff9fc4595..50f0f1379 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/WindowCrash.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/exploits/WindowCrash.java @@ -13,7 +13,7 @@ public class WindowCrash extends Check { @Packet public boolean onWindow(WrappedInWindowClickPacket packet) { - if(packet.getSlot() < 0 && packet.getSlot() != -999 && packet.getSlot() != -1) { + if (packet.getSlot() < 0 && packet.getSlot() != -999 && packet.getSlot() != -1) { vl++; flag("Sent slot %s", packet.getSlot()); return true; @@ -21,11 +21,11 @@ public boolean onWindow(WrappedInWindowClickPacket packet) { InventoryView view = data.getPlayer().getOpenInventory(); int maxSlots = 0; - if(view.getBottomInventory().getType() == InventoryType.PLAYER && view.getTopInventory().getType() == InventoryType.CRAFTING) { + if (view.getBottomInventory().getType() == InventoryType.PLAYER && view.getTopInventory().getType() == InventoryType.CRAFTING) { maxSlots = view.countSlots() + 4; } else maxSlots = view.countSlots(); - if(packet.getSlot() > maxSlots) { + if (packet.getSlot() > maxSlots) { vl++; flag("Sent bad slot %s>-%s", packet.getSlot(), maxSlots); return true; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/timer/TimerA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/timer/TimerA.java index 5e60b958e..b2caa92bd 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/timer/TimerA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/packet/timer/TimerA.java @@ -33,7 +33,7 @@ public void onTeleport(WrappedOutPositionPacket event) { @Packet public void onBlockPlace(WrappedInBlockPlacePacket packet) { //In versions 1.17 and newer, players will send an extra flying when right clicking - if(data.playerVersion.isOrAbove(ProtocolVersion.v1_17)) + if (data.playerVersion.isOrAbove(ProtocolVersion.v1_17)) totalTimer-= 50; } @@ -41,13 +41,13 @@ public void onBlockPlace(WrappedInBlockPlacePacket packet) { //can infinitely never flag if a user was cheating on a 1.9+ client. @Packet public void onTransaction(WrappedInTransactionPacket packet, long now) { - if(data.playerVersion.isBelow(ProtocolVersion.V1_9)) return; + if (data.playerVersion.isBelow(ProtocolVersion.V1_9)) return; Kauri.INSTANCE.keepaliveProcessor.getKeepById(packet.getAction()).ifPresent(ka -> { long delta = now - ka.startStamp; //We want to make sure the player isn't lagging before we reset their timer. - if(delta < 1095L && totalTimer - (now + 100) > 3000L) { + if (delta < 1095L && totalTimer - (now + 100) > 3000L) { totalTimer = now - 300; } }); @@ -57,7 +57,7 @@ public void onTransaction(WrappedInTransactionPacket packet, long now) { public void onFlying(WrappedInFlyingPacket packet, long now) { check: { //This means we haven't started counting - if(totalTimer == -1) { + if (totalTimer == -1) { totalTimer = data.creation - 50; debug("Set base time"); } @@ -70,7 +70,7 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { boolean isLagProblem = (Kauri.INSTANCE.keepaliveProcessor.laggyPlayers / (double)Kauri.INSTANCE.keepaliveProcessor.totalPlayers) > 0.8; - if(totalTimer > threshold + if (totalTimer > threshold //If most players on the server are lagging, it's very likely we have an unstable netty thread //and therefore cannot rely on this detection. && !isLagProblem) { @@ -81,7 +81,7 @@ public void onFlying(WrappedInFlyingPacket packet, long now) { totalTimer = now - 80; debug("Reset time"); lastFlag.reset(); - } else if(lastFlag.isPassed(5000L)) buffer = 0; + } else if (lastFlag.isPassed(5000L)) buffer = 0; debug("d=%s, thr=%s, b=%s lp=%s cp=%s", delta, threshold, buffer, isLagProblem, (data.lagInfo.lastPingDrop.isPassed(4) diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockA.java index 1e2cab7ec..0bb351fcd 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockA.java @@ -31,15 +31,15 @@ public void onBlock(WrappedInBlockPlacePacket event) { double dist = delta.distance(dir), dist2 = opposite.distance(MathUtils.getDirection(data.playerInfo.to).setY(0)); boolean check = dist <= 1 && dist > 0.7 && dist2 >= 0.5 && dist2 < 1; - if(check && event.getFace().getAdjacentY() == 0 + if (check && event.getFace().getAdjacentY() == 0 && event.getPlayer().getItemInHand().getType().isBlock() && data.playerInfo.sprinting) { - if((buffer+= 4) > 15) { + if ((buffer+= 4) > 15) { vl++; flag("dist=%.3f dist2=%.3f placeVec=%s", dist, dist2, dir.toString()); buffer = 14; } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; debug("dist=%.3f dist2=%.3f", dist, dist2); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockB.java index ed4b48e9b..999af91c3 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockB.java @@ -22,34 +22,34 @@ public class BlockB extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet, long timestamp) { - if(data.playerInfo.creative || data.excuseNextFlying) return; + if (data.playerInfo.creative || data.excuseNextFlying) return; - if(place) { + if (place) { long delta = timestamp - lastPlace; - if(delta >= 25) { - if(++buffer >= 10f) { + if (delta >= 25) { + if (++buffer >= 10f) { vl++; flag(""); } - } else if(vl > 0) vl-= 0.25f; + } else if (vl > 0) vl-= 0.25f; place = false; } } @Packet public void onBlockPlace(WrappedInBlockPlacePacket packet, long timestamp) { - if(data.pastLocations.isEmpty()) return; + if (data.pastLocations.isEmpty()) return; KLocation lastMovePacket = data.pastLocations.getLast().one; - if(lastMovePacket == null) return; + if (lastMovePacket == null) return; final long delta = timestamp - lastMovePacket.timeStamp; - if(delta <= 25) { + if (delta <= 25) { lastPlace = timestamp; place = true; - } else if(buffer > 0) buffer-= 0.25f; + } else if (buffer > 0) buffer-= 0.25f; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockC.java index 094b3b75f..9f13a0c6b 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockC.java @@ -44,19 +44,19 @@ public void onBlockPlace(WrappedInBlockPlacePacket event) { Location loc = event.getBlockPosition().toBukkitVector().toLocation(event.getPlayer().getWorld()); Optional optionalBlock = BlockUtils.getBlockAsync(loc); - if(!optionalBlock.isPresent()) return; + if (!optionalBlock.isPresent()) return; final Block block = optionalBlock.get(); CollisionBox box = BlockData.getData(block.getType()).getBox(block, data.playerVersion); - if(!(box instanceof SimpleCollisionBox)) { + if (!(box instanceof SimpleCollisionBox)) { debug("Not SimpleCollisionBox"); return; } final SimpleCollisionBox simpleBox = ((SimpleCollisionBox) box); - if(Math.abs(simpleBox.yMax - simpleBox.yMin) != 1. + if (Math.abs(simpleBox.yMax - simpleBox.yMin) != 1. || Math.abs(simpleBox.xMax - simpleBox.xMin) != 1. || Math.abs(simpleBox.zMax - simpleBox.zMin) != 1.) { debug("not full block: x=%.1f y=%.1f z=%.1f", @@ -91,8 +91,8 @@ public void onFlying(WrappedInFlyingPacket packet) { final boolean collided = rayTo.isCollided(box) || rayFrom.isCollided(box); - if(!collided) { - if(verbose.add() > 4) { + if (!collided) { + if (verbose.add() > 4) { vl++; flag("to=[x=%.1f y=%.1f z=%.1f yaw=%.1f pitch=%.1f] loc=[%.1f,%.1f,%.1f]", to.x, to.y, to.z, to.yaw, from.pitch, diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockG.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockG.java index d3ed825f2..8bc43695a 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockG.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/block/BlockG.java @@ -19,7 +19,7 @@ public class BlockG extends Check { @Packet public void onFlying(WrappedInFlyingPacket packet) { - if(packet.isLook()) { + if (packet.isLook()) { aimCount++; rotChange+= Math.abs(data.playerInfo.deltaYaw) + Math.abs(data.playerInfo.deltaPitch); } @@ -28,11 +28,11 @@ public void onFlying(WrappedInFlyingPacket packet) { @Event public void onBlockPlace(BlockPlaceEvent event) { BlockFace face = event.getBlockPlaced().getFace(event.getBlockAgainst()); - if((Math.abs(aimCount - lastAimCount) <= 1 && aimCount > 2 && rotChange > 100) + if ((Math.abs(aimCount - lastAimCount) <= 1 && aimCount > 2 && rotChange > 100) || (aimCount <= 5 && rotChange > 300 && event.getPlayer().getLocation().distanceSquared(event.getBlockPlaced().getLocation()) <= 4 && event.getPlayer().getLocation().getY() > event.getBlockPlaced().getY() + 0.8)) { - if(++buffer > 3) { + if (++buffer > 3) { vl++; flag("a=%s,r=%.2f,b=%s", aimCount, rotChange, buffer); } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandA.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandA.java index 44f131fda..f3a6c1bf8 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandA.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandA.java @@ -20,19 +20,19 @@ public class HandA extends Check { @Packet public void use(WrappedInBlockPlacePacket packet, long current) { long delta = current - lastFlying; - if(delta < 10 && data.lagInfo.lastPacketDrop.isPassed(1)) { - if(++buffer > 7) { + if (delta < 10 && data.lagInfo.lastPacketDrop.isPassed(1)) { + if (++buffer > 7) { vl++; flag("delta=%s", delta); } - } else if(buffer > 0) buffer--; + } else if (buffer > 0) buffer--; debug("delta=%sms buffer=%s", delta, buffer); } @Packet public void flying(WrappedInFlyingPacket packet, long current) { - if(data.playerInfo.lastTeleportTimer.isPassed(0) && !data.excuseNextFlying) + if (data.playerInfo.lastTeleportTimer.isPassed(0) && !data.excuseNextFlying) lastFlying = current; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandB.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandB.java index 05c243448..6a2736a93 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandB.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandB.java @@ -20,8 +20,8 @@ public class HandB extends Check { public void onDig(WrappedInBlockDigPacket packet, long timeStamp) { long delta = timeStamp - lastFlying; - if(!data.lagInfo.lagging && data.lagInfo.lastPacketDrop.isPassed(5) && delta < 10) { - if(vl++ > 6) { + if (!data.lagInfo.lagging && data.lagInfo.lastPacketDrop.isPassed(5) && delta < 10) { + if (vl++ > 6) { flag("delta=%sms action=%s", delta, packet.getAction().name()); } } else vl-= vl > 0 ? 1f : 0; @@ -31,7 +31,7 @@ public void onDig(WrappedInBlockDigPacket packet, long timeStamp) { @Packet public void onFlying(WrappedInFlyingPacket packet, long current) { - if(data.playerInfo.lastTeleportTimer.isPassed(0)) + if (data.playerInfo.lastTeleportTimer.isPassed(0)) lastFlying = current; } } diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandC.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandC.java index 55bccef62..601c65ee4 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandC.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandC.java @@ -20,8 +20,8 @@ public class HandC extends Check { public void onUse(WrappedInUseEntityPacket packet, long timeStamp) { long delta = timeStamp - lastBlockDig; - if(!data.lagInfo.lagging && data.lagInfo.lastPacketDrop.isPassed(5) && delta < 10) { - if(vl++ > 3) { + if (!data.lagInfo.lagging && data.lagInfo.lastPacketDrop.isPassed(5) && delta < 10) { + if (vl++ > 3) { flag("delta=%sms", delta); } } else vl-= vl > 0 ? 0.5f : 0; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandD.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandD.java index e771bb50b..3ccfa18c5 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandD.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandD.java @@ -18,9 +18,9 @@ public class HandD extends Check { @Packet public void onFlying(WrappedInUseEntityPacket packet) { - if(!packet.getAction().equals(WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK)) return; + if (!packet.getAction().equals(WrappedInUseEntityPacket.EnumEntityUseAction.ATTACK)) return; - if(attackTicks++ > 3 + if (attackTicks++ > 3 && data.playerInfo.lastFlyingTimer.isNotPassed(1) && !data.lagInfo.lagging) { vl++; diff --git a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandE.java b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandE.java index 7e52c3268..a52b455cd 100644 --- a/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandE.java +++ b/Detections/src/main/java/dev/brighten/anticheat/check/impl/world/hand/HandE.java @@ -12,13 +12,13 @@ public class HandE extends Check { @Packet public void onUse(WrappedInUseEntityPacket packet) { - if(!(packet.getEntity() instanceof Player) || packet.getVec() == null) return; + if (!(packet.getEntity() instanceof Player) || packet.getVec() == null) return; double x = Math.abs(packet.getVec().a), y = Math.abs(packet.getVec().b), z = Math.abs(packet.getVec().c); debug("x=%.2f y=%.2f z=%.2f", x, y, z); - if(packet.getVec().a == -1 && packet.getVec().b == -1 && packet.getVec().c == -1) return; + if (packet.getVec().a == -1 && packet.getVec().b == -1 && packet.getVec().c == -1) return; - if(x > 0.4001 || y > 1.901 || z > 0.4001) { + if (x > 0.4001 || y > 1.901 || z > 0.4001) { vl++; flag("size too large"); } diff --git a/Impl/src/main/java/dev/brighten/anticheat/Kauri.java b/Impl/src/main/java/dev/brighten/anticheat/Kauri.java index f18149a84..33908f75a 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/Kauri.java +++ b/Impl/src/main/java/dev/brighten/anticheat/Kauri.java @@ -118,7 +118,7 @@ public void unload(boolean reload) { Bukkit.getScheduler().cancelTasks(this); //Cancelling all Bukkit tasks for this plugin. MiscUtils.printToConsole("&7Unloading Discord Webhooks..."); - if(DiscordAPI.INSTANCE != null) DiscordAPI.INSTANCE.unload(); + if (DiscordAPI.INSTANCE != null) DiscordAPI.INSTANCE.unload(); DiscordAPI.INSTANCE = null; try { @@ -137,12 +137,12 @@ public void unload(boolean reload) { Check.checkClasses.clear(); Check.checkSettings.clear(); Atlas.getInstance().getPacketProcessor().removeListeners(Kauri.INSTANCE); - if(!reload) { + if (!reload) { PacketProcessor.incomingPackets.clear(); PacketProcessor.outgoingPackets.clear(); } - if(reload) { + if (reload) { SystemUtil.CRC_32 = new CRC32(); } @@ -151,13 +151,13 @@ public void unload(boolean reload) { MiscUtils.printToConsole("&7Finshing up nullification..."); msgHandler = null; onReload.clear(); - if(!reload) + if (!reload) onReload = null; KauriAPI.INSTANCE.service.shutdown(); KauriAPI.INSTANCE.dataManager = null; KauriAPI.INSTANCE.exemptHandler = null; KauriAPI.INSTANCE = null; - if(!reload) + if (!reload) tps = null; dev.brighten.anticheat.utils.MiscUtils.testers.clear(); //Shutting down threads. @@ -167,7 +167,7 @@ public void unload(boolean reload) { Atlas.getInstance().getBukkitCommandManagers().remove(Kauri.INSTANCE.getDescription().getName()); commandManager = null; - if(!reload) + if (!reload) INSTANCE = null; MiscUtils.printToConsole("&aCompleted shutdown process."); } @@ -195,10 +195,10 @@ public void runTpsTask() { currentTick++; long currentTime = System.currentTimeMillis(); - if(currentTime - lastTick > 120) { + if (currentTime - lastTick > 120) { lastTickLag.reset(); } - if(ticks.get() >= 10) { + if (ticks.get() >= 10) { ticks.set(0); tps.add(500D / (currentTime - lastTimeStamp.get()) * 20); lastTimeStamp.set(currentTime); diff --git a/Impl/src/main/java/dev/brighten/anticheat/check/api/Check.java b/Impl/src/main/java/dev/brighten/anticheat/check/api/Check.java index 51296da29..fbfb5e922 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/check/api/Check.java +++ b/Impl/src/main/java/dev/brighten/anticheat/check/api/Check.java @@ -83,13 +83,13 @@ public class Check implements KauriCheck { public T find(Class clazz) { Check check = detectionCache.computeIfAbsent(clazz, key -> { - if(!clazz.isAnnotationPresent(CheckInfo.class)) { + if (!clazz.isAnnotationPresent(CheckInfo.class)) { return null; } return data.checkManager.checks.get(clazz.getAnnotation(CheckInfo.class).name()); }); - if(check != null) + if (check != null) return clazz.cast(check); return null; @@ -100,7 +100,7 @@ public void setData(ObjectData data) { } public static void register(Class checkRawClass) { - if(!checkRawClass.isAnnotationPresent(CheckInfo.class)) { + if (!checkRawClass.isAnnotationPresent(CheckInfo.class)) { Log.warn("Attempted to register class {} without CheckInfo annotations", checkRawClass.getName()); return; @@ -111,7 +111,7 @@ public static void register(Class checkRawClass) { String name = info.name(); CancelType type = null; - if(checkRawClass.isAnnotationPresent(Cancellable.class)) { + if (checkRawClass.isAnnotationPresent(Cancellable.class)) { type = checkRawClass.getAnnotation(Cancellable.class).cancelType(); } @@ -152,7 +152,7 @@ public static void register(Class checkRawClass) { private static void runLoop(CheckSettings settings) { for(String executableCommand : settings.executableCommands) { - if(executableCommand.equals("%global_commands%")) { + if (executableCommand.equals("%global_commands%")) { settings.executableCommands.remove(executableCommand); settings.executableCommands.addAll(Config.punishCommands); runLoop(settings); @@ -190,11 +190,11 @@ private String addPlaceHolders(String string) { public void flag(boolean devAlerts, int resetVLTime, String information, Object... variables) { Kauri.INSTANCE.loggingThread.execute(() -> { - if(Kauri.INSTANCE.getTps() < 18) + if (Kauri.INSTANCE.getTps() < 18) vl = 0; - if(KauriAPI.INSTANCE.exemptHandler.isExempt(data.uuid, checkType)) return; - if(System.currentTimeMillis() - lastFlagRun < 50L) return; + if (KauriAPI.INSTANCE.exemptHandler.isExempt(data.uuid, checkType)) return; + if (System.currentTimeMillis() - lastFlagRun < 50L) return; lastFlagRun = System.currentTimeMillis(); final String finalInformation = String.format(information, variables); @@ -208,26 +208,26 @@ public void flag(boolean devAlerts, int resetVLTime, String information, Object. .onFlag(data.getPlayer(), this, information, currentResult.isCancelled()); } - if(currentResult.isCancelled()) return; + if (currentResult.isCancelled()) return; - if(cancellable && cancelMode != null && vl > vlToFlag) { + if (cancellable && cancelMode != null && vl > vlToFlag) { cancelAction(cancelMode); } boolean dev = devAlerts || (!devStage.isRelease() || vl <= vlToFlag) || Kauri.INSTANCE.getTps() < 18; - if(lastAlert.isPassed(resetVLTime)) vl = 0; + if (lastAlert.isPassed(resetVLTime)) vl = 0; final String info = finalInformation .replace("%p", String.valueOf(data.lagInfo.transPing)) .replace("%t", String.valueOf(MathUtils.round(Kauri.INSTANCE.getTps(), 2))); - if(vl > 0) Kauri.INSTANCE.loggerManager.addLog(data, this, info); + if (vl > 0) Kauri.INSTANCE.loggerManager.addLog(data, this, info); if (lastAlert.isPassed(MathUtils.millisToTicks(Config.alertsDelay))) { //Sending Discord webhook alert - if(DiscordAPI.INSTANCE != null) + if (DiscordAPI.INSTANCE != null) DiscordAPI.INSTANCE.sendFlag(data.getPlayer(), this, dev, vl); List components = new ArrayList<>(); - if(dev) { + if (dev) { components.add(new TextComponent(createTxt("&8[&cDev&8] "))); } val text = createTxt(Kauri.INSTANCE.msgHandler.getLanguage().msg("cheat-alert", @@ -245,12 +245,12 @@ public void flag(boolean devAlerts, int resetVLTime, String information, Object. TextComponent[] toSend = components.toArray(new TextComponent[0]); - if(Config.testMode && (dev ? !Kauri.INSTANCE.dataManager.hasAlerts.contains(data.uuid.hashCode()) + if (Config.testMode && (dev ? !Kauri.INSTANCE.dataManager.hasAlerts.contains(data.uuid.hashCode()) : !Kauri.INSTANCE.dataManager.devAlerts.contains(data.uuid.hashCode()))) data.getPlayer().spigot().sendMessage(toSend); - if(Config.alertsConsole) MiscUtils.printToConsole(new TextComponent(toSend).toPlainText()); - if(!dev) { + if (Config.alertsConsole) MiscUtils.printToConsole(new TextComponent(toSend).toPlainText()); + if (!dev) { synchronized (Kauri.INSTANCE.dataManager.hasAlerts) { for (int data : Kauri.INSTANCE.dataManager.hasAlerts.toArray(new int[0])) { Kauri.INSTANCE.dataManager.dataMap.get(data).getPlayer().spigot().sendMessage(toSend); @@ -296,7 +296,7 @@ public void cancelAction(CancelType type) { } public void cancelAction(CancelType type, boolean overrideUserSetting) { - if(!cancellable && !overrideUserSetting) return; + if (!cancellable && !overrideUserSetting) return; final List events = KauriAPI.INSTANCE.getAllEvents(); @@ -310,7 +310,7 @@ public void cancelAction(CancelType type, boolean overrideUserSetting) { } // Did an API call say we should cancel this? Then we will cancel - if(currentResult.isCancelled()) { + if (currentResult.isCancelled()) { return; } @@ -340,7 +340,7 @@ public void cancelAction(CancelType type, boolean overrideUserSetting) { public void fixMovementBugs() { BukkitAPI.INSTANCE.setGliding(data.getPlayer(), false); - if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.v1_18)) + if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.v1_18)) RunUtils.task(() -> { synchronized (data.blockInfo.blocks) { for (Block b : data.blockInfo.blocks) { @@ -360,7 +360,7 @@ private String formatAlert(String toFormat, String info) { public void punish() { Kauri.INSTANCE.loggingThread.execute(() -> { - if(devStage.ordinal() > Arrays.stream(DevStage.values()) + if (devStage.ordinal() > Arrays.stream(DevStage.values()) .filter(ds -> ds.name().equalsIgnoreCase(Config.minimumStageBan)).findFirst() .orElseThrow(() -> new IllegalArgumentException("\"" + Config.minimumStageBan + "\" is not a proper DevStage. Options: [Release, Beta, Alpha]")).ordinal() @@ -371,7 +371,7 @@ public void punish() { vl = 0; - if(!executable || (banExempt && Config.punishmentBypassPerm)) return; + if (!executable || (banExempt && Config.punishmentBypassPerm)) return; PunishResult punishResult = PunishResult.builder().cancelled(false) .broadcastMessage(Config.broadcastMessage).commands(executableCommands).build(); @@ -390,10 +390,10 @@ public void punish() { final String broadcastMessage = punishResult.getBroadcastMessage(); final List punishCommands = punishResult.getCommands(); - if(!punishResult.isCancelled()) { + if (!punishResult.isCancelled()) { Kauri.INSTANCE.loggerManager.addPunishment(data, this); - if(!data.banned) { - if(!Config.broadcastMessage.equalsIgnoreCase("off")) { + if (!data.banned) { + if (!Config.broadcastMessage.equalsIgnoreCase("off")) { if (!Config.bungeeBroadcast) { RunUtils.task(() -> { if (!broadcastMessage.equalsIgnoreCase("off")) { @@ -404,7 +404,7 @@ public void punish() { BungeeAPI.broadcastMessage(Color.translate(addPlaceHolders(broadcastMessage))); } } - if(!Config.bungeePunishments) { + if (!Config.bungeePunishments) { RunUtils.task(() -> { ConsoleCommandSender sender = Bukkit.getConsoleSender(); punishCommands. @@ -421,7 +421,7 @@ public void punish() { } data.banned = true; RunUtils.taskLater(() -> { - if(data != null) data.banned = false; + if (data != null) data.banned = false; }, Kauri.INSTANCE, 10); } } @@ -429,7 +429,7 @@ public void punish() { } public void debug(String information, Object... variables) { - if(data.debugging.size() == 0) return; + if (data.debugging.size() == 0) return; Kauri.INSTANCE.loggingThread.execute(() -> { final String finalInformation = String.format(information, variables); diff --git a/Impl/src/main/java/dev/brighten/anticheat/commands/AlertsCommand.java b/Impl/src/main/java/dev/brighten/anticheat/commands/AlertsCommand.java index e54687de5..fcf6e4c69 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/commands/AlertsCommand.java +++ b/Impl/src/main/java/dev/brighten/anticheat/commands/AlertsCommand.java @@ -19,11 +19,11 @@ public class AlertsCommand extends BaseCommand { public void onCommand(Player player) { ObjectData data = Kauri.INSTANCE.dataManager.getData(player); - if(data != null) { + if (data != null) { synchronized (Kauri.INSTANCE.dataManager.hasAlerts) { boolean hasAlerts = Kauri.INSTANCE.dataManager.hasAlerts.contains(data.uuid.hashCode()); - if(!hasAlerts) { + if (!hasAlerts) { Kauri.INSTANCE.dataManager.hasAlerts.add(data.uuid.hashCode()); player.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage().msg("alerts-on", "&aYou are now viewing cheat alerts.")); @@ -45,10 +45,10 @@ public void onCommand(Player player) { public void onDevAlertsMain(Player player) { ObjectData data = Kauri.INSTANCE.dataManager.getData(player); - if(data != null) { + if (data != null) { synchronized (Kauri.INSTANCE.dataManager.devAlerts) { boolean hasDevAlerts = Kauri.INSTANCE.dataManager.devAlerts.contains(data.uuid.hashCode()); - if(!hasDevAlerts) { + if (!hasDevAlerts) { Kauri.INSTANCE.dataManager.devAlerts.add(data.uuid.hashCode()); player.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage().msg("dev-alerts-on", "&aYou are now viewing developer cheat alerts.")); diff --git a/Impl/src/main/java/dev/brighten/anticheat/commands/BungeeCommand.java b/Impl/src/main/java/dev/brighten/anticheat/commands/BungeeCommand.java index fb81fdd71..64a0c517f 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/commands/BungeeCommand.java +++ b/Impl/src/main/java/dev/brighten/anticheat/commands/BungeeCommand.java @@ -19,11 +19,11 @@ public class BungeeCommand extends BaseCommand { @CommandAlias("bungeecmd") @CommandPermission("kauri.command.bungee") public void onCommand(Player player, String[] args) { - if(!bungeeCmd) { + if (!bungeeCmd) { player.sendMessage(Color.Red + "Bungee command is disabled!"); return; } - if(args.length == 0) { + if (args.length == 0) { player.sendMessage(Color.Red + "Invalid arguments."); return; } diff --git a/Impl/src/main/java/dev/brighten/anticheat/commands/KauriCommand.java b/Impl/src/main/java/dev/brighten/anticheat/commands/KauriCommand.java index 3d3c11652..cdb8bed99 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/commands/KauriCommand.java +++ b/Impl/src/main/java/dev/brighten/anticheat/commands/KauriCommand.java @@ -54,7 +54,7 @@ public KauriCommand() { contexts.registerOptionalContext(Integer.class, c -> { String arg = c.popFirstArg(); - if(arg == null) return null; + if (arg == null) return null; try { return Integer.parseInt(arg); } catch(NumberFormatException e) { @@ -77,8 +77,8 @@ public static void onHelp(CommandSender sender, CommandHelp help) { @CommandPermission("kauri.command.test") @Description("Toggle test debug alerts") public void onTest(Player player) { - if(MiscUtils.testers.contains(player.getUniqueId())) { - if(MiscUtils.testers.remove(player.getUniqueId())) { + if (MiscUtils.testers.contains(player.getUniqueId())) { + if (MiscUtils.testers.remove(player.getUniqueId())) { player.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("tester-remove-success", "&cRemoved you from test messaging for developers.")); } else player.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() @@ -97,11 +97,11 @@ public void onTest(Player player) { public void onCommand(Player player) { ObjectData data = Kauri.INSTANCE.dataManager.getData(player); - if(data != null) { + if (data != null) { synchronized (Kauri.INSTANCE.dataManager.hasAlerts) { boolean hasAlerts = Kauri.INSTANCE.dataManager.hasAlerts.contains(data.uuid.hashCode()); - if(!hasAlerts) { + if (!hasAlerts) { Kauri.INSTANCE.dataManager.hasAlerts.add(data.uuid.hashCode()); player.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage().msg("alerts-on", "&aYou are now viewing cheat alerts.")); @@ -123,10 +123,10 @@ public void onCommand(Player player) { public void onDevAlertsMain(Player player) { ObjectData data = Kauri.INSTANCE.dataManager.getData(player); - if(data != null) { + if (data != null) { synchronized (Kauri.INSTANCE.dataManager.devAlerts) { boolean hasDevAlerts = Kauri.INSTANCE.dataManager.devAlerts.contains(data.uuid.hashCode()); - if(!hasDevAlerts) { + if (!hasDevAlerts) { Kauri.INSTANCE.dataManager.devAlerts.add(data.uuid.hashCode()); player.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage().msg("dev-alerts-on", "&aYou are now viewing developer cheat alerts.")); @@ -149,12 +149,12 @@ public void onDevAlertsMain(Player player) { public void onCommand(Player player, @Single String check, @Optional OnlinePlayer target) { ObjectData data = Kauri.INSTANCE.dataManager.getData(player); - if(data == null) { + if (data == null) { player.sendMessage(Color.Red + "There was an error trying to find your data object."); return; } - if(check.equalsIgnoreCase("none")) { + if (check.equalsIgnoreCase("none")) { for (ObjectData tdata : Kauri.INSTANCE.dataManager.dataMap.values()) { synchronized (tdata.boxDebuggers) { tdata.boxDebuggers.remove(player); @@ -169,8 +169,8 @@ public void onCommand(Player player, @Single String check, @Optional OnlinePlaye } else { final Player targetPlayer = target != null ? target.getPlayer() : player; final ObjectData targetData = Kauri.INSTANCE.dataManager.getData(targetPlayer); - if(check.equalsIgnoreCase("sniff")) { - if(!targetData.sniffing) { + if (check.equalsIgnoreCase("sniff")) { + if (!targetData.sniffing) { player.sendMessage("Sniffing + " + targetPlayer.getName()); targetData.sniffing = true; } else { @@ -186,7 +186,7 @@ public void onCommand(Player player, @Single String check, @Optional OnlinePlaye targetData.sniffedPackets.clear(); } } else { - if(Check.isCheck(check.replace("_", " "))) { + if (Check.isCheck(check.replace("_", " "))) { targetData.debugging.put(player.getUniqueId(), check.replace("_", " ")); player.sendMessage(Color.Green + "You are now debugging " + check @@ -204,15 +204,15 @@ public void onCommand(Player player, @Single String check, @Optional OnlinePlaye @CommandPermission("kauri.command.block") public void onBlock(CommandSender sender, @Optional String block) { Material material; - if(block != null) { - if(MiscUtils.isInteger(block)) { + if (block != null) { + if (MiscUtils.isInteger(block)) { material = Material.getMaterial(Integer.parseInt(block)); } else material = Arrays.stream(Material.values()) .filter(mat -> mat.name().equalsIgnoreCase(block)).findFirst() .orElse((XMaterial.AIR.parseMaterial())); - } else if(sender instanceof Player) { + } else if (sender instanceof Player) { Player player = (Player) sender; - if(player.getItemInHand() != null) { + if (player.getItemInHand() != null) { material = player.getItemInHand().getType(); } else { sender.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() @@ -226,7 +226,7 @@ public void onBlock(CommandSender sender, @Optional String block) { return; } - if(material != null) { + if (material != null) { sender.sendMessage(cc.funkemunky.api.utils.MiscUtils.line(Color.Dark_Gray)); sender.sendMessage(Color.Gold + Color.Bold + material.name() + Color.Gray + ":"); sender.sendMessage(""); @@ -257,7 +257,7 @@ public void onBlock(CommandSender sender, @Optional String block) { public void onDebugBox(Player player, @Optional OnlinePlayer target) { String[] debuggingPlayers; ObjectData.debugBoxes(false, player); - if(target == null) { + if (target == null) { ObjectData.debugBoxes(true, player, player.getUniqueId()); debuggingPlayers = new String[] {player.getName()}; } else { @@ -394,7 +394,7 @@ public void onLagGc(CommandSender sender) { public void onLagPlayer(CommandSender sender, OnlinePlayer target) { ObjectData data = Kauri.INSTANCE.dataManager.getData(target.getPlayer()); - if(data != null) { + if (data != null) { StringUtils.Messages.LINE.send(sender); StringUtils.sendMessage(sender, Color.Gold + Color.Bold + target.getPlayer().getName() + "'s Lag Information"); @@ -411,7 +411,7 @@ public void onLagPlayer(CommandSender sender, OnlinePlayer target) { @Description("Debug collision boxes") @CommandPermission("kauri.command.wand") public void onWand(Player player) { - if(Arrays.stream(player.getInventory().getContents()) + if (Arrays.stream(player.getInventory().getContents()) .anyMatch(item -> item == null || item.getType().equals(XMaterial.AIR.parseMaterial()))) { player.getInventory().addItem(BukkitListener.MAGIC_WAND); player.updateInventory(); @@ -429,13 +429,13 @@ public void onWand(Player player) { @CommandPermission("kauri.command.info") public void onCommand(Player player, String[] args) { Kauri.INSTANCE.executor.execute(() -> { - if(args.length > 0) { + if (args.length > 0) { Player target = Bukkit.getPlayer(args[0]); - if(target != null) { + if (target != null) { ObjectData targetData = Kauri.INSTANCE.dataManager.getData(target); - if(targetData != null) { + if (targetData != null) { PlayerInformationGUI info = new PlayerInformationGUI(targetData); RunUtils.task(() -> { @@ -457,7 +457,7 @@ public void onCommand(Player player, String[] args) { @CommandPermission("kauri.command.simlag") public void onSimLag(CommandSender sender, @Optional Integer amount) { PacketProcessor.simLag = !PacketProcessor.simLag; - if(amount != null) + if (amount != null) PacketProcessor.amount = amount; sender.sendMessage(String.format(Color.translate("&aSimLag (%s): " @@ -492,7 +492,7 @@ public void onReload(CommandSender sender) { @CommandCompletion("@checks") public void onCommand(CommandSender sender, @Single String check) { Kauri.INSTANCE.executor.execute(() -> { - if(Check.isCheck(check)) { + if (Check.isCheck(check)) { CheckInfo checkInfo = Check.getCheckInfo(check.replace("_", " ")); String path = "checks." + checkInfo.name() + ".enabled"; diff --git a/Impl/src/main/java/dev/brighten/anticheat/commands/LogCommand.java b/Impl/src/main/java/dev/brighten/anticheat/commands/LogCommand.java index d1cd829ea..083752419 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/commands/LogCommand.java +++ b/Impl/src/main/java/dev/brighten/anticheat/commands/LogCommand.java @@ -38,8 +38,8 @@ public class LogCommand extends BaseCommand { @Description("View the logs of a user") public void onCommand(CommandSender sender, String[] args) { Kauri.INSTANCE.executor.execute(() -> { - if(args.length == 0) { - if(sender instanceof Player) { + if (args.length == 0) { + if (sender instanceof Player) { Player player = (Player) sender; LogsGUI gui = new LogsGUI(player.getName(), player.getUniqueId()); RunUtils.task(() -> { @@ -54,14 +54,14 @@ public void onCommand(CommandSender sender, String[] args) { } else { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); - if(player == null) { + if (player == null) { sender.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("offline-player-not-found", "&cSomehow, out of hundreds of millions of" + "Minecraft accounts, you found one that doesn't exist.")); return; } - if(sender instanceof Player) { + if (sender instanceof Player) { LogsGUI gui = new LogsGUI(player.getName(), player.getUniqueId()); RunUtils.task(() -> { gui.showMenu((Player) sender); @@ -83,8 +83,8 @@ public void onCommand(CommandSender sender, String[] args) { @Description("View the logs of a user") public void onLogsWeb(CommandSender sender, String[] args) { Kauri.INSTANCE.executor.execute(() -> { - if(args.length == 0) { - if(sender instanceof Player) { + if (args.length == 0) { + if (sender instanceof Player) { Player player = (Player) sender; runWebLog(sender, player); @@ -95,7 +95,7 @@ public void onLogsWeb(CommandSender sender, String[] args) { } else { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); - if(player == null) { + if (player == null) { sender.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("offline-player-not-found", "&cSomehow, out of hundreds of millions of" + "Minecraft accounts, you found one that doesn't exist.")); @@ -114,21 +114,21 @@ public void onLogsWeb(CommandSender sender, String[] args) { @CommandCompletion("@players") @Description("Clear logs of a player") public void onLogsClear(CommandSender sender, String[] args) { - if(args.length > 0) { + if (args.length > 0) { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); - if(player == null) { + if (player == null) { sender.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("offline-player-not-found", "&cSomehow, out of hundreds of millions of" + "Minecraft accounts, you found one that doesn't exist.")); return; } - if(sender instanceof Player) { + if (sender instanceof Player) { ConfirmationMenu menu = new ConfirmationMenu( "Clear " + player.getName() + "'s logs?", (pl, confirmed) -> { - if(confirmed) { + if (confirmed) { Kauri.INSTANCE.executor.execute(() -> { sender.sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("clearing-logs", "&7Clearing logs from %player%...") @@ -158,7 +158,7 @@ private void runWebLog(CommandSender sender, OfflinePlayer target) { Map violations = new HashMap<>(); for (Log log : logs) { violations.compute(log.checkName, (name, count) -> { - if(count == null) { + if (count == null) { return 1; } @@ -222,7 +222,7 @@ public static String getLogsFromUUID(UUID uuid) { List logs = Kauri.INSTANCE.loggerManager.getLogs(uuid, null, 0, 2000, 0, System.currentTimeMillis()); List punishments = Kauri.INSTANCE.loggerManager.getPunishments(uuid); - if(logs.size() == 0) return "No Logs"; + if (logs.size() == 0) return "No Logs"; String body; diff --git a/Impl/src/main/java/dev/brighten/anticheat/commands/MenuCommand.java b/Impl/src/main/java/dev/brighten/anticheat/commands/MenuCommand.java index 22b1c70ed..2bc524f28 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/commands/MenuCommand.java +++ b/Impl/src/main/java/dev/brighten/anticheat/commands/MenuCommand.java @@ -241,7 +241,7 @@ private static ChestMenu getChecksMenu(CheckType type) { .forEach(data -> { Check check = data.checkManager.checks.get(val.name); - if(check == null) { + if (check == null) { Kauri.INSTANCE.getLogger() .warning("Check " + val.name + " is null for player " + data.getPlayer()); @@ -278,7 +278,7 @@ private static ChestMenu getChecksMenu(CheckType type) { .forEach(data -> { Check check = data.checkManager.checks.get(val.name); - if(check == null) { + if (check == null) { Kauri.INSTANCE.getLogger() .warning("Check " + val.name + " is null for player " + data.getPlayer()); @@ -316,7 +316,7 @@ private static ChestMenu getChecksMenu(CheckType type) { .forEach(data -> { Check check = data.checkManager.checks.get(val.name); - if(check == null) { + if (check == null) { Kauri.INSTANCE.getLogger() .warning("Check " + val.name + " is null for player " + data.getPlayer()); @@ -395,7 +395,7 @@ public static ChestMenu getCheckEdit(CheckSettings settings) { .forEach(data -> { Check check = data.checkManager.checks.get(settings.name); - if(check == null) { + if (check == null) { Kauri.INSTANCE.getLogger() .warning("Check " + settings.name + " is null for player " + data.getPlayer()); @@ -427,7 +427,7 @@ public static ChestMenu getCheckEdit(CheckSettings settings) { .forEach(data -> { Check check = data.checkManager.checks.get(settings.name); - if(check == null) { + if (check == null) { Kauri.INSTANCE.getLogger() .warning("Check " + settings.name + " is null for player " + data.getPlayer()); @@ -460,7 +460,7 @@ public static ChestMenu getCheckEdit(CheckSettings settings) { .forEach(data -> { Check check = data.checkManager.checks.get(settings.name); - if(check == null) { + if (check == null) { Kauri.INSTANCE.getLogger() .warning("Check " + settings.name + " is null for player " + data.getPlayer()); diff --git a/Impl/src/main/java/dev/brighten/anticheat/data/ObjectData.java b/Impl/src/main/java/dev/brighten/anticheat/data/ObjectData.java index 4317eec00..22d1b1fe8 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/data/ObjectData.java +++ b/Impl/src/main/java/dev/brighten/anticheat/data/ObjectData.java @@ -112,9 +112,9 @@ public ObjectData(UUID uuid) { || Atlas.getInstance().getBungeeManager().isAtlasBungeeInstalled(); //Alerts from database update - if(getPlayer().hasPermission("kauri.command.alerts")) { + if (getPlayer().hasPermission("kauri.command.alerts")) { Kauri.INSTANCE.loggerManager.storage.alertsStatus(uuid, result -> { - if(result) { + if (result) { synchronized (Kauri.INSTANCE.dataManager.hasAlerts) { Kauri.INSTANCE.dataManager.hasAlerts.add(uuid.hashCode()); } @@ -124,9 +124,9 @@ public ObjectData(UUID uuid) { }); } - if(getPlayer().hasPermission("kauri.command.alerts.dev")) { + if (getPlayer().hasPermission("kauri.command.alerts.dev")) { Kauri.INSTANCE.loggerManager.storage.devAlertsStatus(uuid, result -> { - if(result) { + if (result) { synchronized (Kauri.INSTANCE.dataManager.devAlerts) { Kauri.INSTANCE.dataManager.devAlerts.add(uuid.hashCode()); } @@ -176,7 +176,7 @@ public void unregister() { Kauri.INSTANCE.dataManager.hasAlerts.remove(uuid.hashCode()); Kauri.INSTANCE.dataManager.devAlerts.remove(uuid.hashCode()); Kauri.INSTANCE.dataManager.dataMap.remove(uuid.hashCode()); - if(checkManager != null) { + if (checkManager != null) { checkManager.checkMethods.clear(); checkManager.checks.clear(); checkManager = null; @@ -218,7 +218,7 @@ public int[] getReceived() { int[] toReturn = new int[] {0, 0}; val op = Kauri.INSTANCE.keepaliveProcessor.getResponse(this); - if(op.isPresent()) { + if (op.isPresent()) { toReturn[0] = op.get().start; val op2 = op.get().getReceived(uuid); @@ -274,7 +274,7 @@ public void runInstantAction(Consumer runnable, boolean flush) { } public void sendPacket(Object packet) { - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { + if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { TinyProtocol1_8 tp = (TinyProtocol1_8) TinyProtocolHandler.getInstance(); tp.sendPacket(tp.getChannel(player), packet); } else { @@ -292,7 +292,7 @@ public int runKeepaliveAction(Consumer action, int later) { } public Player getPlayer() { - if(player == null) { + if (player == null) { this.player = Bukkit.getPlayer(uuid); } return this.player; @@ -314,14 +314,14 @@ public static void debugBoxes(boolean debugging, Player debugger) { debugBoxes(debugging, debugger, new ObjectData[0]); } public static void debugBoxes(boolean debugging, Player debugger, ObjectData... targets) { - if(!debugging) { + if (!debugging) { List toRemove = targets.length == 0 ? new ArrayList<>(Kauri.INSTANCE.dataManager.dataMap.values()) : Arrays.asList(targets); toRemove.stream() .filter(d -> d.boxDebuggers.contains(debugger)) .forEach(d -> d.boxDebuggers.remove(debugger)); - } else if(targets.length > 0) { + } else if (targets.length > 0) { Arrays.stream(targets).forEach(d -> d.boxDebuggers.add(debugger)); } } diff --git a/Impl/src/main/java/dev/brighten/anticheat/data/classes/BlockInformation.java b/Impl/src/main/java/dev/brighten/anticheat/data/classes/BlockInformation.java index 40090f4a3..6234681fa 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/data/classes/BlockInformation.java +++ b/Impl/src/main/java/dev/brighten/anticheat/data/classes/BlockInformation.java @@ -58,7 +58,7 @@ public BlockInformation(ObjectData objectData) { } public void runCollisionCheck() { - if(!Kauri.INSTANCE.enabled + if (!Kauri.INSTANCE.enabled || Kauri.INSTANCE.lastEnabled.isNotPassed(6)) return; @@ -73,9 +73,9 @@ public void runCollisionCheck() { = onIce = onSoulSand = blocksAbove = collidesVertically = bedNear = collidesHorizontally = blocksNear = inBlock = miscNear = collidedWithEntity = blocksBelow = inPortal = false; - if(dy > 10) dy = 10; - else if(dy < -10) dy = -10; - if(dh > 10) dh = 10; + if (dy > 10) dy = 10; + else if (dy < -10) dy = -10; + if (dh > 10) dh = 10; int startX = Location.locToBlock(objectData.playerInfo.to.x - 1 - dh); int endX = Location.locToBlock(objectData.playerInfo.to.x + 1 + dh); @@ -141,7 +141,7 @@ public void runCollisionCheck() { if (it-- <= 0) { break start; } - if(y > 400 || y < -50) continue; + if (y > 400 || y < -50) continue; Block block = chunk.getBlock(x & 15, y, z & 15); final Material type = block.getType(); if (type != Material.AIR) { @@ -150,59 +150,59 @@ public void runCollisionCheck() { CollisionBox blockBox = BlockData.getData(type) .getBox(block, objectData.playerVersion); - if(blockBox.isCollided(normalBox)) { - if(type.equals(cobweb)) + if (blockBox.isCollided(normalBox)) { + if (type.equals(cobweb)) inWeb = true; - else if(type.equals(scaffolding)) inScaffolding = true; - else if(type.equals(honey)) inHoney = true; + else if (type.equals(scaffolding)) inScaffolding = true; + else if (type.equals(honey)) inHoney = true; } - if(type.equals(rosebush)) + if (type.equals(rosebush)) roseBush = true; - if(normalBox.copy().offset(0, 0.6f, 0).isCollided(blockBox)) + if (normalBox.copy().offset(0, 0.6f, 0).isCollided(blockBox)) blocksAbove = true; - if(normalBox.copy().expand(1, -0.0001, 1).isIntersected(blockBox)) + if (normalBox.copy().expand(1, -0.0001, 1).isIntersected(blockBox)) blocksNear = true; - if(normalBox.copy().expand(0.1, 0, 0.1) + if (normalBox.copy().expand(0.1, 0, 0.1) .offset(0, 1,0).isCollided(blockBox)) { synchronized (aboveCollisions) { blockBox.downCast(aboveCollisions); } } - if(normalBox.copy().expand(0.1, 0, 0.1).offset(0, -1, 0) + if (normalBox.copy().expand(0.1, 0, 0.1).offset(0, -1, 0) .isCollided(blockBox)) { synchronized (belowCollisions) { blockBox.downCast(belowCollisions); } - if(Materials.checkFlag(type, Materials.FENCE) + if (Materials.checkFlag(type, Materials.FENCE) || Materials.checkFlag(type, Materials.WALL)) { fenceBelow = true; } } - if(normalBox.copy().expand(0.25, 0, 0.25) + if (normalBox.copy().expand(0.25, 0, 0.25) .offset(0, -0.8, 0).isCollided(blockBox) && (Materials.checkFlag(type, Materials.FENCE) || Materials.checkFlag(type, Materials.WALL))) { fenceNear = true; } - if(Materials.checkFlag(type, Materials.SOLID)) { + if (Materials.checkFlag(type, Materials.SOLID)) { SimpleCollisionBox groundBox = normalBox.copy() .offset(0, -.49, 0).expandMax(0, -1.2, 0); XMaterial blockMaterial = getXMaterial(type); - if(normalBox.copy().expand(0.4, 0, 0.4).expandMin(0, -1, 0) + if (normalBox.copy().expand(0.4, 0, 0.4).expandMin(0, -1, 0) .isIntersected(blockBox)) blocksBelow = true; - if(normalBox.isIntersected(blockBox)) inBlock = true; + if (normalBox.isIntersected(blockBox)) inBlock = true; SimpleCollisionBox box = objectData.box.copy(); @@ -217,14 +217,14 @@ public void runCollisionCheck() { if (blockBox.isCollided(box)) collidesVertically = true; - if(groundBox.copy().expandMin(0, -0.8, 0).expand(0.2, 0, 0.2) + if (groundBox.copy().expandMin(0, -0.8, 0).expand(0.2, 0, 0.2) .isIntersected(blockBox)) objectData.playerInfo.nearGround = true; - if(groundBox.isCollided(blockBox)) { + if (groundBox.isCollided(blockBox)) { objectData.playerInfo.serverGround = true; - if(blockMaterial != null) + if (blockMaterial != null) switch (blockMaterial) { case ICE: case BLUE_ICE: @@ -243,7 +243,7 @@ public void runCollisionCheck() { } } } - if(objectData.playerInfo.deltaY > 0 + if (objectData.playerInfo.deltaY > 0 && objectData.playerVersion.isBelow(ProtocolVersion.V1_14) && Materials.checkFlag(type, Materials.LADDER) && normalBox.copy().expand(0.2f, 0, 0.2f) @@ -251,13 +251,13 @@ public void runCollisionCheck() { onClimbable = true; } - if(blockMaterial != null) { + if (blockMaterial != null) { switch (blockMaterial) { case PISTON: case PISTON_HEAD: case MOVING_PISTON: case STICKY_PISTON: { - if(normalBox.copy().expand(0.5, 0.5, 0.5) + if (normalBox.copy().expand(0.5, 0.5, 0.5) .isCollided(blockBox)) pistonNear = true; break; @@ -265,14 +265,14 @@ public void runCollisionCheck() { } } - if(groundBox.copy().expand(0.5, 0.6, 0.5).isCollided(blockBox)) { - if(Materials.checkFlag(type, Materials.SLABS)) + if (groundBox.copy().expand(0.5, 0.6, 0.5).isCollided(blockBox)) { + if (Materials.checkFlag(type, Materials.SLABS)) onSlab = true; else - if(Materials.checkFlag(type, Materials.STAIRS)) + if (Materials.checkFlag(type, Materials.STAIRS)) onStairs = true; else - if(blockMaterial != null) + if (blockMaterial != null) switch(blockMaterial) { case CAKE: case BREWING_STAND: @@ -315,10 +315,10 @@ public void runCollisionCheck() { } } } - } else if(blockBox.isCollided(normalBox)) { + } else if (blockBox.isCollided(normalBox)) { XMaterial blockMaterial = getXMaterial(type); - if(blockMaterial != null) + if (blockMaterial != null) switch(blockMaterial) { case END_PORTAL: case NETHER_PORTAL: { @@ -335,7 +335,7 @@ public void runCollisionCheck() { } } - if(!objectData.playerInfo.worldLoaded) + if (!objectData.playerInfo.worldLoaded) return; CollisionHandler handler = new CollisionHandler(blocks, @@ -347,25 +347,25 @@ public void runCollisionCheck() { for (Entity entity : handler.getEntities()) { CollisionBox entityBox = EntityData.getEntityBox(entity.getLocation(), entity); - if(entityBox == null) continue; + if (entityBox == null) continue; - if(entityBox.isCollided(normalBox.copy().offset(0, -.25, 0))) + if (entityBox.isCollided(normalBox.copy().offset(0, -.25, 0))) objectData.playerInfo.serverGround = true; - if(entityBox.isCollided(normalBox)) + if (entityBox.isCollided(normalBox)) collidedWithEntity = true; } //Bukkit.broadcastMessage("chigga5"); onHalfBlock = onSlab || onStairs || miscNear || bedNear; - if((objectData.playerInfo.deltaY <= 0 || objectData.playerVersion.isOrAbove(ProtocolVersion.V1_14)) + if ((objectData.playerInfo.deltaY <= 0 || objectData.playerVersion.isOrAbove(ProtocolVersion.V1_14)) && !onClimbable) { onClimbable = objectData.playerInfo.blockOnTo != null && BlockUtils.isClimbableBlock(objectData.playerInfo.blockOnTo); } - if(objectData.boxDebuggers.size() > 0) { + if (objectData.boxDebuggers.size() > 0) { handler.setSize(4, 4); handler.setOffset(-1); handler.getCollisionBoxes().forEach(cb -> cb.draw(WrappedEnumParticle.FLAME, objectData.boxDebuggers)); diff --git a/Impl/src/main/java/dev/brighten/anticheat/data/classes/CheckManager.java b/Impl/src/main/java/dev/brighten/anticheat/data/classes/CheckManager.java index 5303fa634..d72434b1d 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/data/classes/CheckManager.java +++ b/Impl/src/main/java/dev/brighten/anticheat/data/classes/CheckManager.java @@ -33,18 +33,18 @@ public CheckManager(ObjectData objectData) { * @param timeStamp Long time of packet received */ public void runPacket(NMSObject object, long timeStamp) { - if(objectData.bypassing) return; + if (objectData.bypassing) return; val methods = checkMethods.get(object.getClass()); - if(methods == null) return; + if (methods == null) return; int currentTick = Kauri.INSTANCE.currentTick; for (WrappedCheck wrapped : methods) { try { - if(!wrapped.isBoolean && wrapped.isPacket && wrapped.check.enabled && wrapped.isCompatible()) { - if(wrapped.oneParam) wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object); + if (!wrapped.isBoolean && wrapped.isPacket && wrapped.check.enabled && wrapped.isCompatible()) { + if (wrapped.oneParam) wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object); else { - if(wrapped.isTimeStamp) { + if (wrapped.isTimeStamp) { wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object, timeStamp); } else wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object, currentTick); } @@ -58,23 +58,23 @@ public void runPacket(NMSObject object, long timeStamp) { } public boolean runPacketCancellable(NMSObject object, long timeStamp) { - if(objectData.bypassing) return false; + if (objectData.bypassing) return false; val methods = checkMethods.get(object.getClass()); - if(methods == null) return false; + if (methods == null) return false; int currentTick = Kauri.INSTANCE.currentTick; boolean cancelled = false; for (WrappedCheck wrapped : methods) { - if(!wrapped.isBoolean) continue; + if (!wrapped.isBoolean) continue; try { - if(wrapped.isPacket && wrapped.check.enabled && wrapped.isCompatible()) { - if(wrapped.oneParam) { - if((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object)) cancelled = true; - } else if(wrapped.isTimeStamp) { - if((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object, timeStamp)) + if (wrapped.isPacket && wrapped.check.enabled && wrapped.isCompatible()) { + if (wrapped.oneParam) { + if ((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object)) cancelled = true; + } else if (wrapped.isTimeStamp) { + if ((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object, timeStamp)) cancelled = true; - } else if((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object, currentTick)) + } else if ((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, object, currentTick)) cancelled = true; } } catch(Exception e) { @@ -87,14 +87,14 @@ public boolean runPacketCancellable(NMSObject object, long timeStamp) { } public void runEvent(Event event) { - if(objectData.bypassing) return; + if (objectData.bypassing) return; synchronized (checkMethods) { val methods = checkMethods.get(event.getClass()); - if(methods == null) return; + if (methods == null) return; for (WrappedCheck wrapped : methods) { - if(wrapped.isEvent && wrapped.check.enabled) { + if (wrapped.isEvent && wrapped.check.enabled) { try { wrapped.access.invoke(wrapped.check, wrapped.methodIndex, event); } catch(Exception e) { @@ -108,29 +108,29 @@ public void runEvent(Event event) { } public boolean runEvent(Object event) { - if(objectData.bypassing) return false; + if (objectData.bypassing) return false; val methods = checkMethods.get(event.getClass()); - if(methods == null) return false; + if (methods == null) return false; boolean cancelled = false; for (WrappedCheck wrapped : methods) { - if(!wrapped.isPacket && wrapped.check.enabled) { - if(!wrapped.isBoolean) { + if (!wrapped.isPacket && wrapped.check.enabled) { + if (!wrapped.isBoolean) { wrapped.access.invoke(wrapped.check, wrapped.methodIndex, event); - } else if((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, event)) cancelled = true; + } else if ((boolean)wrapped.access.invoke(wrapped.check, wrapped.methodIndex, event)) cancelled = true; } } return cancelled; } public void runEvent(AtlasEvent event) { - if(objectData.bypassing || !checkMethods.containsKey(event.getClass())) return; + if (objectData.bypassing || !checkMethods.containsKey(event.getClass())) return; val methods = checkMethods.get(event.getClass()); for (WrappedCheck wrapped : methods) { - if(!wrapped.isPacket && wrapped.check.enabled) { + if (!wrapped.isPacket && wrapped.check.enabled) { wrapped.access.invoke(wrapped.check, wrapped.methodIndex, event); } } @@ -138,12 +138,12 @@ public void runEvent(AtlasEvent event) { public void addChecks() { assert objectData != null: "ObjectData is null in CheckManager"; - if(objectData.getPlayer() + if (objectData.getPlayer() .hasPermission("kauri.bypass") && Config.flagBypassPerm) return; //Whitelisting players with prefix for bedrock users - if(!Config.prefixWhitelist.equals("disabled") + if (!Config.prefixWhitelist.equals("disabled") && objectData.getPlayer().getName().startsWith(Config.prefixWhitelist)) return; synchronized (checks) { @@ -189,7 +189,7 @@ public void addChecks() { new ArrayList<>()); methods.add(new WrappedCheck(check, method)); - if(method.getMethod().isAnnotationPresent(Packet.class)) { + if (method.getMethod().isAnnotationPresent(Packet.class)) { methods.sort(Comparator.comparing(m -> m.method.getMethod().getAnnotation(Packet.class).priority().getPriority())); } else { diff --git a/Impl/src/main/java/dev/brighten/anticheat/data/classes/PredictionService.java b/Impl/src/main/java/dev/brighten/anticheat/data/classes/PredictionService.java index 70ae84f14..1285974fc 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/data/classes/PredictionService.java +++ b/Impl/src/main/java/dev/brighten/anticheat/data/classes/PredictionService.java @@ -27,7 +27,7 @@ public PredictionService(ObjectData data) { public void onReceive(WrappedInFlyingPacket packet) { error = true; //Will be stay true if something went wrong - if(data.playerInfo.to == null || data.playerInfo.from == null) return; + if (data.playerInfo.to == null || data.playerInfo.from == null) return; //Updating position and look values motionX = data.playerInfo.deltaX; @@ -39,13 +39,13 @@ public void onReceive(WrappedInFlyingPacket packet) { onGround = data.playerInfo.lClientGround; //Calculations - if(packet.isPos()) { + if (packet.isPos()) { //Checking for other conditions that may cause us problems - if(velocity) { + if (velocity) { lmotionX = data.playerInfo.velocityX; lmotionZ = data.playerInfo.velocityZ; } - if(!velocity + if (!velocity && !data.blockInfo.inLiquid && !data.playerInfo.onLadder //If player is not moving but sending positions anyway @@ -53,7 +53,7 @@ public void onReceive(WrappedInFlyingPacket packet) { //When a player jumps, we don't want to check since we don't have math for it and checking for jump //can be unreliable && !(!data.playerInfo.clientGround && data.playerInfo.lClientGround && (lSprinting || sprinting))) { - if(lSprinting && hit) { + if (lSprinting && hit) { lmotionX*= 0.6; lmotionZ*= 0.6; } @@ -72,13 +72,13 @@ public void onReceive(WrappedInFlyingPacket packet) { } //Miscellanious caveat updating - if(dropItem) usingItem = dropItem = false; + if (dropItem) usingItem = dropItem = false; //lMotion calculations lmotionX = motionX; lmotionZ = motionZ; - if(!error) { + if (!error) { lmotionX*= drag; lmotionZ*= drag; } @@ -95,7 +95,7 @@ private void calculateNewPosition() { calculation: { float cstrafe = (float)strafe, cforward = (float)forward; - if(sneaking) { + if (sneaking) { cstrafe*= .3; cforward*= .3; } @@ -106,7 +106,7 @@ private void calculateNewPosition() { aiMoveSpeed = data.getPlayer().getWalkSpeed() / 2f; - if(sprinting) aiMoveSpeed+= aiMoveSpeed * 0.3f; + if (sprinting) aiMoveSpeed+= aiMoveSpeed * 0.3f; data.potionProcessor.getEffectByType(PotionEffectType.SPEED).ifPresent(speed -> aiMoveSpeed+= (speed.getAmplifier() + 1) * (double)0.2f * aiMoveSpeed); @@ -115,12 +115,12 @@ private void calculateNewPosition() { double motionForward; - if(onGround) { + if (onGround) { Block underBlock = BlockUtils.getBlock(data.playerInfo.to .toLocation(data.getPlayer().getWorld()) .clone().subtract(0, 1, 0)); - if(underBlock == null) + if (underBlock == null) break calculation; drag*= MinecraftReflection.getFriction(underBlock); @@ -130,7 +130,7 @@ private void calculateNewPosition() { double keyedMotion = cforward * cforward + cstrafe + cstrafe; - if(keyedMotion >= 1.0E-4F) { + if (keyedMotion >= 1.0E-4F) { keyedMotion = motionForward / Math.max(1.0, Math.sqrt(keyedMotion)); cforward*= keyedMotion; cstrafe*= keyedMotion; @@ -221,7 +221,7 @@ private void calcKey(double mx, double mz) { forward = moveF; this.key = key; - /*if(data.getPlayer().getName().equals("Dogeritoz")) { + /*if (data.getPlayer().getName().equals("Dogeritoz")) { Bukkit.broadcastMessage("key=" + key + " mx=" + MathUtils.round(mx, 6) + " mz=" + MathUtils.round(mz, 6) + " myaw=" + MathUtils.round(motionYaw, 4) + " velocity=" + velocity + " vx=" + data.playerInfo.velocityX + " vz=" + data.playerInfo.velocityZ); diff --git a/Impl/src/main/java/dev/brighten/anticheat/data/classes/WrappedCheck.java b/Impl/src/main/java/dev/brighten/anticheat/data/classes/WrappedCheck.java index 52b8fa856..ff388b903 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/data/classes/WrappedCheck.java +++ b/Impl/src/main/java/dev/brighten/anticheat/data/classes/WrappedCheck.java @@ -30,7 +30,7 @@ public WrappedCheck(Check check, WrappedMethod method) { methodIndex = this.access.getIndex(method.getName(), method.getMethod().getParameterTypes()); - if(!oneParam) { + if (!oneParam) { isTick = method.getMethod().getParameterTypes()[1] == int.class; isTimeStamp = !isTick; } @@ -39,9 +39,9 @@ public WrappedCheck(Check check, WrappedMethod method) { } public boolean isCompatible() { - if(didVersionCheck) return canRunWithVersion; + if (didVersionCheck) return canRunWithVersion; - if(!check.data.playerVersion.equals(ProtocolVersion.UNKNOWN)) { + if (!check.data.playerVersion.equals(ProtocolVersion.UNKNOWN)) { didVersionCheck = true; return this.canRunWithVersion = check.data.playerVersion.isOrBelow(check.maxVersion) && check.data.playerVersion.isOrAbove(check.minVersion); diff --git a/Impl/src/main/java/dev/brighten/anticheat/discord/DiscordAPI.java b/Impl/src/main/java/dev/brighten/anticheat/discord/DiscordAPI.java index 1e776408c..e2a6eb21e 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/discord/DiscordAPI.java +++ b/Impl/src/main/java/dev/brighten/anticheat/discord/DiscordAPI.java @@ -51,7 +51,7 @@ public DiscordAPI() { private static boolean devAlerts = false; public void load() { - if(!enabled) { + if (!enabled) { MiscUtils.printToConsole("&7Discord webhooks not enabled. Cancelling..."); return; } @@ -72,7 +72,7 @@ public void load() { author = new WebhookEmbed.EmbedAuthor("Kauri", "https://i.imgur.com/QkJPEor.jpg", "https://i.imgur.com/QkJPEor.jpg"); - if(startMsg) + if (startMsg) client.send(new WebhookMessageBuilder().setUsername(author.getName()).setAvatarUrl(author.getIconUrl()) .setContent("Started webhook").build()); } @@ -81,7 +81,7 @@ public void load() { public void unload() { MiscUtils.printToConsole("&cUnloading Discord Webhook..."); - if(client != null) { + if (client != null) { client.close(); client = null; } @@ -95,12 +95,12 @@ public void unload() { private static final int banRed = 0xD9471A, noBanOrange = 0xE8A83A, flagYellow = 0xFFEB33; public void sendBan(Player player, KauriCheck check, boolean exempt) { - if(!enabled) return; - if(!sendBans || client == null || (!devAlerts && check.getDevStage() != DevStage.RELEASE)) return; + if (!enabled) return; + if (!sendBans || client == null || (!devAlerts && check.getDevStage() != DevStage.RELEASE)) return; lastDiscordSend.compute(player.getUniqueId(), (key, lastTime) -> { long now = System.currentTimeMillis(); - if(lastTime == null || now - lastTime > delay) { + if (lastTime == null || now - lastTime > delay) { client.send(new WebhookEmbedBuilder().setAuthor(author) .setColor(check.isExecutable() || exempt ? banRed : noBanOrange) .setTitle(new WebhookEmbed.EmbedTitle("Kauri Ban", "")) @@ -120,11 +120,11 @@ public void sendBan(Player player, KauriCheck check, boolean exempt) { } public void sendFlag(Player player, KauriCheck check, boolean dev, float vl) { - if(!enabled) return; - if(!sendAlerts || client == null || (!devAlerts && dev)) return; + if (!enabled) return; + if (!sendAlerts || client == null || (!devAlerts && dev)) return; lastDiscordSend.compute(player.getUniqueId(), (key, lastTime) -> { long now = System.currentTimeMillis(); - if(lastTime == null || now - lastTime > delay) { + if (lastTime == null || now - lastTime > delay) { client.send(new WebhookEmbedBuilder().setAuthor(author).setColor(flagYellow) .setTitle(new WebhookEmbed.EmbedTitle("Kauri Flag", "")) .addField(field("Player", player.getName())) diff --git a/Impl/src/main/java/dev/brighten/anticheat/listeners/BukkitCheckListeners.java b/Impl/src/main/java/dev/brighten/anticheat/listeners/BukkitCheckListeners.java index b642dfa5b..cfbc19e3a 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/listeners/BukkitCheckListeners.java +++ b/Impl/src/main/java/dev/brighten/anticheat/listeners/BukkitCheckListeners.java @@ -20,11 +20,11 @@ public class BukkitCheckListeners implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onInteract(PlayerInteractEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.playerInfo.breakingBlock = event.getAction().equals(Action.LEFT_CLICK_BLOCK); data.checkManager.runEvent(event); } @@ -32,13 +32,13 @@ public void onInteract(PlayerInteractEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onDamage(EntityDamageByEntityEvent event) { - if(event.getDamager() instanceof Player) { + if (event.getDamager() instanceof Player) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getDamager().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getDamager().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData((Player) event.getDamager()); - if(data != null) { + if (data != null) { data.checkManager.runEvent(event); } } @@ -47,11 +47,11 @@ public void onDamage(EntityDamageByEntityEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onMove(PlayerMoveEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.checkManager.runEvent(event); } } @@ -60,13 +60,13 @@ public void onMove(PlayerMoveEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onEvent(PlayerTeleportEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.moveProcessor.moveTo(event.getTo()); - if(data.checkManager != null) + if (data.checkManager != null) data.checkManager.runEvent(event); } } @@ -74,13 +74,13 @@ public void onEvent(PlayerTeleportEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onEvent(PlayerRespawnEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.moveProcessor.moveTo(event.getRespawnLocation()); - if(data.checkManager != null) + if (data.checkManager != null) data.checkManager.runEvent(event); } } @@ -88,11 +88,11 @@ public void onEvent(PlayerRespawnEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onBlock(BlockPlaceEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.checkManager.runEvent(event); } } @@ -100,11 +100,11 @@ public void onBlock(BlockPlaceEvent event) { @EventHandler(priority = EventPriority.HIGH) public void onBookEdit(PlayerEditBookEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.checkManager.runEvent(event); } } @@ -112,11 +112,11 @@ public void onBookEdit(PlayerEditBookEvent event) { @EventHandler(priority = EventPriority.HIGH) public void onEvent(SignChangeEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) { + if (data != null) { data.checkManager.runEvent(event); } } diff --git a/Impl/src/main/java/dev/brighten/anticheat/listeners/BungeeListener.java b/Impl/src/main/java/dev/brighten/anticheat/listeners/BungeeListener.java index c4e420cca..95c90b0ac 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/listeners/BungeeListener.java +++ b/Impl/src/main/java/dev/brighten/anticheat/listeners/BungeeListener.java @@ -28,19 +28,19 @@ public class BungeeListener implements AtlasListener, Listener { @Listen public void onBungee(BungeeReceiveEvent event) { - if(!Config.bungeeAlerts || event.objects.length != 4) return; + if (!Config.bungeeAlerts || event.objects.length != 4) return; final UUID uuid = (UUID)event.objects[0]; final String checkName = (String)event.objects[1]; final CheckEntry entry = new CheckEntry(uuid, checkName); final Timer lastAlert; - if(!lastAlertsMap.containsKey(entry)) { + if (!lastAlertsMap.containsKey(entry)) { lastAlert = new AtlasTimer(MathUtils.millisToTicks(Config.alertsDelay)); lastAlertsMap.put(entry, lastAlert); } else { lastAlert = lastAlertsMap.get(entry); } - if(lastAlert.isPassed(MathUtils.millisToTicks(Config.alertsDelay))) { + if (lastAlert.isPassed(MathUtils.millisToTicks(Config.alertsDelay))) { final float vl = (float)event.objects[2]; final String info = (String)event.objects[3]; diff --git a/Impl/src/main/java/dev/brighten/anticheat/listeners/CancelListeners.java b/Impl/src/main/java/dev/brighten/anticheat/listeners/CancelListeners.java index 2392e8213..4faffa2b2 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/listeners/CancelListeners.java +++ b/Impl/src/main/java/dev/brighten/anticheat/listeners/CancelListeners.java @@ -25,14 +25,14 @@ public class CancelListeners implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onEvent(PlayerMoveEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null && data.typesToCancel.size() > 0) { + if (data != null && data.typesToCancel.size() > 0) { data.playerInfo.lastMoveCancel.reset(); for (CancelType cancelType : data.typesToCancel) { - if(!cancelType.equals(CancelType.MOVEMENT)) continue; + if (!cancelType.equals(CancelType.MOVEMENT)) continue; val ground = event.getTo().getWorld().equals(data.playerInfo.setbackLocation.getWorld()) ? data.playerInfo.setbackLocation @@ -50,16 +50,16 @@ public void onEvent(PlayerMoveEvent event) { /** Cancels for ATTACK **/ @EventHandler(priority = EventPriority.MONITOR) public void onEvent(EntityDamageByEntityEvent event) { - if(!(event.getDamager() instanceof Player)) return; + if (!(event.getDamager() instanceof Player)) return; //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getDamager().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getDamager().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData((Player)event.getDamager()); - if(data != null && data.typesToCancel.size() > 0) { + if (data != null && data.typesToCancel.size() > 0) { for (CancelType cancelType : data.typesToCancel) { - if(!cancelType.equals(CancelType.ATTACK)) continue; + if (!cancelType.equals(CancelType.ATTACK)) continue; event.setCancelled(true); synchronized (data.typesToCancel) { @@ -74,13 +74,13 @@ public void onEvent(EntityDamageByEntityEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onEvent(BlockPlaceEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null && data.typesToCancel.size() > 0) { + if (data != null && data.typesToCancel.size() > 0) { for (CancelType cancelType : data.typesToCancel) { - if(!cancelType.equals(CancelType.PLACE)) continue; + if (!cancelType.equals(CancelType.PLACE)) continue; event.setCancelled(true); synchronized (data.typesToCancel) { @@ -95,12 +95,12 @@ public void onEvent(BlockPlaceEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onEvent(BlockBreakEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null && data.typesToCancel.size() > 0) { + if (data != null && data.typesToCancel.size() > 0) { for (CancelType cancelType : data.typesToCancel) { - if(!cancelType.equals(CancelType.BREAK)) continue; + if (!cancelType.equals(CancelType.BREAK)) continue; event.setCancelled(true); synchronized (data.typesToCancel) { @@ -116,12 +116,12 @@ public void onEvent(BlockBreakEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onEvent(PlayerInteractEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null && data.typesToCancel.size() > 0) { + if (data != null && data.typesToCancel.size() > 0) { for (CancelType cancelType : data.typesToCancel) { - if(!cancelType.equals(CancelType.INTERACT)) continue; + if (!cancelType.equals(CancelType.INTERACT)) continue; event.setCancelled(true); synchronized (data.typesToCancel) { @@ -136,16 +136,16 @@ public void onEvent(PlayerInteractEvent event) { //Done for interacting with entities like NPC or players. @EventHandler(priority = EventPriority.MONITOR) public void onEvent(EntityInteractEvent event) { - if(!(event.getEntity() instanceof Player)) return; + if (!(event.getEntity() instanceof Player)) return; //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getEntity().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getEntity().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData((Player)event.getEntity()); - if(data != null && data.typesToCancel.size() > 0) { + if (data != null && data.typesToCancel.size() > 0) { for (CancelType cancelType : data.typesToCancel) { - if(!cancelType.equals(CancelType.INTERACT)) continue; + if (!cancelType.equals(CancelType.INTERACT)) continue; event.setCancelled(true); synchronized (data.typesToCancel) { diff --git a/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/BukkitListener.java b/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/BukkitListener.java index 837380630..239b0103b 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/BukkitListener.java +++ b/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/BukkitListener.java @@ -46,20 +46,20 @@ public void onJoin(PlayerJoinEvent event) { public void onLeave(PlayerQuitEvent event) { ThreadHandler.INSTANCE.removePlayer(event.getPlayer()); //Removing if the player has debug access so there aren't any null objects left to cause problems later. - if(event.getPlayer().hasPermission("kauri.debug")) + if (event.getPlayer().hasPermission("kauri.debug")) ObjectData.debugBoxes(false, event.getPlayer()); ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data != null) data.unregister(); + if (data != null) data.unregister(); } @EventHandler public void onInteract(PlayerInteractEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; - if(event.getClickedBlock() == null || !event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return; + if (event.getClickedBlock() == null || !event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return; - if(event.getItem() != null && event.getItem().isSimilar(MAGIC_WAND)) { + if (event.getItem() != null && event.getItem().isSimilar(MAGIC_WAND)) { BlockData data = BlockData.getData(event.getClickedBlock().getType()); CollisionBox box = data.getBox(event.getClickedBlock(), ProtocolVersion.getGameVersion()); @@ -82,7 +82,7 @@ public void onInteract(PlayerInteractEvent event) { event.getPlayer().sendMessage("x=" + subbed.getX() + " y=" + subbed.getY() + " z=" + subbed.getZ()); } - if(BlockUtils.isDoor(event.getClickedBlock())) { + if (BlockUtils.isDoor(event.getClickedBlock())) { int direction = (int) BlockStateManager.getInterface("facing", event.getClickedBlock()); boolean open = (boolean) BlockStateManager.getInterface("open", event.getClickedBlock()); boolean hinge = (boolean) BlockStateManager.getInterface("hinge", event.getClickedBlock()); @@ -100,13 +100,13 @@ public void onInteract(PlayerInteractEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void onBlockPlace(BlockPlaceEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(event.getPlayer()); - if(data == null || event.getBlockPlaced() == null) return; + if (data == null || event.getBlockPlaced() == null) return; - if(event.isCancelled()) { + if (event.isCancelled()) { data.ghostBlocks.put(event.getBlockPlaced().getLocation(), BlockData.getData(event.getBlockPlaced().getType()) .getBox(event.getBlockPlaced(), data.playerVersion)); @@ -116,11 +116,11 @@ public void onBlockPlace(BlockPlaceEvent event) { @EventHandler public void onEntityInteract(PlayerInteractEntityEvent event) { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; - if(event.getPlayer().getItemInHand() == null + if (event.getPlayer().getItemInHand() == null || !event.getPlayer().getItemInHand().isSimilar(MAGIC_WAND)) return; - if(MiscUtils.entityDimensions.containsKey(event.getRightClicked().getType())) { + if (MiscUtils.entityDimensions.containsKey(event.getRightClicked().getType())) { Vector dimension = MiscUtils.entityDimensions.get(event.getRightClicked().getType()); SimpleCollisionBox box = new SimpleCollisionBox(event.getRightClicked().getLocation().toVector(), event.getRightClicked().getLocation().toVector()) @@ -146,7 +146,7 @@ public void onEntityInteract(PlayerInteractEntityEvent event) { private static String vectorString = "{%1$.2f, %2$.2f, %3$.2f}"; private static String boxToString(CollisionBox box) { - if(box instanceof SimpleCollisionBox) { + if (box instanceof SimpleCollisionBox) { SimpleCollisionBox sbox = (SimpleCollisionBox) box; return "SimpleCollisionBox[" + vectorToString(sbox.toBoundingBox().getMinimum()) + ", " + vectorToString(sbox.toBoundingBox().getMaximum()) + "]"; diff --git a/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/ChatCheck.java b/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/ChatCheck.java index 1beb0482f..e7a040b12 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/ChatCheck.java +++ b/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/ChatCheck.java @@ -30,15 +30,15 @@ public class ChatCheck { private final PacketListener chatCheckListener = Atlas.getInstance().getPacketProcessor() .process(Kauri.INSTANCE, EventPriority.HIGHEST, event -> { - if(!enabled) return; + if (!enabled) return; //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(event.getPlayer().getUniqueId())) return; WrappedInChatPacket packet = new WrappedInChatPacket(event.getPacket(), event.getPlayer()); - if(packet.getMessage().length() <= 0) return; + if (packet.getMessage().length() <= 0) return; - if(packet.getMessage().length() > lengthMax) { + if (packet.getMessage().length() > lengthMax) { event.getPlayer().sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("msg-too-long", "&8[&6K&8] &cYour chat message was cancelled because it was too long.")); @@ -49,7 +49,7 @@ public class ChatCheck { int max = allowExtendedCharacters ? 591 : 255; for (char c : packet.getMessage().toCharArray()) { - if((int)c > min && (int)c < max || whitelistedCharacters.contains(c)) continue; + if ((int)c > min && (int)c < max || whitelistedCharacters.contains(c)) continue; event.getPlayer().sendMessage(Kauri.INSTANCE.msgHandler.getLanguage() .msg("illegal-chars", diff --git a/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/LagCheck.java b/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/LagCheck.java index d87038bbe..9979e32e7 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/LagCheck.java +++ b/Impl/src/main/java/dev/brighten/anticheat/listeners/generalChecks/LagCheck.java @@ -15,7 +15,7 @@ public class LagCheck extends AtlasEvent { @Listen public void onEvent(TickEvent event) { - if(!enabled || !Kauri.INSTANCE.enabled) return; + if (!enabled || !Kauri.INSTANCE.enabled) return; //We do this to ensure no one is abusing fake lag attempts. long timeStamp = System.currentTimeMillis(); @@ -23,8 +23,8 @@ public void onEvent(TickEvent event) { .parallelStream() .forEach(data -> { //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(data.uuid)) return; - if(timeStamp - data.lagInfo.lastClientTrans > 10000L + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(data.uuid)) return; + if (timeStamp - data.lagInfo.lastClientTrans > 10000L && Kauri.INSTANCE.keepaliveProcessor.tick - data.playerInfo.to.timeStamp < 2L) { data.lagTicks++; diff --git a/Impl/src/main/java/dev/brighten/anticheat/logs/LoggerManager.java b/Impl/src/main/java/dev/brighten/anticheat/logs/LoggerManager.java index eae49df03..9befd6d11 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/logs/LoggerManager.java +++ b/Impl/src/main/java/dev/brighten/anticheat/logs/LoggerManager.java @@ -19,9 +19,9 @@ public class LoggerManager { public DataStorage storage; public LoggerManager() { - if(MongoConfig.enabled) { + if (MongoConfig.enabled) { storage = new MongoStorage(); - } else if(MySQLConfig.enabled) { + } else if (MySQLConfig.enabled) { storage = new MySQLStorage(); } else storage = new FlatfileStorage(); } diff --git a/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/FlatfileStorage.java b/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/FlatfileStorage.java index 48b638f2f..005f97211 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/FlatfileStorage.java +++ b/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/FlatfileStorage.java @@ -70,7 +70,7 @@ public FlatfileStorage() { }); RunUtils.taskTimerAsync(() -> { - if(logs.size() > 0) { + if (logs.size() > 0) { synchronized (logs) { final StringBuilder values = new StringBuilder(); @@ -86,7 +86,7 @@ public FlatfileStorage() { objectsToInsert.add(log.tps); objectsToInsert.add(log.info); - if(++amount >= 150) break; + if (++amount >= 150) break; } for (int i = 0; i < amount; i++) { @@ -98,7 +98,7 @@ public FlatfileStorage() { .append(objectsToInsert.toArray()); - if(MySQLConfig.debugMessages) + if (MySQLConfig.debugMessages) Kauri.INSTANCE.getLogger().log(Level.INFO, "Inserted " + amount + " logs into the database."); @@ -107,7 +107,7 @@ public FlatfileStorage() { objectsToInsert.clear(); } } - if(punishments.size() > 0) { + if (punishments.size() > 0) { synchronized (punishments) { final StringBuilder values = new StringBuilder(); @@ -119,7 +119,7 @@ public FlatfileStorage() { objectsToInsert.add(punishment.timeStamp); objectsToInsert.add(punishment.checkName); - if(++amount >= 150) break; + if (++amount >= 150) break; } for (int i = 0; i < amount; i++) { @@ -130,7 +130,7 @@ public FlatfileStorage() { "(`uuid`,`time`,`check`) values " + values) .append(objectsToInsert.toArray()); - if(MySQLConfig.debugMessages) + if (MySQLConfig.debugMessages) Kauri.INSTANCE.getLogger().log(Level.INFO, "Inserted " + amount + " punishments into the database."); @@ -142,7 +142,7 @@ public FlatfileStorage() { @Override public void shutdown() { - if(task != null) { + if (task != null) { task.cancel(); task = null; } @@ -160,7 +160,7 @@ public void importFromFlatfile(Consumer result) { public List getLogs(UUID uuid, Check check, int arrayMin, int arrayMax, long timeFrom, long timeTo) { List logs = new ArrayList<>(); - if(uuid != null) { + if (uuid != null) { Query.prepare("select `time`, `vl`, `check`, `ping`, `tps`, `info` " + "from `violations` where `uuid` = ?"+ (check != null ? " and where `check` = " + check.name : "") + " and `time` between ? and ? order by `time` desc limit ?,?") @@ -191,7 +191,7 @@ public List getLogs(UUID uuid, Check check, int arrayMin, int arrayMax, lon public List getPunishments(UUID uuid, int arrayMin, int arrayMax, long timeFrom, long timeTo) { List punishments = new ArrayList<>(); - if(uuid != null) { + if (uuid != null) { Query.prepare("select `time`, `check` from `punishments` " + "where `uuid` = ? and TIME between ? and ? order by `time` desc limit ?,?") .append(uuid.toString()).append(timeFrom).append(timeTo).append(arrayMin).append(arrayMax) @@ -217,10 +217,10 @@ public List getHighestVL(UUID uuid, Check check, int limit, long timeFrom, Map logsMax = new HashMap<>(); logs.forEach(log -> { - if(logsMax.containsKey(log.checkName)) { + if (logsMax.containsKey(log.checkName)) { Log toCheck = logsMax.get(log.checkName); - if(toCheck.vl < log.vl) { + if (toCheck.vl < log.vl) { logsMax.put(log.checkName, log); } } else logsMax.put(log.checkName, log); @@ -268,10 +268,10 @@ public UUID getUUIDFromName(String name) { while(rs.next()) { String uuidString = rs.getString("uuid"); - if(uuidString != null) { + if (uuidString != null) { UUID uuid = UUID.fromString(rs.getString("uuid")); - if(System.currentTimeMillis() - rs.getTimestamp("timestamp").getTime() > TimeUnit.DAYS.toMillis(1)) { + if (System.currentTimeMillis() - rs.getTimestamp("timestamp").getTime() > TimeUnit.DAYS.toMillis(1)) { Kauri.INSTANCE.loggingThread.execute(() -> { Query.prepare("delete from `namecache` where `uuid` = ?").append(uuidString).execute(); MiscUtils.printToConsole("Deleted " + uuidString + " from name cache (age > 1 day)."); @@ -298,8 +298,8 @@ public String getNameFromUUID(UUID uuid) { while(rs.next()) { String name = rs.getString("name"); - if(name != null) { - if(System.currentTimeMillis() - rs.getTimestamp("timestamp").getTime() > TimeUnit.DAYS.toMillis(1)) { + if (name != null) { + if (System.currentTimeMillis() - rs.getTimestamp("timestamp").getTime() > TimeUnit.DAYS.toMillis(1)) { Kauri.INSTANCE.loggingThread.execute(() -> { Query.prepare("delete from `namecache` where `name` = ?").append(name).execute(); MiscUtils.printToConsole("Deleted " + name + " from name cache (age > 1 day)."); @@ -317,7 +317,7 @@ public String getNameFromUUID(UUID uuid) { @Override public void updateAlerts(UUID uuid, boolean alertsEnabled) { Kauri.INSTANCE.loggingThread.execute(() -> { - if(alertsEnabled) { + if (alertsEnabled) { Query.prepare("insert into `alerts` (`uuid`) values (?)") .append(uuid.toString()).execute(); } else Query.prepare("delete from `alerts` where `uuid` = ?").append(uuid.toString()).execute(); @@ -327,7 +327,7 @@ public void updateAlerts(UUID uuid, boolean alertsEnabled) { @Override public void updateDevAlerts(UUID uuid, boolean devAlertsEnabled) { Kauri.INSTANCE.loggingThread.execute(() -> { - if(devAlertsEnabled) { + if (devAlertsEnabled) { Query.prepare("insert into `dev_alerts` (`uuid`) values (?)") .append(uuid.toString()).execute(); } else Query.prepare("delete from `dev_alerts` where `uuid` = ?").append(uuid.toString()).execute(); diff --git a/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MongoStorage.java b/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MongoStorage.java index 1ed0c83e9..724def6e0 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MongoStorage.java +++ b/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MongoStorage.java @@ -39,12 +39,12 @@ public class MongoStorage implements DataStorage { public MongoStorage() { MongoClient client; - if(!MongoConfig.connectionURL.equals("This will override your connection details")) { + if (!MongoConfig.connectionURL.equals("This will override your connection details")) { ConnectionString cs = new ConnectionString(MongoConfig.connectionURL); MongoClientSettings settings = MongoClientSettings.builder().applyConnectionString(cs).build(); client = MongoClients.create(settings); } else { - if(MongoConfig.loginDetails) { + if (MongoConfig.loginDetails) { client = MongoClients.create(MongoClientSettings.builder().readPreference(ReadPreference.nearest()).applyToClusterSettings(builder -> builder.hosts(Collections.singletonList(new ServerAddress(MongoConfig.ip, MongoConfig.port)))) .credential(MongoCredential.createCredential(MongoConfig.username, @@ -66,7 +66,7 @@ public MongoStorage() { Kauri.INSTANCE.loggingThread.execute(() -> { AtomicInteger indexes = new AtomicInteger(); logsCollection.listIndexes().forEach((Consumer) doc -> indexes.getAndIncrement()); - if(indexes.get() < 4) { + if (indexes.get() < 4) { MiscUtils.printToConsole("&7Creating indexes for logs..."); MiscUtils.printToConsole("&oCreating uuid index..."); logsCollection.createIndex(Indexes.ascending("uuid")); @@ -78,7 +78,7 @@ public MongoStorage() { } indexes.set(0); logsCollection.listIndexes().forEach((Consumer) doc -> indexes.getAndIncrement()); - if(indexes.get() < 2) { + if (indexes.get() < 2) { MiscUtils.printToConsole("&7Creating index for punishments..."); punishmentsCollection.createIndex(Indexes.ascending("uuid")); MiscUtils.printToConsole("&aCompleted index creation!"); @@ -91,11 +91,11 @@ public MongoStorage() { final List docsToInsert = new ArrayList<>(); while((doc = logs.poll()) != null) { docsToInsert.add(doc); - if(++count >= MongoConfig.batchInsertMax) + if (++count >= MongoConfig.batchInsertMax) break; } - if(count > 0) { + if (count > 0) { logsCollection.insertMany(docsToInsert); docsToInsert.clear(); count = 0; @@ -104,11 +104,11 @@ public MongoStorage() { while((doc = punishments.poll()) != null) { docsToInsert.add(doc); - if(++count >= MongoConfig.batchInsertMax) + if (++count >= MongoConfig.batchInsertMax) break; } - if(count > 0) { + if (count > 0) { punishmentsCollection.insertMany(docsToInsert); docsToInsert.clear(); count = 0; @@ -123,13 +123,13 @@ public List getLogs(UUID uuid, Check check, int arrayMin, int arrayMax, lon List aggregates = new ArrayList<>(); - if(uuid != null) aggregates.add(Aggregates.match(Filters.eq("uuid", uuid.toString()))); - if(check != null) aggregates.add(Aggregates.match(Filters.eq("check", check.name))); + if (uuid != null) aggregates.add(Aggregates.match(Filters.eq("uuid", uuid.toString()))); + if (check != null) aggregates.add(Aggregates.match(Filters.eq("check", check.name))); aggregates.addAll(Arrays.asList(Aggregates.match(Filters.eq("time", document)), new BasicDBObject("$sort", new BasicDBObject("time", -1)))); - if(arrayMin != 0 && arrayMax != Integer.MAX_VALUE) { + if (arrayMin != 0 && arrayMax != Integer.MAX_VALUE) { aggregates.addAll(Arrays.asList(new BasicDBObject("$skip", arrayMin), new BasicDBObject("$limit", arrayMax))); } @@ -231,10 +231,10 @@ public List getHighestVL(UUID uuid, Check check, int limit, long timeFrom, doc.getDouble("vl").floatValue(), doc.getInteger("ping"), doc.getLong("time"), doc.getDouble("tps"))) .forEach(log -> { - if(logsMax.containsKey(log.checkName)) { + if (logsMax.containsKey(log.checkName)) { Log toCheck = logsMax.get(log.checkName); - if(toCheck.vl < log.vl) { + if (toCheck.vl < log.vl) { logsMax.put(log.checkName, log); } } else logsMax.put(log.checkName, log); @@ -279,7 +279,7 @@ public void cacheAPICall(UUID uuid, String name) { public UUID getUUIDFromName(String name) { Document doc = nameUUIDCollection.find(Filters.eq("name", name)).first(); - if(doc != null) { + if (doc != null) { return UUID.fromString(doc.getString("uuid")); } @@ -290,7 +290,7 @@ public UUID getUUIDFromName(String name) { public String getNameFromUUID(UUID uuid) { Document doc = nameUUIDCollection.find(Filters.eq("uuid", uuid.toString())).first(); - if(doc != null) { + if (doc != null) { return doc.getString("name"); } @@ -302,7 +302,7 @@ public void updateAlerts(UUID uuid, boolean alertsEnabled) { Kauri.INSTANCE.loggingThread.execute(() -> { Document doc = alertsCollection.find(Filters.eq("uuid", uuid.toString())).first(); - if(doc == null) { + if (doc == null) { doc = new Document("uuid", uuid.toString()); doc.put("normal", alertsEnabled); doc.put("dev", false); @@ -320,7 +320,7 @@ public void updateDevAlerts(UUID uuid, boolean devAlertsEnabled) { Kauri.INSTANCE.loggingThread.execute(() -> { Document doc = alertsCollection.find(Filters.eq("uuid", uuid.toString())).first(); - if(doc == null) { + if (doc == null) { doc = new Document("uuid", uuid.toString()); doc.put("normal", false); doc.put("dev", devAlertsEnabled); @@ -338,7 +338,7 @@ public void alertsStatus(UUID uuid, Consumer result) { Kauri.INSTANCE.loggingThread.execute(() -> { Document doc = alertsCollection.find(Filters.eq("uuid", uuid.toString())).first(); - if(doc != null) { + if (doc != null) { result.accept(doc.getBoolean("normal")); } else result.accept(false); }); @@ -349,7 +349,7 @@ public void devAlertsStatus(UUID uuid, Consumer result) { Kauri.INSTANCE.loggingThread.execute(() -> { Document doc = alertsCollection.find(Filters.eq("uuid", uuid.toString())).first(); - if(doc != null) { + if (doc != null) { result.accept(doc.getBoolean("dev")); } else result.accept(false); }); diff --git a/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MySQLStorage.java b/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MySQLStorage.java index 906334b09..41b3d5278 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MySQLStorage.java +++ b/Impl/src/main/java/dev/brighten/anticheat/logs/data/impl/MySQLStorage.java @@ -64,7 +64,7 @@ public MySQLStorage() { }); task = Kauri.INSTANCE.loggingThread.scheduleAtFixedRate(() -> { - if(logs.size() > 0) { + if (logs.size() > 0) { synchronized (logs) { final StringBuilder values = new StringBuilder(); @@ -80,7 +80,7 @@ public MySQLStorage() { objectsToInsert.add(log.tps); objectsToInsert.add(log.info); - if(++amount >= 150) break; + if (++amount >= 150) break; } for (int i = 0; i < amount; i++) { @@ -92,7 +92,7 @@ public MySQLStorage() { .append(objectsToInsert.toArray()); - if(MySQLConfig.debugMessages) + if (MySQLConfig.debugMessages) Kauri.INSTANCE.getLogger().log(Level.INFO, "Inserted " + amount + " logs into the database."); @@ -101,7 +101,7 @@ public MySQLStorage() { objectsToInsert.clear(); } } - if(punishments.size() > 0) { + if (punishments.size() > 0) { synchronized (punishments) { String values = IntStream.range(0, Math.min(punishments.size(), 150)).mapToObj(i -> "(?,?,?)") .collect(Collectors.joining(",")); @@ -115,10 +115,10 @@ public MySQLStorage() { statement = statement.append(punishment.uuid.toString()).append(punishment.uuid.toString()) .append(punishment.timeStamp).append(punishment.checkName); - if(++amount >= 150) break; + if (++amount >= 150) break; } - if(MySQLConfig.debugMessages) + if (MySQLConfig.debugMessages) Kauri.INSTANCE.getLogger().log(Level.INFO, "Inserted " + amount + " punishments into the database."); @@ -146,7 +146,7 @@ public void importFromFlatfile(Consumer result) { public List getLogs(UUID uuid, Check check, int arrayMin, int arrayMax, long timeFrom, long timeTo) { List logs = new ArrayList<>(); - if(uuid != null) { + if (uuid != null) { Query.prepare("SELECT `TIME`, `vl`, `CHECK`, `PING`, `TPS`, `INFO` " + "FROM `VIOLATIONS` WHERE `UUID` = ?"+ (check != null ? " AND WHERE `CHECK` = " + check.name : "") + " AND `TIME` BETWEEN ? AND ? ORDER BY `TIME` DESC LIMIT ?,?") @@ -176,7 +176,7 @@ public List getLogs(UUID uuid, Check check, int arrayMin, int arrayMax, lon public List getPunishments(UUID uuid, int arrayMin, int arrayMax, long timeFrom, long timeTo) { List punishments = new ArrayList<>(); - if(uuid != null) { + if (uuid != null) { Query.prepare("SELECT `TIME`, `CHECK` FROM `PUNISHMENTS` " + "WHERE `UUID` = ? AND TIME BETWEEN ? AND ? ORDER BY `TIME` DESC LIMIT ?,?") .append(uuid.toString()).append(timeFrom).append(timeTo).append(arrayMin).append(arrayMax) @@ -247,10 +247,10 @@ public UUID getUUIDFromName(String name) { String uuidString = rs.getString("UUID"); - if(uuidString != null) { + if (uuidString != null) { UUID uuid = UUID.fromString(rs.getString("UUID")); - if(System.currentTimeMillis() - rs.getLong("TIMESTAMP") > TimeUnit.DAYS.toMillis(1)) { + if (System.currentTimeMillis() - rs.getLong("TIMESTAMP") > TimeUnit.DAYS.toMillis(1)) { Kauri.INSTANCE.loggingThread.execute(() -> { Query.prepare("DELETE FROM `NAMECACHE` WHERE `UUID` = ?").append(uuidString).execute(); MiscUtils.printToConsole("Deleted " + uuidString + " from name cache (age > 1 day)."); @@ -275,8 +275,8 @@ public String getNameFromUUID(UUID uuid) { String name = rs.getString("NAME"); - if(name != null) { - if(System.currentTimeMillis() - rs.getLong("TIMESTAMP") > TimeUnit.DAYS.toMillis(1)) { + if (name != null) { + if (System.currentTimeMillis() - rs.getLong("TIMESTAMP") > TimeUnit.DAYS.toMillis(1)) { Kauri.INSTANCE.loggingThread.execute(() -> { Query.prepare("DELETE FROM `NAMECACHE` WHERE `NAME` = ?").append(name).execute(); MiscUtils.printToConsole("Deleted " + name + " from name cache (age > 1 day)."); @@ -293,7 +293,7 @@ public String getNameFromUUID(UUID uuid) { @Override public void updateAlerts(UUID uuid, boolean alertsEnabled) { Kauri.INSTANCE.loggingThread.execute(() -> { - if(alertsEnabled) { + if (alertsEnabled) { Query.prepare("insert into `ALERTS` (`UUID`) values (?)") .append(uuid.toString()).execute(); } else Query.prepare("delete from `ALERTS` where `UUID` = ?").append(uuid.toString()).execute(); @@ -303,7 +303,7 @@ public void updateAlerts(UUID uuid, boolean alertsEnabled) { @Override public void updateDevAlerts(UUID uuid, boolean devAlertsEnabled) { Kauri.INSTANCE.loggingThread.execute(() -> { - if(devAlertsEnabled) { + if (devAlertsEnabled) { Query.prepare("insert into `DEV_ALERTS` (`UUID`) values (?)") .append(uuid.toString()).execute(); } else Query.prepare("delete from `DEV_ALERTS` where `UUID` = ?").append(uuid.toString()).execute(); diff --git a/Impl/src/main/java/dev/brighten/anticheat/logs/data/sql/MySQL.java b/Impl/src/main/java/dev/brighten/anticheat/logs/data/sql/MySQL.java index 78949eb1c..39181d001 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/logs/data/sql/MySQL.java +++ b/Impl/src/main/java/dev/brighten/anticheat/logs/data/sql/MySQL.java @@ -41,7 +41,7 @@ public static void init() { public static void initSqlLite() { File dataFolder = new File(Kauri.INSTANCE.getDataFolder(), MySQLConfig.database + ".db"); try {//https://nexus.funkemunky.cc/service/local/repositories/releases/content/com/h2database/h2/1.4.199/h2-1.4.199.jar - if(dataFolder.createNewFile()) { + if (dataFolder.createNewFile()) { Kauri.INSTANCE.getLogger().info("Successfully created " + MySQLConfig.database + ".db" + " in Kauri folder!"); } } catch (IOException e) { @@ -64,8 +64,8 @@ public static void initSqlLite() { public static void shutdown() { try { - if(conn != null && !conn.isClosed()) { - if(conn instanceof NonClosableConnection) { + if (conn != null && !conn.isClosed()) { + if (conn instanceof NonClosableConnection) { ((NonClosableConnection)conn).shutdown(); } else conn.close(); conn = null; diff --git a/Impl/src/main/java/dev/brighten/anticheat/menu/LogsGUI.java b/Impl/src/main/java/dev/brighten/anticheat/menu/LogsGUI.java index 09b86fc7f..32aa38727 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/menu/LogsGUI.java +++ b/Impl/src/main/java/dev/brighten/anticheat/menu/LogsGUI.java @@ -84,7 +84,7 @@ private void setButtons(int page) { Math.min(page * 45, filteredLogs.size())); for (int i = 0; i < subList.size(); i++) setItem(i, buttonFromLog(subList.get(i))); - if(subList.size() < 45) { + if (subList.size() < 45) { for(int i = subList.size() ; i < 45 ; i++) { setItem(i, new FillerButton()); } @@ -152,7 +152,7 @@ private void setButtons(int page) { setItem(48, back); } else setItem(48, new FillerButton()); - if(filtered.size() > 0) { + if (filtered.size() > 0) { List lore = new ArrayList<>(Arrays.asList("", Color.translate("&eFilters:"))); for (String s : filtered) { @@ -213,8 +213,8 @@ private ChestMenu getSummary() { "&f&oLeft-Click &7&oto add check to vl filter.", "&f&oRight-Click &7&oto remove check from vl filter.").build(), (player, info) -> { - if(info.getClickType().name().contains("LEFT")) filtered.add(check); - else if(info.getClickType().name().contains("RIGHT")) filtered.remove(check); + if (info.getClickType().name().contains("LEFT")) filtered.add(check); + else if (info.getClickType().name().contains("RIGHT")) filtered.remove(check); else return; setButtons(1); @@ -251,7 +251,7 @@ private ChestMenu getSummary() { }); summary.addItem(button); }); - if(filtered.size() > 0) { + if (filtered.size() > 0) { List lore = new ArrayList<>(Arrays.asList("", Color.translate("&eFilters:"))); for (String s : filtered) { diff --git a/Impl/src/main/java/dev/brighten/anticheat/menu/PlayerInformationGUI.java b/Impl/src/main/java/dev/brighten/anticheat/menu/PlayerInformationGUI.java index 72e0f5b78..a360f46a6 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/menu/PlayerInformationGUI.java +++ b/Impl/src/main/java/dev/brighten/anticheat/menu/PlayerInformationGUI.java @@ -42,7 +42,7 @@ public void addItems() { modData == null || modData.getMods().size() == 0 ? null : (player, info) -> modsGUI().showMenu(player))); violationsButton = new Button(false, violationsButton(), (player, info) -> { - if(info.getClickType().name().contains("LEFT")) { + if (info.getClickType().name().contains("LEFT")) { info.getMenu().close(player); Bukkit.dispatchCommand(player, "kauri logs " + data.getPlayer().getName()); } @@ -82,7 +82,7 @@ private ItemStack forgeItem() { "&eUsing Lunar&7: &f" + data.usingLunar, "")); - if(modData != null) { + if (modData != null) { List modList = new ArrayList<>(modData.getMods()); loreList.add(modList.size() > 0 ? "&7&oRight click to view mods" : "&c&oNo mods."); @@ -133,7 +133,7 @@ private ChestMenu modsGUI() { private void update() { updatingTask = RunUtils.taskTimerAsync(() -> { - if(data == null) { + if (data == null) { updatingTask.cancel(); return; } diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/ClickProcessor.java b/Impl/src/main/java/dev/brighten/anticheat/processing/ClickProcessor.java index fe295e5be..cd3adeacd 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/ClickProcessor.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/ClickProcessor.java @@ -42,9 +42,9 @@ public void onFlying(WrappedInTransactionPacket packet) { public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { long delta = flyingTicks; - if(data.playerInfo.breakingBlock) cpsList.clear(); + if (data.playerInfo.breakingBlock) cpsList.clear(); - if(delta < 15 + if (delta < 15 && !data.playerInfo.breakingBlock && !data.playerInfo.lookingAtBlock && data.playerInfo.lastBlockPlacePacket.isPassed(1) @@ -53,7 +53,7 @@ public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { cpsList.add(delta); zeros = cpsList.stream().filter(dt -> dt <= 2).count(); - if(cpsList.size() >= 20) { + if (cpsList.size() >= 20) { outliersTuple = MiscUtils.getOutliersLong(cpsList); outliers = (lowOutliers = outliersTuple.one.size()) + (highOutliers = outliersTuple.two.size()); } @@ -63,7 +63,7 @@ public void onArm(WrappedInArmAnimationPacket packet, long timeStamp) { sum = 0; for (Long v : cpsList) { sum+= v; - if(v > 20) { + if (v > 20) { min = Math.min(v, min); max = Math.max(v, max); } diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/EntityLocationProcessor.java b/Impl/src/main/java/dev/brighten/anticheat/processing/EntityLocationProcessor.java index 1d77c5f62..99483f386 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/EntityLocationProcessor.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/EntityLocationProcessor.java @@ -48,7 +48,7 @@ public Optional getEntityLocation(Entity entity) { * */ void onFlying() { - if(lastFlying.isNotPassed(1)) streak++; + if (lastFlying.isNotPassed(1)) streak++; else { streak = 1; } @@ -66,24 +66,24 @@ void onFlying() { void onRelPosition(WrappedOutRelativePosition packet) { Optional op = Atlas.getInstance().getWorldInfo(data.getPlayer().getWorld()).getEntity(packet.getId()); - if(!op.isPresent()) return; + if (!op.isPresent()) return; Entity entity = op.get(); - if(!allowedEntityTypes.contains(entity.getType())) return; + if (!allowedEntityTypes.contains(entity.getType())) return; EntityLocation eloc = entityLocationMap.computeIfAbsent(entity.getUniqueId(), key -> new EntityLocation(entity)); runAction(entity, () -> { //We don't need to do version checking here. Atlas handles this for us. - if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_9)) { + if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_9)) { eloc.newX += (byte)packet.getX() / 32D; eloc.newY += (byte)packet.getY() / 32D; eloc.newZ += (byte)packet.getZ() / 32D; eloc.newYaw += (float)(byte)packet.getYaw() / 256.0F * 360.0F; eloc.newPitch += (float)(byte)packet.getPitch() / 256.0F * 360.0F; - } else if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_14)) { + } else if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_14)) { eloc.newX += (int)packet.getX() / 4096D; eloc.newY += (int)packet.getY() / 4096D; eloc.newZ += (int)packet.getZ() / 4096D; @@ -110,17 +110,17 @@ void onRelPosition(WrappedOutRelativePosition packet) { void onTeleportSent(WrappedOutEntityTeleportPacket packet) { Optional op = Atlas.getInstance().getWorldInfo(data.getPlayer().getWorld()).getEntity(packet.entityId); - if(!op.isPresent()) return; + if (!op.isPresent()) return; Entity entity = op.get(); - if(!allowedEntityTypes.contains(entity.getType())) return; + if (!allowedEntityTypes.contains(entity.getType())) return; EntityLocation eloc = entityLocationMap.computeIfAbsent(entity.getUniqueId(), key -> new EntityLocation(entity)); runAction(entity, () -> { - if(data.playerVersion.isOrAbove(ProtocolVersion.V1_9)) { + if (data.playerVersion.isOrAbove(ProtocolVersion.V1_9)) { if (!(Math.abs(eloc.x - packet.x) >= 0.03125D) && !(Math.abs(eloc.y - packet.y) >= 0.015625D) && !(Math.abs(eloc.z - packet.z) >= 0.03125D)) { @@ -165,13 +165,13 @@ void onTeleportSent(WrappedOutEntityTeleportPacket packet) { * @param action Runnable */ private void runAction(Entity entity, Runnable action) { - if(data.target != null && data.target.getEntityId() == entity.getEntityId()) { + if (data.target != null && data.target.getEntityId() == entity.getEntityId()) { AtomicLong start = new AtomicLong(); data.runInstantAction(ia -> { - if(!ia.isEnd()) { + if (!ia.isEnd()) { long delta = System.currentTimeMillis() - start.get(); - if(delta > 10) { + if (delta > 10) { lastProblem.reset(); } action.run(); diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/MovementProcessor.java b/Impl/src/main/java/dev/brighten/anticheat/processing/MovementProcessor.java index 90c17777f..7f60efbbd 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/MovementProcessor.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/MovementProcessor.java @@ -49,7 +49,7 @@ public class MovementProcessor { public final EvictingList sensitivitySamples = new EvictingList<>(50); private static String keepaliveAcceptListener = Kauri.INSTANCE.eventHandler .listen(KeepaliveAcceptedEvent.class, listner -> { - if(listner.getData().playerInfo.serverGround || listner.getData().playerInfo.clientGround) { + if (listner.getData().playerInfo.serverGround || listner.getData().playerInfo.clientGround) { listner.getData().playerInfo.kGroundTicks++; listner.getData().playerInfo.kAirTicks = 0; } else { @@ -63,7 +63,7 @@ public class MovementProcessor { public MovementProcessor(ObjectData data) { this.data = data; - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { + if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { try { levitation = PotionEffectType.getByName("LEVITATION"); } catch(Exception e) { @@ -90,18 +90,18 @@ public void moveTo(Location location) { } public void process(WrappedInFlyingPacket packet, long timeStamp) { - if(data.playerInfo.checkMovement) data.playerInfo.moveTicks++; + if (data.playerInfo.checkMovement) data.playerInfo.moveTicks++; else { data.playerInfo.moveTicks = 0; } - if(data.playerInfo.moveTicks == 0) { + if (data.playerInfo.moveTicks == 0) { data.playerInfo.doingTeleport = true; } else data.playerInfo.doingTeleport = false; data.playerInfo.doingBlockUpdate = data.blockUpdates > 0; - if(timeStamp - data.lagInfo.lastClientTrans > 1000L) { + if (timeStamp - data.lagInfo.lastClientTrans > 1000L) { for (ObjectData.Action action : data.keepAliveStamps) { if (System.currentTimeMillis() - action.stamp > 1000L) continue; @@ -111,13 +111,13 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { } } - if(data.playerInfo.doingBlockUpdate) { + if (data.playerInfo.doingBlockUpdate) { data.playerInfo.lastGhostCollision.reset(); } //We check if it's null and intialize the from and to as equal to prevent large deltas causing false positives since there //was no previous from (Ex: delta of 380 instead of 0.45 caused by jump jump in location from 0,0,0 to 380,0,0) - if(data.playerInfo.moveTicks > 0) { + if (data.playerInfo.moveTicks > 0) { if (data.playerInfo.from == null && packet.isPos()) { data.playerInfo.from @@ -140,20 +140,20 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { data.playerInfo.to.y = packet.getY(); data.playerInfo.to.z = packet.getZ(); //if this is the case, this assumes client movement in between therefore we have to calculate where ground would be. - } else if(packet.isGround() && !data.playerInfo.clientGround) { //this is the last ground + } else if (packet.isGround() && !data.playerInfo.clientGround) { //this is the last ground synchronized (data.blockInfo.belowCollisions) { val optional = data.blockInfo.belowCollisions.stream() .filter(box -> Math.pow(box.yMax - data.playerInfo.to.y, 2) <= 9.0E-4D && data.box.copy() .offset(0, -.1, 0).isCollided(box)).findFirst(); - if(optional.isPresent()) { + if (optional.isPresent()) { data.playerInfo.to.y-= data.playerInfo.to.y - optional.get().yMax; data.playerInfo.clientGround = data.playerInfo.serverGround = true; } } } - if(data.playerInfo.serverGround && data.playerInfo.lastMoveCancel.isPassed()) { + if (data.playerInfo.serverGround && data.playerInfo.lastMoveCancel.isPassed()) { data.playerInfo.setbackLocation = new Location(data.getPlayer().getWorld(), data.playerInfo.to.x, data.playerInfo.to.y, data.playerInfo.to.z, data.playerInfo.to.yaw, data.playerInfo.to.pitch); @@ -177,14 +177,14 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { data.playerInfo.blockBelow = BlockUtils.getBlock(data.playerInfo.to.toLocation(data.getPlayer().getWorld()) .subtract(0, 1, 0)); - if(packet.isPos()) { + if (packet.isPos()) { //We create a separate from BoundingBox for the predictionService since it should operate on pre-motion data. data.box = PlayerSizeHandler.instance.bounds(data.getPlayer(), data.playerInfo.to.x, data.playerInfo.to.y, data.playerInfo.to.z); data.playerInfo.lastMoveTimer.reset(); //Looking for teleport packets - if(packet.isLook() && !data.playerInfo.clientGround) { + if (packet.isLook() && !data.playerInfo.clientGround) { synchronized (data.playerInfo.posLocs) { Iterator iterator = data.playerInfo.posLocs.iterator(); @@ -195,7 +195,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { double distance = MiscUtils.getDistanceWithoutRoot(data.playerInfo.to, posLoc); - if(distance < 1E-9) { + if (distance < 1E-9) { data.playerInfo.lastTeleportTimer.reset(); iterator.remove(); break; @@ -203,7 +203,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { } //Ensuring the list doesn't overflow with old locations, a potential crash exploit. - if(data.teleportsToConfirm == 0 && data.playerInfo.posLocs.size() > 0) { + if (data.teleportsToConfirm == 0 && data.playerInfo.posLocs.size() > 0) { data.playerInfo.posLocs.clear(); } } @@ -211,7 +211,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { } data.blockInfo.runCollisionCheck(); - if(packet.isPos() || packet.isLook()) { + if (packet.isPos() || packet.isLook()) { KLocation origin = data.playerInfo.to.clone(); origin.y+= data.playerInfo.sneaking ? 1.54f : 1.62f; RayCollision collision = new RayCollision(origin.toVector(), MathUtils.getDirection(origin)); @@ -226,38 +226,38 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { } } - if(!data.getPlayer().getGameMode().equals(lastGamemode)) data.playerInfo.lastGamemodeTimer.reset(); + if (!data.getPlayer().getGameMode().equals(lastGamemode)) data.playerInfo.lastGamemodeTimer.reset(); lastGamemode = data.getPlayer().getGameMode(); data.playerInfo.creative = !data.getPlayer().getGameMode().equals(GameMode.SURVIVAL) && !data.getPlayer().getGameMode().equals(GameMode.ADVENTURE); data.blockInfo.fromFriction = data.blockInfo.currentFriction; - if(data.playerInfo.blockBelow != null) { + if (data.playerInfo.blockBelow != null) { val mat = XMaterial.matchXMaterial( data.playerInfo.blockBelow.getType().name()); mat.ifPresent(xMaterial -> data.blockInfo.currentFriction = BlockUtils.getFriction(xMaterial)); } - if(data.playerInfo.nearGround || data.playerInfo.serverGround) data.playerInfo.nearGroundTimer.reset(); + if (data.playerInfo.nearGround || data.playerInfo.serverGround) data.playerInfo.nearGroundTimer.reset(); - if(data.playerInfo.calcVelocityY > 0) { + if (data.playerInfo.calcVelocityY > 0) { data.playerInfo.calcVelocityY-= 0.08f; data.playerInfo.calcVelocityY*= 0.98f; } else data.playerInfo.calcVelocityY = 0; - if(Math.abs(data.playerInfo.calcVelocityX) > 0.005) { + if (Math.abs(data.playerInfo.calcVelocityX) > 0.005) { data.playerInfo.calcVelocityX*= data.playerInfo.lClientGround ? data.blockInfo.currentFriction * 0.91f : 0.91f; } else data.playerInfo.calcVelocityX = 0; - if(Math.abs(data.playerInfo.calcVelocityZ) > 0.005) { + if (Math.abs(data.playerInfo.calcVelocityZ) > 0.005) { data.playerInfo.calcVelocityZ*= data.playerInfo.lClientGround ? data.blockInfo.currentFriction * 0.91f : 0.91f; } else data.playerInfo.calcVelocityZ = 0; //Setting player's previous locations - if(packet.isPos() && !data.playerInfo.doingTeleport & !data.playerInfo.canFly && !data.playerInfo.creative + if (packet.isPos() && !data.playerInfo.doingTeleport & !data.playerInfo.canFly && !data.playerInfo.creative && !data.playerInfo.inVehicle && timeStamp - data.creation > 500L) { synchronized (data.pastLocations) { //To prevent ConcurrentModificationExceptions @@ -269,8 +269,8 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { synchronized (data.playerInfo.velocities) { for (Vector velocity : data.playerInfo.velocities) { - if(Math.abs(velocity.getY() - data.playerInfo.deltaY) < 0.01) { - if(data.playerInfo.doingVelocity) { + if (Math.abs(velocity.getY() - data.playerInfo.deltaY) < 0.01) { + if (data.playerInfo.doingVelocity) { data.playerInfo.lastVelocity.reset(); data.playerInfo.doingVelocity = false; data.playerInfo.lastVelocityTimestamp = System.currentTimeMillis(); @@ -286,14 +286,14 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { } } - if(data.playerInfo.insideBlock = (data.playerInfo.blockOnTo != null && !data.playerInfo.blockOnTo.getType() + if (data.playerInfo.insideBlock = (data.playerInfo.blockOnTo != null && !data.playerInfo.blockOnTo.getType() .equals(XMaterial.AIR.parseMaterial()))) { data.playerInfo.lastInsideBlock.reset(); } //We set the yaw and pitch like this to prevent inaccurate data input. Like above, it will return both pitch //and yaw as 0 if it isnt a look packet. - if(packet.isLook()) { + if (packet.isLook()) { data.playerInfo.to.yaw = packet.getYaw(); data.playerInfo.to.pitch = packet.getPitch(); } @@ -328,7 +328,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { origin.y+= data.playerInfo.sneaking ? 1.54 : 1.62; - if(data.playerInfo.lastTeleportTimer.isPassed(1)) { + if (data.playerInfo.lastTeleportTimer.isPassed(1)) { predictionHandling: { float yawGcd = data.playerInfo.yawGCD, @@ -341,7 +341,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { if (data.playerInfo.pitchGCD > 0.01 && data.playerInfo.pitchGCD < 1.2) pitchGcdList.add(pitchGcd); - if(yawGcdList.size() < 20 || pitchGcdList.size() < 20) { + if (yawGcdList.size() < 20 || pitchGcdList.size() < 20) { accurateYawData = false; break predictionHandling; } @@ -454,7 +454,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { data.playerInfo.wasOnSlime = data.blockInfo.onSlime; } - if((data.playerInfo.onLadder = MovementUtils.isOnLadder(data)) + if ((data.playerInfo.onLadder = MovementUtils.isOnLadder(data)) && (data.playerInfo.deltaY <= 0 || data.blockInfo.collidesHorizontally)) { data.playerInfo.isClimbing = true; } @@ -463,9 +463,9 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { synchronized (data.ghostBlocks) { SimpleCollisionBox boxToCheck = data.box.copy().expand(0.4f); for (Location location : data.ghostBlocks.keySet()) { - if(location.toVector().distanceSquared(data.playerInfo.to.toVector()) > 25) continue; + if (location.toVector().distanceSquared(data.playerInfo.to.toVector()) > 25) continue; - if(data.ghostBlocks.get(location).isCollided(boxToCheck)) { + if (data.ghostBlocks.get(location).isCollided(boxToCheck)) { data.playerInfo.lastGhostCollision.reset(); break; } @@ -503,12 +503,12 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { data.playerInfo.baseSpeed = MovementUtils.getBaseSpeed(data); } - if(data.playerInfo.inVehicle) { + if (data.playerInfo.inVehicle) { data.playerInfo.vehicleTimer.reset(); data.runKeepaliveAction(ka -> data.playerInfo.vehicleTimer.reset()); } - if(data.playerInfo.gliding = BukkitAPI.INSTANCE.isGliding(data.getPlayer())) + if (data.playerInfo.gliding = BukkitAPI.INSTANCE.isGliding(data.getPlayer())) data.playerInfo.lastGlideTimer.reset(); /* @@ -516,7 +516,7 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { * It only sends when they start gliding. So basically, for some checks we need to see if they even have * the ability to glide at all. */ - if(data.playerVersion.isOrAbove(ProtocolVersion.V1_9)) { + if (data.playerVersion.isOrAbove(ProtocolVersion.V1_9)) { data.playerInfo.canUseElytra = data.getPlayer().getInventory() .getChestplate() == XMaterial.ELYTRA.parseItem(); } @@ -531,10 +531,10 @@ public void process(WrappedInFlyingPacket packet, long timeStamp) { (float)data.playerInfo.jumpHeight); } - if(data.blockInfo.fenceBelow) + if (data.blockInfo.fenceBelow) data.playerInfo.lastFenceBelow.reset(); - if(!data.playerInfo.worldLoaded) + if (!data.playerInfo.worldLoaded) data.playerInfo.lastChunkUnloaded.reset(); data.lagInfo.lagging = data.lagInfo.lagTicks.subtract() > 0 diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/PacketProcessor.java b/Impl/src/main/java/dev/brighten/anticheat/processing/PacketProcessor.java index a6cde3337..a047b6405 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/PacketProcessor.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/PacketProcessor.java @@ -53,22 +53,22 @@ public class PacketProcessor { public final PacketListener listener = Atlas.getInstance().getPacketProcessor() .process(Kauri.INSTANCE, EventPriority.NORMAL, info -> { - if(info.isCancelled()) return; + if (info.isCancelled()) return; ObjectData data = Kauri.INSTANCE.dataManager.getData(info.getPlayer()); - if(data == null || data.checkManager == null) return; + if (data == null || data.checkManager == null) return; //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(data.uuid)) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(data.uuid)) return; if (data.checkManager == null) return; try { - if(outgoingPackets.contains(info.getType())) { + if (outgoingPackets.contains(info.getType())) { processServer(data, info.getPacket(), info.getType(), info.getTimestamp()); - } else if(incomingPackets.contains(info.getType())) { + } else if (incomingPackets.contains(info.getType())) { processClient(data, info.getPacket(), info.getType(), info.getTimestamp()); - if(simLag && info.getType().equals(Packet.Client.FLYING)) { + if (simLag && info.getType().equals(Packet.Client.FLYING)) { IntStream.range(0, amount).forEach(i -> { try { SecureRandom.getInstanceStrong().generateSeed(500); @@ -79,7 +79,7 @@ public class PacketProcessor { } } - if(data.checkManager.runEvent(info)) info.setCancelled(true); + if (data.checkManager.runEvent(info)) info.setCancelled(true); } catch(Exception e) { e.printStackTrace(); } @@ -89,16 +89,16 @@ public class PacketProcessor { .process(Kauri.INSTANCE, EventPriority.LOW, info -> { ObjectData data = Kauri.INSTANCE.dataManager.getData(info.getPlayer()); - if(data == null || data.checkManager == null) return; + if (data == null || data.checkManager == null) return; //Packet exemption check - if(KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(data.uuid)) return; + if (KauriAPI.INSTANCE.getPacketExemptedPlayers().contains(data.uuid)) return; switch(info.getType()) { case Packet.Client.USE_ENTITY: { val packet = new WrappedInUseEntityPacket(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -106,7 +106,7 @@ public class PacketProcessor { case Packet.Client.CUSTOM_PAYLOAD: { val packet = new WrappedInCustomPayload(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -114,7 +114,7 @@ public class PacketProcessor { case Packet.Client.WINDOW_CLICK: { val packet = new WrappedInWindowClickPacket(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -125,14 +125,14 @@ public class PacketProcessor { case Packet.Client.LOOK: { val packet = new WrappedInFlyingPacket(info.getPacket(), info.getPlayer()); - if(packet.getX() > 3.0E7 || packet.getY() > 3.0E7 || packet.getZ() > 3.0E7 + if (packet.getX() > 3.0E7 || packet.getY() > 3.0E7 || packet.getZ() > 3.0E7 || packet.getYaw() > 100000 || packet.getPitch() > 100000) { data.getPlayer().kickPlayer("Bad boy"); info.setCancelled(true); return; } - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -140,7 +140,7 @@ public class PacketProcessor { case Packet.Client.CREATIVE_SLOT: { val packet = new WrappedInSetCreativeSlotPacket(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -154,7 +154,7 @@ public class PacketProcessor { case Packet.Server.LEGACY_REL_POSITION_LOOK: { val packet = new WrappedOutRelativePosition(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -163,7 +163,7 @@ public class PacketProcessor { WrappedOutEntityTeleportPacket packet = new WrappedOutEntityTeleportPacket(info.getPacket(), data.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -171,7 +171,7 @@ public class PacketProcessor { case Packet.Server.TRANSACTION: { val packet = new WrappedOutTransaction(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -179,7 +179,7 @@ public class PacketProcessor { case Packet.Server.ENTITY_VELOCITY: { val packet = new WrappedOutVelocityPacket(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -187,7 +187,7 @@ public class PacketProcessor { case Packet.Client.CHAT: { val packet = new WrappedInChatPacket(info.getPacket(), info.getPlayer()); - if(data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { + if (data.checkManager.runPacketCancellable(packet, info.getTimestamp())) { info.setCancelled(true); } break; @@ -208,11 +208,11 @@ public void processClient(ObjectData data, Object object, String type, case Packet.Client.ABILITIES: { WrappedInAbilitiesPacket packet = new WrappedInAbilitiesPacket(object, data.getPlayer()); - if(data.playerInfo.canFly) + if (data.playerInfo.canFly) data.playerInfo.flying = packet.isFlying(); data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getWalkSpeed() + ";" + packet.getFlySpeed() + ";" + packet.isAllowedFlight() + ";" + packet.isCreativeMode() + "; " + packet.isInvulnerable() + ";" + packet.isFlying() @@ -246,10 +246,10 @@ public void processClient(ObjectData data, Object object, String type, data.predictionService.hit = true; data.playerInfo.usingItem = false; } - if(packet.getEntity() != null) + if (packet.getEntity() != null) data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getId() + ";" + packet.getAction().name() + ":@:" + timestamp); } @@ -261,7 +261,7 @@ public void processClient(ObjectData data, Object object, String type, case Packet.Client.LOOK: { WrappedInFlyingPacket packet = new WrappedInFlyingPacket(object, data.getPlayer()); - if(data.playerVersion.isOrAbove(ProtocolVersion.v1_17) + if (data.playerVersion.isOrAbove(ProtocolVersion.v1_17) && packet.isPos() && packet.isLook() && MiscUtils.isSameLocation(new KLocation(packet.getX(), packet.getY(), packet.getZ()), data.playerInfo.to)) { @@ -270,7 +270,7 @@ public void processClient(ObjectData data, Object object, String type, data.entityLocationProcessor.onFlying(); - if(!data.excuseNextFlying) { + if (!data.excuseNextFlying) { if (timestamp - data.lagInfo.lastFlying <= 15) { data.lagInfo.lastPacketDrop.reset(); } @@ -285,7 +285,7 @@ public void processClient(ObjectData data, Object object, String type, data.playerInfo.lastFlyingTimer.reset(); } - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getX() + ";" + packet.getY() + ";" + packet.getZ() + ";" + packet.getYaw() + ";" + packet.getPitch() + ";" + packet.isGround() @@ -305,7 +305,7 @@ public void processClient(ObjectData data, Object object, String type, data.checkManager.runPacket(packet, timestamp); //MiscUtils.testMessage(data.getPlayer().getName() + ": " + packet.getAction()); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getAction().name() + ":@:" + timestamp); } @@ -339,7 +339,7 @@ public void processClient(ObjectData data, Object object, String type, break; } } - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getAction().name() + ";" + packet.getDirection().name() + ";" + "(" + packet.getPosition().getX() + "," @@ -354,20 +354,20 @@ public void processClient(ObjectData data, Object object, String type, data.playerInfo.lastBlockPlacePacket.reset(); if (data.getPlayer().getItemInHand() != null) { - if(data.getPlayer().getItemInHand().getType().name().contains("BUCKET")) { + if (data.getPlayer().getItemInHand().getType().name().contains("BUCKET")) { data.playerInfo.lastPlaceLiquid.reset(); } IntVector pos = packet.getBlockPosition(); val stack = packet.getItemStack(); - if(pos.getX() == -1 && (pos.getY() == 255 || pos.getY() == -1) + if (pos.getX() == -1 && (pos.getY() == 255 || pos.getY() == -1) && pos.getZ() == -1 && stack != null && (stack.getType().name().contains("SWORD") || stack.getType().equals(XMaterial.BOW.parseMaterial()))) { data.playerInfo.usingItem = true; data.playerInfo.lastUseItem.reset(); - } else if(stack != null) { - if(stack.getType().isBlock() && stack.getType().getId() != 0) { + } else if (stack != null) { + if (stack.getType().isBlock() && stack.getType().getId() != 0) { data.playerInfo.lastBlockPlace.reset(); Location loc = new Location( data.getPlayer().getWorld(), pos.getX(), pos.getY(), pos.getZ()); @@ -381,7 +381,7 @@ public void processClient(ObjectData data, Object object, String type, } } } - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + (packet.getItemStack() != null ? packet.getItemStack().toString() : "NULL") + ";(" + packet.getBlockPosition().getX() + "," @@ -399,7 +399,7 @@ public void processClient(ObjectData data, Object object, String type, long time = packet.getTime(); - if(data.keepAlives.containsKey(time)) { + if (data.keepAlives.containsKey(time)) { long last = data.keepAlives.get(time); data.lagInfo.lastPing = data.lagInfo.ping; @@ -410,7 +410,7 @@ public void processClient(ObjectData data, Object object, String type, } data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + time + ":@:" + timestamp); } break; @@ -418,14 +418,14 @@ public void processClient(ObjectData data, Object object, String type, case Packet.Client.CLIENT_COMMAND: { WrappedInClientCommandPacket packet = new WrappedInClientCommandPacket(object, data.getPlayer()); - if(packet.getCommand() + if (packet.getCommand() .equals(WrappedInClientCommandPacket.EnumClientCommand.OPEN_INVENTORY_ACHIEVEMENT)) { data.playerInfo.inventoryOpen = true; } data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getCommand().name() + ":@:" + timestamp); } @@ -434,8 +434,8 @@ public void processClient(ObjectData data, Object object, String type, case Packet.Client.TRANSACTION: { WrappedInTransactionPacket packet = new WrappedInTransactionPacket(object, data.getPlayer()); - if(packet.getId() == 0) { - if(Kauri.INSTANCE.keepaliveProcessor.keepAlives.getIfPresent(packet.getAction()) != null) { + if (packet.getId() == 0) { + if (Kauri.INSTANCE.keepaliveProcessor.keepAlives.getIfPresent(packet.getAction()) != null) { Kauri.INSTANCE.keepaliveProcessor.addResponse(data, packet.getAction()); val optional = Kauri.INSTANCE.keepaliveProcessor.getResponse(data); @@ -447,11 +447,11 @@ public void processClient(ObjectData data, Object object, String type, data.lagInfo.lastTransPing = data.lagInfo.transPing; data.lagInfo.transPing = (current - ka.start); - if(data.instantTransaction.size() > 0) { + if (data.instantTransaction.size() > 0) { synchronized (data.instantTransaction) { Deque toRemove = new LinkedList<>(); data.instantTransaction.forEach((key, tuple) -> { - if((timestamp - tuple.one.getStamp()) > data.lagInfo.transPing * 52L + 750L) { + if ((timestamp - tuple.one.getStamp()) > data.lagInfo.transPing * 52L + 750L) { tuple.two.accept(tuple.one); toRemove.add(key); } @@ -493,7 +493,7 @@ public void processClient(ObjectData data, Object object, String type, } data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getAction() + ";" + packet.getId() + ":@:" + timestamp); } @@ -504,7 +504,7 @@ public void processClient(ObjectData data, Object object, String type, data.clickProcessor.onArm(packet, timestamp); data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + timestamp); } break; @@ -520,7 +520,7 @@ public void processClient(ObjectData data, Object object, String type, data.playerInfo.usingItem = false; data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getSlot() + ":@:" + timestamp); @@ -530,9 +530,9 @@ public void processClient(ObjectData data, Object object, String type, case Packet.Client.TAB_COMPLETE: { WrappedInTabComplete packet = new WrappedInTabComplete(object, data.getPlayer()); - if(packet.getMessage().startsWith("/yourmom")) { + if (packet.getMessage().startsWith("/yourmom")) { WrappedOutTabComplete tabComplete; - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_13)) { + if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_13)) { tabComplete = new WrappedOutTabComplete(0, packet.getMessage(), "gay", "homo"); } else { tabComplete = new WrappedOutTabComplete("gay", "homo"); @@ -555,7 +555,7 @@ public void processClient(ObjectData data, Object object, String type, data.playerInfo.lastWindowClick.reset(); data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getAction().name() + ";" + packet.getButton() + ";" + packet.getId() + ";" + (packet.getItem() != null ? packet.getItem().toString() : "NULL") @@ -573,7 +573,7 @@ public void processClient(ObjectData data, Object object, String type, data.checkManager.runPacket(packet, timestamp); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + timestamp); } break; @@ -581,19 +581,19 @@ public void processClient(ObjectData data, Object object, String type, case Packet.Client.STEER_VEHICLE: { WrappedInSteerVehiclePacket packet = new WrappedInSteerVehiclePacket(object, data.getPlayer()); - if(data.getPlayer().isInsideVehicle() && packet.isUnmount()) { + if (data.getPlayer().isInsideVehicle() && packet.isUnmount()) { data.playerInfo.vehicleTimer.reset(); data.playerInfo.inVehicle = false; } - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.isUnmount() + ";" + packet.getForward() + ";" + packet.getSideways() + ";" + packet.isJump() + ";" + timestamp); } break; } default: { - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + timestamp); } break; @@ -632,7 +632,7 @@ public void processServer(ObjectData data, Object object, String type, long time case Packet.Server.ENTITY_EFFECT: { WrappedOutEntityEffectPacket packet = new WrappedOutEntityEffectPacket(object, data.getPlayer()); - if(packet.entityId == data.getPlayer().getEntityId()) { + if (packet.entityId == data.getPlayer().getEntityId()) { data.potionProcessor.onPotionEffect(packet); data.checkManager.runPacket(packet, timestamp); } @@ -667,8 +667,8 @@ public void processServer(ObjectData data, Object object, String type, long time data.playerInfo.velocities.add(vector); data.playerInfo.doingVelocity = true; data.runInstantAction(keepalive -> { - if(keepalive.isEnd() && data.playerInfo.velocities.contains(vector)) { - if(data.playerInfo.doingVelocity) { + if (keepalive.isEnd() && data.playerInfo.velocities.contains(vector)) { + if (data.playerInfo.doingVelocity) { data.playerInfo.lastVelocity.reset(); data.playerInfo.doingVelocity = false; @@ -695,8 +695,8 @@ public void processServer(ObjectData data, Object object, String type, long time data.playerInfo.velocities.add(vector); data.playerInfo.doingVelocity = true; data.runInstantAction(keepalive -> { - if(keepalive.isEnd() && data.playerInfo.velocities.contains(vector)) { - if(data.playerInfo.doingVelocity) { + if (keepalive.isEnd() && data.playerInfo.velocities.contains(vector)) { + if (data.playerInfo.doingVelocity) { data.playerInfo.lastVelocity.reset(); data.playerInfo.doingVelocity = false; @@ -714,7 +714,7 @@ public void processServer(ObjectData data, Object object, String type, long time }); } - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getId() + ";" + packet.getX() + ";" + packet.getY() + ";" + packet.getZ() + ":@:" + timestamp); @@ -733,7 +733,7 @@ public void processServer(ObjectData data, Object object, String type, long time case Packet.Server.ATTACH: { WrappedOutAttachEntity packet = new WrappedOutAttachEntity(object, data.getPlayer()); - if(packet.getHoldingEntityId() != -1) { + if (packet.getHoldingEntityId() != -1) { data.playerInfo.inVehicle = true; data.playerInfo.vehicleTimer.reset(); } else { @@ -741,7 +741,7 @@ public void processServer(ObjectData data, Object object, String type, long time data.playerInfo.vehicleTimer.reset(); } - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getHoldingEntityId() + ";" + packet.getAttachedEntityId()); } @@ -763,7 +763,7 @@ public void processServer(ObjectData data, Object object, String type, long time case Packet.Server.ENTITY_TELEPORT: { WrappedOutEntityTeleportPacket packet = new WrappedOutEntityTeleportPacket(object, data.getPlayer()); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.entityId + ";" + packet.x + ";" + packet.y + ";" + packet.z + ";" + packet.yaw + ";" + packet.pitch + ":" + timestamp); } @@ -790,7 +790,7 @@ public void processServer(ObjectData data, Object object, String type, long time case Packet.Server.TRANSACTION: { WrappedOutTransaction packet = new WrappedOutTransaction(object, data.getPlayer()); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getId() + ";" + packet.getAction() + ":@:" + timestamp); } @@ -803,7 +803,7 @@ public void processServer(ObjectData data, Object object, String type, long time Location loc = new Location(data.getPlayer().getWorld(), blockChange.getPosition().getX(), blockChange.getPosition().getY(), blockChange.getPosition().getZ()); - if(loc.distanceSquared(data.getPlayer().getLocation()) < 25) { + if (loc.distanceSquared(data.getPlayer().getLocation()) < 25) { data.blockUpdates++; data.playerInfo.lastGhostCollision.reset(); @@ -829,19 +829,19 @@ public void processServer(ObjectData data, Object object, String type, long time packet.getYaw(), packet.getPitch()); int i = 0; - if(packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.X)) { + if (packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.X)) { loc.x+= data.playerInfo.to.x; } - if(packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.Y)) { + if (packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.Y)) { loc.y+= data.playerInfo.to.y; } - if(packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.Z)) { + if (packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.Z)) { loc.z+= data.playerInfo.to.z; } - if(packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.X_ROT)) { + if (packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.X_ROT)) { loc.pitch+= data.playerInfo.to.pitch; } - if(packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.Y_ROT)) { + if (packet.getFlags().contains(WrappedOutPositionPacket.EnumPlayerTeleportFlags.Y_ROT)) { loc.yaw+= data.playerInfo.to.yaw; } @@ -856,7 +856,7 @@ public void processServer(ObjectData data, Object object, String type, long time data.getPlayer().setSprinting(false); - if(data.sniffing) { + if (data.sniffing) { data.sniffedPackets.add(type + ":@:" + packet.getX() + ";" + packet.getY() + ";" + packet.getZ() + ":@:" + timestamp); } diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/PotionProcessor.java b/Impl/src/main/java/dev/brighten/anticheat/processing/PotionProcessor.java index e4120f3f1..3203d364c 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/PotionProcessor.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/PotionProcessor.java @@ -20,7 +20,7 @@ public class PotionProcessor { public void onFlying(WrappedInFlyingPacket packet) { for (PotionEffect effect : potionEffects) { - if(packet.getPlayer().hasPotionEffect(effect.getType())) continue; + if (packet.getPlayer().hasPotionEffect(effect.getType())) continue; data.runKeepaliveAction(d -> data.potionProcessor.potionEffects.remove(effect)); } @@ -39,7 +39,7 @@ public void onPotionEffect(WrappedOutEntityEffectPacket packet) { public boolean hasPotionEffect(PotionEffectType type) { for (PotionEffect potionEffect : potionEffects) { - if(potionEffect.getType().equals(type)) + if (potionEffect.getType().equals(type)) return true; } return false; @@ -47,7 +47,7 @@ public boolean hasPotionEffect(PotionEffectType type) { public Optional getEffectByType(PotionEffectType type) { for (PotionEffect potionEffect : potionEffects) { - if(potionEffect.getType().equals(type)) + if (potionEffect.getType().equals(type)) return Optional.of(potionEffect); } return Optional.empty(); diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/keepalive/KeepaliveProcessor.java b/Impl/src/main/java/dev/brighten/anticheat/processing/keepalive/KeepaliveProcessor.java index 0fa8ee704..1cdbb31de 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/keepalive/KeepaliveProcessor.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/keepalive/KeepaliveProcessor.java @@ -55,17 +55,17 @@ public void run() { for (ObjectData value : Kauri.INSTANCE.dataManager.dataMap.values()) { totalPlayers++; - if(value.lagInfo.lastPingDrop.isNotPassed(2) + if (value.lagInfo.lastPingDrop.isNotPassed(2) || System.currentTimeMillis() - value.lagInfo.lastClientTrans > 135L) laggyPlayers++; - if(value.target != null) { + if (value.target != null) { value.targetPastLocation.addLocation(value.target.getLocation()); } TinyProtocolHandler.sendPacket(value.getPlayer(), packet); double dh = value.playerInfo.deltaXZ, dy = Math.abs(value.playerInfo.deltaY); - if(tick % 5 == 0) { + if (tick % 5 == 0) { if (dh < 1 && dy < 1) value.playerInfo.nearbyEntities = value.getPlayer() .getNearbyEntities(2 + dh, 3 + dy, 2 + dh); @@ -74,7 +74,7 @@ public void run() { //Checking for AtlasBungee stuff incase a player joined before a heartbeat check could be sent //by Atlas - if(Atlas.getInstance().getBungeeManager().isBungee()) { + if (Atlas.getInstance().getBungeeManager().isBungee()) { value.atlasBungeeInstalled = Atlas.getInstance().getBungeeManager().isAtlasBungeeInstalled(); } } @@ -89,14 +89,14 @@ public Optional getKeepById(short id) { } public Optional getResponse(ObjectData data) { - if(!lastResponses.containsKey(data.uuid.hashCode())) + if (!lastResponses.containsKey(data.uuid.hashCode())) return Optional.empty(); return getKeepById(lastResponses.get(data.uuid.hashCode())); } public void start() { - if(task == null) { + if (task == null) { task = RunUtils.taskTimer(this, Kauri.INSTANCE, 20L, 0L); } } @@ -109,7 +109,7 @@ public void addResponse(ObjectData data, short id) { } public void stop() { - if(task != null) { + if (task != null) { task.cancel(); task = null; } diff --git a/Impl/src/main/java/dev/brighten/anticheat/processing/thread/ThreadHandler.java b/Impl/src/main/java/dev/brighten/anticheat/processing/thread/ThreadHandler.java index 05f180870..b215b6be4 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/processing/thread/ThreadHandler.java +++ b/Impl/src/main/java/dev/brighten/anticheat/processing/thread/ThreadHandler.java @@ -26,7 +26,7 @@ public ThreadHandler() { public PlayerThread getThread(ObjectData player) { synchronized (threadCorrelations) { - if(threadCorrelations.containsKey(player.getUUID())) { + if (threadCorrelations.containsKey(player.getUUID())) { return services.get(threadCorrelations.get(player.getUUID())); } @@ -47,7 +47,7 @@ public PlayerThread getThread(ObjectData player) { public void removePlayer(Player player) { synchronized (threadCorrelations) { - if(threadCorrelations.containsKey(player.getUniqueId())) { + if (threadCorrelations.containsKey(player.getUniqueId())) { int index = threadCorrelations.remove(player.getUniqueId()); services.get(index).subtractCount(); diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/CollisionHandler.java b/Impl/src/main/java/dev/brighten/anticheat/utils/CollisionHandler.java index 65638462d..182783b4d 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/CollisionHandler.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/CollisionHandler.java @@ -79,9 +79,9 @@ public boolean isCollidedWith(SimpleCollisionBox playerBox, int bitmask) { } } - if(bitmask == 0) { + if (bitmask == 0) { for(Entity entity : entities) { - if(EntityData.getEntityBox(entity.getLocation(), entity).isCollided(playerBox)) + if (EntityData.getEntityBox(entity.getLocation(), entity).isCollided(playerBox)) return true; } } @@ -112,9 +112,9 @@ public boolean isIntersectsWith(SimpleCollisionBox playerBox, int bitmask) { } } - if(bitmask == 0) { + if (bitmask == 0) { for(Entity entity : entities) { - if(EntityData.getEntityBox(entity.getLocation(), entity).isIntersected(playerBox)) + if (EntityData.getEntityBox(entity.getLocation(), entity).isIntersected(playerBox)) return true; } } @@ -124,7 +124,7 @@ public boolean isIntersectsWith(SimpleCollisionBox playerBox, int bitmask) { public boolean isCollidedWithEntity(SimpleCollisionBox box) { for(Entity entity : entities) { - if(EntityData.getEntityBox(entity.getLocation(), entity).isCollided(box)) + if (EntityData.getEntityBox(entity.getLocation(), entity).isCollided(box)) return true; } return false; @@ -168,14 +168,14 @@ public List getCollisionBoxes(SimpleCollisionBox playerBox) { Material material = data.playerInfo.shitMap.getOrDefault(block, b.getType()); CollisionBox box; - if((box = BlockData.getData(material).getBox(b, ProtocolVersion.getGameVersion())).isCollided(playerBox)) { + if ((box = BlockData.getData(material).getBox(b, ProtocolVersion.getGameVersion())).isCollided(playerBox)) { collided.add(box); } } for(Entity entity : entities) { CollisionBox box = EntityData.getEntityBox(entity.getLocation(), entity); - if(box.isCollided(playerBox)) + if (box.isCollided(playerBox)) collided.add(box); } @@ -212,9 +212,9 @@ public boolean isCollidedWith(SimpleCollisionBox playerBox, Material... material } } - if(materials.length == 0) { + if (materials.length == 0) { for(Entity entity : entities) { - if(EntityData.getEntityBox(entity.getLocation(), entity).isCollided(playerBox)) + if (EntityData.getEntityBox(entity.getLocation(), entity).isCollided(playerBox)) return true; } } @@ -242,7 +242,7 @@ public void runFutures() { Location block = b.getLocation(); Material material = data.playerInfo.shitMap.getOrDefault(block, b.getType()); for (Triad> intersect : intersects) { - if(!Materials.checkFlag(material, intersect.second)) continue; + if (!Materials.checkFlag(material, intersect.second)) continue; SimpleCollisionBox playerBox = new SimpleCollisionBox() .offset(location.x, location.y, location.z) @@ -256,7 +256,7 @@ public void runFutures() { } } for (Triad> collides : collides) { - if(!Materials.checkFlag(material, collides.second)) continue; + if (!Materials.checkFlag(material, collides.second)) continue; SimpleCollisionBox playerBox = new SimpleCollisionBox() .offset(location.x, location.y, location.z) diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/EntityLocation.java b/Impl/src/main/java/dev/brighten/anticheat/utils/EntityLocation.java index 4e565276a..5bdab6ba1 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/EntityLocation.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/EntityLocation.java @@ -71,7 +71,7 @@ public List getInterpolatedLocations() { public void interpolateLocation() { oldLocation = new KLocation(x, y, z, yaw, pitch); oldLocations.add(oldLocation); - if(increment > 0) { + if (increment > 0) { double d0 = x + (newX - x) / increment; double d1 = y + (newY - y) / increment; double d2 = z + (newZ - z) / increment; diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/Helper.java b/Impl/src/main/java/dev/brighten/anticheat/utils/Helper.java index e81473491..08ea214dc 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/Helper.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/Helper.java @@ -158,7 +158,7 @@ public static List getBlocksNearby(CollisionHandler handler, CollisionBox for (Block block : handler.getBlocks()) { final Material type = block.getType(); - if(type.equals(AIR) + if (type.equals(AIR) || !BlockData.getData(type).getBox(block, ProtocolVersion.getGameVersion()) .isIntersected(collisionBox)) continue; @@ -261,14 +261,14 @@ public static List getCollisionsOnRay(RayCollision collision, Worl .map(loc -> { Block block = BlockUtils.getBlock(loc); - if(block == null) return null; - if(Materials.checkFlag(block.getType(), Materials.SOLID)) { + if (block == null) return null; + if (Materials.checkFlag(block.getType(), Materials.SOLID)) { return BlockData.getData(block.getType()).getBox(block, ProtocolVersion.getGameVersion()); } return null; }) .filter(box -> { - if(box == null) return false; + if (box == null) return false; return collision.isCollided(box); }).collect(Collectors.toList()); } diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/MiscUtils.java b/Impl/src/main/java/dev/brighten/anticheat/utils/MiscUtils.java index a39d346ec..a543f1b67 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/MiscUtils.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/MiscUtils.java @@ -66,7 +66,7 @@ public static void forceBanPlayer(ObjectData data, String reason) { Check ban = data.checkManager.checks.get("ForceBan"); //Fixing users potentially misconfiguring forceban - if(!ban.isExecutable()) ban.setExecutable(true); + if (!ban.isExecutable()) ban.setExecutable(true); ban.vl = 2; ban.flag("Banning user for: " + reason); @@ -92,8 +92,8 @@ public static boolean isInMaterialBB(World world, SimpleCollisionBox entityBox, Location loc = new Location(world, x, y, z); Optional op = BlockUtils.getBlockAsync(loc); - if(op.isPresent()) { - if(XMaterial.matchXMaterial(op.get().getType()).equals(xmaterial)) + if (op.isPresent()) { + if (XMaterial.matchXMaterial(op.get().getType()).equals(xmaterial)) return true; } } @@ -116,8 +116,8 @@ public static boolean isInMaterialBB(World world, SimpleCollisionBox entityBox, Location loc = new Location(world, x, y, z); Optional op = BlockUtils.getBlockAsync(loc); - if(op.isPresent()) { - if(Materials.checkFlag(op.get().getType(), bitmask)) + if (op.isPresent()) { + if (Materials.checkFlag(op.get().getType(), bitmask)) return true; } } @@ -142,13 +142,13 @@ public static List getNearbyEntities(Player player, double horz, double final SimpleCollisionBox playerBox = new SimpleCollisionBox(player.getLocation(), 0.6, 1.8); for(Entity entity : Atlas.getInstance().getTrackedEntities().values()) { - if(!entity.getWorld().getUID().equals(player.getWorld().getUID()) + if (!entity.getWorld().getUID().equals(player.getWorld().getUID()) || player.getEntityId() == entity.getEntityId()) continue; SimpleCollisionBox box = new SimpleCollisionBox(entity.getLocation(), horz * 2, vert / 2) .expandMin(0, -(vert / 2), 0); - if(box.isCollided(playerBox)) nearbyEntities.add(entity); + if (box.isCollided(playerBox)) nearbyEntities.add(entity); } return nearbyEntities; @@ -174,7 +174,7 @@ public static Float getMode(Collection collect) { public static void sendMessage(CommandSender player, String message, Object... objects) { String toSend = String.format(Color.translate(message), objects); - if(player instanceof Player) { + if (player instanceof Player) { ((Player)player).spigot().sendMessage(TextComponent.fromLegacyText(toSend)); } else player.sendMessage(toSend); } @@ -246,7 +246,7 @@ public static void close(Closeable... closeables) { private static Object minecraftServer = null; //TODO Make this use the new abstraction system. public static int currentTick() { - if(minecraftServer == null) minecraftServer = CraftReflection.getMinecraftServer(); + if (minecraftServer == null) minecraftServer = CraftReflection.getMinecraftServer(); return ticksField.get(minecraftServer); } @@ -265,7 +265,7 @@ public static void close(AutoCloseable... closeables) { * @return GCD of both inputs */ public static float gcdSmall(float current, float previous) { - if(current < previous) return gcdSmall(Math.abs(previous), Math.abs(current)); + if (current < previous) return gcdSmall(Math.abs(previous), Math.abs(current)); //The larger number has to be first. return (Math.abs(previous) <= 0.001f) ? current : gcdSmall(previous, current - (float)Math.floor(current / previous) * previous); @@ -289,7 +289,7 @@ public static double getGrid(final Collection entry) { public static boolean isAnimated(HumanEntity entity) { Object itemInUse = MinecraftReflection.getItemInUse(entity); - if(itemInUse == null) return false; + if (itemInUse == null) return false; Object animation = MinecraftReflection.getItemAnimation(itemInUse); @@ -358,7 +358,7 @@ public static E randomElement(final Collection collection) { //Args: Tuple (a) is low outliers, Tupe (B) is high outliers public static Tuple, List> getOutliers(List values) { - if(values.size() < 4) return new Tuple<>(new ArrayList<>(), new ArrayList<>()); + if (values.size() < 4) return new Tuple<>(new ArrayList<>(), new ArrayList<>()); double q1 = getMedian(values.subList(0, values.size() / 2)), q3 = getMedian(values.subList(values.size() / 2, values.size())); @@ -369,16 +369,16 @@ public static Tuple, List> getOutliers(List values) val tuple = new Tuple, List>(new ArrayList<>(), new ArrayList<>()); for (Double value : values) { - if(value < lowThreshold) tuple.one.add(value); - if(value < lowThreshold) tuple.one.add(value); - else if(value > highThreshold) tuple.two.add(value); + if (value < lowThreshold) tuple.one.add(value); + if (value < lowThreshold) tuple.one.add(value); + else if (value > highThreshold) tuple.two.add(value); } return tuple; } public static Tuple, List> getOutliersFloat(List values) { - if(values.size() < 4) return new Tuple<>(new ArrayList<>(), new ArrayList<>()); + if (values.size() < 4) return new Tuple<>(new ArrayList<>(), new ArrayList<>()); double q1 = getMedian(values.subList(0, values.size() / 2)), q3 = getMedian(values.subList(values.size() / 2, values.size())); @@ -389,8 +389,8 @@ public static Tuple, List> getOutliersFloat(List value val tuple = new Tuple, List>(new ArrayList<>(), new ArrayList<>()); for (Float value : values) { - if(value < lowThreshold) tuple.one.add(value); - else if(value > highThreshold) tuple.two.add(value); + if (value < lowThreshold) tuple.one.add(value); + else if (value > highThreshold) tuple.two.add(value); } return tuple; @@ -399,7 +399,7 @@ public static Tuple, List> getOutliersFloat(List value public static Tuple, List> getOutliersLong(List collection) { List values = new ArrayList<>(collection); - if(values.size() < 4) return new Tuple<>(new ArrayList<>(), new ArrayList<>()); + if (values.size() < 4) return new Tuple<>(new ArrayList<>(), new ArrayList<>()); double q1 = getMedian(values.subList(0, values.size() / 2)), q3 = getMedian(values.subList(values.size() / 2, values.size())); @@ -410,15 +410,15 @@ public static Tuple, List> getOutliersLong(List collectio val tuple = new Tuple, List>(new ArrayList<>(), new ArrayList<>()); for (Long value : values) { - if(value < lowThreshold) tuple.one.add(value); - else if(value > highThreshold) tuple.two.add(value); + if (value < lowThreshold) tuple.one.add(value); + else if (value > highThreshold) tuple.two.add(value); } return tuple; } public static double getMedian(List data) { - if(data.size() > 1) { + if (data.size() > 1) { if (data.size() % 2 == 0) return (data.get(data.size() / 2) + data.get(data.size() / 2 - 1)) / 2; else @@ -448,7 +448,7 @@ public static double getKurtosisApache(Iterable iterable) { values.add(v); } - if(values.size() < 2) return kurt; + if (values.size() < 2) return kurt; double mean = total / values.size(); double stdDev = MathUtils.stdev(values); @@ -494,7 +494,7 @@ public static double getKurtosis(final Iterable iterable) { public static float pow(float number, int times) { float answer = number; - if(times <= 0) return 0; + if (times <= 0) return 0; for(int i = 1 ; i < times ; i++) { answer*= number; @@ -546,7 +546,7 @@ public static double getSkewnessApache(Iterable iterable) { values.add(v); } - if(values.size() < 2) return skew; + if (values.size() < 2) return skew; double m = total / values.size(); double accum = 0.0D; @@ -647,9 +647,9 @@ public static float getYawChangeToEntity(Player player, LivingEntity entity, KLo double deltaX = entity.getLocation().getX() - player.getLocation().getX(); double deltaZ = entity.getLocation().getZ() - player.getLocation().getZ(); double yawToEntity; - if(deltaZ < 0.0D && deltaX < 0.0D) { + if (deltaZ < 0.0D && deltaX < 0.0D) { yawToEntity = 90.0D + Math.toDegrees(Math.atan(deltaZ / deltaX)); - } else if(deltaZ < 0.0D && deltaX > 0.0D) { + } else if (deltaZ < 0.0D && deltaX > 0.0D) { yawToEntity = -90.0D + Math.toDegrees(Math.atan(deltaZ / deltaX)); } else { yawToEntity = Math.toDegrees(-Math.atan(deltaX / deltaZ)); diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/MovementUtils.java b/Impl/src/main/java/dev/brighten/anticheat/utils/MovementUtils.java index f83b71d93..6645cf0bf 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/MovementUtils.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/MovementUtils.java @@ -45,17 +45,17 @@ public static boolean isOnLadder(ObjectData data) { : MinecraftReflection.playerConnection.getFieldByName(ProtocolVersion.getGameVersion() .isOrAbove(ProtocolVersion.v1_17) ? "y" : "teleportPos"); public static boolean checkMovement(Object playerConnection) { - if(ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_9)) { + if (ProtocolVersion.getGameVersion().isBelow(ProtocolVersion.V1_9)) { return checkMovement.get(playerConnection); } else return (checkMovement.get(playerConnection) == null); } public static int getDepthStriderLevel(Player player) { - if(DEPTH == null) return 0; + if (DEPTH == null) return 0; val boots = player.getInventory().getBoots(); - if(boots == null) return 0; + if (boots == null) return 0; return boots.getEnchantmentLevel(DEPTH); } @@ -74,7 +74,7 @@ public static double getBaseSpeed(ObjectData data) { public static float getFriction(Block block) { Optional matched = XMaterial.matchXMaterial(block.getType().name()); - if(!matched.isPresent()) return 0.6f; + if (!matched.isPresent()) return 0.6f; switch(matched.get()) { case SLIME_BLOCK: return 0.8f; @@ -97,7 +97,7 @@ public static float getTotalHeight(ProtocolVersion version, float initial) { int count = 0; while ((nextCalc = (nextCalc - 0.08f) * 0.98f) > (version.isOrBelow(ProtocolVersion.V1_8_9) ? 0.005 : 0)) { total+= nextCalc; - if(count++ > 15) { + if (count++ > 15) { return total * 4; } } @@ -107,7 +107,7 @@ public static float getTotalHeight(ProtocolVersion version, float initial) { static { try { - if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { + if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { DEPTH = Enchantment.getByName("DEPTH_STRIDER"); } diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/Pastebin.java b/Impl/src/main/java/dev/brighten/anticheat/utils/Pastebin.java index 085969fdc..629db43b1 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/Pastebin.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/Pastebin.java @@ -41,7 +41,7 @@ static public String makePaste(String body, String name, Privacy privacy) String data = "body=" + content + "&name=" + title + "&privacy=" + privacy.name(); String response = Pastebin.page(Pastebin.pasteURL, data); - if(response == null) return ""; + if (response == null) return ""; String check = Pastebin.checkResponse(response); if (!check.equals("")) { return check; diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/SimpleAverage.java b/Impl/src/main/java/dev/brighten/anticheat/utils/SimpleAverage.java index cc341c6cf..01ae8cbc2 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/SimpleAverage.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/SimpleAverage.java @@ -18,14 +18,14 @@ public SimpleAverage(int size, double initial) { public void add(double value) { total+= value; - if(++count > size) { + if (++count > size) { total-= getAverage(); count--; } } public double getAverage() { - if(count == 0) return initial; + if (count == 0) return initial; return total / count; } diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/StringUtils.java b/Impl/src/main/java/dev/brighten/anticheat/utils/StringUtils.java index f7eb64811..2a4b99674 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/StringUtils.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/StringUtils.java @@ -16,7 +16,7 @@ public class StringUtils { public static void sendMessage(CommandSender sender, TextComponent component) { - if(sender instanceof Player) { + if (sender instanceof Player) { ((Player) sender).spigot().sendMessage(component); } else { sender.sendMessage(component.toLegacyText()); diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/Verbose.java b/Impl/src/main/java/dev/brighten/anticheat/utils/Verbose.java index 1b82e58db..06ef9d27d 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/Verbose.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/Verbose.java @@ -15,7 +15,7 @@ public Verbose(double maxVl, int resetTicks) { } public boolean flag(double toAdd, double max) { - if(lastFlag.isPassed()) { + if (lastFlag.isPassed()) { vl.subtract(maxVl * 1.5); } lastFlag.reset(); diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/menu/MenuListener.java b/Impl/src/main/java/dev/brighten/anticheat/utils/menu/MenuListener.java index 82d982c92..1a2425e1f 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/menu/MenuListener.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/menu/MenuListener.java @@ -72,7 +72,7 @@ public void onInventoryClick(InventoryClickEvent event) { } } } - if(!event.getAction().equals(InventoryAction.NOTHING) + if (!event.getAction().equals(InventoryAction.NOTHING) && inventory instanceof AnvilInventory && anvils.containsKey(inventory)) { event.setResult(Event.Result.DENY); @@ -104,7 +104,7 @@ public void onInventoryClose(InventoryCloseEvent event) { }); } } - if(inventory instanceof AnvilInventory && anvils.containsKey(inventory)) { + if (inventory instanceof AnvilInventory && anvils.containsKey(inventory)) { AnvilInventory anvil = (AnvilInventory) inventory; anvils.get(anvil).consumer.accept(event.getPlayer(), Color.translate(anvil.getName())); diff --git a/Impl/src/main/java/dev/brighten/anticheat/utils/menu/type/impl/PagedMenu.java b/Impl/src/main/java/dev/brighten/anticheat/utils/menu/type/impl/PagedMenu.java index 7b5c8c236..05f8e8641 100644 --- a/Impl/src/main/java/dev/brighten/anticheat/utils/menu/type/impl/PagedMenu.java +++ b/Impl/src/main/java/dev/brighten/anticheat/utils/menu/type/impl/PagedMenu.java @@ -87,7 +87,7 @@ public void checkBounds(int index) throws IndexOutOfBoundsException { @Override public Optional