aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0755-check-global-player-list-where-appropriate.patch
blob: 2c629600b21464186c7f57c0804e2b9a94f0de7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Tue, 22 Nov 2022 13:16:01 -0800
Subject: [PATCH] check global player list where appropriate

Makes certain entities check all players when searching for a player
instead of just checking players in their world.

diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index ad39671baae44714488eefbdbd4924824fd45fbc..8e72d36c2e2b5ff91b16188c95646b8447b6b2b8 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -2368,4 +2368,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
             entity.updateDynamicGameEventListener(DynamicGameEventListener::move);
         }
     }
+
+    // Paper start - check global player list where appropriate
+    @Override
+    @Nullable
+    public Player getGlobalPlayerByUUID(UUID uuid) {
+        return this.server.getPlayerList().getPlayer(uuid);
+    }
+    // Paper end - check global player list where appropriate
 }
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 28eb50111e524bce5aadb1dd2eea14a7df0105f2..26c25f9ccd59922ced968abef41683c2b6b45e7d 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3877,7 +3877,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public void onItemPickup(ItemEntity item) {
-        Entity entity = item.getOwner();
+        Entity entity = item.thrower != null ? this.level().getGlobalPlayerByUUID(item.thrower) : null; // Paper - check global player list where appropriate
 
         if (entity instanceof ServerPlayer) {
             CriteriaTriggers.THROWN_ITEM_PICKED_UP_BY_ENTITY.trigger((ServerPlayer) entity, item.getItem(), this);
diff --git a/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java b/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java
index a5d13b8bf7d0b6423ef428042e1134f5999cc24b..30bce56a70f923b0ec77c8e3f29e435a71c71510 100644
--- a/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java
+++ b/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java
@@ -262,7 +262,7 @@ public class ZombieVillager extends Zombie implements VillagerDataHolder {
             entityvillager.finalizeSpawn(world, world.getCurrentDifficultyAt(entityvillager.blockPosition()), EntitySpawnReason.CONVERSION, (SpawnGroupData) null);
             entityvillager.refreshBrain(world);
             if (this.conversionStarter != null) {
-                Player entityhuman = world.getPlayerByUUID(this.conversionStarter);
+            Player entityhuman = world.getGlobalPlayerByUUID(this.conversionStarter); // Paper - check global player list where appropriate
 
                 if (entityhuman instanceof ServerPlayer) {
                     CriteriaTriggers.CURED_ZOMBIE_VILLAGER.trigger((ServerPlayer) entityhuman, this, entityvillager);
diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java
index dac8305f1c897e6f82a2dde67c5b1b6b8b649b19..e185a33b5b1f8e8e0a0e666b24ba3e9186a8a7ff 100644
--- a/src/main/java/net/minecraft/world/level/EntityGetter.java
+++ b/src/main/java/net/minecraft/world/level/EntityGetter.java
@@ -165,4 +165,11 @@ public interface EntityGetter {
 
         return null;
     }
+
+    // Paper start - check global player list where appropriate
+    @Nullable
+    default Player getGlobalPlayerByUUID(UUID uuid) {
+        return this.getPlayerByUUID(uuid);
+    }
+    // Paper end - check global player list where appropriate
 }
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
index 4bc3eded897b067e00c8e310c1be603aa7097ac4..84b6d88fdfe2cb8de297ef8a62cf923f004ee397 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SculkShriekerBlockEntity.java
@@ -105,6 +105,13 @@ public class SculkShriekerBlockEntity extends BlockEntity implements GameEventLi
 
     @Nullable
     public static ServerPlayer tryGetPlayer(@Nullable Entity entity) {
+        // Paper start - check global player list where appropriate; ensure level is the same for sculk events
+        final ServerPlayer player = tryGetPlayer0(entity);
+        return player != null && player.level() == entity.level() ? player : null;
+    }
+    @Nullable
+    private static ServerPlayer tryGetPlayer0(@Nullable Entity entity) {
+        // Paper end - check global player list where appropriate
         if (entity instanceof ServerPlayer) {
             return (ServerPlayer)entity;
         } else {