From b16c0ae023e9ee0114db520aa3e2324c7fbf5dea Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:38:18 +0200 Subject: [PATCH] Add offline PDC API (#8117) --- patches/api/0495-Add-Offline-PDC-API.patch | 40 +++++++++ ...w-accessible-directly-from-ItemStack.patch | 85 ++++++++++--------- patches/server/1065-Add-Offline-PDC-API.patch | 45 ++++++++++ 3 files changed, 130 insertions(+), 40 deletions(-) create mode 100644 patches/api/0495-Add-Offline-PDC-API.patch create mode 100644 patches/server/1065-Add-Offline-PDC-API.patch diff --git a/patches/api/0495-Add-Offline-PDC-API.patch b/patches/api/0495-Add-Offline-PDC-API.patch new file mode 100644 index 0000000000..32bafdb4b3 --- /dev/null +++ b/patches/api/0495-Add-Offline-PDC-API.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> +Date: Sat, 9 Jul 2022 17:17:04 +0200 +Subject: [PATCH] Add Offline PDC API + + +diff --git a/src/main/java/org/bukkit/OfflinePlayer.java b/src/main/java/org/bukkit/OfflinePlayer.java +index 3993fecec5b4c2bbd77e175a168afcad571ce4d1..a028f2fe541491729856051780b33dba07832fb6 100644 +--- a/src/main/java/org/bukkit/OfflinePlayer.java ++++ b/src/main/java/org/bukkit/OfflinePlayer.java +@@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable; + * player that is stored on the disk and can, thus, be retrieved without the + * player needing to be online. + */ +-public interface OfflinePlayer extends ServerOperator, AnimalTamer, ConfigurationSerializable { ++public interface OfflinePlayer extends ServerOperator, AnimalTamer, ConfigurationSerializable, io.papermc.paper.persistence.PersistentDataViewHolder { // Paper - Add Offline PDC API + + /** + * Checks if this player is currently online +@@ -557,4 +557,20 @@ public interface OfflinePlayer extends ServerOperator, AnimalTamer, Configuratio + */ + @Nullable + public Location getLocation(); ++ // Paper start - add pdc to offline player ++ /** ++ * Yields a view of the persistent data container for this offline player. ++ * In case this {@link OfflinePlayer} instance was created for an offline player, the returned view will wrap the persistent ++ * data on disk. ++ *
++ * As such, this method as well as queries to the {@link io.papermc.paper.persistence.PersistentDataContainerView}
++ * may produce blocking IO requests to read the requested data from disk.
++ * Caution in its usage is hence advised.
++ *
++ * @return the persistent data container view
++ * @see io.papermc.paper.persistence.PersistentDataViewHolder#getPersistentDataContainer()
++ */
++ @Override
++ io.papermc.paper.persistence.@NotNull PersistentDataContainerView getPersistentDataContainer();
++ // Paper end - add pdc to offline player
+ }
diff --git a/patches/server/1018-Make-a-PDC-view-accessible-directly-from-ItemStack.patch b/patches/server/1018-Make-a-PDC-view-accessible-directly-from-ItemStack.patch
index 31fdc957f8..f86fe8c7dd 100644
--- a/patches/server/1018-Make-a-PDC-view-accessible-directly-from-ItemStack.patch
+++ b/patches/server/1018-Make-a-PDC-view-accessible-directly-from-ItemStack.patch
@@ -6,29 +6,33 @@ Subject: [PATCH] Make a PDC view accessible directly from ItemStack
diff --git a/src/main/java/io/papermc/paper/persistence/PaperPersistentDataContainerView.java b/src/main/java/io/papermc/paper/persistence/PaperPersistentDataContainerView.java
new file mode 100644
-index 0000000000000000000000000000000000000000..fac401280d3f3689b00e16c19155ca753faa06e0
+index 0000000000000000000000000000000000000000..122c32e82b299cafd7d0c6a9f4818523470c9f05
--- /dev/null
+++ b/src/main/java/io/papermc/paper/persistence/PaperPersistentDataContainerView.java
-@@ -0,0 +1,86 @@
+@@ -0,0 +1,120 @@
+package io.papermc.paper.persistence;
+
+import com.google.common.base.Preconditions;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
++import java.util.Collections;
++import java.util.HashSet;
++import java.util.Set;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtIo;
+import net.minecraft.nbt.Tag;
+import org.bukkit.NamespacedKey;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataAdapterContext;
++import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
+import org.bukkit.persistence.PersistentDataAdapterContext;
++import org.bukkit.persistence.PersistentDataContainer;
+import org.bukkit.persistence.PersistentDataType;
-+import org.checkerframework.checker.nullness.qual.NonNull;
-+import org.checkerframework.checker.nullness.qual.Nullable;
-+import org.checkerframework.framework.qual.DefaultQualifier;
++import org.jspecify.annotations.NullMarked;
++import org.jspecify.annotations.Nullable;
+
-+@DefaultQualifier(NonNull.class)
++@NullMarked
+public abstract class PaperPersistentDataContainerView implements PersistentDataContainerView {
+
+ protected final CraftPersistentDataTypeRegistry registry;
@@ -48,7 +52,7 @@ index 0000000000000000000000000000000000000000..fac401280d3f3689b00e16c19155ca75
+ Preconditions.checkArgument(key != null, "The NamespacedKey key cannot be null");
+ Preconditions.checkArgument(type != null, "The provided type cannot be null");
+
-+ final @Nullable Tag value = this.getTag(key.toString());
++ final Tag value = this.getTag(key.toString());
+ if (value == null) {
+ return false;
+ }
@@ -67,7 +71,7 @@ index 0000000000000000000000000000000000000000..fac401280d3f3689b00e16c19155ca75
+ Preconditions.checkArgument(key != null, "The NamespacedKey key cannot be null");
+ Preconditions.checkArgument(type != null, "The provided type cannot be null");
+
-+ final @Nullable Tag value = this.getTag(key.toString());
++ final Tag value = this.getTag(key.toString());
+ if (value == null) {
+ return null;
+ }
@@ -82,13 +86,43 @@ index 0000000000000000000000000000000000000000..fac401280d3f3689b00e16c19155ca75
+ }
+
+ @Override
++ public Set