@@ -16,6 +16,8 @@ The full list of classes that support the PDC are:
16
16
- [ ` ItemMeta ` ] ( #itemmeta )
17
17
- [ ` GeneratedStructure ` ] ( #generatedstructure )
18
18
- [ ` Raid ` ] ( #raid )
19
+ - [ ` OfflinePlayer ` ] ( #offlineplayer )
20
+ - [ ` ItemStack ` ] ( #itemstack )
19
21
20
22
## What is it used for?
21
23
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
201
203
- ` GeneratedStructure#getPersistentDataContainer() `
202
204
- ##### <Javadoc name = { " org.bukkit.Raid" } >` Raid ` </Javadoc >
203
205
- ` Raid#getPersistentDataContainer() `
206
+ - ##### <Javadoc name = { " org.bukkit.OfflinePlayer" } >` OfflinePlayer ` </Javadoc >
207
+ - OfflinePlayer only exposes a read-only version of the persistent data container.
208
+ It can be accessed via ` OfflinePlayer#getPersistentDataContainer() ` .
209
+ - ##### <Javadoc name = { " org.bukkit.inventory.ItemStack" } >` ItemStack ` </Javadoc >
210
+ - The persistent data container of an ` ItemStack ` has historically been accessed by
211
+ the ` ItemStack ` 's ` ItemMeta ` . This, however, includes the overhead of constructing the entire
212
+ ` ItemMeta ` , which acts as a snapshot of the ` ItemStack ` 's data at the point of creation.
213
+
214
+ To avoid this overhead, ItemStack exposes a read-only view of its persistent data container at
215
+ ` ItemStack#getPersistentDataContainer() ` .
216
+ Edits to the persistent data container can be achieved via ` ItemStack#editPersistentDataContainer(Consumer) ` .
217
+ The persistent data container available in the consumer is not valid outside the consumer.
218
+ ``` java
219
+ ItemStack itemStack = ... ;
220
+ itemStack. editPersistentDataContainer(pdc - > {
221
+ pdc. set(key, PersistentDataType . STRING , " I love Tacos!" );
222
+ });
223
+ ```
0 commit comments