From 8e87273780df9f5fd924d4298aa37abf66f647b5 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 8 Jul 2021 23:57:32 -0700 Subject: [PATCH] OfflinePlayer advancements --- .../api/0387-OfflinePlayer-advancements.patch | 29 +++++++++ .../0918-OfflinePlayer-advancements.patch | 59 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 patches/api/0387-OfflinePlayer-advancements.patch create mode 100644 patches/server/0918-OfflinePlayer-advancements.patch diff --git a/patches/api/0387-OfflinePlayer-advancements.patch b/patches/api/0387-OfflinePlayer-advancements.patch new file mode 100644 index 0000000000..453cdc5d48 --- /dev/null +++ b/patches/api/0387-OfflinePlayer-advancements.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Thu, 22 Apr 2021 01:42:02 -0700 +Subject: [PATCH] OfflinePlayer advancements + + +diff --git a/src/main/java/org/bukkit/OfflinePlayer.java b/src/main/java/org/bukkit/OfflinePlayer.java +index a7d1f1e701f23e851f735584a30bedadb0d8b9bd..2946b0432316fff2c77dca303dea297bbda239d5 100644 +--- a/src/main/java/org/bukkit/OfflinePlayer.java ++++ b/src/main/java/org/bukkit/OfflinePlayer.java +@@ -203,6 +203,18 @@ public interface OfflinePlayer extends ServerOperator, AnimalTamer, Configuratio + * @return last seen time + */ + public long getLastSeen(); ++ ++ /** ++ * Return the player's progression on the specified advancement. ++ * May cause an I/O operation. ++ *

++ * You cannot award criteria to an offline player! ++ * ++ * @param advancement advancement ++ * @return object detailing the player's progress ++ */ ++ @NotNull ++ org.bukkit.advancement.AdvancementProgress getAdvancementProgress(@NotNull org.bukkit.advancement.Advancement advancement); + // Paper end + + /** diff --git a/patches/server/0918-OfflinePlayer-advancements.patch b/patches/server/0918-OfflinePlayer-advancements.patch new file mode 100644 index 0000000000..7a905811fe --- /dev/null +++ b/patches/server/0918-OfflinePlayer-advancements.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +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