Skip to content

Commit 619a62a

Browse files
committed
feat: deserializing components from list binary tags
1 parent ad8d730 commit 619a62a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

text-serializer-nbt/src/main/java/net/kyori/adventure/text/serializer/nbt/NBTComponentSerializerImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,19 @@ static final class Instances {
114114
public @NotNull Component deserialize(@NotNull BinaryTag input) {
115115
if (input instanceof StringBinaryTag) {
116116
return Component.text(((StringBinaryTag) input).value());
117-
}
117+
} else if (input instanceof ListBinaryTag) {
118+
ListBinaryTag castTag = (ListBinaryTag) input;
119+
if (castTag.isEmpty()) {
120+
throw new IllegalArgumentException("The list binary tag must not be empty");
121+
}
122+
123+
Component rootTag = this.deserialize(castTag.get(0));
124+
for (int index = 1; index < castTag.size(); index++) {
125+
rootTag = rootTag.append(this.deserialize(castTag.get(index)));
126+
}
118127

119-
if (!(input instanceof CompoundBinaryTag)) {
128+
return rootTag;
129+
} else if (!(input instanceof CompoundBinaryTag)) {
120130
throw new IllegalArgumentException("The input isn't a compound or string binary tag");
121131
}
122132

text-serializer-nbt/src/main/java/net/kyori/adventure/text/serializer/nbt/NBTSerializerOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
public final class NBTSerializerOptions {
3838

3939
/**
40-
* Whether to emit text components with no style and no children as plain text.
40+
* Whether to emit text components with no style and no children as a plain text.
4141
*
4242
* @since 4.24.0
4343
* @sinceMinecraft 1.20.3
@@ -92,7 +92,6 @@ public final class NBTSerializerOptions {
9292

9393
// TODO: Add show item hover data mode
9494
// TODO: Add component type field emitting mode
95-
// TODO: Add a way to serialize components as lists
9695
// TODO: Add source field emitting mode
9796
// TODO: Add show item hover data mode
9897

0 commit comments

Comments
 (0)