From 27c46717f66dbe326a044f206e94d41c09f03990 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Tue, 23 Apr 2024 23:44:48 -0700
Subject: [PATCH] 405

---
 .../Add-BlockStateMeta-clearBlockState.patch  |  2 +-
 ...PlayerAttackEntityCooldownResetEvent.patch |  0
 .../Add-PlayerRecipeBookClickEvent.patch      |  0
 ...-Plugin-Tickets-to-API-Chunk-Methods.patch |  4 +-
 .../server/Add-PrepareResultEvent.patch       |  0
 .../server/Add-entity-liquid-API.patch        |  0
 ...n-for-console-having-all-permissions.patch |  0
 .../Add-permission-for-command-blocks.patch   |  2 +-
 ...ntom-creative-and-insomniac-controls.patch |  0
 .../server/Add-villager-reputation-API.patch  |  0
 ...nvert-legacy-attributes-in-Item-Meta.patch |  0
 ...o-not-accept-invalid-client-settings.patch |  0
 ...k-for-portal-on-world-gen-entity-add.patch |  0
 ...t-fire-BlockFade-on-worldgen-threads.patch |  2 +-
 ...move-existing-players-to-world-spawn.patch |  2 +-
 ...-position-and-AABB-are-never-invalid.patch |  6 +-
 ...der-respects-game-and-entity-rules-f.patch |  2 +-
 .../server/Ensure-safe-gateway-teleport.patch |  0
 .../server/Entity-getEntitySpawnReason.patch  |  2 +-
 .../server/ExperienceOrbMergeEvent.patch      |  0
 .../server/Expose-game-version.patch          |  0
 ...ataPlayer-leak-due-from-quitting-ear.patch |  0
 ...er-runTaskTimerAsynchronously-Plugin.patch |  0
 ...ld-Difficulty-Remembering-Difficulty.patch |  2 +-
 .../Fix-PotionEffect-ignores-icon-flag.patch  | 12 ++--
 ...4-Bukkit-world-container-is-not-used.patch |  0
 ...-5885-Unable-to-disable-advancements.patch |  0
 .../server/Fix-SPIGOT-5989.patch              |  0
 ...ix-arrows-never-despawning-MC-125757.patch |  0
 ...item-duplication-and-teleport-issues.patch | 10 ++--
 ...ssing-chunks-due-to-integer-overflow.patch |  0
 ...ston-physics-inconsistency-MC-188840.patch |  0
 ...ix-villager-trading-demand-MC-163962.patch |  0
 .../Hide-sync-chunk-writes-behind-flag.patch  |  2 +-
 .../server/Implement-Mob-Goal-API.patch       |  0
 ...-Legacy-Component-serialization-size.patch |  0
 ...ve-fix-EntityTargetLivingEntityEvent.patch |  0
 ...Holder-method-without-block-snapshot.patch |  0
 .../server/Maps-shouldn-t-load-chunks.patch   | 19 +++---
 ...pawn-point-if-spawn-in-unloaded-worl.patch | 59 +++++++++----------
 ...ze-NetworkManager-Exception-Handling.patch | 12 ----
 ...-maximum-exp-value-when-merging-orbs.patch |  0
 .../server/Paper-dumpitem-command.patch       |  0
 .../server/Potential-bed-API.patch            |  0
 ...t-position-desync-causing-tp-exploit.patch |  0
 .../Prevent-teleporting-dead-entities.patch   |  0
 ...-per-thread-native-byte-buffer-cache.patch |  0
 ...-Vanilla-Command-permission-checking.patch |  0
 ...ookup-for-Treasure-Maps-Fixes-lag-fr.patch | 20 +++++++
 ...PickItem-Packet-and-kick-for-invalid.patch |  0
 .../server/Villager-Restocks-API.patch        |  0
 ...Wait-for-Async-Tasks-during-shutdown.patch |  2 +-
 .../server/misc-debugging-dumps.patch         |  2 +-
 ...ookup-for-Treasure-Maps-Fixes-lag-fr.patch | 27 ---------
 ...0405-Support-old-UUID-format-for-NBT.patch |  0
 ...pdate-itemstack-legacy-name-and-lore.patch |  0
 56 files changed, 83 insertions(+), 106 deletions(-)
 rename patches/{unapplied => }/server/Add-BlockStateMeta-clearBlockState.patch (85%)
 rename patches/{unapplied => }/server/Add-PlayerAttackEntityCooldownResetEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-PlayerRecipeBookClickEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch (96%)
 rename patches/{unapplied => }/server/Add-PrepareResultEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-entity-liquid-API.patch (100%)
 rename patches/{unapplied => }/server/Add-option-for-console-having-all-permissions.patch (100%)
 rename patches/{unapplied => }/server/Add-permission-for-command-blocks.patch (98%)
 rename patches/{unapplied => }/server/Add-phantom-creative-and-insomniac-controls.patch (100%)
 rename patches/{unapplied => }/server/Add-villager-reputation-API.patch (100%)
 rename patches/{unapplied => }/server/Convert-legacy-attributes-in-Item-Meta.patch (100%)
 rename patches/{unapplied => }/server/Do-not-accept-invalid-client-settings.patch (100%)
 rename patches/{unapplied => }/server/Don-t-check-chunk-for-portal-on-world-gen-entity-add.patch (100%)
 rename patches/{unapplied => }/server/Don-t-fire-BlockFade-on-worldgen-threads.patch (90%)
 rename patches/{unapplied => }/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch (91%)
 rename patches/{unapplied => }/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch (93%)
 rename patches/{unapplied => }/server/Ensure-safe-gateway-teleport.patch (100%)
 rename patches/{unapplied => }/server/ExperienceOrbMergeEvent.patch (100%)
 rename patches/{unapplied => }/server/Expose-game-version.patch (100%)
 rename patches/{unapplied => }/server/Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch (100%)
 rename patches/{unapplied => }/server/Fix-CraftScheduler-runTaskTimerAsynchronously-Plugin.patch (100%)
 rename patches/{unapplied => }/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch (98%)
 rename patches/{unapplied => }/server/Fix-PotionEffect-ignores-icon-flag.patch (82%)
 rename patches/{unapplied => }/server/Fix-SPIGOT-5824-Bukkit-world-container-is-not-used.patch (100%)
 rename patches/{unapplied => }/server/Fix-SPIGOT-5885-Unable-to-disable-advancements.patch (100%)
 rename patches/{unapplied => }/server/Fix-SPIGOT-5989.patch (100%)
 rename patches/{unapplied => }/server/Fix-arrows-never-despawning-MC-125757.patch (100%)
 rename patches/{unapplied => }/server/Fix-item-duplication-and-teleport-issues.patch (95%)
 rename patches/{unapplied => }/server/Fix-missing-chunks-due-to-integer-overflow.patch (100%)
 rename patches/{unapplied => }/server/Fix-piston-physics-inconsistency-MC-188840.patch (100%)
 rename patches/{unapplied => }/server/Fix-villager-trading-demand-MC-163962.patch (100%)
 rename patches/{unapplied => }/server/Hide-sync-chunk-writes-behind-flag.patch (94%)
 rename patches/{unapplied => }/server/Implement-Mob-Goal-API.patch (100%)
 rename patches/{unapplied => }/server/Improve-Legacy-Component-serialization-size.patch (100%)
 rename patches/{unapplied => }/server/Improve-fix-EntityTargetLivingEntityEvent.patch (100%)
 rename patches/{unapplied => }/server/Inventory-getHolder-method-without-block-snapshot.patch (100%)
 rename patches/{unapplied => }/server/Maps-shouldn-t-load-chunks.patch (60%)
 rename patches/{unapplied => }/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch (72%)
 rename patches/{unapplied => }/server/Optimize-NetworkManager-Exception-Handling.patch (59%)
 rename patches/{unapplied => }/server/Option-for-maximum-exp-value-when-merging-orbs.patch (100%)
 rename patches/{unapplied => }/server/Paper-dumpitem-command.patch (100%)
 rename patches/{unapplied => }/server/Potential-bed-API.patch (100%)
 rename patches/{unapplied => }/server/Prevent-position-desync-causing-tp-exploit.patch (100%)
 rename patches/{unapplied => }/server/Prevent-teleporting-dead-entities.patch (100%)
 rename patches/{unapplied => }/server/Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch (100%)
 rename patches/{unapplied => }/server/Thread-Safe-Vanilla-Command-permission-checking.patch (100%)
 create mode 100644 patches/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch
 rename patches/{unapplied => }/server/Validate-PickItem-Packet-and-kick-for-invalid.patch (100%)
 rename patches/{unapplied => }/server/Villager-Restocks-API.patch (100%)
 rename patches/{unapplied => }/server/Wait-for-Async-Tasks-during-shutdown.patch (93%)
 rename patches/{unapplied => }/server/misc-debugging-dumps.patch (98%)
 delete mode 100644 patches/unapplied/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch
 rename patches/unapplied/server/Support-old-UUID-format-for-NBT.patch => removed-patches-1-20-5/0405-Support-old-UUID-format-for-NBT.patch (100%)
 rename patches/unapplied/server/Update-itemstack-legacy-name-and-lore.patch => removed-patches-1-20-5/0410-Update-itemstack-legacy-name-and-lore.patch (100%)

