From 8088a420294bf50dc95cfdd678eee0319b5dc7d7 Mon Sep 17 00:00:00 2001
From: stonar96 <minecraft.stonar96@gmail.com>
Date: Sat, 27 Jun 2020 04:27:03 +0200
Subject: [PATCH] Fix Anti-Xray

---
 Spigot-Server-Patches/Anti-Xray.patch | 36 ++++++++++-----------------
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git a/Spigot-Server-Patches/Anti-Xray.patch b/Spigot-Server-Patches/Anti-Xray.patch
index 29e5b2e0e2..facbe05cd0 100644
--- a/Spigot-Server-Patches/Anti-Xray.patch
+++ b/Spigot-Server-Patches/Anti-Xray.patch
@@ -891,19 +891,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
 +
 +    public int read() {
-+        int value = (int) (current >>> bitInLongIndex) & mask;
-+        bitInLongIndex += bitsPerObject;
-+
-+        if (bitInLongIndex > 63) {
-+            bitInLongIndex -= 64;
++        if (bitInLongIndex + bitsPerObject > 64) {
++            bitInLongIndex = 0;
 +            longInDataBitsIndex += 8;
 +            init();
-+
-+            if (bitInLongIndex > 0) {
-+                value |= current << bitsPerObject - bitInLongIndex & mask;
-+            }
 +        }
 +
++        int value = (int) (current >>> bitInLongIndex) & mask;
++        bitInLongIndex += bitsPerObject;
 +        return value;
 +    }
 +}
@@ -969,29 +964,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
 +
 +    public void write(int value) {
++        if (bitInLongIndex + bitsPerObject > 64) {
++            finish();
++            bitInLongIndex = 0;
++            longInDataBitsIndex += 8;
++            init();
++        }
++
 +        current = current & ~(mask << bitInLongIndex) | (value & mask) << bitInLongIndex;
 +        dirty = true;
 +        bitInLongIndex += bitsPerObject;
-+
-+        if (bitInLongIndex > 63) {
-+            finish();
-+            bitInLongIndex -= 64;
-+            longInDataBitsIndex += 8;
-+            init();
-+
-+            if (bitInLongIndex > 0) {
-+                current = current & ~(mask >>> bitsPerObject - bitInLongIndex) | (value & mask) >>> bitsPerObject - bitInLongIndex;
-+                dirty = true;
-+            }
-+        }
 +    }
 +
 +    public void skip() {
 +        bitInLongIndex += bitsPerObject;
 +
-+        if (bitInLongIndex > 63) {
++        if (bitInLongIndex > 64) {
 +            finish();
-+            bitInLongIndex -= 64;
++            bitInLongIndex = bitsPerObject;
 +            longInDataBitsIndex += 8;
 +            init();
 +        }