From cad688b318f04d8bcddb0bdf72890b4d9593d6ae Mon Sep 17 00:00:00 2001 From: Bjarne Koll <lynxplay101@gmail.com> Date: Sun, 16 Feb 2025 17:14:45 +0100 Subject: [PATCH 1/5] Document more pdc usages in the API --- docs/paper/dev/api/pdc.mdx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/paper/dev/api/pdc.mdx b/docs/paper/dev/api/pdc.mdx index 91a8d79a6..9738cdd81 100644 --- a/docs/paper/dev/api/pdc.mdx +++ b/docs/paper/dev/api/pdc.mdx @@ -16,6 +16,8 @@ The full list of classes that support the PDC are: - [`ItemMeta`](#itemmeta) - [`GeneratedStructure`](#generatedstructure) - [`Raid`](#raid) +- [`OfflinePlayer`](#offlineplayer) +- [`ItemStack`](#itemstack) ## What is it used for? In the past, developers resorted to a variety of methods to store custom data on objects: @@ -201,3 +203,21 @@ and their PDC can be fetched with <Javadoc name={"org.bukkit.persistence.Persist - `GeneratedStructure#getPersistentDataContainer()` - ##### <Javadoc name={"org.bukkit.Raid"}>`Raid`</Javadoc> - `Raid#getPersistentDataContainer()` +- ##### <Javadoc name={"org.bukkit.OfflinePlayer"}>`OfflinePlayer`</Javadoc> + - OfflinePlayer only exposes a read-only version of the persistent data container. + It can be accessed via `OfflinePlayer#getPersistentDataContainer` +- ##### <Javadoc name={"org.bukkit.inventory.ItemStack"}>`ItemStack`</Javadoc> + - The persistent data container of an ItemStack has historically been accessed by + the ItemStack's ItemMeta. This however includes the overhead of constructing the entire + ItemMeta, which acts as a snapshot of the ItemStack's data at the point of creation. + + To avoid this overhead, ItemStack exposes a read-only view of its persistent data container at + `ItemStack#getPersistentDataContainer`. + Edits to the persistent data container can be achieved via `ItemStack#editPersistentDataContainer(Consumer)`. + The persistent data container available in the consumer is not valid outside the consumer. + ```java + ItemStack itemStack = ...; + itemStack.editPersistentDataContainer(p -> { + p.set(key, PersistentDataType.STRING, "I love Tacos!"); + }); + ``` From be3d031602b34be9b5abef308e43da85c69eebb6 Mon Sep 17 00:00:00 2001 From: Bjarne Koll <LynxPlay101@gmail.com> Date: Sun, 16 Feb 2025 17:30:42 +0100 Subject: [PATCH 2/5] Update docs/paper/dev/api/pdc.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matouš Kučera <mk@kcra.me> --- docs/paper/dev/api/pdc.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/paper/dev/api/pdc.mdx b/docs/paper/dev/api/pdc.mdx index 9738cdd81..f5c2469fb 100644 --- a/docs/paper/dev/api/pdc.mdx +++ b/docs/paper/dev/api/pdc.mdx @@ -207,9 +207,9 @@ and their PDC can be fetched with <Javadoc name={"org.bukkit.persistence.Persist - OfflinePlayer only exposes a read-only version of the persistent data container. It can be accessed via `OfflinePlayer#getPersistentDataContainer` - ##### <Javadoc name={"org.bukkit.inventory.ItemStack"}>`ItemStack`</Javadoc> - - The persistent data container of an ItemStack has historically been accessed by - the ItemStack's ItemMeta. This however includes the overhead of constructing the entire - ItemMeta, which acts as a snapshot of the ItemStack's data at the point of creation. + - The persistent data container of an `ItemStack` has historically been accessed by + the `ItemStack`'s `ItemMeta`. This, however, includes the overhead of constructing the entire + `ItemMeta`, which acts as a snapshot of the `ItemStack`'s data at the point of creation. To avoid this overhead, ItemStack exposes a read-only view of its persistent data container at `ItemStack#getPersistentDataContainer`. From 2a685e9a10880be465122761a1276e2b0ba12079 Mon Sep 17 00:00:00 2001 From: Bjarne Koll <LynxPlay101@gmail.com> Date: Sun, 16 Feb 2025 17:30:51 +0100 Subject: [PATCH 3/5] Update docs/paper/dev/api/pdc.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matouš Kučera <mk@kcra.me> --- docs/paper/dev/api/pdc.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/paper/dev/api/pdc.mdx b/docs/paper/dev/api/pdc.mdx index f5c2469fb..56e34b619 100644 --- a/docs/paper/dev/api/pdc.mdx +++ b/docs/paper/dev/api/pdc.mdx @@ -205,7 +205,7 @@ and their PDC can be fetched with <Javadoc name={"org.bukkit.persistence.Persist - `Raid#getPersistentDataContainer()` - ##### <Javadoc name={"org.bukkit.OfflinePlayer"}>`OfflinePlayer`</Javadoc> - OfflinePlayer only exposes a read-only version of the persistent data container. - It can be accessed via `OfflinePlayer#getPersistentDataContainer` + It can be accessed via `OfflinePlayer#getPersistentDataContainer()`. - ##### <Javadoc name={"org.bukkit.inventory.ItemStack"}>`ItemStack`</Javadoc> - The persistent data container of an `ItemStack` has historically been accessed by the `ItemStack`'s `ItemMeta`. This, however, includes the overhead of constructing the entire From 2e40ba57856ef63bfad699347bc2df27392887ae Mon Sep 17 00:00:00 2001 From: Bjarne Koll <LynxPlay101@gmail.com> Date: Sun, 16 Feb 2025 17:30:56 +0100 Subject: [PATCH 4/5] Update docs/paper/dev/api/pdc.mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matouš Kučera <mk@kcra.me> --- docs/paper/dev/api/pdc.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/paper/dev/api/pdc.mdx b/docs/paper/dev/api/pdc.mdx index 56e34b619..01f076ccb 100644 --- a/docs/paper/dev/api/pdc.mdx +++ b/docs/paper/dev/api/pdc.mdx @@ -212,7 +212,7 @@ and their PDC can be fetched with <Javadoc name={"org.bukkit.persistence.Persist `ItemMeta`, which acts as a snapshot of the `ItemStack`'s data at the point of creation. To avoid this overhead, ItemStack exposes a read-only view of its persistent data container at - `ItemStack#getPersistentDataContainer`. + `ItemStack#getPersistentDataContainer()`. Edits to the persistent data container can be achieved via `ItemStack#editPersistentDataContainer(Consumer)`. The persistent data container available in the consumer is not valid outside the consumer. ```java From cc7b92271e45971dea486103a642daef929b05bc Mon Sep 17 00:00:00 2001 From: Bjarne Koll <LynxPlay101@gmail.com> Date: Sun, 16 Feb 2025 18:18:31 +0100 Subject: [PATCH 5/5] Apply suggestions from code review --- docs/paper/dev/api/pdc.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/paper/dev/api/pdc.mdx b/docs/paper/dev/api/pdc.mdx index 01f076ccb..0a2e96f58 100644 --- a/docs/paper/dev/api/pdc.mdx +++ b/docs/paper/dev/api/pdc.mdx @@ -217,7 +217,7 @@ and their PDC can be fetched with <Javadoc name={"org.bukkit.persistence.Persist The persistent data container available in the consumer is not valid outside the consumer. ```java ItemStack itemStack = ...; - itemStack.editPersistentDataContainer(p -> { - p.set(key, PersistentDataType.STRING, "I love Tacos!"); + itemStack.editPersistentDataContainer(pdc -> { + pdc.set(key, PersistentDataType.STRING, "I love Tacos!"); }); ```