Skip to content

Commit 692eb12

Browse files
committed
update README
1 parent 7412397 commit 692eb12

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ $myList[] = (new \Aternos\Nbt\Tag\StringTag())->setValue("Hello");
6666
$myList[] = (new \Aternos\Nbt\Tag\StringTag())->setValue("World");
6767
```
6868

69+
Alternatively, compound tags can be accessed using getter/setter functions. This is especially useful in combination with
70+
the new PHP null safe operator.
71+
```php
72+
/** @var \Aternos\Nbt\Tag\CompoundTag $playerDat */
73+
$playerDat = \Aternos\Nbt\Tag\Tag::load($reader);
74+
75+
$playerDat->set("foo", (new \Aternos\Nbt\Tag\StringTag())->setValue("bar")); //Set a value
76+
$playerDat->delete("foo"); //Delete a value
77+
78+
$playerName = $playerDat->getCompound("bukkit")?->getString("lastKnownName")?->getValue();
79+
echo $playerName ?? "Unknown player name";
80+
```
81+
6982
### Serializing NBT structures
7083
Similar to the reader object to read NBT data, a writer object is required
7184
to write NBT data.

0 commit comments

Comments
 (0)