Skip to content

Fix hex color codes breaking subsequent legacy color codes#2893

Merged
tastybento merged 3 commits into
developfrom
copilot/fix-hex-color-display-error
Apr 2, 2026
Merged

Fix hex color codes breaking subsequent legacy color codes#2893
tastybento merged 3 commits into
developfrom
copilot/fix-hex-color-display-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

Hex colors like &#FF0000 followed by legacy codes like &a rendered incorrectly — the hex color was garbled and all subsequent legacy codes stopped working.

Root cause: translateColorCodes() pre-converted hex codes to §x§F§F… (section-sign format) before passing the string to Adventure's LEGACY_SERIALIZER, which is configured with & as its color character. The serializer didn't recognize §x as a hex prefix (hex parsing is bound to the configured character), so it mangled the hex sequence and lost track of subsequent & codes.

Changes:

  • Stop pre-converting hex to § format — leave &#RRGGBB intact (only expand 3-digit shorthand to 6-digit) so the LEGACY_SERIALIZER with .hexColors() parses them natively alongside &a-style codes
  • Add .useUnusualXRepeatedCharacterHexFormat() to SECTION_SERIALIZER so output uses BungeeCord-compatible §x§R§R§G§G§B§B format instead of §#RRGGBB
  • Add tests for hex+legacy combinations, 3-digit expansion, standalone hex, and legacy-only regression

Before/after for &#FF0000Red &aGreen:

// Before (broken): §x was not recognized, §a lost
"§x§F§F§0§0§0§0Red §aGreen"  →  garbled output

// After: LEGACY_SERIALIZER parses &#FF0000 natively, then SECTION_SERIALIZER outputs BungeeCord format
"&#FF0000Red &aGreen"  →  "§x§f§f§0§0§0§0Red §aGreen"

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
The translateColorCodes method was converting hex codes (e.g., &#FF0000) to
§x§F§F§0§0§0§0 format before passing them to Adventure's LEGACY_SERIALIZER
which uses '&' as its color character. Since the serializer didn't recognize
§x as a hex color prefix (hex parsing is tied to the configured '&' char),
this corrupted the hex color and broke any subsequent legacy color codes.

Fix: Keep hex codes in &#RRGGBB format so the LEGACY_SERIALIZER (which has
.hexColors() enabled) handles them natively. Also add
.useUnusualXRepeatedCharacterHexFormat() to the SECTION_SERIALIZER to ensure
output uses the BungeeCord-compatible §x§R§R§G§G§B§B format.

Fixes BentoBoxWorld/BentoBox hex color display issue.

Agent-Logs-Url: https://github.com/BentoBoxWorld/BentoBox/sessions/ae1441c0-1227-42b3-9020-96b6c2fb42ef

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix hex color display error in localization Fix hex color codes breaking subsequent legacy color codes Apr 1, 2026
Copilot AI requested a review from tastybento April 1, 2026 15:50
@tastybento
Copy link
Copy Markdown
Member

@copilot Since the PR to update to using minimessage formatting, does this PR still make sense to do?

@tastybento tastybento marked this pull request as ready for review April 2, 2026 23:34
@tastybento tastybento merged commit bd9e013 into develop Apr 2, 2026
1 check passed
@tastybento tastybento deleted the copilot/fix-hex-color-display-error branch April 2, 2026 23:34
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hex color display error

2 participants