Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/world/bentobox/bentobox/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import com.google.common.base.Enums;
import com.google.common.base.Optional;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.nms.AbstractMetaData;
Expand Down Expand Up @@ -947,4 +949,22 @@ public static boolean isVersionAtLeast(String targetVersion) {
return SERVER_VERSION.startsWith(targetVersion);
}
}

private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.builder()
.character('&')
.hexColors() // Enables support for modern hex codes (e.g., &#FF0000) alongside legacy codes.
.build();

/**
* Converts a string containing Bukkit color codes ('&') into an Adventure Component.
*
* @param legacyString The string with Bukkit color and format codes.
* @return The resulting Adventure Component.
*/
public static Component bukkitToAdventure(String legacyString) {
if (legacyString == null) {
return Component.empty();
}
return LEGACY_SERIALIZER.deserialize(legacyString);
}
}