Skip to content

Commit

Permalink
Merge pull request #1436 from Ayouuuu/combat-eat
Browse files Browse the repository at this point in the history
Add BadPacketsV
  • Loading branch information
AoElite authored Apr 18, 2024
2 parents d125289 + 2858cb9 commit fa77a80
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ac.grim.grimac.checks.impl.badpackets;

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.item.ItemStack;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;

@CheckData(name = "BadPacketsV", experimental = true)
public class BadPacketsV extends Check implements PacketCheck {
public BadPacketsV(GrimPlayer player) {
super(player);
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {
WrapperPlayClientInteractEntity interactEntity = new WrapperPlayClientInteractEntity(event);
if (interactEntity.getAction() != WrapperPlayClientInteractEntity.InteractAction.ATTACK) return;
if (!player.packetStateData.slowedByUsingItem) return;
ItemStack itemInUse = player.getInventory().getItemInHand(player.packetStateData.eatingHand);
if (flagAndAlert("UseItem=" + itemInUse.getType().getName().getKey()) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
}
}
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 @@ -88,6 +88,7 @@ public CheckManager(GrimPlayer player) {
.put(BadPacketsS.class, new BadPacketsS(player))
.put(BadPacketsT.class, new BadPacketsT(player))
.put(BadPacketsU.class, new BadPacketsU(player))
.put(BadPacketsV.class, new BadPacketsV(player))
.put(FastBreak.class, new FastBreak(player))
.put(TransactionOrder.class, new TransactionOrder(player))
.put(NoSlowB.class, new NoSlowB(player))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ private void markPlayerSlotAsChanged(int clicked) {
inventory.getInventoryStorage().handleClientClaimedSlotSet(playerInvSlotclicked);
}

public ItemStack getItemInHand(InteractionHand hand) {
return hand == InteractionHand.MAIN_HAND ? getHeldItem() : getOffHand();
}

private void markServerForChangingSlot(int clicked, int windowID) {
// Unsupported inventory
if (packetSendingInventorySize == -2) return;
Expand Down

0 comments on commit fa77a80

Please sign in to comment.