From 1bd2f3e5238c4bb1888b4e0c35c033b3bedb7fa8 Mon Sep 17 00:00:00 2001
From: Noah van der Aa <ndvdaa@gmail.com>
Date: Thu, 7 Oct 2021 20:11:15 +0200
Subject: [PATCH] Fix kicking ops when whitelist is reloaded (MC-171420)
 (#6742)

---
 patches/server/Add-PlayerKickEvent-causes.patch           | 2 +-
 ...deop-kicking-non-whitelisted-player-when-white-l.patch | 8 ++++++++
 .../forced-whitelist-use-configurable-kick-message.patch  | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/patches/server/Add-PlayerKickEvent-causes.patch b/patches/server/Add-PlayerKickEvent-causes.patch
index 273a708bd1..562c62a00e 100644
--- a/patches/server/Add-PlayerKickEvent-causes.patch
+++ b/patches/server/Add-PlayerKickEvent-causes.patch
@@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
                  ServerPlayer entityplayer = (ServerPlayer) iterator.next();
  
-                 if (!whitelist.isWhiteListed(entityplayer.getGameProfile())) {
+                 if (!whitelist.isWhiteListed(entityplayer.getGameProfile()) && !this.getPlayerList().isOp(entityplayer.getGameProfile())) { // Paper - Fix kicking ops when whitelist is reloaded (MC-171420)
 -                    entityplayer.connection.disconnect(org.spigotmc.SpigotConfig.whitelistMessage); // Paper - use configurable message
 +                    entityplayer.connection.disconnect(org.spigotmc.SpigotConfig.whitelistMessage, org.bukkit.event.player.PlayerKickEvent.Cause.WHITELIST); // Paper - use configurable message
                  }
diff --git a/patches/server/Fix-deop-kicking-non-whitelisted-player-when-white-l.patch b/patches/server/Fix-deop-kicking-non-whitelisted-player-when-white-l.patch
index 7651dcd769..1038fd6561 100644
--- a/patches/server/Fix-deop-kicking-non-whitelisted-player-when-white-l.patch
+++ b/patches/server/Fix-deop-kicking-non-whitelisted-player-when-white-l.patch
@@ -17,3 +17,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              List<ServerPlayer> list = Lists.newArrayList(playerlist.getPlayers());
              Iterator iterator = list.iterator();
  
+             while (iterator.hasNext()) {
+                 ServerPlayer entityplayer = (ServerPlayer) iterator.next();
+ 
+-                if (!whitelist.isWhiteListed(entityplayer.getGameProfile())) {
++                if (!whitelist.isWhiteListed(entityplayer.getGameProfile()) && !this.getPlayerList().isOp(entityplayer.getGameProfile())) { // Paper - Fix kicking ops when whitelist is reloaded (MC-171420)
+                     entityplayer.connection.disconnect(new TranslatableComponent("multiplayer.disconnect.not_whitelisted"));
+                 }
+             }
diff --git a/patches/server/forced-whitelist-use-configurable-kick-message.patch b/patches/server/forced-whitelist-use-configurable-kick-message.patch
index 8e0f9b4a97..de43dfabcc 100644
--- a/patches/server/forced-whitelist-use-configurable-kick-message.patch
+++ b/patches/server/forced-whitelist-use-configurable-kick-message.patch
@@ -19,7 +19,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
                  ServerPlayer entityplayer = (ServerPlayer) iterator.next();
  
-                 if (!whitelist.isWhiteListed(entityplayer.getGameProfile())) {
+                 if (!whitelist.isWhiteListed(entityplayer.getGameProfile()) && !this.getPlayerList().isOp(entityplayer.getGameProfile())) { // Paper - Fix kicking ops when whitelist is reloaded (MC-171420)
 -                    entityplayer.connection.disconnect(new TranslatableComponent("multiplayer.disconnect.not_whitelisted"));
 +                    entityplayer.connection.disconnect(org.spigotmc.SpigotConfig.whitelistMessage); // Paper - use configurable message
                  }