From 4d8954ef25fda884918d7fd2e5fea22ca3ad13d6 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 9 May 2021 13:50:09 -0700
Subject: [PATCH] Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5601)

---
 Spigot-API-Patches/Adventure.patch            |  2 +-
 .../Make-ProjectileHitEvent-Cancellable.patch | 49 ----------------
 .../Add-ProjectileCollideEvent.patch          |  6 +-
 Spigot-Server-Patches/Adventure.patch         |  4 +-
 ...gurable-projectile-relative-velocity.patch |  2 +-
 .../Implement-PlayerLocaleChangeEvent.patch   |  2 +-
 .../Make-ProjectileHitEvent-Cancellable.patch | 58 -------------------
 ...jectileHitEvent-cancel-where-missing.patch | 20 +++++++
 work/Bukkit                                   |  2 +-
 work/CraftBukkit                              |  2 +-
 work/Spigot                                   |  2 +-
 11 files changed, 31 insertions(+), 118 deletions(-)
 delete mode 100644 Spigot-API-Patches/Make-ProjectileHitEvent-Cancellable.patch
 delete mode 100644 Spigot-Server-Patches/Make-ProjectileHitEvent-Cancellable.patch
 create mode 100644 Spigot-Server-Patches/Respect-ProjectileHitEvent-cancel-where-missing.patch

