From d6adc0b26430badd351e4244e4c3cde6b13ed73a Mon Sep 17 00:00:00 2001
From: Bjarne Koll <git@lynxplay.dev>
Date: Thu, 25 Apr 2024 19:42:24 +0200
Subject: [PATCH] Some more compilation fixes

---
 patches/api/Custom-Potion-Mixes.patch         | 44 ++++++++++++++++++-
 .../server/Buffer-OOB-setBlock-calls.patch    |  3 +-
 patches/server/Custom-Potion-Mixes.patch      | 42 ++++++++++++++----
 ...rojectileHitEvent-for-piercing-arrow.patch | 15 +++----
 ...Folia-scheduler-and-owned-region-API.patch |  2 +-
 patches/server/More-Projectile-API.patch      | 26 +++++++++++
 6 files changed, 112 insertions(+), 20 deletions(-)

diff --git a/patches/api/Custom-Potion-Mixes.patch b/patches/api/Custom-Potion-Mixes.patch
index 895a15ec03..0b06c2d9e8 100644
--- a/patches/api/Custom-Potion-Mixes.patch
+++ b/patches/api/Custom-Potion-Mixes.patch
@@ -195,9 +195,51 @@ diff --git a/src/main/java/org/bukkit/potion/PotionBrewer.java b/src/main/java/o
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/potion/PotionBrewer.java
 +++ b/src/main/java/org/bukkit/potion/PotionBrewer.java
