From 57c673412ddf406d7bd4a8798adb6a5be904f504 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 2 Dec 2021 12:21:33 -0800
Subject: [PATCH] Updated Upstream (Bukkit/CraftBukkit/Spigot) (#6990)

---
 patches/server/Add-Unix-domain-socket-support.patch   |  4 ++--
 patches/server/Add-bypass-host-check.patch            |  6 +++---
 ...shake-event-to-allow-plugins-to-handle-clien.patch | 11 ++++++-----
 ...position-desync-in-playerconnection-causing-.patch |  2 +-
 work/Bukkit                                           |  2 +-
 work/CraftBukkit                                      |  2 +-
 work/Spigot                                           |  2 +-
 7 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/patches/server/Add-Unix-domain-socket-support.patch b/patches/server/Add-Unix-domain-socket-support.patch
index 6f62cbd640..8242494a91 100644
--- a/patches/server/Add-Unix-domain-socket-support.patch
+++ b/patches/server/Add-Unix-domain-socket-support.patch
@@ -127,8 +127,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                      org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t);
                  }
 @@ -0,0 +0,0 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
-                 //if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
-                         String[] split = packet.hostName.split("\00");
+                         // Paper end
+                     // if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
                          if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.BYPASS_HOSTCHECK || ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) { // Paper
 +                            // Paper start - Unix domain socket support
 +                            java.net.SocketAddress socketAddress = connection.getRemoteAddress();
diff --git a/patches/server/Add-bypass-host-check.patch b/patches/server/Add-bypass-host-check.patch
index 9e706e3fc5..adec4049fc 100644
--- a/patches/server/Add-bypass-host-check.patch
+++ b/patches/server/Add-bypass-host-check.patch
@@ -20,9 +20,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public ServerHandshakePacketListenerImpl(MinecraftServer server, Connection connection) {
          this.server = server;
 @@ -0,0 +0,0 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
-                     // Spigot Start
-                 //if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
-                         String[] split = packet.hostName.split("\00");
+                     if (!handledByEvent && proxyLogicEnabled) {
+                         // Paper end
+                     // if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
 -                        if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) {
 +                        if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.BYPASS_HOSTCHECK || ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) { // Paper
                              packet.hostName = split[0];
diff --git a/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch b/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch
index 32d3ca2b1b..fb55e5d5c8 100644
--- a/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch
+++ b/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch
@@ -37,12 +37,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                        handledByEvent = true; // Hooray, we did it!
 +                    }
 +                }
-+                // Don't try and handle default logic if it's been handled by the event.
-+                if (!handledByEvent && proxyLogicEnabled) {
-+                // Paper end
                      // Spigot Start
+                     String[] split = packet.hostName.split("\00");
 -                    if (org.spigotmc.SpigotConfig.bungee) {
-+                //if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
-                         String[] split = packet.hostName.split("\00");
++                    // Don't try and handle default logic if it's been handled by the event.
++                    if (!handledByEvent && proxyLogicEnabled) {
++                        // Paper end
++                    // if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
                          if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) {
                              packet.hostName = split[0];
+                             connection.address = new java.net.InetSocketAddress(split[1], ((java.net.InetSocketAddress) this.connection.getRemoteAddress()).getPort());
diff --git a/patches/server/Prevent-position-desync-in-playerconnection-causing-.patch b/patches/server/Prevent-position-desync-in-playerconnection-causing-.patch
index 34a996e3a4..2a1fa8bc9d 100644
--- a/patches/server/Prevent-position-desync-in-playerconnection-causing-.patch
+++ b/patches/server/Prevent-position-desync-in-playerconnection-causing-.patch
@@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
  
                              this.player.move(MoverType.PLAYER, new Vec3(d7, d8, d9));
-                             this.player.setOnGround(packet.isOnGround()); // CraftBukkit - SPIGOT-5810, SPIGOT-5835: reset by this.player.move
+                             this.player.onGround = packet.isOnGround(); // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move
 +                            // Paper start - prevent position desync
 +                            if (this.awaitingPositionFromClient != null) {
 +                                return; // ... thanks Mojang for letting move calls teleport across dimensions.
diff --git a/work/Bukkit b/work/Bukkit
index fc0fe05559..f023e77ad7 160000
--- a/work/Bukkit
+++ b/work/Bukkit
@@ -1 +1 @@
-Subproject commit fc0fe05559f00c0ef5c45d9140097c0622368b90
+Subproject commit f023e77ad7343fa11812d3118efc956b67cdd242
diff --git a/work/CraftBukkit b/work/CraftBukkit
index a0087010ac..581df1846f 160000
--- a/work/CraftBukkit
+++ b/work/CraftBukkit
@@ -1 +1 @@
-Subproject commit a0087010ac0475f8dbc57ef3f9b4a83cbbcc0f39
+Subproject commit 581df1846f2b3e09b20e71fd44851f3e68f1f7db
diff --git a/work/Spigot b/work/Spigot
index a5dea1cbca..3c40a6c908 160000
--- a/work/Spigot
+++ b/work/Spigot
@@ -1 +1 @@
-Subproject commit a5dea1cbca6d941f1980dcc92102af7081d0b0f5
+Subproject commit 3c40a6c908b0a67b05ebf8f5268d64838e117d41