PaperMC/paper-server/patches/sources/net/minecraft/server/PlayerAdvancements.java.patch

45 lines
2.7 KiB
Diff
Raw Normal View History

--- a/net/minecraft/server/PlayerAdvancements.java
+++ b/net/minecraft/server/PlayerAdvancements.java
@@ -63,6 +63,7 @@
private AdvancementHolder lastSelectedTab;
private boolean isFirstPacket = true;
private final Codec<PlayerAdvancements.Data> codec;
+ public final Map<net.minecraft.advancements.critereon.SimpleCriterionTrigger<?>, Set<CriterionTrigger.Listener<?>>> criterionData = new java.util.IdentityHashMap<>(); // Paper - fix advancement data player leakage
public PlayerAdvancements(DataFixer dataFixer, PlayerList playerManager, ServerAdvancementManager advancementLoader, Path filePath, ServerPlayer owner) {
this.playerList = playerManager;
@@ -162,6 +163,7 @@
}
public void save() {
+ if (org.spigotmc.SpigotConfig.disableAdvancementSaving) return; // Spigot
JsonElement jsonelement = (JsonElement) this.codec.encodeStart(JsonOps.INSTANCE, this.asData()).getOrThrow();
try {
@@ -196,6 +198,7 @@
AdvancementHolder advancementholder = loader.get(minecraftkey);
if (advancementholder == null) {
+ if (!minecraftkey.getNamespace().equals("minecraft")) return; // CraftBukkit
PlayerAdvancements.LOGGER.warn("Ignored advancement '{}' in progress file {} - it doesn't exist anymore?", minecraftkey, this.playerSavePath);
} else {
this.startProgress(advancementholder, advancementprogress);
@@ -223,10 +226,17 @@
boolean flag1 = advancementprogress.isDone();
if (advancementprogress.grantProgress(criterionName)) {
+ // Paper start - Add PlayerAdvancementCriterionGrantEvent
+ if (!new com.destroystokyo.paper.event.player.PlayerAdvancementCriterionGrantEvent(this.player.getBukkitEntity(), advancement.toBukkit(), criterionName).callEvent()) {
+ advancementprogress.revokeProgress(criterionName);
+ return false;
+ }
+ // Paper end - Add PlayerAdvancementCriterionGrantEvent
this.unregisterListeners(advancement);
this.progressChanged.add(advancement);
flag = true;
if (!flag1 && advancementprogress.isDone()) {
+ this.player.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancement.toBukkit())); // CraftBukkit
advancement.value().rewards().grant(this.player);
advancement.value().display().ifPresent((advancementdisplay) -> {
if (advancementdisplay.shouldAnnounceChat() && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) {