Skip to content

Commit

Permalink
InvalidPlace check
Browse files Browse the repository at this point in the history
  • Loading branch information
AoElite committed Dec 27, 2023
1 parent ab48248 commit 10a99fd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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.player.GrimPlayer;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
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 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();
}
}
}
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,12 @@ public void onPacketReceive(PacketReceiveEvent event) {
if ((placedWith.getType().getPlacedType() != null || placedWith.getType() == ItemTypes.FIRE_CHARGE) && !player.compensatedEntities.getSelf().inVehicle())
player.checkManager.onBlockPlace(blockPlace);

if (blockPlace.isCancelled() || player.getSetbackTeleportUtil().shouldBlockMovement()) { // The player tried placing blocks in air/water
event.setCancelled(true);
player.onPacketCancel();
if (event.isCancelled() || blockPlace.isCancelled() || player.getSetbackTeleportUtil().shouldBlockMovement()) { // The player tried placing blocks in air/water

if (!event.isCancelled()) {
event.setCancelled(true);
player.onPacketCancel();
}

Vector3i facePos = new Vector3i(packet.getBlockPosition().getX() + packet.getFace().getModX(), packet.getBlockPosition().getY() + packet.getFace().getModY(), packet.getBlockPosition().getZ() + packet.getFace().getModZ());

Expand Down
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 @@ -83,6 +83,7 @@ public CheckManager(GrimPlayer player) {
.put(BadPacketsQ.class, new BadPacketsQ(player))
.put(BadPacketsR.class, new BadPacketsR(player))
.put(BadPacketsS.class, new BadPacketsS(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

0 comments on commit 10a99fd

Please sign in to comment.