+@@ -0,0 +0,0 @@ import org.jetbrains.annotations.NotNull;
+  * Represents a brewer that can create {@link PotionEffect}s.
+  */
+ public interface PotionBrewer {
+-
++    // Paper start - keep old spigot methods, removal in 1.20.6
+     /**
+      * Creates a {@link PotionEffect} from the given {@link PotionEffectType},
+      * applying duration modifiers and checks.
 @@ -0,0 +0,0 @@ public interface PotionBrewer {
+      * @param duration The duration in ticks
+      * @param amplifier The amplifier of the effect
+      * @return The resulting potion effect
++     * @deprecated use {@link PotionEffectType#createEffect(int, int)} instead.
+      */
++    @Deprecated(forRemoval = true, since = "1.20.5")
      @NotNull
-     @Deprecated
+-    public PotionEffect createEffect(@NotNull PotionEffectType potion, int duration, int amplifier);
++    default PotionEffect createEffect(@NotNull PotionEffectType potion, int duration, int amplifier) {
++        return potion.createEffect(duration, amplifier);
++    }
+ 
+     /**
+      * Returns a collection of {@link PotionEffect} that would be applied from
+@@ -0,0 +0,0 @@ public interface PotionBrewer {
+      * @return The list of effects
+      * @deprecated Non-Functional
+      */
+-    @Deprecated
++    @Deprecated(forRemoval = true, since = "1.20.5")
+     @NotNull
+-    public Collection<PotionEffect> getEffectsFromDamage(int damage);
++    default Collection<PotionEffect> getEffectsFromDamage(final int damage) {
++        return new java.util.ArrayList<>();
++    }
++    // Paper start - keep old spigot methods, removal in 1.20.6
+ 
+     /**
+      * Returns a collection of {@link PotionEffect} that would be applied from
+@@ -0,0 +0,0 @@ public interface PotionBrewer {
+      * @deprecated Upgraded / extended potions are now their own {@link PotionType} use {@link PotionType#getPotionEffects()} instead
+      */
+     @NotNull
+-    @Deprecated
++    @Deprecated(forRemoval = true, since = "1.20.5")
      public Collection<PotionEffect> getEffects(@NotNull PotionType type, boolean upgraded, boolean extended);
 +
 +    // Paper start
diff --git a/patches/server/Buffer-OOB-setBlock-calls.patch b/patches/server/Buffer-OOB-setBlock-calls.patch
index 2720580803..2788221211 100644
--- a/patches/server/Buffer-OOB-setBlock-calls.patch
+++ b/patches/server/Buffer-OOB-setBlock-calls.patch
@@ -28,10 +28,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
  
              return true;
          } else {
--            Util.logAndPauseIfInIde("Detected setBlock in a far chunk [" + i + ", " + j + "], pos: " + String.valueOf(pos) + ", status: " + String.valueOf(this.generatingStatus) + (this.currentlyGenerating == null ? "" : ", currently generating: " + (String) this.currentlyGenerating.get()));
 +            // Paper start - Buffer OOB setBlock calls
 +            if (!hasSetFarWarned) {
-+                Util.logAndPauseIfInIde("Detected setBlock in a far chunk [" + i + ", " + j + "], pos: " + String.valueOf(pos) + ", status: " + String.valueOf(this.generatingStatus) + (this.currentlyGenerating == null ? "" : ", currently generating: " + (String) this.currentlyGenerating.get()));
+             Util.logAndPauseIfInIde("Detected setBlock in a far chunk [" + i + ", " + j + "], pos: " + String.valueOf(pos) + ", status: " + String.valueOf(this.generatingStatus) + (this.currentlyGenerating == null ? "" : ", currently generating: " + (String) this.currentlyGenerating.get()));
 +                hasSetFarWarned = true;
 +                if (this.getServer() != null && this.getServer().isDebugging()) {
 +                    io.papermc.paper.util.TraceUtil.dumpTraceForThread("far setBlock call");
diff --git a/patches/server/Custom-Potion-Mixes.patch b/patches/server/Custom-Potion-Mixes.patch
index a374dec926..dfd02f8f65 100644
--- a/patches/server/Custom-Potion-Mixes.patch
+++ b/patches/server/Custom-Potion-Mixes.patch
@@ -179,10 +179,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      private final io.papermc.paper.datapack.PaperDatapackManager datapackManager; // Paper
      public static Exception excessiveVelEx; // Paper - Velocity warnings
      private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher(); // Paper
-+    private final org.bukkit.craftbukkit.potion.CraftPotionBrewer potionBrewer = new org.bukkit.craftbukkit.potion.CraftPotionBrewer(); // Paper - Custom Potion Mixes
++    private final org.bukkit.craftbukkit.potion.CraftPotionBrewer potionBrewer; // Paper - Custom Potion Mixes
  
      static {
          ConfigurationSerialization.registerClass(CraftOfflinePlayer.class);
+@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
+         if (this.configuration.getBoolean("settings.use-map-color-cache")) {
+             MapPalette.setMapColorCache(new CraftMapColorCache(this.logger));
+         }
++        this.potionBrewer = new org.bukkit.craftbukkit.potion.CraftPotionBrewer(playerList.getServer()); // Paper - custom potion mixes
+         datapackManager = new io.papermc.paper.datapack.PaperDatapackManager(console.getPackRepository()); // Paper
+     }
+ 
 @@ -0,0 +0,0 @@ public final class CraftServer implements Server {
          return datapackManager;
      }
@@ -222,30 +230,48 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +import java.util.ArrayList;
 +import java.util.Collection;
 +import org.bukkit.potion.PotionBrewer;
-+import org.bukkit.potion.PotionData;
 +import org.bukkit.potion.PotionEffect;
 +import org.bukkit.potion.PotionEffectType;
 +import org.bukkit.potion.PotionType;
 +
 +public class CraftPotionBrewer implements PotionBrewer {
 +
++    private final net.minecraft.server.MinecraftServer minecraftServer;
++
++    public CraftPotionBrewer(net.minecraft.server.MinecraftServer minecraftServer) {
++        this.minecraftServer = minecraftServer;
++    }
++
++    // Paper start - keep old spigot methods, removal in 1.20.6
 +    @Override
 +    public Collection<PotionEffect> getEffects(PotionType type, boolean upgraded, boolean extended) {
-+        Preconditions.checkArgument(!type.getKey().getKey().startsWith("strong_"), "Strong potion type cannot be used directly, got %s", type.getKey());
-+        Preconditions.checkArgument(!type.getKey().getKey().startsWith("long_"), "Extended potion type cannot be used directly, got %s", type.getKey());
++        final org.bukkit.NamespacedKey key = type.getKey();
 +
-+        return CraftPotionUtil.fromBukkit(new PotionData(type, upgraded, extended)).getPotionEffects();
++        Preconditions.checkArgument(!key.getKey().startsWith("strong_"), "Strong potion type cannot be used directly, got %s", key);
++        Preconditions.checkArgument(!key.getKey().startsWith("long_"), "Extended potion type cannot be used directly, got %s", key);
++
++        org.bukkit.NamespacedKey effectiveKey = key;
++        if (upgraded) {
++            effectiveKey = new org.bukkit.NamespacedKey(key.namespace(), "strong_" + key.key());
++        } else if (extended) {
++            effectiveKey = new org.bukkit.NamespacedKey(key.namespace(), "long_" + key.key());
++        }
++
++        final org.bukkit.potion.PotionType effectivePotionType = org.bukkit.Registry.POTION.get(effectiveKey);
++        Preconditions.checkNotNull(type, "Unknown potion type from data " + effectiveKey.asMinimalString()); // Legacy error message in 1.20.4
++        return effectivePotionType.getPotionEffects();
 +    }
 +
 +    @Override
 +    public Collection<PotionEffect> getEffectsFromDamage(int damage) {
-+        return new ArrayList<PotionEffect>();
++        return new ArrayList<>();
 +    }
 +
 +    @Override
 +    public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier) {
-+        return new PotionEffect(potion, potion.isInstant() ? 1 : (int) (duration * potion.getDurationModifier()), amplifier);
++        return new PotionEffect(potion, potion.isInstant() ? 1 : duration, amplifier);
 +    }
++    // Paper end - keep old spigot methods, removal in 1.20.6
 +
 +    // Paper start
 +    @Override
@@ -260,7 +286,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +
 +    @Override
 +    public void resetPotionMixes() {
-+        net.minecraft.world.item.alchemy.PotionBrewing.reload();
++        this.minecraftServer.potionBrewing().reload(this.minecraftServer.getWorldData().enabledFeatures());
 +    }
 +    // Paper end
 +}
diff --git a/patches/server/Fix-cancelling-ProjectileHitEvent-for-piercing-arrow.patch b/patches/server/Fix-cancelling-ProjectileHitEvent-for-piercing-arrow.patch
index 60fbfd0b48..042b9661a3 100644
--- a/patches/server/Fix-cancelling-ProjectileHitEvent-for-piercing-arrow.patch
+++ b/patches/server/Fix-cancelling-ProjectileHitEvent-for-piercing-arrow.patch
@@ -23,9 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
      }
  
 +    // Paper start - Fix cancelling ProjectileHitEvent for piercing arrows
-     @Override
--    protected double getDefaultGravity() {
--        return 0.05D;
++    @Override
 +    public ProjectileDeflection preHitTargetOrDeflectSelf(HitResult hitResult) {
 +        if (hitResult instanceof EntityHitResult entityHitResult && this.hitCancelled && this.getPierceLevel() > 0) {
 +            if (this.piercingIgnoreEntityIds == null) {
@@ -33,9 +31,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            }
 +            this.piercingIgnoreEntityIds.add(entityHitResult.getEntity().getId());
 +        }
-+        super.preHitTargetOrDeflectSelf(hitResult);
-     }
++        return super.preHitTargetOrDeflectSelf(hitResult);
++    }
 +    // Paper end - Fix cancelling ProjectileHitEvent for piercing arrows
- 
-     private boolean shouldFall() {
-         return this.inGround && this.level().noCollision((new AABB(this.position(), this.position())).inflate(0.06D));
++
+     @Override
+     protected double getDefaultGravity() {
+         return 0.05D;
diff --git a/patches/server/Folia-scheduler-and-owned-region-API.patch b/patches/server/Folia-scheduler-and-owned-region-API.patch
index 1238551941..44cb1a5d05 100644
--- a/patches/server/Folia-scheduler-and-owned-region-API.patch
+++ b/patches/server/Folia-scheduler-and-owned-region-API.patch
@@ -1256,7 +1256,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
 @@ -0,0 +0,0 @@ public final class CraftServer implements Server {
      private final io.papermc.paper.logging.SysoutCatcher sysoutCatcher = new io.papermc.paper.logging.SysoutCatcher(); // Paper
-     private final org.bukkit.craftbukkit.potion.CraftPotionBrewer potionBrewer = new org.bukkit.craftbukkit.potion.CraftPotionBrewer(); // Paper - Custom Potion Mixes
+     private final org.bukkit.craftbukkit.potion.CraftPotionBrewer potionBrewer; // Paper - Custom Potion Mixes
  
 +    // Paper start - Folia region threading API
 +    private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler();
diff --git a/patches/server/More-Projectile-API.patch b/patches/server/More-Projectile-API.patch
index fdfe3a7d70..4865ef011e 100644
--- a/patches/server/More-Projectile-API.patch
+++ b/patches/server/More-Projectile-API.patch
@@ -132,6 +132,32 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
 +    // Paper end - More projectile API
  }
+diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java
++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java
+@@ -0,0 +0,0 @@ public class CraftAbstractArrow extends AbstractProjectile implements AbstractAr
+         this.getHandle().setCritArrow(critical);
+     }
+ 
+-    @Override
+-    public ProjectileSource getShooter() {
+-        return this.getHandle().projectileSource;
+-    }
+-
+-    @Override
+-    public void setShooter(ProjectileSource shooter) {
+-        if (shooter instanceof Entity) {
+-            this.getHandle().setOwner(((CraftEntity) shooter).getHandle());
+-        } else {
+-            this.getHandle().setOwner(null);
+-        }
+-        this.getHandle().projectileSource = shooter;
+-    }
++    // Paper - moved to AbstractProjectil
+ 
+     @Override
+     public boolean isInBlock() {
 diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java