Skip to content

Commit

Permalink
Merge pull request #1464 from ManInMyVan/bpY
Browse files Browse the repository at this point in the history
add BadPacketsY
  • Loading branch information
AoElite authored May 11, 2024
2 parents 0867f22 + 5758054 commit 02b3882
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientHeldItemChange;

/**
* Checks for out of bounds slot changes
*/
@CheckData(name = "BadPacketsY")
public class BadPacketsY extends Check implements PacketCheck {
public BadPacketsY(GrimPlayer player) {
super(player);
}

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_CHANGE) {
final int slot = new WrapperPlayClientHeldItemChange(event).getSlot();
if (slot > 8 || slot < 0) { // ban
if (flagAndAlert("slot="+slot) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ public void onPacketReceive(PacketReceiveEvent event) {
}

if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_CHANGE) {
int slot = new WrapperPlayClientHeldItemChange(event).getSlot();
final int slot = new WrapperPlayClientHeldItemChange(event).getSlot();

// Stop people from spamming the server with out of bounds exceptions
if (slot > 8) return;
if (slot > 8 || slot < 0) return;

final GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;
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 @@ -91,6 +91,7 @@ public CheckManager(GrimPlayer player) {
.put(BadPacketsV.class, new BadPacketsV(player))
.put(BadPacketsW.class, new BadPacketsW(player))
.put(BadPacketsX.class, new BadPacketsX(player))
.put(BadPacketsY.class, new BadPacketsY(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 @@ -263,12 +263,12 @@ public void onPacketReceive(final PacketReceiveEvent event) {
}

if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_CHANGE) {
WrapperPlayClientHeldItemChange slot = new WrapperPlayClientHeldItemChange(event);
final int slot = new WrapperPlayClientHeldItemChange(event).getSlot();

// Stop people from spamming the server with an out-of-bounds exception
if (slot.getSlot() > 8) return;
if (slot > 8 || slot < 0) return;

inventory.selected = slot.getSlot();
inventory.selected = slot;
}

if (event.getPacketType() == PacketType.Play.Client.CREATIVE_INVENTORY_ACTION) {
Expand Down

0 comments on commit 02b3882

Please sign in to comment.