--- a/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java +++ b/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java @@ -15,41 +_,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 playerAdvancements, CriterionTrigger.Listener listener) { - this.players.computeIfAbsent(playerAdvancements, advancements -> Sets.newHashSet()).add(listener); + playerAdvancements.criterionData.computeIfAbsent(this, managerx -> Sets.newHashSet()).add(listener); // Paper - fix AdvancementDataPlayer leak } @Override public final void removePlayerListener(PlayerAdvancements playerAdvancements, CriterionTrigger.Listener listener) { - Set> set = this.players.get(playerAdvancements); + Set> set = (Set) playerAdvancements.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak if (set != null) { set.remove(listener); if (set.isEmpty()) { - this.players.remove(playerAdvancements); + playerAdvancements.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak } } } @Override public final void removePlayerListeners(PlayerAdvancements playerAdvancements) { - this.players.remove(playerAdvancements); + playerAdvancements.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak } protected void trigger(ServerPlayer player, Predicate testTrigger) { PlayerAdvancements advancements = player.getAdvancements(); - Set> set = this.players.get(advancements); + Set> set = (Set) advancements.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 (testTrigger.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(); }