From 40bdabb57142caa9951c0df6c9ff597157c1d14e Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 8 Dec 2022 10:35:33 -0800
Subject: [PATCH] properly handle xray bypass perm

---
 patches/server/Anti-Xray.patch | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/patches/server/Anti-Xray.patch b/patches/server/Anti-Xray.patch
index 9b8cd973f9..3bfb1f193e 100644
--- a/patches/server/Anti-Xray.patch
+++ b/patches/server/Anti-Xray.patch
@@ -1058,12 +1058,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              if (newWithinViewDistance && !oldWithinViewDistance) {
                  ChunkHolder playerchunk = this.getVisibleChunkIfPresent(pos.toLong());
 @@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
+ 
+         ServerPlayer entityplayer;
+ 
++        java.util.Map<Object, net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket> refreshPackets = new java.util.HashMap<>(); // Paper - Anti-Xray - Bypass
          for (Iterator iterator = this.getPlayers(chunkcoordintpair, false).iterator(); iterator.hasNext(); entityplayer.trackChunk(chunkcoordintpair, (Packet) mutableobject.getValue())) {
              entityplayer = (ServerPlayer) iterator.next();
-             if (mutableobject.getValue() == null) {
+-            if (mutableobject.getValue() == null) {
 -                mutableobject.setValue(new ClientboundLevelChunkWithLightPacket(chunk1, this.lightEngine, (BitSet) null, (BitSet) null, true));
-+                mutableobject.setValue(new ClientboundLevelChunkWithLightPacket(chunk1, this.lightEngine, (BitSet) null, (BitSet) null, true, true)); // Paper - Anti-Xray
-             }
+-            }
++            Boolean shouldModify = chunk1.getLevel().chunkPacketBlockController.shouldModify(entityplayer, chunk1);
++            mutableobject.setValue(refreshPackets.computeIfAbsent(shouldModify, s -> new ClientboundLevelChunkWithLightPacket(chunk1, this.lightEngine, (BitSet) null, (BitSet) null, true, (Boolean) s))); // Paper - Anti-Xray - Bypass
          }
  
      }