PaperMC/patches/server/0918-OfflinePlayer-advancements.patch
2022-06-25 14:18:52 -07:00

59 lines
3.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 22 Apr 2021 01:41:56 -0700
Subject: [PATCH] OfflinePlayer advancements
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 20cdfdb3b9351f74e89bc45b3ab972384165659a..2ac7be4855553268b25615d9ee1a8c3206b84b42 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1479,7 +1479,12 @@ public abstract class PlayerList {
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
UUID uuid = player.getUUID();
- PlayerAdvancements advancementdataplayer = (PlayerAdvancements) player.getAdvancements(); // CraftBukkit
+ // Paper start
+ return this.getPlayerAdvancements(uuid, player);
+ }
+ public PlayerAdvancements getPlayerAdvancements(UUID uuid, @Nullable ServerPlayer player) {
+ PlayerAdvancements advancementdataplayer = player == null ? null : player.getAdvancements(); // CraftBukkit
+ // Paper end
if (advancementdataplayer == null) {
File file = this.server.getWorldPath(LevelResource.PLAYER_ADVANCEMENTS_DIR).toFile();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index 6d2ba650f53de8a460857f1846401a20b50cc43c..37edc2ffe83b26029695f52be4173df884e14ce0 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
@@ -304,6 +304,30 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return result;
}
+
+ @Override
+ public org.bukkit.advancement.AdvancementProgress getAdvancementProgress(org.bukkit.advancement.Advancement advancement) {
+ Player player = this.getPlayer();
+ if (player != null) return player.getAdvancementProgress(advancement);
+ com.google.common.base.Preconditions.checkArgument(advancement != null, "advancement");
+
+ org.bukkit.craftbukkit.advancement.CraftAdvancement craft = (org.bukkit.craftbukkit.advancement.CraftAdvancement) advancement;
+ net.minecraft.server.PlayerAdvancements data = this.server.getHandle().getPlayerAdvancements(this.getUniqueId(), null);
+ net.minecraft.advancements.AdvancementProgress progress = data.getOrStartProgress(craft.getHandle());
+ return new org.bukkit.craftbukkit.advancement.CraftAdvancementProgress(craft, data, progress) {
+ @Override
+ public boolean awardCriteria(String criteria) {
+ throw new UnsupportedOperationException("Cannot award criteria to an offline player");
+ }
+
+ @Override
+ public boolean revokeCriteria(String criteria) {
+ boolean result = super.revokeCriteria(criteria);
+ data.save();
+ return result;
+ }
+ };
+ }
// Paper end
@Override