Skip to content

Commit 99fea55

Browse files
committed
chore: fixup minor code smell
1 parent e8d04e2 commit 99fea55

File tree

1 file changed

+16
-13
lines changed
  • src/content/docs/paper/dev/api

1 file changed

+16
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Persistent data container (PDC)
33
description: A guide to the PDC API for storing data.
44
slug: paper/dev/pdc
5-
version: "1.21.8"
5+
version: 1.21.8
66
---
77

88
The Persistent Data Container (PDC) is a way to store custom data on a whole range of objects; such as items, entities, and block entities.
@@ -39,18 +39,18 @@ NamespacedKey key = new NamespacedKey(pluginInstance, "example-key"); // Create
3939
World world = Bukkit.getServer().getWorlds().getFirst();
4040

4141
PersistentDataContainer pdc = world.getPersistentDataContainer();
42-
pdc.set(key, PersistentDataType.STRING, "I love Tacos!");
42+
pdc.set(key, PersistentDataType.STRING, "I love tacos!");
4343
```
4444

4545
[`ItemStack`](jd:paper:org.bukkit.inventory.ItemStack) however doesn't have this method and instead requires you to use its builder-style consumer:
4646

4747
```java
48-
NamespacedKey key = ...; // Retrieve the key from before
48+
NamespacedKey key = ...;
4949

5050
// For 1.20.4 and below, use 'new ItemStack(Material.DIAMOND)' instead
5151
ItemStack item = ItemStack.of(Material.DIAMOND);
5252
item.editPersistentDataContainer(pdc -> {
53-
pdc.set(key, PersistentDataType.STRING, "I love Tacos!");
53+
pdc.set(key, PersistentDataType.STRING, "I love tacos!");
5454
});
5555
```
5656

@@ -76,13 +76,14 @@ To get data from the PDC, you need to know the `NamespacedKey` and the [`Persist
7676
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.
7777

7878
```java
79-
NamespacedKey key = ...; // Retrieve the key from before
80-
World world = ...; // Retrieve the world from before
79+
NamespacedKey key = ...; // Use the same key as the adding-data example
80+
World world = ...; // Use the same world as the adding-data example
8181

8282
PersistentDataContainer pdc = world.getPersistentDataContainer();
83-
// Utilize the data from the PDC
8483

84+
// Utilize the data from the PDC
8585
String value = pdc.getOrDefault(key, PersistentDataType.STRING, "<null>");
86+
8687
// Do something with the value
8788
player.sendPlainMessage(value);
8889
```
@@ -100,7 +101,7 @@ The PDC supports a wide range of data types, such as:
100101
- `Boolean`
101102
- `Tag Containers` - a way to nest PDCs within each other. To create a new `PersistentDataContainer`, you can use:
102103
```java
103-
// Get the existing container
104+
// Get an existing container
104105
PersistentDataContainer container = ...;
105106
// Create a new container
106107
PersistentDataContainer newContainer = container.getAdapterContext().newPersistentDataContainer();
@@ -115,7 +116,7 @@ The PDC supports a wide range of data types, such as:
115116
List.of("a", "list", "of", "strings")
116117
);
117118

118-
// Storing a list of strings in a container by using the api
119+
// Storing a list of strings in a container by using the API
119120
// provided pre-definitions of commonly used list types.
120121
container.set(key, PersistentDataType.LIST.strings(), List.of("a", "list", "of", "strings"));
121122

@@ -197,12 +198,14 @@ Mutable objects, like the [`PersistentDataHolder#getPersistentDataContainer()`](
197198
That's why it's better to use unmodifiable "views" for read-only operations.
198199

199200
```java
200-
NamespacedKey key = ...; // Retrieve the key from before
201-
ItemStack item = ...; // Retrieve the item from before
201+
NamespacedKey key = ...;
202+
ItemStack item = ...;
202203

203204
PersistentDataContainerView pdcView = item.getPersistentDataContainer();
205+
204206
// Utilize the data from the PDC "view"
205207
String value = pdcView.getOrDefault(key, PersistentDataType.STRING, "<null>");
208+
206209
// Do something with the value
207210
player.sendPlainMessage(value);
208211
```
@@ -236,7 +239,7 @@ and their PDC can be fetched with `PersistentDataHolder#getPersistentDataContain
236239
```java
237240
ItemStack itemStack = ...;
238241
itemStack.editPersistentDataContainer(pdc -> {
239-
pdc.set(key, PersistentDataType.STRING, "I love Tacos!");
242+
pdc.set(key, PersistentDataType.STRING, "I love tacos!");
240243
});
241244
```
242245
- ##### [`Chunk`](jd:paper:org.bukkit.Chunk)
@@ -251,7 +254,7 @@ and their PDC can be fetched with `PersistentDataHolder#getPersistentDataContain
251254
```java
252255
Block block = ...;
253256
if (block.getState() instanceof Chest chest) {
254-
chest.getPersistentDataContainer().set(key, PersistentDataType.STRING, "I love Tacos!");
257+
chest.getPersistentDataContainer().set(key, PersistentDataType.STRING, "I love tacos!");
255258
chest.update();
256259
}
257260
```

0 commit comments

Comments
 (0)