Skip to content

Commit

Permalink
Fix perf downgrade caused by last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MachineBreaker committed Apr 29, 2024
1 parent 5f7d759 commit 9872675
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ else if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(Serve

@Override
public void onPacketReceive(PacketReceiveEvent event) {
final GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;

if (event.getPacketType() == PacketType.Play.Client.PLAYER_DIGGING) {
WrapperPlayClientPlayerDigging dig = new WrapperPlayClientPlayerDigging(event);

if (dig.getAction() == DiggingAction.RELEASE_USE_ITEM) {
final GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;

player.packetStateData.slowedByUsingItem = false;
player.packetStateData.slowedByUsingItemTransaction = player.lastTransactionReceived.get();

Expand All @@ -141,15 +141,24 @@ public void onPacketReceive(PacketReceiveEvent event) {
}
}

if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType()) && !player.packetStateData.lastPacketWasTeleport && !player.packetStateData.lastPacketWasOnePointSeventeenDuplicate) {
player.packetStateData.wasSlowedByUsingItem = player.packetStateData.slowedByUsingItem;
if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType())) {
final GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;

if (!player.packetStateData.lastPacketWasTeleport && !player.packetStateData.lastPacketWasOnePointSeventeenDuplicate) {
player.packetStateData.wasSlowedByUsingItem = player.packetStateData.slowedByUsingItem;
}
}

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

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

final GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;

// Prevent issues if the player switches slots, while lagging, standing still, and is placing blocks
CheckManagerListener.handleQueuedPlaces(player, false, 0, 0, System.currentTimeMillis());

Expand All @@ -167,6 +176,9 @@ public void onPacketReceive(PacketReceiveEvent event) {
}

if (event.getPacketType() == PacketType.Play.Client.USE_ITEM || (event.getPacketType() == PacketType.Play.Client.PLAYER_BLOCK_PLACEMENT && new WrapperPlayClientPlayerBlockPlacement(event).getFace() == BlockFace.OTHER)) {
final GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser());
if (player == null) return;

final InteractionHand hand = event.getPacketType() == PacketType.Play.Client.USE_ITEM
? new WrapperPlayClientUseItem(event).getHand()
: InteractionHand.MAIN_HAND;
Expand Down

0 comments on commit 9872675

Please sign in to comment.