Skip to content

Commit 22cbc1c

Browse files
committed
chore: minimal cleanup
1 parent a35eddb commit 22cbc1c

File tree

1 file changed

+7
-8
lines changed
  • src/content/docs/paper/dev/api

1 file changed

+7
-8
lines changed

src/content/docs/paper/dev/api/pdc.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ NamespacedKey key = ...; // Retrieve the key from before
4949

5050
// For 1.20.4 and below, use 'new ItemStack(Material.DIAMOND)' instead
5151
ItemStack item = ItemStack.of(Material.DIAMOND);
52-
// ItemStack provides a util method, so we can directly edit its PDC
5352
item.editPersistentDataContainer(pdc -> {
5453
pdc.set(key, PersistentDataType.STRING, "I love Tacos!");
5554
});
@@ -68,13 +67,12 @@ It is considered good practice to reuse `NamespacedKey` objects. They can be con
6867
- A [`Plugin`](jd:paper:org.bukkit.plugin.Plugin) instance and a [`String`](jd:java:java.lang.String) identifier
6968
- A [`String`](jd:java:java.lang.String) namespace and a [`String`](jd:java:java.lang.String) identifier
7069

71-
The first option is often preferred as it will automatically use the plugin's lowercased name as namespace; however, the second option can be used if you
72-
want to use a different namespace or access the data from another plugin.
70+
The first option is often preferred as it will automatically use the plugin's lowercased name as namespace; however, the second option can be used if you want to use a different namespace or access the data from another plugin.
7371

7472
:::
7573

7674
## Getting data
77-
To get data from the PDC, you need to know the `NamespacedKey` and the `PersistentDataType` of the data.
75+
To get data from the PDC, you need to know the `NamespacedKey` and the [`PersistentDataType`](jd:paper:org.bukkit.persistence.PersistentDataType) of the data.
7876
Some API parts, such as Adventure's [`Component.text(String)`](https://jd.advntr.dev/api/latest/net/kyori/adventure/text/Component.html#text(java.lang.String)), require non-null values. In such cases, use the [`getOrDefault`](jd:paper:io.papermc.paper.persistence.PersistentDataContainerView#getOrDefault(org.bukkit.NamespacedKey,org.bukkit.persistence.PersistentDataType,C)) on the pdc instead of [`get`](jd:paper:io.papermc.paper.persistence.PersistentDataContainerView#get(org.bukkit.NamespacedKey,org.bukkit.persistence.PersistentDataType)), which is nullable.
7977

8078
```java
@@ -83,6 +81,7 @@ World world = ...; // Retrieve the world from before
8381

8482
PersistentDataContainer pdc = world.getPersistentDataContainer();
8583
// Utilize the data from the PDC
84+
8685
String value = pdc.getOrDefault(key, PersistentDataType.STRING, "<null>");
8786
// Do something with the value
8887
player.sendPlainMessage(value);
@@ -134,7 +133,7 @@ The [`Boolean`](jd:paper:org.bukkit.persistence.PersistentDataType#BOOLEAN) PDC
134133
### Custom data types
135134

136135
You can store a wide range of data in the PDC with the native adapters; however, if you need a more complex data type, you can
137-
implement your own [`PersistentDataType`](jd:paper:org.bukkit.persistence.PersistentDataType) and use that instead.
136+
implement your own `PersistentDataType` and use that instead.
138137
The `PersistentDataType`'s job is to "deconstruct" a complex data type into something that is natively supported (see above) and then vice-versa.
139138

140139
Here is an example of how to do that for a UUID:
@@ -194,7 +193,7 @@ container.set(key, UUIDDataType.INSTANCE, uuid);
194193
Certain classes, like `ItemStack` or [`OfflinePlayer`](jd:paper:org.bukkit.OfflinePlayer), provide a read-only view of their PDC.
195194
In contrast to `ItemStack`, `OfflinePlayer` does <u>not</u> provide any way to modify the underlying container.
196195
This is because the `OfflinePlayer` is directly read from disk and would require a blocking file operation.
197-
Mutable objects, like the `PersistentDataHolder#getPersistentDataContainer()`, generally need to be re-saved even without modification or monitored.
196+
Mutable objects, like the [`PersistentDataHolder#getPersistentDataContainer()`](jd:paper:org.bukkit.persistence.PersistentDataHolder#getPersistentDataContainer()), generally need to be re-saved even without modification or monitored.
198197
That's why it's better to use unmodifiable "views" for read-only operations.
199198

200199
```java
@@ -225,13 +224,13 @@ E.g. Placing an ItemStack as a Block (with a TileState) ***does not*** copy over
225224
:::
226225

227226
Objects that can have a PDC implement the [`PersistentDataHolder`](jd:paper:org.bukkit.persistence.PersistentDataHolder) interface
228-
and their PDC can be fetched with [`PersistentDataHolder#getPersistentDataContainer()`](jd:paper:org.bukkit.persistence.PersistentDataHolder#getPersistentDataContainer()).
227+
and their PDC can be fetched with `PersistentDataHolder#getPersistentDataContainer()`.
229228

230229
- ##### [`ItemStack`](jd:paper:org.bukkit.inventory.ItemStack)
231230
- The persistent data container of an `ItemStack` has historically been accessed by
232231
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.
233232

234-
To avoid this overhead in 1.21.1+, ItemStack exposes a read-only view of its persistent data container at `ItemStack#getPersistentDataContainer()`.
233+
To avoid this overhead in 1.21.1+, ItemStack exposes a read-only view of its persistent data container at [`ItemStack#getPersistentDataContainer()`](jd:paper:org.bukkit.inventory.ItemStack#getPersistentDataContainer()).
235234
Edits to the persistent data container can also be simplified in 1.21.4+ using `ItemStack#editPersistentDataContainer(java.util.function.Consumer)`.
236235
The persistent data container available in the consumer is not valid outside the consumer.
237236
```java

0 commit comments

Comments
 (0)