File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/main/java/world/bentobox/bentobox/util Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 5151import com .google .common .base .Enums ;
5252import com .google .common .base .Optional ;
5353
54+ import net .kyori .adventure .text .Component ;
55+ import net .kyori .adventure .text .serializer .legacy .LegacyComponentSerializer ;
5456import world .bentobox .bentobox .BentoBox ;
5557import world .bentobox .bentobox .api .user .User ;
5658import world .bentobox .bentobox .nms .AbstractMetaData ;
@@ -947,4 +949,22 @@ public static boolean isVersionAtLeast(String targetVersion) {
947949 return SERVER_VERSION .startsWith (targetVersion );
948950 }
949951 }
952+
953+ private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer .builder ()
954+ .character ('&' )
955+ .hexColors () // Enables support for modern hex codes (e.g., &#FF0000) alongside legacy codes.
956+ .build ();
957+
958+ /**
959+ * Converts a string containing Bukkit color codes ('&') into an Adventure Component.
960+ *
961+ * @param legacyString The string with Bukkit color and format codes.
962+ * @return The resulting Adventure Component.
963+ */
964+ public static Component bukkitToAdventure (String legacyString ) {
965+ if (legacyString == null ) {
966+ return Component .empty ();
967+ }
968+ return LEGACY_SERIALIZER .deserialize (legacyString );
969+ }
950970}
You can’t perform that action at this time.
0 commit comments