Skip to content

Commit

Permalink
Merge pull request #2540 from BentoBoxWorld/2538_hex_color_format_broke
Browse files Browse the repository at this point in the history
Fix hex codes conversion.
  • Loading branch information
tastybento authored Oct 23, 2024
2 parents 57b8a51 + fdd8b7f commit 9a24ee9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ public void sendMessage(String reference, String... variables) {
* @param message The message to send, containing inline commands in square brackets.
*/
public void sendRawMessage(String message) {
BentoBox.getInstance().logDebug(message);
// Create a base TextComponent for the message
TextComponent baseComponent = new TextComponent();

Expand All @@ -632,7 +633,7 @@ public void sendRawMessage(String message) {
// Add any text before the current match
if (matcher.start() > lastMatchEnd) {
String beforeMatch = message.substring(lastMatchEnd, matcher.start());
baseComponent.addExtra(new TextComponent(beforeMatch));
baseComponent.addExtra(TextComponent.fromLegacy(beforeMatch));
}

// Check if it's a recognized command or an unknown bracketed text
Expand All @@ -658,12 +659,12 @@ public void sendRawMessage(String message) {
break;
default:
// Unrecognized command; preserve it in the output text
baseComponent.addExtra(new TextComponent(matcher.group(0)));
baseComponent.addExtra(TextComponent.fromLegacy(matcher.group(0)));
}

} else if (matcher.group(3) != null) {
// Unrecognized bracketed text; preserve it in the output
baseComponent.addExtra(new TextComponent("[[" + matcher.group(3) + "]]"));
baseComponent.addExtra(TextComponent.fromLegacy("[[" + matcher.group(3) + "]]"));
}

// Update the last match end position
Expand All @@ -673,7 +674,7 @@ public void sendRawMessage(String message) {
// Add any remaining text after the last match
if (lastMatchEnd < message.length()) {
String remainingText = message.substring(lastMatchEnd);
baseComponent.addExtra(new TextComponent(remainingText));
baseComponent.addExtra(TextComponent.fromLegacy(remainingText));
}

// Apply the first encountered ClickEvent and HoverEvent to the entire message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void checkSpigotMessage(String expectedMessage, int expectedOccurrences)
List<TextComponent> capturedMessages = captor.getAllValues();

// Count the number of occurrences of the expectedMessage in the captured messages
long actualOccurrences = capturedMessages.stream().map(component -> component.toPlainText()) // Convert each TextComponent to plain text
long actualOccurrences = capturedMessages.stream().map(component -> component.toLegacyText()) // Convert each TextComponent to plain text
.filter(messageText -> messageText.contains(expectedMessage)) // Check if the message contains the expected text
.count(); // Count how many times the expected message appears

Expand Down

0 comments on commit 9a24ee9

Please sign in to comment.