Skip to content

Commit

Permalink
Merge pull request #1426 from ManInMyVan/fix/InvalidPlace
Browse files Browse the repository at this point in the history
fix InvalidPlace
  • Loading branch information
AoElite authored Apr 12, 2024
2 parents 9c70d9e + ecb13e5 commit 25889d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
package ac.grim.grimac.checks.impl.scaffolding;

import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.checks.type.BlockPlaceCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import ac.grim.grimac.utils.anticheat.update.BlockPlace;
import com.github.retrooper.packetevents.util.Vector3f;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerBlockPlacement;

@CheckData(name = "InvalidPlace")
public class InvalidPlace extends Check implements PacketCheck {

public class InvalidPlace extends BlockPlaceCheck {
public InvalidPlace(GrimPlayer player) {
super(player);
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.PLAYER_BLOCK_PLACEMENT) {
WrapperPlayClientPlayerBlockPlacement wrapper = new WrapperPlayClientPlayerBlockPlacement(event);
Vector3f cursor = wrapper.getCursorPosition();
if (cursor == null) return;
if (invalid(cursor.getX()) || invalid(cursor.getY()) || invalid(cursor.getZ())) {
if (flag() && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
public void onBlockPlace(final BlockPlace place) {
Vector3f cursor = place.getCursor();
if (cursor == null) return;
if (!Float.isFinite(cursor.getX()) || !Float.isFinite(cursor.getY()) || !Float.isFinite(cursor.getZ())) {
if (flagAndAlert() && shouldModifyPackets() && shouldCancel()) {
place.resync();
}
}
}

private boolean invalid(float value) {
return Float.isInfinite(value) || Float.isNaN(value);
}

}
2 changes: 1 addition & 1 deletion src/main/java/ac/grim/grimac/manager/CheckManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public CheckManager(GrimPlayer player) {
.put(BadPacketsR.class, new BadPacketsR(player))
.put(BadPacketsS.class, new BadPacketsS(player))
.put(BadPacketsT.class, new BadPacketsT(player))
.put(InvalidPlace.class, new InvalidPlace(player))
.put(FastBreak.class, new FastBreak(player))
.put(TransactionOrder.class, new TransactionOrder(player))
.put(NoSlowB.class, new NoSlowB(player))
Expand Down Expand Up @@ -126,6 +125,7 @@ public CheckManager(GrimPlayer player) {
.build();

blockPlaceCheck = new ImmutableClassToInstanceMap.Builder<BlockPlaceCheck>()
.put(InvalidPlace.class, new InvalidPlace(player))
.put(AirLiquidPlace.class, new AirLiquidPlace(player))
.put(FarPlace.class, new FarPlace(player))
.put(FabricatedPlace.class, new FabricatedPlace(player))
Expand Down

0 comments on commit 25889d9

Please sign in to comment.