Skip to content

Commit f63005f

Browse files
authored
Merge pull request #2782 from BentoBoxWorld/adventure_component_utility
Adds a bukkit to adventure conversion. Could be useful.
2 parents d09de1c + 87c3379 commit f63005f

File tree

1 file changed

+20
-0
lines changed
  • src/main/java/world/bentobox/bentobox/util

1 file changed

+20
-0
lines changed

src/main/java/world/bentobox/bentobox/util/Util.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import com.google.common.base.Enums;
5252
import com.google.common.base.Optional;
5353

54+
import net.kyori.adventure.text.Component;
55+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
5456
import world.bentobox.bentobox.BentoBox;
5557
import world.bentobox.bentobox.api.user.User;
5658
import 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
}

0 commit comments

Comments
 (0)