OfflinePlayer advancements

This commit is contained in:
Jake Potrebic 2021-07-08 23:57:32 -07:00
parent e7036bb2d7
commit 8e87273780
No known key found for this signature in database
GPG key ID: 27CC63F7CBC866C7
2 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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.
+ * <p>
+ * <b>You cannot award criteria to an offline player!</b>
+ *
+ * @param advancement advancement
+ * @return object detailing the player's progress
+ */
+ @NotNull
+ org.bukkit.advancement.AdvancementProgress getAdvancementProgress(@NotNull org.bukkit.advancement.Advancement advancement);
// Paper end
/**

View file

@ -0,0 +1,59 @@
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