From 4c24ef27faac8e772aa507c4c621ec42b23e26c5 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 21 Sep 2023 20:29:51 -0700
Subject: [PATCH] some more patches

---
 ...Add-PlayerAttackEntityCooldownResetEvent.patch |  0
 ...-phantom-creative-and-insomniac-controls.patch |  0
 ...if-player-is-attempted-to-be-removed-fro.patch |  2 +-
 ...Don-t-fire-BlockFade-on-worldgen-threads.patch |  0
 ...-run-entity-collision-code-if-not-needed.patch |  2 +-
 ...nding-Broken-behavior-of-PlayerJoinEvent.patch |  2 +-
 ...-item-duplication-issues-and-teleport-is.patch |  2 +-
 .../Implement-Player-Client-Options-API.patch     |  9 ++++-----
 .../server/Improved-Watchdog-Support.patch        | 15 +++++++--------
 ...to-spawn-point-if-spawn-in-unloaded-worl.patch |  0
 .../server/Optimize-Pathfinding.patch             |  0
 .../Prevent-opening-inventories-when-frozen.patch |  0
 .../Reduce-Either-Optional-allocation.patch       |  0
 ...educe-memory-footprint-of-NBTTagCompound.patch | 14 +++++++-------
 14 files changed, 22 insertions(+), 24 deletions(-)
 rename patches/{unapplied => }/server/Add-PlayerAttackEntityCooldownResetEvent.patch (100%)
 rename patches/{unapplied => }/server/Add-phantom-creative-and-insomniac-controls.patch (100%)
 rename patches/{unapplied => }/server/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch (92%)
 rename patches/{unapplied => }/server/Don-t-fire-BlockFade-on-worldgen-threads.patch (100%)
 rename patches/{unapplied => }/server/Don-t-run-entity-collision-code-if-not-needed.patch (98%)
 rename patches/{unapplied => }/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch (99%)
 rename patches/{unapplied => }/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch (99%)
 rename patches/{unapplied => }/server/Implement-Player-Client-Options-API.patch (91%)
 rename patches/{unapplied => }/server/Improved-Watchdog-Support.patch (97%)
 rename patches/{unapplied => }/server/Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch (100%)
 rename patches/{unapplied => }/server/Optimize-Pathfinding.patch (100%)
 rename patches/{unapplied => }/server/Prevent-opening-inventories-when-frozen.patch (100%)
 rename patches/{unapplied => }/server/Reduce-Either-Optional-allocation.patch (100%)
 rename patches/{unapplied => }/server/Reduce-memory-footprint-of-NBTTagCompound.patch (79%)

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-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/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch b/patches/server/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch
similarity index 92%
rename from patches/unapplied/server/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch
rename to patches/server/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch
index ff04083261..c143fab0de 100644
--- a/patches/unapplied/server/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch
+++ b/patches/server/Don-t-crash-if-player-is-attempted-to-be-removed-fro.patch
@@ -20,4 +20,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        if (objectset == null || objectset.isEmpty()) { // Paper
              this.playersPerChunk.remove(i);
              this.naturalSpawnChunkCounter.update(i, Integer.MAX_VALUE, false);
-             //this.playerTicketManager.update(i, Integer.MAX_VALUE, false); // Paper - no longer used
+             this.playerTicketManager.update(i, Integer.MAX_VALUE, false);
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 100%
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
diff --git a/patches/unapplied/server/Don-t-run-entity-collision-code-if-not-needed.patch b/patches/server/Don-t-run-entity-collision-code-if-not-needed.patch
similarity index 98%
rename from patches/unapplied/server/Don-t-run-entity-collision-code-if-not-needed.patch
rename to patches/server/Don-t-run-entity-collision-code-if-not-needed.patch
index 9421551a00..79256d1a2a 100644
--- a/patches/unapplied/server/Don-t-run-entity-collision-code-if-not-needed.patch
+++ b/patches/server/Don-t-run-entity-collision-code-if-not-needed.patch
@@ -38,6 +38,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              if (!list.isEmpty()) {
 -                int i = this.level().getGameRules().getInt(GameRules.RULE_MAX_ENTITY_CRAMMING);
 +                // Paper - moved up
-                 int j;
  
                  if (i > 0 && list.size() > i - 1 && this.random.nextInt(4) == 0) {
+                     int j = 0;
diff --git a/patches/unapplied/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch b/patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch
similarity index 99%
rename from patches/unapplied/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch
rename to patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch
index 68f4cb2665..717f3e3f48 100644
--- a/patches/unapplied/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch
+++ b/patches/server/Fix-Longstanding-Broken-behavior-of-PlayerJoinEvent.patch
@@ -51,9 +51,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      public boolean joining = true;
      public boolean sentListPacket = false;
 +    public boolean supressTrackerForLogin = false; // Paper
-     public Integer clientViewDistance;
      public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
      // CraftBukkit end
+     public boolean isRealPlayer; // Paper
 diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/server/players/PlayerList.java
diff --git a/patches/unapplied/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch b/patches/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch
similarity index 99%
rename from patches/unapplied/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch
rename to patches/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch
index 64f50e6165..6a46c7dab7 100644
--- a/patches/unapplied/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch
+++ b/patches/server/Fix-numerous-item-duplication-issues-and-teleport-is.patch
@@ -36,7 +36,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              // CraftBukkit start
 @@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
      @Nullable
-     public Entity teleportTo(ServerLevel worldserver, PositionImpl location) {
+     public Entity teleportTo(ServerLevel worldserver, Vec3 location) {
          // CraftBukkit end
 +        // Paper start - fix bad state entities causing dupes
 +        if (!this.isAlive() || !this.valid) {
diff --git a/patches/unapplied/server/Implement-Player-Client-Options-API.patch b/patches/server/Implement-Player-Client-Options-API.patch
similarity index 91%
rename from patches/unapplied/server/Implement-Player-Client-Options-API.patch
rename to patches/server/Implement-Player-Client-Options-API.patch
index 58a3afebf8..cd41a68b37 100644
--- a/patches/unapplied/server/Implement-Player-Client-Options-API.patch
+++ b/patches/server/Implement-Player-Client-Options-API.patch
@@ -108,12 +108,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        return map;
 +    }
 +    // Paper end
-     public String locale = null; // CraftBukkit - add, lowercase // Paper - default to null
-     public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
-     public void updateOptions(ServerboundClientInformationPacket packet) {
-+        new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), getClientOptionMap(packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.chatVisibility().name()), packet.chatColors(), new com.destroystokyo.paper.PaperSkinParts(packet.modelCustomisation()), packet.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT, packet.allowsListing(), packet.textFilteringEnabled())).callEvent(); // Paper - settings event
++
+     public void updateOptions(ClientInformation clientOptions) {
++        new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), getClientOptionMap(clientOptions.language(), clientOptions.viewDistance(), com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(clientOptions.chatVisibility().name()), clientOptions.chatColors(), new com.destroystokyo.paper.PaperSkinParts(clientOptions.modelCustomisation()), clientOptions.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT, clientOptions.allowsListing(), clientOptions.textFilteringEnabled())).callEvent(); // Paper - settings event
          // CraftBukkit start
-         if (getMainArm() != packet.mainHand()) {
+         if (getMainArm() != clientOptions.mainHand()) {
              PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
diff --git a/patches/unapplied/server/Improved-Watchdog-Support.patch b/patches/server/Improved-Watchdog-Support.patch
similarity index 97%
rename from patches/unapplied/server/Improved-Watchdog-Support.patch
rename to patches/server/Improved-Watchdog-Support.patch
index 02ed572868..4a0e386696 100644
--- a/patches/unapplied/server/Improved-Watchdog-Support.patch
+++ b/patches/server/Improved-Watchdog-Support.patch
@@ -92,7 +92,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +
      public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
          AtomicReference<S> atomicreference = new AtomicReference();
-         Thread thread = new io.papermc.paper.util.TickThread(() -> { // Paper - rewrite chunk system
+         Thread thread = new Thread(() -> {
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
  
      // CraftBukkit start
@@ -122,13 +122,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          if (this.metricsRecorder.isRecording()) {
              this.cancelRecordingMetrics();
 @@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
-             this.getProfileCache().save(false); // Paper
          }
          // Spigot end
-+
+ 
 +        // Paper start - move final shutdown items here
 +        LOGGER.info("Flushing Chunk IO");
-         io.papermc.paper.chunk.system.io.RegionFileIOThread.close(true); // Paper // Paper - rewrite chunk system
++        // TODO chunk system patch has a line here
 +        LOGGER.info("Closing Thread Pool");
 +        Util.shutdownExecutors(); // Paper
 +        LOGGER.info("Closing Server");
@@ -475,14 +474,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/spigotmc/WatchdogThread.java
 +++ b/src/main/java/org/spigotmc/WatchdogThread.java
 @@ -0,0 +0,0 @@ import org.bukkit.Bukkit;
- public final class WatchdogThread extends io.papermc.paper.util.TickThread // Paper - rewrite chunk system
+ public class WatchdogThread extends Thread
  {
  
 +    public static final boolean DISABLE_WATCHDOG = Boolean.getBoolean("disable.watchdog"); // Paper
      private static WatchdogThread instance;
      private long timeoutTime;
      private boolean restart;
-@@ -0,0 +0,0 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
+@@ -0,0 +0,0 @@ public class WatchdogThread extends Thread
      {
          if ( WatchdogThread.instance == null )
          {
@@ -490,7 +489,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
              WatchdogThread.instance = new WatchdogThread( timeoutTime * 1000L, restart );
              WatchdogThread.instance.start();
          } else
-@@ -0,0 +0,0 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
+@@ -0,0 +0,0 @@ public class WatchdogThread extends Thread
              // Paper start
              Logger log = Bukkit.getServer().getLogger();
              long currentTime = WatchdogThread.monotonicMillis();
@@ -507,7 +506,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
                  lastEarlyWarning = currentTime;
                  if (isLongTimeout) {
                  // Paper end
-@@ -0,0 +0,0 @@ public final class WatchdogThread extends io.papermc.paper.util.TickThread // Pa
+@@ -0,0 +0,0 @@ public class WatchdogThread extends Thread
  
                  if ( isLongTimeout )
                  {
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 100%
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
diff --git a/patches/unapplied/server/Optimize-Pathfinding.patch b/patches/server/Optimize-Pathfinding.patch
similarity index 100%
rename from patches/unapplied/server/Optimize-Pathfinding.patch
rename to patches/server/Optimize-Pathfinding.patch
diff --git a/patches/unapplied/server/Prevent-opening-inventories-when-frozen.patch b/patches/server/Prevent-opening-inventories-when-frozen.patch
similarity index 100%
rename from patches/unapplied/server/Prevent-opening-inventories-when-frozen.patch
rename to patches/server/Prevent-opening-inventories-when-frozen.patch
diff --git a/patches/unapplied/server/Reduce-Either-Optional-allocation.patch b/patches/server/Reduce-Either-Optional-allocation.patch
similarity index 100%
rename from patches/unapplied/server/Reduce-Either-Optional-allocation.patch
rename to patches/server/Reduce-Either-Optional-allocation.patch
diff --git a/patches/unapplied/server/Reduce-memory-footprint-of-NBTTagCompound.patch b/patches/server/Reduce-memory-footprint-of-NBTTagCompound.patch
similarity index 79%
rename from patches/unapplied/server/Reduce-memory-footprint-of-NBTTagCompound.patch
rename to patches/server/Reduce-memory-footprint-of-NBTTagCompound.patch
index 0791f0b674..d96a736ac6 100644
--- a/patches/unapplied/server/Reduce-memory-footprint-of-NBTTagCompound.patch
+++ b/patches/server/Reduce-memory-footprint-of-NBTTagCompound.patch
@@ -12,14 +12,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java
 +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java
 @@ -0,0 +0,0 @@ public class CompoundTag implements Tag {
-             if (i > 512) {
-                 throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
-             } else {
--                Map<String, Tag> map = Maps.newHashMap();
-+                it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - reduce memory footprint of NBTTagCompound
  
-                 byte b;
-                 while((b = CompoundTag.readNamedTagType(dataInput, nbtAccounter)) != 0) {
+         private static CompoundTag loadCompound(DataInput input, NbtAccounter tracker) throws IOException {
+             tracker.accountBytes(48L);
+-            Map<String, Tag> map = Maps.newHashMap();
++            it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - reduce memory footprint of NBTTagCompound
+ 
+             byte b;
+             while((b = input.readByte()) != 0) {
 @@ -0,0 +0,0 @@ public class CompoundTag implements Tag {
      }