File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,19 @@ $myList[] = (new \Aternos\Nbt\Tag\StringTag())->setValue("Hello");
66
66
$myList[] = (new \Aternos\Nbt\Tag\StringTag())->setValue("World");
67
67
```
68
68
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
+
69
82
### Serializing NBT structures
70
83
Similar to the reader object to read NBT data, a writer object is required
71
84
to write NBT data.
You can’t perform that action at this time.
0 commit comments