Skip to content

Commit 30ff648

Browse files
committed
Add handling for unnamed simple components as serialized compounds
1 parent 6c5d9be commit 30ff648

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

api/src/main/java/com/github/retrooper/packetevents/util/adventure/AdventureNBTSerialization.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ private static Component readComponent(DataInput input, TagType rootType, int de
210210
while ((type = resolveNbtType(input.readByte())) != TagType.END) {
211211
String key = input.readUTF();
212212
switch (key) {
213+
// this case resolves an edge-case where a simple component would
214+
// be serialized to an unnamed compound because of nbt lists
215+
case "":
213216
case TEXT:
214217
requireType(type, TagType.STRING);
215218
requireState(text == null);
@@ -249,7 +252,7 @@ private static Component readComponent(DataInput input, TagType rootType, int de
249252
scoreObjective = input.readUTF();
250253
break;
251254
default:
252-
throw new IllegalStateException("Invalid nbt key read for score key: " + scoreKey);
255+
throw new IllegalStateException("Invalid nbt key read for score key: '" + scoreKey + "'");
253256
}
254257
}
255258
requireState(scoreName != null && scoreObjective != null);
@@ -368,7 +371,7 @@ private static Component readComponent(DataInput input, TagType rootType, int de
368371
clickEventAction = ClickEvent.Action.COPY_TO_CLIPBOARD;
369372
break;
370373
default:
371-
throw new IllegalStateException("Illegal click event action read: " + actionId);
374+
throw new IllegalStateException("Illegal click event action read: '" + actionId + "'");
372375
}
373376
break;
374377
case CLICK_EVENT_VALUE:
@@ -377,7 +380,7 @@ private static Component readComponent(DataInput input, TagType rootType, int de
377380
clickEventValue = input.readUTF();
378381
break;
379382
default:
380-
throw new IllegalStateException("Illegal click event nbt key read: " + clickKey);
383+
throw new IllegalStateException("Illegal click event nbt key read: '" + clickKey + "'");
381384
}
382385
}
383386
requireState(clickEventAction != null && clickEventValue != null);
@@ -406,7 +409,7 @@ private static Component readComponent(DataInput input, TagType rootType, int de
406409
hoverEventAction = HoverEvent.Action.SHOW_ENTITY;
407410
break;
408411
default:
409-
throw new IllegalStateException("Illegal hover event action read: " + actionId);
412+
throw new IllegalStateException("Illegal hover event action read: '" + actionId + "'");
410413
}
411414
break;
412415
case HOVER_EVENT_CONTENTS:
@@ -489,13 +492,13 @@ private static Component readComponent(DataInput input, TagType rootType, int de
489492
}
490493
break;
491494
default:
492-
throw new IllegalStateException("Illegal hover event nbt key read: " + hoverKey);
495+
throw new IllegalStateException("Illegal hover event nbt key read: '" + hoverKey + "'");
493496
}
494497
}
495498
requireState(hoverEventContents != null);
496499
break;
497500
default:
498-
throw new IllegalStateException("Illegal component nbt key read: " + key);
501+
throw new IllegalStateException("Illegal component nbt key read: '" + key + "'");
499502
}
500503
}
501504

0 commit comments

Comments
 (0)