geforkt von Mirrors/Paper
53 Zeilen
3.4 KiB
Diff
53 Zeilen
3.4 KiB
Diff
--- 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<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 playerAdvancements, CriterionTrigger.Listener<T> 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<T> listener) {
|
|
- 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.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<T> testTrigger) {
|
|
PlayerAdvancements advancements = player.getAdvancements();
|
|
- Set<CriterionTrigger.Listener<T>> set = this.players.get(advancements);
|
|
+ Set<CriterionTrigger.Listener<T>> 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<CriterionTrigger.Listener<T>> list = null;
|
|
|
|
for (CriterionTrigger.Listener<T> listener : set) {
|
|
T simpleInstance = listener.trigger();
|
|
if (testTrigger.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();
|
|
}
|