Skip to content

Commit 8ac2676

Browse files
committed
Fix NPE when handling legacy reset format in certain cases
Will be properly solved with #1505
1 parent 778218f commit 8ac2676

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

patch/adventure-text-serializer-legacy/src/main/java/net/kyori/adventure/text/serializer/legacy/LegacyComponentSerializerImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ private TextComponent extractUrl(final TextComponent component) {
274274
return state.toString();
275275
}
276276

277-
private static boolean applyFormat(final TextComponent.@NotNull Builder builder, final @NotNull TextFormat format) {
277+
private static boolean applyFormat(final TextComponent.@NotNull Builder builder, final @Nullable TextFormat format) { // packetevents patch
278278
if (format instanceof TextColor) {
279279
builder.colorIfAbsent((TextColor) format);
280280
return true;
281281
} else if (format instanceof TextDecoration) {
282282
builder.decoration((TextDecoration) format, TextDecoration.State.TRUE);
283283
return false;
284-
} else if (format instanceof Reset) {
284+
} else if (format == null || format instanceof Reset) { // packetevents patch
285285
return true;
286286
}
287287
throw new IllegalArgumentException(String.format("unknown format '%s'", format.getClass()));
@@ -558,12 +558,9 @@ enum FormatCodeType {
558558

559559
static final class DecodedFormat {
560560
final FormatCodeType encodedFormat;
561-
final TextFormat format;
561+
final @Nullable TextFormat format; // packetevents patch
562562

563-
private DecodedFormat(final FormatCodeType encodedFormat, final TextFormat format) {
564-
if (format == null) {
565-
throw new IllegalStateException("No format found");
566-
}
563+
private DecodedFormat(final FormatCodeType encodedFormat, final @Nullable TextFormat format) { // packetevents patch
567564
this.encodedFormat = encodedFormat;
568565
this.format = format;
569566
}

0 commit comments

Comments
 (0)