Skip to content

The issue "Formatting was not a valid color: §m"#12863

Closed
Nu11ified wants to merge 1 commit into
PaperMC:mainfrom
Nu11ified:fix-formatting-color-bug
Closed

The issue "Formatting was not a valid color: §m"#12863
Nu11ified wants to merge 1 commit into
PaperMC:mainfrom
Nu11ified:fix-formatting-color-bug

Conversation

@Nu11ified
Copy link
Copy Markdown

This pull request improves error handling and validation in the AdventureCodecs and PaperAdventure classes. The changes ensure better differentiation between formatting codes and valid colors, enhancing clarity and robustness in handling text color conversions.

Error Handling Improvements:

  • AdventureCodecs (paper-server/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java): Added checks to identify and reject formatting codes (e.g., §k, §l, etc.) when they are mistakenly passed as colors. This ensures that only valid color codes or named colors are processed, with appropriate error messages for invalid inputs.

  • PaperAdventure (paper-server/src/main/java/io/papermc/paper/adventure/PaperAdventure.java): Enhanced the error message in the asAdventure method to include the specific formatting code that caused the exception, providing more context for debugging.

occurs because:
1. The TextColor.parseColor method in Minecraft is trying to parse
formatting codes (like §m, §n, §o, §k, §l) as colors
2. These codes are formatting codes (strikethrough, underline, italic,
obfuscated, bold), not color codes
3. When the server tries to serialize text components during world
saving, these formatting codes are incorrectly processed through the color parsing pipeline
4. The PaperAdventure.asAdventure(ChatFormatting) method throws an
exception when it encounters formatting codes because
ChatFormatting.getColor() returns null for these codes

The fix:
Fix in PaperAdventure.java where the the error message was
improved to be more descriptive.

Fix in AdventureCodecs.java where the TEXT_COLOR_CODEC was
modified to handle formatting codes properly.

The changes ensure that:

1. Server crashes are prevented when encountering formatting codes
during world saving.
2. Clear error messages are provided for debugging.
3. The serialization system can handle the errors
gracefully instead of crashing the entire server.
@lynxplay
Copy link
Copy Markdown
Contributor

This does not actually fix the bug, nor is it really a bug.
The server had a scoreboard team with an invalid colour code (none colours, like m for strikethrough)
There is nothing here we can do bar I guess magically stripping those codes. Or the server administrator removing them.

Thank you anyway for the PR!

@lynxplay lynxplay closed this Jul 17, 2025
@github-project-automation github-project-automation Bot moved this from Awaiting review to Closed in Paper PR Queue Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants