Skip to content

Commit

Permalink
Add NoSwingBreak
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Sep 13, 2024
1 parent 1f07772 commit 009422d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/ac/grim/grimac/checks/impl/breaking/FastBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import ac.grim.grimac.utils.nmsutil.ReachUtils;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.attribute.Attributes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.DiggingAction;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
Expand All @@ -35,6 +36,7 @@ public FastBreak(GrimPlayer playerData) {

private Vector3i targetBlock = null;
private double progress;
private boolean sentAnimation;

@Override
public void onBlockBreak(BlockBreak blockBreak) {
Expand Down Expand Up @@ -62,17 +64,26 @@ public void onBlockBreak(BlockBreak blockBreak) {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (targetBlock == null) {
sentAnimation = false;
return;
}

if (event.getPacketType() == PacketType.Play.Client.ANIMATION) {
sentAnimation = true;
}

if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType())) {
if (!player.compensatedEntities.getSelf().inVehicle()) {
if (!didRayTraceHit() || !isWithinRange()) {
return;
}
}

progress += BlockBreakSpeed.getBlockDamage(player, targetBlock);
if (sentAnimation) {
progress += BlockBreakSpeed.getBlockDamage(player, targetBlock);
}

sentAnimation = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ac.grim.grimac.checks.impl.breaking;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.BlockBreakCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.BlockBreak;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.DiggingAction;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

@CheckData(name = "NoSwingBreak")
public class NoSwingBreak extends Check implements BlockBreakCheck {
public NoSwingBreak(GrimPlayer playerData) {
super(playerData);
}

private boolean sentAnimation;
private boolean sentBreak;

@Override
public void onBlockBreak(BlockBreak blockBreak) {
if (blockBreak.action != DiggingAction.CANCELLED_DIGGING) {
sentBreak = true;
}
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.ANIMATION) {
sentAnimation = true;
}

if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType())) {
if (sentBreak && !sentAnimation) {
flagAndAlert();
}

sentAnimation = sentBreak = false;
}
}
}
1 change: 1 addition & 0 deletions src/main/java/ac/grim/grimac/manager/CheckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public CheckManager(GrimPlayer player) {
.put(PositionBreakA.class, new PositionBreakA(player))
.put(PositionBreakB.class, new PositionBreakB(player))
.put(FarBreak.class, new FarBreak(player))
.put(NoSwingBreak.class, new NoSwingBreak(player))
.put(FastBreak.class, new FastBreak(player))
.build();

Expand Down

0 comments on commit 009422d

Please sign in to comment.