Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-21 05:50:05 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
95 Zeilen
5.4 KiB
Diff
95 Zeilen
5.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
|
Date: Mon, 13 Jul 2020 06:22:54 -0700
|
|
Subject: [PATCH] Fix AdvancementDataPlayer leak due from quitting early in
|
|
login
|
|
|
|
Move the criterion storage to the AdvancementDataPlayer object
|
|
itself, so the criterion object stores no references - and thus
|
|
needs no cleanup.
|
|
|
|
diff --git a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
|
index 31650e41b37e322d2e8a4d4a3deec95851e72675..a645c79af856d2484a4ce7aa2885a32358b9a480 100644
|
|
--- a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
|
+++ b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java
|
|
@@ -16,25 +16,25 @@ import net.minecraft.world.level.storage.loot.LootContext;
|
|
|
|
public abstract class SimpleCriterionTrigger<T extends AbstractCriterionTriggerInstance> implements CriterionTrigger<T> {
|
|
|
|
- private final Map<PlayerAdvancements, Set<CriterionTrigger.Listener<T>>> a = Maps.newIdentityHashMap();
|
|
+ //private final Map<AdvancementDataPlayer, Set<CriterionTrigger.a<T>>> a = Maps.newIdentityHashMap(); // Paper - moved into AdvancementDataPlayer to fix memory leak
|
|
|
|
public SimpleCriterionTrigger() {}
|
|
|
|
@Override
|
|
public final void a(PlayerAdvancements advancementdataplayer, CriterionTrigger.Listener<T> criteriontrigger_a) {
|
|
- ((Set) this.a.computeIfAbsent(advancementdataplayer, (advancementdataplayer1) -> {
|
|
+ (advancementdataplayer.criterionData.computeIfAbsent(this, (advancementdataplayer1) -> { // Paper - fix AdvancementDataPlayer leak
|
|
return Sets.newHashSet();
|
|
})).add(criteriontrigger_a);
|
|
}
|
|
|
|
@Override
|
|
public final void b(PlayerAdvancements advancementdataplayer, CriterionTrigger.Listener<T> criteriontrigger_a) {
|
|
- Set<CriterionTrigger.Listener<T>> set = (Set) this.a.get(advancementdataplayer);
|
|
+ Set<CriterionTrigger.Listener<T>> set = (Set) advancementdataplayer.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak
|
|
|
|
if (set != null) {
|
|
set.remove(criteriontrigger_a);
|
|
if (set.isEmpty()) {
|
|
- this.a.remove(advancementdataplayer);
|
|
+ advancementdataplayer.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak
|
|
}
|
|
}
|
|
|
|
@@ -42,7 +42,7 @@ public abstract class SimpleCriterionTrigger<T extends AbstractCriterionTriggerI
|
|
|
|
@Override
|
|
public final void removePlayerListeners(PlayerAdvancements tracker) {
|
|
- this.a.remove(tracker);
|
|
+ advancementdataplayer.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak
|
|
}
|
|
|
|
protected abstract T createInstance(JsonObject obj, EntityPredicate.Composite playerPredicate, DeserializationContext predicateDeserializer);
|
|
@@ -56,7 +56,7 @@ public abstract class SimpleCriterionTrigger<T extends AbstractCriterionTriggerI
|
|
|
|
protected void trigger(ServerPlayer player, Predicate<T> tester) {
|
|
PlayerAdvancements advancementdataplayer = player.getAdvancements();
|
|
- Set<CriterionTrigger.Listener<T>> set = (Set) this.a.get(advancementdataplayer);
|
|
+ Set<CriterionTrigger.Listener<T>> set = (Set) advancementdataplayer.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak
|
|
|
|
if (set != null && !set.isEmpty()) {
|
|
LootContext loottableinfo = EntityPredicate.createContext(player, player);
|
|
@@ -67,7 +67,7 @@ public abstract class SimpleCriterionTrigger<T extends AbstractCriterionTriggerI
|
|
|
|
while (iterator.hasNext()) {
|
|
criteriontrigger_a = (CriterionTrigger.Listener) iterator.next();
|
|
- T t0 = (AbstractCriterionTriggerInstance) criteriontrigger_a.a();
|
|
+ T t0 = (T) criteriontrigger_a.a(); // Paper - decompile fix
|
|
|
|
if (t0.getPlayerPredicate().matches(loottableinfo) && tester.test(t0)) {
|
|
if (list == null) {
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerAdvancements.java b/src/main/java/net/minecraft/server/PlayerAdvancements.java
|
|
index af8553f1b22e24fbeb732937fbbffc95cb9dfe90..acb41cc3965154c5b515cd8e808bf2cf5dc850e4 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerAdvancements.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerAdvancements.java
|
|
@@ -39,6 +39,7 @@ import net.minecraft.advancements.Criterion;
|
|
import net.minecraft.advancements.CriterionProgress;
|
|
import net.minecraft.advancements.CriterionTrigger;
|
|
import net.minecraft.advancements.CriterionTriggerInstance;
|
|
+import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
|
|
import net.minecraft.network.chat.ChatType;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
import net.minecraft.network.protocol.game.ClientboundSelectAdvancementsTabPacket;
|
|
@@ -69,6 +70,10 @@ public class PlayerAdvancements {
|
|
private Advancement lastSelectedTab;
|
|
private boolean isFirstPacket = true;
|
|
|
|
+ // Paper start - fix advancement data player leakage
|
|
+ public final Map<SimpleCriterionTrigger, Set<CriterionTrigger.Listener>> criterionData = Maps.newIdentityHashMap();
|
|
+ // Paper end - fix advancement data player leakage
|
|
+
|
|
public PlayerAdvancements(DataFixer datafixer, PlayerList playerlist, ServerAdvancementManager advancementdataworld, File file, ServerPlayer entityplayer) {
|
|
this.dataFixer = datafixer;
|
|
this.playerList = playerlist;
|