diff --git a/src/main/java/world/bentobox/bentobox/util/Util.java b/src/main/java/world/bentobox/bentobox/util/Util.java index 0c6ce9f77..36498f1ca 100644 --- a/src/main/java/world/bentobox/bentobox/util/Util.java +++ b/src/main/java/world/bentobox/bentobox/util/Util.java @@ -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; @@ -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); + } }