diff --git a/patches/unapplied/server/Add-BlockStateMeta-clearBlockState.patch b/patches/server/Add-BlockStateMeta-clearBlockState.patch
similarity index 85%
rename from patches/unapplied/server/Add-BlockStateMeta-clearBlockState.patch
rename to patches/server/Add-BlockStateMeta-clearBlockState.patch
index f1dadbf5ef..ccd4619eeb 100644
--- a/patches/unapplied/server/Add-BlockStateMeta-clearBlockState.patch
+++ b/patches/server/Add-BlockStateMeta-clearBlockState.patch
@@ -21,4 +21,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +
      @Override
      public BlockState getBlockState() {
-         Material stateMaterial = (this.material != Material.SHIELD) ? this.material : CraftMetaBlockState.shieldToBannerHack(this.blockEntityTag); // Only actually used for jigsaws
+         return (this.blockEntityTag != null) ? this.blockEntityTag.copy() : CraftMetaBlockState.getBlockState(this.material, null);
diff --git a/patches/unapplied/server/Add-PlayerAttackEntityCooldownResetEvent.patch b/patches/server/Add-PlayerAttackEntityCooldownResetEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-PlayerAttackEntityCooldownResetEvent.patch
rename to patches/server/Add-PlayerAttackEntityCooldownResetEvent.patch
diff --git a/patches/unapplied/server/Add-PlayerRecipeBookClickEvent.patch b/patches/server/Add-PlayerRecipeBookClickEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-PlayerRecipeBookClickEvent.patch
rename to patches/server/Add-PlayerRecipeBookClickEvent.patch
diff --git a/patches/unapplied/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch b/patches/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch
similarity index 96%
rename from patches/unapplied/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch
rename to patches/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch
index 27d23f2b36..8e7f791226 100644
--- a/patches/unapplied/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch
+++ b/patches/server/Add-Plugin-Tickets-to-API-Chunk-Methods.patch
@@ -31,7 +31,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          this.warningState = WarningState.value(this.configuration.getString("settings.deprecated-verbose"));
 -        TicketType.PLUGIN.timeout = this.configuration.getInt("chunk-gc.period-in-ticks");
 +        TicketType.PLUGIN.timeout = Math.min(20, this.configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second
-         this.minimumAPI = this.configuration.getString("settings.minimum-api");
+         this.minimumAPI = ApiVersion.getOrCreateVersion(this.configuration.getString("settings.minimum-api"));
          this.loadIcon();
  
 @@ -0,0 +0,0 @@ public final class CraftServer implements Server {
@@ -40,7 +40,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          this.warningState = WarningState.value(this.configuration.getString("settings.deprecated-verbose"));
 -        TicketType.PLUGIN.timeout = this.configuration.getInt("chunk-gc.period-in-ticks");
 +        TicketType.PLUGIN.timeout = Math.min(20, configuration.getInt("chunk-gc.period-in-ticks")); // Paper - cap plugin loads to 1 second
-         this.minimumAPI = this.configuration.getString("settings.minimum-api");
+         this.minimumAPI = ApiVersion.getOrCreateVersion(this.configuration.getString("settings.minimum-api"));
          this.printSaveWarning = false;
          this.console.autosavePeriod = this.configuration.getInt("ticks-per.autosave");
 diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
diff --git a/patches/unapplied/server/Add-PrepareResultEvent.patch b/patches/server/Add-PrepareResultEvent.patch
similarity index 100%
rename from patches/unapplied/server/Add-PrepareResultEvent.patch
rename to patches/server/Add-PrepareResultEvent.patch
diff --git a/patches/unapplied/server/Add-entity-liquid-API.patch b/patches/server/Add-entity-liquid-API.patch
similarity index 100%
rename from patches/unapplied/server/Add-entity-liquid-API.patch
rename to patches/server/Add-entity-liquid-API.patch
diff --git a/patches/unapplied/server/Add-option-for-console-having-all-permissions.patch b/patches/server/Add-option-for-console-having-all-permissions.patch
similarity index 100%
rename from patches/unapplied/server/Add-option-for-console-having-all-permissions.patch
rename to patches/server/Add-option-for-console-having-all-permissions.patch
diff --git a/patches/unapplied/server/Add-permission-for-command-blocks.patch b/patches/server/Add-permission-for-command-blocks.patch
similarity index 98%
rename from patches/unapplied/server/Add-permission-for-command-blocks.patch
rename to patches/server/Add-permission-for-command-blocks.patch
index cd0171b241..c983e4c213 100644
--- a/patches/unapplied/server/Add-permission-for-command-blocks.patch
+++ b/patches/server/Add-permission-for-command-blocks.patch
@@ -57,7 +57,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/level/block/CommandBlock.java
 +++ b/src/main/java/net/minecraft/world/level/block/CommandBlock.java
 @@ -0,0 +0,0 @@ public class CommandBlock extends BaseEntityBlock implements GameMasterBlock {
-     public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+     protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
          BlockEntity tileentity = world.getBlockEntity(pos);
  
 -        if (tileentity instanceof CommandBlockEntity && player.canUseGameMasterBlocks()) {
diff --git a/patches/unapplied/server/Add-phantom-creative-and-insomniac-controls.patch b/patches/server/Add-phantom-creative-and-insomniac-controls.patch
similarity index 100%
rename from patches/unapplied/server/Add-phantom-creative-and-insomniac-controls.patch
rename to patches/server/Add-phantom-creative-and-insomniac-controls.patch
diff --git a/patches/unapplied/server/Add-villager-reputation-API.patch b/patches/server/Add-villager-reputation-API.patch
similarity index 100%
rename from patches/unapplied/server/Add-villager-reputation-API.patch
rename to patches/server/Add-villager-reputation-API.patch
diff --git a/patches/unapplied/server/Convert-legacy-attributes-in-Item-Meta.patch b/patches/server/Convert-legacy-attributes-in-Item-Meta.patch
similarity index 100%
rename from patches/unapplied/server/Convert-legacy-attributes-in-Item-Meta.patch
rename to patches/server/Convert-legacy-attributes-in-Item-Meta.patch
diff --git a/patches/unapplied/server/Do-not-accept-invalid-client-settings.patch b/patches/server/Do-not-accept-invalid-client-settings.patch
similarity index 100%
rename from patches/unapplied/server/Do-not-accept-invalid-client-settings.patch
rename to patches/server/Do-not-accept-invalid-client-settings.patch
diff --git a/patches/unapplied/server/Don-t-check-chunk-for-portal-on-world-gen-entity-add.patch b/patches/server/Don-t-check-chunk-for-portal-on-world-gen-entity-add.patch
similarity index 100%
rename from patches/unapplied/server/Don-t-check-chunk-for-portal-on-world-gen-entity-add.patch
rename to patches/server/Don-t-check-chunk-for-portal-on-world-gen-entity-add.patch
diff --git a/patches/unapplied/server/Don-t-fire-BlockFade-on-worldgen-threads.patch b/patches/server/Don-t-fire-BlockFade-on-worldgen-threads.patch
similarity index 90%
rename from patches/unapplied/server/Don-t-fire-BlockFade-on-worldgen-threads.patch
rename to patches/server/Don-t-fire-BlockFade-on-worldgen-threads.patch
index 40eec0ec1b..fd1ce928c5 100644
--- a/patches/unapplied/server/Don-t-fire-BlockFade-on-worldgen-threads.patch
+++ b/patches/server/Don-t-fire-BlockFade-on-worldgen-threads.patch
@@ -10,7 +10,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +++ b/src/main/java/net/minecraft/world/level/block/FireBlock.java
 @@ -0,0 +0,0 @@ public class FireBlock extends BaseFireBlock {
      @Override
-     public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
+     protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
          // CraftBukkit start
 +        if (!(world instanceof ServerLevel)) return this.canSurvive(state, world, pos) ? (BlockState) this.getStateWithAge(world, pos, (Integer) state.getValue(FireBlock.AGE)) : Blocks.AIR.defaultBlockState(); // Paper - don't fire events in world generation
          if (!this.canSurvive(state, world, pos)) {
diff --git a/patches/server/Don-t-move-existing-players-to-world-spawn.patch b/patches/server/Don-t-move-existing-players-to-world-spawn.patch
index b49c952c3c..02947b01de 100644
--- a/patches/server/Don-t-move-existing-players-to-world-spawn.patch
+++ b/patches/server/Don-t-move-existing-players-to-world-spawn.patch
@@ -40,7 +40,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +++ b/src/main/java/net/minecraft/server/players/PlayerList.java
 @@ -0,0 +0,0 @@ public abstract class PlayerList {
          // Paper start - Entity#getEntitySpawnReason
-         if (nbttagcompound == null) {
+         if (optional.isEmpty()) {
              player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
 +            player.fudgeSpawnLocation(worldserver1); // Paper - Don't move existing players to world spawn
          }
diff --git a/patches/unapplied/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch b/patches/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch
similarity index 91%
rename from patches/unapplied/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch
rename to patches/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch
index e802d11f8d..0f2b1a6e94 100644
--- a/patches/unapplied/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch
+++ b/patches/server/Ensure-Entity-position-and-AABB-are-never-invalid.patch
@@ -9,7 +9,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
 +++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
      }
  
      public void setPos(double x, double y, double z) {
@@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      }
  
      protected AABB makeBoundingBox() {
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
          return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
      }
  
@@ -50,7 +50,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          if (this.position.x != x || this.position.y != y || this.position.z != z) {
              this.position = new Vec3(x, y, z);
              int i = Mth.floor(x);
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
              this.levelCallback.onMove();
          }
  
diff --git a/patches/unapplied/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch b/patches/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch
similarity index 93%
rename from patches/unapplied/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch
rename to patches/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch
index 8e8ee25ee3..b5fddc7753 100644
--- a/patches/unapplied/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch
+++ b/patches/server/Ensure-EntityRaider-respects-game-and-entity-rules-f.patch
@@ -16,4 +16,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            if (!this.mob.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || !this.mob.canPickUpLoot()) return false; // Paper - respect game and entity rules for picking up items
              Raid raid = this.mob.getCurrentRaid();
  
-             if (this.mob.hasActiveRaid() && !this.mob.getCurrentRaid().isOver() && this.mob.canBeLeader() && !ItemStack.matches(this.mob.getItemBySlot(EquipmentSlot.HEAD), Raid.getLeaderBannerInstance())) {
+             if (this.mob.hasActiveRaid() && !this.mob.getCurrentRaid().isOver() && this.mob.canBeLeader() && !ItemStack.matches(this.mob.getItemBySlot(EquipmentSlot.HEAD), Raid.getLeaderBannerInstance(this.mob.registryAccess().lookupOrThrow(Registries.BANNER_PATTERN)))) {
diff --git a/patches/unapplied/server/Ensure-safe-gateway-teleport.patch b/patches/server/Ensure-safe-gateway-teleport.patch
similarity index 100%
rename from patches/unapplied/server/Ensure-safe-gateway-teleport.patch
rename to patches/server/Ensure-safe-gateway-teleport.patch
diff --git a/patches/server/Entity-getEntitySpawnReason.patch b/patches/server/Entity-getEntitySpawnReason.patch
index 47e524dbe8..0c2968a668 100644
--- a/patches/server/Entity-getEntitySpawnReason.patch
+++ b/patches/server/Entity-getEntitySpawnReason.patch
@@ -42,7 +42,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          }
  
 +        // Paper start - Entity#getEntitySpawnReason
-+        if (nbttagcompound == null) {
++        if (optional.isEmpty()) {
 +            player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
 +        }
 +        // Paper end - Entity#getEntitySpawnReason
diff --git a/patches/unapplied/server/ExperienceOrbMergeEvent.patch b/patches/server/ExperienceOrbMergeEvent.patch
similarity index 100%
rename from patches/unapplied/server/ExperienceOrbMergeEvent.patch
rename to patches/server/ExperienceOrbMergeEvent.patch
diff --git a/patches/unapplied/server/Expose-game-version.patch b/patches/server/Expose-game-version.patch
similarity index 100%
rename from patches/unapplied/server/Expose-game-version.patch
rename to patches/server/Expose-game-version.patch
diff --git a/patches/unapplied/server/Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch b/patches/server/Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch
similarity index 100%
rename from patches/unapplied/server/Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch
rename to patches/server/Fix-AdvancementDataPlayer-leak-due-from-quitting-ear.patch
diff --git a/patches/unapplied/server/Fix-CraftScheduler-runTaskTimerAsynchronously-Plugin.patch b/patches/server/Fix-CraftScheduler-runTaskTimerAsynchronously-Plugin.patch
similarity index 100%
rename from patches/unapplied/server/Fix-CraftScheduler-runTaskTimerAsynchronously-Plugin.patch
rename to patches/server/Fix-CraftScheduler-runTaskTimerAsynchronously-Plugin.patch
diff --git a/patches/unapplied/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch b/patches/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch
similarity index 98%
rename from patches/unapplied/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch
rename to patches/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch
index 0e3b24f03b..565e370e83 100644
--- a/patches/unapplied/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch
+++ b/patches/server/Fix-Per-World-Difficulty-Remembering-Difficulty.patch
@@ -12,7 +12,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/server/MinecraftServer.java
 +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
-         if (worldserver.getWorld().getKeepSpawnInMemory()) worldloadlistener.stop(); // Paper - Configurable Keep Spawn Loaded range per world
+         worldloadlistener.stop();
          // CraftBukkit start
          // this.updateMobSpawningFlags();
 -        worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
diff --git a/patches/unapplied/server/Fix-PotionEffect-ignores-icon-flag.patch b/patches/server/Fix-PotionEffect-ignores-icon-flag.patch
similarity index 82%
rename from patches/unapplied/server/Fix-PotionEffect-ignores-icon-flag.patch
rename to patches/server/Fix-PotionEffect-ignores-icon-flag.patch
index f96d586958..3d8aa79634 100644
--- a/patches/unapplied/server/Fix-PotionEffect-ignores-icon-flag.patch
+++ b/patches/server/Fix-PotionEffect-ignores-icon-flag.patch
@@ -13,7 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
      @Override
      public boolean addPotionEffect(PotionEffect effect, boolean force) {
--        this.getHandle().addEffect(new MobEffectInstance(CraftPotionEffectType.bukkitToMinecraft(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
+-        this.getHandle().addEffect(new MobEffectInstance(CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN);
 +        this.getHandle().addEffect(org.bukkit.craftbukkit.potion.CraftPotionUtil.fromBukkit(effect), EntityPotionEffectEvent.Cause.PLUGIN); // Paper - Don't ignore icon
          return true;
      }
@@ -21,8 +21,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
      @Override
      public PotionEffect getPotionEffect(PotionEffectType type) {
-         MobEffectInstance handle = this.getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraft(type));
--        return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
+         MobEffectInstance handle = this.getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type));
+-        return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftHolderToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible());
 +        return (handle == null) ? null : org.bukkit.craftbukkit.potion.CraftPotionUtil.toBukkit(handle); // Paper
      }
  
@@ -31,7 +31,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public Collection<PotionEffect> getActivePotionEffects() {
          List<PotionEffect> effects = new ArrayList<PotionEffect>();
          for (MobEffectInstance handle : this.getHandle().activeEffects.values()) {
--            effects.add(new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
+-            effects.add(new PotionEffect(CraftPotionEffectType.minecraftHolderToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()));
 +            effects.add(org.bukkit.craftbukkit.potion.CraftPotionUtil.toBukkit(handle)); // Paper
          }
          return effects;
@@ -43,7 +43,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public class CraftPotionUtil {
  
      public static MobEffectInstance fromBukkit(PotionEffect effect) {
-         MobEffect type = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
+         Holder<MobEffect> type = CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType());
 -        return new MobEffectInstance(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
 +        return new MobEffectInstance(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.hasIcon()); // Paper
      }
@@ -57,4 +57,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        return new PotionEffect(type, duration, amp, ambient, particles, effect.showIcon()); // Paper
      }
  
-     public static boolean equals(MobEffect mobEffect, PotionEffectType type) {
+     public static boolean equals(Holder<MobEffect> mobEffect, PotionEffectType type) {
diff --git a/patches/unapplied/server/Fix-SPIGOT-5824-Bukkit-world-container-is-not-used.patch b/patches/server/Fix-SPIGOT-5824-Bukkit-world-container-is-not-used.patch
similarity index 100%
rename from patches/unapplied/server/Fix-SPIGOT-5824-Bukkit-world-container-is-not-used.patch
rename to patches/server/Fix-SPIGOT-5824-Bukkit-world-container-is-not-used.patch
diff --git a/patches/unapplied/server/Fix-SPIGOT-5885-Unable-to-disable-advancements.patch b/patches/server/Fix-SPIGOT-5885-Unable-to-disable-advancements.patch
similarity index 100%
rename from patches/unapplied/server/Fix-SPIGOT-5885-Unable-to-disable-advancements.patch
rename to patches/server/Fix-SPIGOT-5885-Unable-to-disable-advancements.patch
diff --git a/patches/unapplied/server/Fix-SPIGOT-5989.patch b/patches/server/Fix-SPIGOT-5989.patch
similarity index 100%
rename from patches/unapplied/server/Fix-SPIGOT-5989.patch
rename to patches/server/Fix-SPIGOT-5989.patch
diff --git a/patches/unapplied/server/Fix-arrows-never-despawning-MC-125757.patch b/patches/server/Fix-arrows-never-despawning-MC-125757.patch
similarity index 100%
rename from patches/unapplied/server/Fix-arrows-never-despawning-MC-125757.patch
rename to patches/server/Fix-arrows-never-despawning-MC-125757.patch
diff --git a/patches/unapplied/server/Fix-item-duplication-and-teleport-issues.patch b/patches/server/Fix-item-duplication-and-teleport-issues.patch
similarity index 95%
rename from patches/unapplied/server/Fix-item-duplication-and-teleport-issues.patch
rename to patches/server/Fix-item-duplication-and-teleport-issues.patch
index 8b90fcb3c6..f26a337da1 100644
--- a/patches/unapplied/server/Fix-item-duplication-and-teleport-issues.patch
+++ b/patches/server/Fix-item-duplication-and-teleport-issues.patch
@@ -19,7 +19,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
 +++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
          } else {
              // CraftBukkit start - Capture drops for death event
              if (this instanceof net.minecraft.world.entity.LivingEntity && !((net.minecraft.world.entity.LivingEntity) this).forceDrops) {
@@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
              entityitem.setDefaultPickUpDelay();
              // CraftBukkit start
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
      @Nullable
      public Entity teleportTo(ServerLevel worldserver, Vec3 location) {
          // CraftBukkit end
@@ -47,7 +47,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          if (this.level() instanceof ServerLevel && !this.isRemoved()) {
              this.level().getProfiler().push("changeDimension");
              // CraftBukkit start
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
                  // CraftBukkit end
  
                  this.level().getProfiler().popPush("reloading");
@@ -59,7 +59,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                  Entity entity = this.getType().create(worldserver);
  
                  if (entity != null) {
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
                      // CraftBukkit start - Forward the CraftEntity to the new entity
                      this.getBukkitEntity().setHandle(entity);
                      entity.bukkitEntity = this.getBukkitEntity();
@@ -70,7 +70,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                      // CraftBukkit end
                  }
  
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
      }
  
      public boolean canChangeDimensions() {
diff --git a/patches/unapplied/server/Fix-missing-chunks-due-to-integer-overflow.patch b/patches/server/Fix-missing-chunks-due-to-integer-overflow.patch
similarity index 100%
rename from patches/unapplied/server/Fix-missing-chunks-due-to-integer-overflow.patch
rename to patches/server/Fix-missing-chunks-due-to-integer-overflow.patch
diff --git a/patches/unapplied/server/Fix-piston-physics-inconsistency-MC-188840.patch b/patches/server/Fix-piston-physics-inconsistency-MC-188840.patch
similarity index 100%
rename from patches/unapplied/server/Fix-piston-physics-inconsistency-MC-188840.patch
rename to patches/server/Fix-piston-physics-inconsistency-MC-188840.patch
diff --git a/patches/unapplied/server/Fix-villager-trading-demand-MC-163962.patch b/patches/server/Fix-villager-trading-demand-MC-163962.patch
similarity index 100%
rename from patches/unapplied/server/Fix-villager-trading-demand-MC-163962.patch
rename to patches/server/Fix-villager-trading-demand-MC-163962.patch
diff --git a/patches/unapplied/server/Hide-sync-chunk-writes-behind-flag.patch b/patches/server/Hide-sync-chunk-writes-behind-flag.patch
similarity index 94%
rename from patches/unapplied/server/Hide-sync-chunk-writes-behind-flag.patch
rename to patches/server/Hide-sync-chunk-writes-behind-flag.patch
index a8499fa156..1a55aacd48 100644
--- a/patches/unapplied/server/Hide-sync-chunk-writes-behind-flag.patch
+++ b/patches/server/Hide-sync-chunk-writes-behind-flag.patch
@@ -18,6 +18,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          }, 29999984);
 -        this.syncChunkWrites = this.get("sync-chunk-writes", true);
 +        this.syncChunkWrites = this.get("sync-chunk-writes", true) && Boolean.getBoolean("Paper.enable-sync-chunk-writes"); // Paper - Hide sync chunk writes behind flag
+         this.regionFileComression = this.get("region-file-compression", "deflate");
          this.enableJmxMonitoring = this.get("enable-jmx-monitoring", false);
          this.enableStatus = this.get("enable-status", true);
-         this.hideOnlinePlayers = this.get("hide-online-players", false);
diff --git a/patches/unapplied/server/Implement-Mob-Goal-API.patch b/patches/server/Implement-Mob-Goal-API.patch
similarity index 100%
rename from patches/unapplied/server/Implement-Mob-Goal-API.patch
rename to patches/server/Implement-Mob-Goal-API.patch
diff --git a/patches/unapplied/server/Improve-Legacy-Component-serialization-size.patch b/patches/server/Improve-Legacy-Component-serialization-size.patch
similarity index 100%
rename from patches/unapplied/server/Improve-Legacy-Component-serialization-size.patch
rename to patches/server/Improve-Legacy-Component-serialization-size.patch
diff --git a/patches/unapplied/server/Improve-fix-EntityTargetLivingEntityEvent.patch b/patches/server/Improve-fix-EntityTargetLivingEntityEvent.patch
similarity index 100%
rename from patches/unapplied/server/Improve-fix-EntityTargetLivingEntityEvent.patch
rename to patches/server/Improve-fix-EntityTargetLivingEntityEvent.patch
diff --git a/patches/unapplied/server/Inventory-getHolder-method-without-block-snapshot.patch b/patches/server/Inventory-getHolder-method-without-block-snapshot.patch
similarity index 100%
rename from patches/unapplied/server/Inventory-getHolder-method-without-block-snapshot.patch
rename to patches/server/Inventory-getHolder-method-without-block-snapshot.patch
diff --git a/patches/unapplied/server/Maps-shouldn-t-load-chunks.patch b/patches/server/Maps-shouldn-t-load-chunks.patch
similarity index 60%
rename from patches/unapplied/server/Maps-shouldn-t-load-chunks.patch
rename to patches/server/Maps-shouldn-t-load-chunks.patch
index 0f38337ba6..7dc4a2394f 100644
--- a/patches/unapplied/server/Maps-shouldn-t-load-chunks.patch
+++ b/patches/server/Maps-shouldn-t-load-chunks.patch
@@ -19,14 +19,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/world/item/MapItem.java
 +++ b/src/main/java/net/minecraft/world/item/MapItem.java
 @@ -0,0 +0,0 @@ public class MapItem extends ComplexItem {
-                             int j2 = (j / i + k1 - 64) * i;
-                             int k2 = (k / i + l1 - 64) * i;
+                             int r = (j / i + o - 64) * i;
+                             int s = (k / i + p - 64) * i;
                              Multiset<MapColor> multiset = LinkedHashMultiset.create();
--                            LevelChunk chunk = world.getChunk(SectionPos.blockToSectionCoord(j2), SectionPos.blockToSectionCoord(k2));
-+                            LevelChunk chunk = world.getChunkIfLoaded(SectionPos.blockToSectionCoord(j2), SectionPos.blockToSectionCoord(k2)); // Paper - Maps shouldn't load chunks
- 
--                            if (!chunk.isEmpty()) {
-+                            if (chunk != null && !chunk.isEmpty()) { // Paper - Maps shouldn't load chunks
-                                 int l2 = 0;
-                                 double d1 = 0.0D;
-                                 int i3;
+-                            LevelChunk levelChunk = world.getChunk(SectionPos.blockToSectionCoord(r), SectionPos.blockToSectionCoord(s));
+-                            if (!levelChunk.isEmpty()) {
++                            LevelChunk levelChunk = world.getChunkIfLoaded(SectionPos.blockToSectionCoord(r), SectionPos.blockToSectionCoord(s)); // Paper - Maps shouldn't load chunks
++                            if (levelChunk != null && !levelChunk.isEmpty()) { // Paper - Maps shouldn't load chunks
+                                 int t = 0;
+                                 double e = 0.0;
+                                 if (world.dimensionType().hasCeiling()) {
diff --git a/patches/unapplied/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch b/patches/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch
similarity index 72%
rename from patches/unapplied/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch
rename to patches/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch
index 88d67887a2..5ab45f0e10 100644
--- a/patches/unapplied/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch
+++ b/patches/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch
@@ -16,25 +16,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 @@ -0,0 +0,0 @@ public abstract class PlayerList {
          }
  
-         CompoundTag nbttagcompound = this.load(player);
--        ResourceKey resourcekey;
+         Optional<CompoundTag> optional = this.load(player); // CraftBukkit - decompile error
 +        ResourceKey<Level> resourcekey = null; // Paper
          // CraftBukkit start - Better rename detection
-         if (nbttagcompound != null && nbttagcompound.contains("bukkit")) {
-             CompoundTag bukkit = nbttagcompound.getCompound("bukkit");
+         if (optional.isPresent()) {
+             CompoundTag nbttagcompound = optional.get();
 @@ -0,0 +0,0 @@ public abstract class PlayerList {
+             }
          }
          // CraftBukkit end
- 
+-        ResourceKey<Level> resourcekey = (ResourceKey) optional.flatMap((nbttagcompound) -> {
 +        // Paper start - move logic in Entity to here, to use bukkit supplied world UUID & reset to main world spawn if no valid world is found
-+        boolean invalidPlayerWorld = false;
-+        bukkitData: if (nbttagcompound != null) {
++        boolean[] invalidPlayerWorld = {false};
++        bukkitData: if (optional.isPresent()) {
 +            // The main way for bukkit worlds to store the world is the world UUID despite mojang adding custom worlds
 +            final org.bukkit.World bWorld;
-+            if (nbttagcompound.contains("WorldUUIDMost") && nbttagcompound.contains("WorldUUIDLeast")) {
-+                bWorld = org.bukkit.Bukkit.getServer().getWorld(new UUID(nbttagcompound.getLong("WorldUUIDMost"), nbttagcompound.getLong("WorldUUIDLeast")));
-+            } else if (nbttagcompound.contains("world", net.minecraft.nbt.Tag.TAG_STRING)) { // Paper - legacy bukkit world name
-+                bWorld = org.bukkit.Bukkit.getServer().getWorld(nbttagcompound.getString("world"));
++            if (optional.get().contains("WorldUUIDMost") && optional.get().contains("WorldUUIDLeast")) {
++                bWorld = org.bukkit.Bukkit.getServer().getWorld(new UUID(optional.get().getLong("WorldUUIDMost"), optional.get().getLong("WorldUUIDLeast")));
++            } else if (optional.get().contains("world", net.minecraft.nbt.Tag.TAG_STRING)) { // Paper - legacy bukkit world name
++                bWorld = org.bukkit.Bukkit.getServer().getWorld(optional.get().getString("world"));
 +            } else {
 +                break bukkitData; // if neither of the bukkit data points exist, proceed to the vanilla migration section
 +            }
@@ -42,46 +42,43 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                resourcekey = ((CraftWorld) bWorld).getHandle().dimension();
 +            } else {
 +                resourcekey = Level.OVERWORLD;
-+                invalidPlayerWorld = true;
++                invalidPlayerWorld[0] = true;
 +            }
 +        }
 +        if (resourcekey == null) { // only run the vanilla logic if we haven't found a world from the bukkit data
 +        // Below is the vanilla way of getting the dimension, this is for migration from vanilla servers
-+        // Paper end
-         if (nbttagcompound != null) {
++        resourcekey = optional.flatMap((nbttagcompound) -> {
++            // Paper end
              DataResult<ResourceKey<Level>> dataresult = DimensionType.parseLegacy(new Dynamic(NbtOps.INSTANCE, nbttagcompound.get("Dimension"))); // CraftBukkit - decompile error
              Logger logger = PlayerList.LOGGER;
  
              Objects.requireNonNull(logger);
--            resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElse(player.serverLevel().dimension()); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD
+-            return dataresult.resultOrPartial(logger::error);
+-        }).orElse(player.serverLevel().dimension()); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD
 +            // Paper start - reset to main world spawn if no valid world is found
 +            final Optional<ResourceKey<Level>> result = dataresult.resultOrPartial(logger::error);
-+            invalidPlayerWorld = result.isEmpty();
-+            resourcekey = result.orElse(Level.OVERWORLD);
-+            // Paper end
-         } else {
--            resourcekey = player.serverLevel().dimension(); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD
-+            resourcekey = Level.OVERWORLD; // Paper - revert to vanilla default main world, this isn't an "invalid world" since no player data existed
-         }
-+        } // Paper
++            invalidPlayerWorld[0] = result.isEmpty();
++            return result;
++        }).orElse(Level.OVERWORLD); // Paper - revert to vanilla default main world, this isn't an "invalid world" since no player data existed
++        }
++        // Paper end
+         ServerLevel worldserver = this.server.getLevel(resourcekey);
+         ServerLevel worldserver1;
  
-         ResourceKey<Level> resourcekey1 = resourcekey;
-         ServerLevel worldserver = this.server.getLevel(resourcekey1);
-@@ -0,0 +0,0 @@ public abstract class PlayerList {
          if (worldserver == null) {
-             PlayerList.LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", resourcekey1);
+             PlayerList.LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", resourcekey);
              worldserver1 = this.server.overworld();
-+            invalidPlayerWorld = true; // Paper - reset to main world if no world with parsed value is found
++            invalidPlayerWorld[0] = true; // Paper - reset to main world if no world with parsed value is found
          } else {
              worldserver1 = worldserver;
          }
 @@ -0,0 +0,0 @@ public abstract class PlayerList {
          // Paper start - Entity#getEntitySpawnReason
-         if (nbttagcompound == null) {
+         if (optional.isEmpty()) {
              player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
 +            // Paper start - reset to main world spawn if first spawn or invalid world
 +        }
-+        if (nbttagcompound == null || invalidPlayerWorld) {
++        if (optional.isEmpty() || invalidPlayerWorld[0]) {
 +            // Paper end - reset to main world spawn if first spawn or invalid world
              player.fudgeSpawnLocation(worldserver1); // Paper - Don't move existing players to world spawn
          }
@@ -90,7 +87,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
 +++ b/src/main/java/net/minecraft/world/entity/Entity.java
-@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
+@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
              }
              // CraftBukkit end
  
diff --git a/patches/unapplied/server/Optimize-NetworkManager-Exception-Handling.patch b/patches/server/Optimize-NetworkManager-Exception-Handling.patch
similarity index 59%
rename from patches/unapplied/server/Optimize-NetworkManager-Exception-Handling.patch
rename to patches/server/Optimize-NetworkManager-Exception-Handling.patch
index 23031e1f97..299b70ed3e 100644
--- a/patches/unapplied/server/Optimize-NetworkManager-Exception-Handling.patch
+++ b/patches/server/Optimize-NetworkManager-Exception-Handling.patch
@@ -4,18 +4,6 @@ Date: Sun, 5 Jul 2020 22:38:18 -0400
 Subject: [PATCH] Optimize NetworkManager Exception Handling
 
 
-diff --git a/src/main/java/net/minecraft/network/ConnectionProtocol.java b/src/main/java/net/minecraft/network/ConnectionProtocol.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/net/minecraft/network/ConnectionProtocol.java
-+++ b/src/main/java/net/minecraft/network/ConnectionProtocol.java
-@@ -0,0 +0,0 @@ public enum ConnectionProtocol {
- 
-         @Nullable
-         public Packet<?> createPacket(int id, FriendlyByteBuf buf) {
-+            if (id < 0 || id >= this.idToDeserializer.size()) return null; // Paper - Perf: Optimize exception handling
-             Function<FriendlyByteBuf, ? extends Packet<? super T>> function = this.idToDeserializer.get(id);
-             return (Packet<?>)(function != null ? function.apply(buf) : null);
-         }
 diff --git a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java b/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/network/Varint21FrameDecoder.java
diff --git a/patches/unapplied/server/Option-for-maximum-exp-value-when-merging-orbs.patch b/patches/server/Option-for-maximum-exp-value-when-merging-orbs.patch
similarity index 100%
rename from patches/unapplied/server/Option-for-maximum-exp-value-when-merging-orbs.patch
rename to patches/server/Option-for-maximum-exp-value-when-merging-orbs.patch
diff --git a/patches/unapplied/server/Paper-dumpitem-command.patch b/patches/server/Paper-dumpitem-command.patch
similarity index 100%
rename from patches/unapplied/server/Paper-dumpitem-command.patch
rename to patches/server/Paper-dumpitem-command.patch
diff --git a/patches/unapplied/server/Potential-bed-API.patch b/patches/server/Potential-bed-API.patch
similarity index 100%
rename from patches/unapplied/server/Potential-bed-API.patch
rename to patches/server/Potential-bed-API.patch
diff --git a/patches/unapplied/server/Prevent-position-desync-causing-tp-exploit.patch b/patches/server/Prevent-position-desync-causing-tp-exploit.patch
similarity index 100%
rename from patches/unapplied/server/Prevent-position-desync-causing-tp-exploit.patch
rename to patches/server/Prevent-position-desync-causing-tp-exploit.patch
diff --git a/patches/unapplied/server/Prevent-teleporting-dead-entities.patch b/patches/server/Prevent-teleporting-dead-entities.patch
similarity index 100%
rename from patches/unapplied/server/Prevent-teleporting-dead-entities.patch
rename to patches/server/Prevent-teleporting-dead-entities.patch
diff --git a/patches/unapplied/server/Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch b/patches/server/Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch
similarity index 100%
rename from patches/unapplied/server/Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch
rename to patches/server/Set-cap-on-JDK-per-thread-native-byte-buffer-cache.patch
diff --git a/patches/unapplied/server/Thread-Safe-Vanilla-Command-permission-checking.patch b/patches/server/Thread-Safe-Vanilla-Command-permission-checking.patch
similarity index 100%
rename from patches/unapplied/server/Thread-Safe-Vanilla-Command-permission-checking.patch
rename to patches/server/Thread-Safe-Vanilla-Command-permission-checking.patch
diff --git a/patches/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch b/patches/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch
new file mode 100644
index 0000000000..28408264c7
--- /dev/null
+++ b/patches/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch
@@ -0,0 +1,20 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <aikar@aikar.co>
+Date: Sun, 7 Jun 2020 19:25:13 -0400
+Subject: [PATCH] Use seed based lookup for Treasure Maps - Fixes lag from
+ carto/sunken maps
+
+
+diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/item/MapItem.java
++++ b/src/main/java/net/minecraft/world/item/MapItem.java
+@@ -0,0 +0,0 @@ public class MapItem extends ComplexItem {
+ 
+                 for (int n = 0; n < 128; n++) {
+                     for (int o = 0; o < 128; o++) {
+-                        Holder<Biome> holder = world.getBiome(mutableBlockPos.set((l + o) * i, 0, (m + n) * i));
++                        Holder<Biome> holder = world.getUncachedNoiseBiome((l + o) * i, 0, (m + n) * i); // Paper - Perf: Use seed based lookup for treasure maps
+                         bls[n * 128 + o] = holder.is(BiomeTags.WATER_ON_MAP_OUTLINES);
+                     }
+                 }
diff --git a/patches/unapplied/server/Validate-PickItem-Packet-and-kick-for-invalid.patch b/patches/server/Validate-PickItem-Packet-and-kick-for-invalid.patch
similarity index 100%
rename from patches/unapplied/server/Validate-PickItem-Packet-and-kick-for-invalid.patch
rename to patches/server/Validate-PickItem-Packet-and-kick-for-invalid.patch
diff --git a/patches/unapplied/server/Villager-Restocks-API.patch b/patches/server/Villager-Restocks-API.patch
similarity index 100%
rename from patches/unapplied/server/Villager-Restocks-API.patch
rename to patches/server/Villager-Restocks-API.patch
diff --git a/patches/unapplied/server/Wait-for-Async-Tasks-during-shutdown.patch b/patches/server/Wait-for-Async-Tasks-during-shutdown.patch
similarity index 93%
rename from patches/unapplied/server/Wait-for-Async-Tasks-during-shutdown.patch
rename to patches/server/Wait-for-Async-Tasks-during-shutdown.patch
index f199ceaa6f..d68256c4a5 100644
--- a/patches/unapplied/server/Wait-for-Async-Tasks-during-shutdown.patch
+++ b/patches/server/Wait-for-Async-Tasks-during-shutdown.patch
@@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            this.server.waitForAsyncTasksShutdown(); // Paper - Wait for Async Tasks during shutdown
          }
          // CraftBukkit end
-         this.getConnection().stop();
+         if (io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper != null) io.papermc.paper.plugin.PluginInitializerManager.instance().pluginRemapper.shutdown(); // Paper - Plugin remapping
 diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
diff --git a/patches/unapplied/server/misc-debugging-dumps.patch b/patches/server/misc-debugging-dumps.patch
similarity index 98%
rename from patches/unapplied/server/misc-debugging-dumps.patch
rename to patches/server/misc-debugging-dumps.patch
index 8e8760bef6..d67de0b5c2 100644
--- a/patches/unapplied/server/misc-debugging-dumps.patch
+++ b/patches/server/misc-debugging-dumps.patch
@@ -86,7 +86,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          super.onDisconnect(reason);
      }
 @@ -0,0 +0,0 @@ public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketLis
-             this.connection.resumeInboundAfterProtocolChange();
+             playerlist.placeNewPlayer(this.connection, entityplayer, this.createCookie(this.clientInformation));
          } catch (Exception exception) {
              ServerConfigurationPacketListenerImpl.LOGGER.error("Couldn't place player in world", exception);
 +            // Paper start - Debugging
diff --git a/patches/unapplied/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch b/patches/unapplied/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch
deleted file mode 100644
index 643f0e86f4..0000000000
--- a/patches/unapplied/server/Use-seed-based-lookup-for-Treasure-Maps-Fixes-lag-fr.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Aikar <aikar@aikar.co>
-Date: Sun, 7 Jun 2020 19:25:13 -0400
-Subject: [PATCH] Use seed based lookup for Treasure Maps - Fixes lag from
- carto/sunken maps
-
-
-diff --git a/src/main/java/net/minecraft/world/item/MapItem.java b/src/main/java/net/minecraft/world/item/MapItem.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/net/minecraft/world/item/MapItem.java
-+++ b/src/main/java/net/minecraft/world/item/MapItem.java
-@@ -0,0 +0,0 @@ public class MapItem extends ComplexItem {
-                 boolean[] aboolean = new boolean[16384];
-                 int l = j / i - 64;
-                 int i1 = k / i - 64;
--                BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
- 
-                 int j1;
-                 int k1;
- 
-                 for (j1 = 0; j1 < 128; ++j1) {
-                     for (k1 = 0; k1 < 128; ++k1) {
--                        Holder<Biome> holder = world.getBiome(blockposition_mutableblockposition.set((l + k1) * i, 0, (i1 + j1) * i));
-+                        Holder<Biome> holder = world.getUncachedNoiseBiome((l + k1) * i, 0, (i1 + j1) * i); // Paper - Perf: Use seed based lookup for treasure maps
- 
-                         aboolean[j1 * 128 + k1] = holder.is(BiomeTags.WATER_ON_MAP_OUTLINES);
-                     }
diff --git a/patches/unapplied/server/Support-old-UUID-format-for-NBT.patch b/removed-patches-1-20-5/0405-Support-old-UUID-format-for-NBT.patch
similarity index 100%
rename from patches/unapplied/server/Support-old-UUID-format-for-NBT.patch
rename to removed-patches-1-20-5/0405-Support-old-UUID-format-for-NBT.patch
diff --git a/patches/unapplied/server/Update-itemstack-legacy-name-and-lore.patch b/removed-patches-1-20-5/0410-Update-itemstack-legacy-name-and-lore.patch
similarity index 100%
rename from patches/unapplied/server/Update-itemstack-legacy-name-and-lore.patch
rename to removed-patches-1-20-5/0410-Update-itemstack-legacy-name-and-lore.patch