From df12d57bed698489affa0f9ca8be22c4d4e8fa1e Mon Sep 17 00:00:00 2001
From: XanderDeKeijzer <30620748+XanderWander@users.noreply.github.com>
Date: Thu, 16 Mar 2023 17:06:40 +0100
Subject: [PATCH] Fix changeGameModeForPlayer to use gameModeForPlayer
 MC-259571 (#8987)

---
 .../server/Fix-a-bunch-of-vanilla-bugs.patch    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/patches/server/Fix-a-bunch-of-vanilla-bugs.patch b/patches/server/Fix-a-bunch-of-vanilla-bugs.patch
index 9ec064ccec..08744f1d7f 100644
--- a/patches/server/Fix-a-bunch-of-vanilla-bugs.patch
+++ b/patches/server/Fix-a-bunch-of-vanilla-bugs.patch
@@ -44,6 +44,9 @@ https://bugs.mojang.com/browse/MC-258535
   by: Jake Potrebic <jake.m.potrebic@gmail.com>
   Fixes certain explosion damage not scaling with difficulty
 
+https://bugs.mojang.com/browse/MC-259571
+  Fix changeGameModeForPlayer to use gameModeForPlayer
+
 Co-authored-by: William Blake Galbreath <blake.galbreath@gmail.com>
 Co-authored-by: MelnCat <melncatuwu@gmail.com>
 
@@ -248,3 +251,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
      }
  }
+
+diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
++++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+@@ -0,0 +0,0 @@ public class ServerPlayerGameMode {
+                 return event; // Paper
+             }
+             // CraftBukkit end
+-            this.setGameModeForPlayer(gameMode, this.previousGameModeForPlayer);
++            this.setGameModeForPlayer(gameMode, this.gameModeForPlayer); // Paper - Fix MC-259571
+             this.player.onUpdateAbilities();
+             this.player.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, this.player), this.player); // CraftBukkit
+             this.level.updateSleepingPlayerList();