--- 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 implements CriterionTrigger { - private final Map>> players = Maps.newIdentityHashMap(); + // private final Map>> players = Maps.newIdentityHashMap(); // Paper - fix AdvancementDataPlayer leak; moved into AdvancementDataPlayer to fix memory leak @Override public final void addPlayerListener(PlayerAdvancements manager, CriterionTrigger.Listener 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 conditions) { - Set> set = this.players.get(manager); + Set> 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 predicate) { PlayerAdvancements playerAdvancements = player.getAdvancements(); - Set> set = this.players.get(playerAdvancements); + Set> 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> list = null; for (CriterionTrigger.Listener listener : set) { T simpleInstance = listener.trigger(); if (predicate.test(simpleInstance)) { Optional 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(); }