aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1030-Add-Offline-PDC-API.patch
blob: f1513955cbe4c850c222890b3b65f26b941bd31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Date: Sat, 9 Jul 2022 17:28:42 +0200
Subject: [PATCH] Add Offline PDC API


diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index 4f4e3ee18d586f61706504218cddc06a38ca5580..94ca0407303c4493ab4928b12ec6ecc75aaca549 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
@@ -325,6 +325,34 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
     }
     // Paper end
 
+    // Paper start - Add Offline PDC API
+    private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
+    private io.papermc.paper.persistence.@org.checkerframework.checker.nullness.qual.MonotonicNonNull PersistentDataContainerView persistentDataContainerView;
+
+    @Override
+    public io.papermc.paper.persistence.PersistentDataContainerView getPersistentDataContainer() {
+        if (this.persistentDataContainerView == null) {
+            this.persistentDataContainerView = new io.papermc.paper.persistence.PaperPersistentDataContainerView(DATA_TYPE_REGISTRY) {
+
+                private CompoundTag getPersistentTag() {
+                    return net.minecraft.Optionull.map(CraftOfflinePlayer.this.getData(), data -> data.getCompound("BukkitValues"));
+                }
+
+                @Override
+                public CompoundTag toTagCompound() {
+                    return java.util.Objects.requireNonNullElseGet(this.getPersistentTag(), CompoundTag::new);
+                }
+
+                @Override
+                public net.minecraft.nbt.Tag getTag(String key) {
+                    return net.minecraft.Optionull.map(this.getPersistentTag(), tag -> tag.get(key));
+                }
+            };
+        }
+        return this.persistentDataContainerView;
+    }
+    // Paper end - Add Offline PDC API
+
     @Override
     public Location getLastDeathLocation() {
         if (this.getData().contains("LastDeathLocation", 10)) {