diff --git a/Spigot-API-Patches/Adventure.patch b/Spigot-API-Patches/Adventure.patch
index 86c92f3ee2..d02e6b2b38 100644
--- a/Spigot-API-Patches/Adventure.patch
+++ b/Spigot-API-Patches/Adventure.patch
@@ -1580,7 +1580,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    @NotNull java.util.Locale locale();
 +    // Paper end
      /**
-      * Gets the player's current locale.
+      * Gets the player's estimated ping in milliseconds.
       *
 @@ -0,0 +0,0 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
       * they wish.
diff --git a/Spigot-API-Patches/Make-ProjectileHitEvent-Cancellable.patch b/Spigot-API-Patches/Make-ProjectileHitEvent-Cancellable.patch
deleted file mode 100644
index 843efc8924..0000000000
--- a/Spigot-API-Patches/Make-ProjectileHitEvent-Cancellable.patch
+++ /dev/null
@@ -1,49 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Aikar <aikar@aikar.co>
-Date: Sat, 16 Jan 2021 14:00:16 -0500
-Subject: [PATCH] Make ProjectileHitEvent Cancellable
-
-Allows cancelling things like detonating TNT from Fire Arrows
-
-diff --git a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
-+++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
-@@ -0,0 +0,0 @@ import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Projectile;
-+import org.bukkit.event.Cancellable;
- import org.bukkit.event.HandlerList;
- import org.jetbrains.annotations.NotNull;
- import org.jetbrains.annotations.Nullable;
-@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable;
- /**
-  * Called when a projectile hits an object
-  */
--public class ProjectileHitEvent extends EntityEvent {
-+public class ProjectileHitEvent extends EntityEvent implements Cancellable { // Paper
-     private static final HandlerList handlers = new HandlerList();
-     private final Entity hitEntity;
-     private final Block hitBlock;
-     private final BlockFace hitFace;
-+    // Paper start - make cancellable
-+    private boolean canceled;
-+    /**
-+     * @return If the arrow activating a block should be cancelled
-+     */
-+    public boolean isCancelled() {
-+        return canceled;
-+    }
-+
-+    /**
-+     * Whether or not to cancel any behavior that would occur from the arrow hitting the block
-+     * @param cancel true if you wish to cancel this event
-+     */
-+    public void setCancelled(boolean cancel) {
-+        canceled = cancel;
-+    }
-+    // Paper end
- 
-     public ProjectileHitEvent(@NotNull final Projectile projectile) {
-         this(projectile, null, null);
diff --git a/Spigot-Server-Patches/Add-ProjectileCollideEvent.patch b/Spigot-Server-Patches/Add-ProjectileCollideEvent.patch
index 5a54799854..246f6579d4 100644
--- a/Spigot-Server-Patches/Add-ProjectileCollideEvent.patch
+++ b/Spigot-Server-Patches/Add-ProjectileCollideEvent.patch
@@ -24,7 +24,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                // Paper end
 +
                  if (object != null && !flag) {
-                     this.a((MovingObjectPosition) object);
+                     this.preOnHit((MovingObjectPosition) object); // CraftBukkit - projectile hit event
                      this.impulse = true;
 diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@@ -53,7 +53,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            // Paper end
 +
 +            if (movingobjectposition != null && movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { // Paper - add null check in case cancelled
-                 this.a(movingobjectposition);
+                 this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
  
                  // CraftBukkit start - Fire ProjectileHitEvent
 diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/EntityProjectile.java
@@ -81,7 +81,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            }
 +            if (movingobjectposition != null) {
 +            // Paper end
-             this.a(movingobjectposition);
+             this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
 +            } // Paper
          }
  
diff --git a/Spigot-Server-Patches/Adventure.patch b/Spigot-Server-Patches/Adventure.patch
index aafc27945a..c17fa89e63 100644
--- a/Spigot-Server-Patches/Adventure.patch
+++ b/Spigot-Server-Patches/Adventure.patch
@@ -2249,8 +2249,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +    }
 +    // Paper end
      @Override
-     public String getLocale() {
-         return getHandle().locale;
+     public int getPing() {
+         return getHandle().ping;
 @@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
          getInventory().setItemInMainHand(hand);
      }
diff --git a/Spigot-Server-Patches/Configurable-projectile-relative-velocity.patch b/Spigot-Server-Patches/Configurable-projectile-relative-velocity.patch
index b4c27332db..0e58198579 100644
--- a/Spigot-Server-Patches/Configurable-projectile-relative-velocity.patch
+++ b/Spigot-Server-Patches/Configurable-projectile-relative-velocity.patch
@@ -50,4 +50,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        if (!entity.world.paperConfig.disableRelativeProjectileVelocity) this.setMot(this.getMot().add(vec3d.x, entity.isOnGround() ? 0.0D : vec3d.y, vec3d.z)); // Paper - allow disabling relative velocity
      }
  
-     protected void a(MovingObjectPosition movingobjectposition) {
+     // CraftBukkit start - call projectile hit event
diff --git a/Spigot-Server-Patches/Implement-PlayerLocaleChangeEvent.patch b/Spigot-Server-Patches/Implement-PlayerLocaleChangeEvent.patch
index b17b69f64c..551a52c013 100644
--- a/Spigot-Server-Patches/Implement-PlayerLocaleChangeEvent.patch
+++ b/Spigot-Server-Patches/Implement-PlayerLocaleChangeEvent.patch
@@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
 +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
 @@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
-     // Paper end
+ 
      @Override
      public String getLocale() {
 -        return getHandle().locale;
diff --git a/Spigot-Server-Patches/Make-ProjectileHitEvent-Cancellable.patch b/Spigot-Server-Patches/Make-ProjectileHitEvent-Cancellable.patch
deleted file mode 100644
index f615b597f6..0000000000
--- a/Spigot-Server-Patches/Make-ProjectileHitEvent-Cancellable.patch
+++ /dev/null
@@ -1,58 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Aikar <aikar@aikar.co>
-Date: Sat, 16 Jan 2021 14:30:12 -0500
-Subject: [PATCH] Make ProjectileHitEvent Cancellable
-
-Allows cancelling things like detonating TNT from Fire Arrows
-
-diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
-+++ b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
-@@ -0,0 +0,0 @@ public abstract class EntityFireball extends IProjectile {
- 
-                 // CraftBukkit start - Fire ProjectileHitEvent
-                 if (this.dead) {
--                    CraftEventFactory.callProjectileHitEvent(this, movingobjectposition);
-+                    if (!CraftEventFactory.callProjectileHitEvent(this, movingobjectposition)) return; // Paper - this is an undesired duplicate event, but make cancellable
-                 }
-                 // CraftBukkit end
-             }
-diff --git a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
-+++ b/src/main/java/net/minecraft/world/entity/projectile/IProjectile.java
-@@ -0,0 +0,0 @@ public abstract class IProjectile extends Entity {
-     }
- 
-     protected void a(MovingObjectPosition movingobjectposition) {
--        org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); // CraftBukkit - Call event
-+        if (!org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition)) return; // CraftBukkit - Call event // Paper - make cancellable
-         MovingObjectPosition.EnumMovingObjectType movingobjectposition_enummovingobjecttype = movingobjectposition.getType();
- 
-         if (movingobjectposition_enummovingobjecttype == MovingObjectPosition.EnumMovingObjectType.ENTITY) {
-diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
-index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
---- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
-+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
-@@ -0,0 +0,0 @@ public class CraftEventFactory {
-         return event;
-     }
- 
--    public static void callProjectileHitEvent(Entity entity, MovingObjectPosition position) {
-+    public static boolean callProjectileHitEvent(Entity entity, MovingObjectPosition position) { // Paper - make cancellable
-         if (position.getType() == MovingObjectPosition.EnumMovingObjectType.MISS) {
--            return;
-+            return false; // Paper - make cancellable
-         }
- 
-         Block hitBlock = null;
-@@ -0,0 +0,0 @@ public class CraftEventFactory {
-         }
- 
-         ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), hitEntity, hitBlock, hitFace);
--        entity.world.getServer().getPluginManager().callEvent(event);
-+        return event.callEvent(); // Paper
-     }
- 
-     public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
diff --git a/Spigot-Server-Patches/Respect-ProjectileHitEvent-cancel-where-missing.patch b/Spigot-Server-Patches/Respect-ProjectileHitEvent-cancel-where-missing.patch
new file mode 100644
index 0000000000..8c136b1b64
--- /dev/null
+++ b/Spigot-Server-Patches/Respect-ProjectileHitEvent-cancel-where-missing.patch
@@ -0,0 +1,20 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <aikar@aikar.co>
+Date: Sat, 16 Jan 2021 14:30:12 -0500
+Subject: [PATCH] Respect ProjectileHitEvent cancel where missing
+
+The duplicate ProjectileHitEvent in EntityFireball was not cancelled
+
+diff --git a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
+index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
+--- a/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
++++ b/src/main/java/net/minecraft/world/entity/projectile/EntityFireball.java
+@@ -0,0 +0,0 @@ public abstract class EntityFireball extends IProjectile {
+ 
+                 // CraftBukkit start - Fire ProjectileHitEvent
+                 if (this.dead) {
+-                    CraftEventFactory.callProjectileHitEvent(this, movingobjectposition);
++                    if (CraftEventFactory.callProjectileHitEvent(this, movingobjectposition).isCancelled()) return; // Paper - this is an undesired duplicate event, but make cancellable
+                 }
+                 // CraftBukkit end
+             }
diff --git a/work/Bukkit b/work/Bukkit
index 5eece9f858..b9ef9229d4 160000
--- a/work/Bukkit
+++ b/work/Bukkit
@@ -1 +1 @@
-Subproject commit 5eece9f8580658aff45ba851b79059c0e16b921a
+Subproject commit b9ef9229d4c10b4068d9fbdce8845cfd4a9f8fc5
diff --git a/work/CraftBukkit b/work/CraftBukkit
index 7ea8b96b4a..d28f36c684 160000
--- a/work/CraftBukkit
+++ b/work/CraftBukkit
@@ -1 +1 @@
-Subproject commit 7ea8b96b4a9a168723d1eb109c5abc6fe91b78d6
+Subproject commit d28f36c68405c1815857139e613a1098f4168029
diff --git a/work/Spigot b/work/Spigot
index 4225eac084..bd6b566898 160000
--- a/work/Spigot
+++ b/work/Spigot
@@ -1 +1 @@
-Subproject commit 4225eac084af31c8b9dca9eed3f7d146f3bc3625
+Subproject commit bd6b56689828d8bb08f6b5f46935162f9cc43d87