aboutsummaryrefslogtreecommitdiffhomepage
path: root/paper-server/patches/unapplied/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java.patch
blob: d080616002710729caaa973adb92d31120f22307 (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
--- a/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
+++ b/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
@@ -15,41 +15,41 @@
 import net.minecraft.world.level.storage.loot.LootContext;
 
 public abstract class SimpleCriterionTrigger<T extends SimpleCriterionTrigger.SimpleInstance> implements CriterionTrigger<T> {
-    private final Map<PlayerAdvancements, Set<CriterionTrigger.Listener<T>>> players = Maps.newIdentityHashMap();
+    // private final Map<PlayerAdvancements, Set<CriterionTrigger.Listener<T>>> players = Maps.newIdentityHashMap(); // Paper - fix AdvancementDataPlayer leak; moved into AdvancementDataPlayer to fix memory leak
 
     @Override
     public final void addPlayerListener(PlayerAdvancements manager, CriterionTrigger.Listener<T> conditions) {
-        this.players.computeIfAbsent(manager, managerx -> Sets.newHashSet()).add(conditions);
+        manager.criterionData.computeIfAbsent(this, managerx -> Sets.newHashSet()).add(conditions);  // Paper - fix AdvancementDataPlayer leak
     }
 
     @Override
     public final void removePlayerListener(PlayerAdvancements manager, CriterionTrigger.Listener<T> conditions) {
-        Set<CriterionTrigger.Listener<T>> set = this.players.get(manager);
+        Set<CriterionTrigger.Listener<T>> set = (Set) manager.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak
         if (set != null) {
             set.remove(conditions);
             if (set.isEmpty()) {
-                this.players.remove(manager);
+                manager.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak
             }
         }
     }
 
     @Override
     public final void removePlayerListeners(PlayerAdvancements tracker) {
-        this.players.remove(tracker);
+        tracker.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak
     }
 
     protected void trigger(ServerPlayer player, Predicate<T> predicate) {
         PlayerAdvancements playerAdvancements = player.getAdvancements();
-        Set<CriterionTrigger.Listener<T>> set = this.players.get(playerAdvancements);
+        Set<CriterionTrigger.Listener<T>> set = (Set) playerAdvancements.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak
         if (set != null && !set.isEmpty()) {
-            LootContext lootContext = EntityPredicate.createContext(player, player);
+            LootContext lootContext = null; // EntityPredicate.createContext(player, player); // Paper - Perf: lazily create LootContext for criterions
             List<CriterionTrigger.Listener<T>> list = null;
 
             for (CriterionTrigger.Listener<T> listener : set) {
                 T simpleInstance = listener.trigger();
                 if (predicate.test(simpleInstance)) {
                     Optional<ContextAwarePredicate> optional = simpleInstance.player();
-                    if (optional.isEmpty() || optional.get().matches(lootContext)) {
+                    if (optional.isEmpty() || optional.get().matches(lootContext = (lootContext == null ? EntityPredicate.createContext(player, player) : lootContext))) { // Paper - Perf: lazily create LootContext for criterions
                         if (list == null) {
                             list = Lists.newArrayList();
                         }