From a9be834ffa6f88dc73fc89c823b04dccbe55efd6 Mon Sep 17 00:00:00 2001
From: Warrior <50800980+Warriorrrr@users.noreply.github.com>
Date: Sun, 17 Sep 2023 00:37:38 +0300
Subject: [PATCH] Fix Projectile#setOwner(null) not clearing owner (#9715)

* Fix Projectile#setOwner(null) not clearing owner

* rebased and merged into mentioned patch

---------

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
---
 .../Refresh-ProjectileSource-for-projectiles.patch   | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/patches/server/Refresh-ProjectileSource-for-projectiles.patch b/patches/server/Refresh-ProjectileSource-for-projectiles.patch
index d8f994e1e5..b883c244fa 100644
--- a/patches/server/Refresh-ProjectileSource-for-projectiles.patch
+++ b/patches/server/Refresh-ProjectileSource-for-projectiles.patch
@@ -8,6 +8,11 @@ the API matches the owner UUID specified in the entity nbt.
 Previously, after the entity reloaded, Projectile#getShooter
 would return null, while the entity still had an owner.
 
+Also fixes setting the shooter/owner to null actually
+clearing the owner.
+
+Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
+
 diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/net/minecraft/world/entity/Entity.java
@@ -30,6 +35,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
          }
 -        this.projectileSource = (entity != null && entity.getBukkitEntity() instanceof ProjectileSource) ? (ProjectileSource) entity.getBukkitEntity() : null; // CraftBukkit
 -
++        // Paper start - Fix null owners not being handled
++        else {
++            this.ownerUUID = null;
++            this.cachedOwner = null;
++            this.projectileSource = null;
++        }
++        // Paper end
 +        this.refreshProjectileSource(false); // Paper
 +    }
 +    // Paper start