Skip to content

Commit

Permalink
MCStrings: Fix hex patterns when converting to components
Browse files Browse the repository at this point in the history
I'm seriously starting to dislike the way Adventure forces you to build text in an object like way instead of just parsing it. I'll probably will end up making MCUtils rely on Minimessage and just translate MCUtils format to Minimessage's format.
  • Loading branch information
xDec0de committed Nov 3, 2024
1 parent 4acefb5 commit e370637
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version
snakeyaml = { group = "org.yaml", name = "snakeyaml", version.ref = "snakeyaml" }
adventure = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventure-bukkit = { group = "net.kyori", name = "adventure-platform-bukkit", version.ref = "adventure-bukkit" }
adventure-legacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure" }
spigot = { module = "org.spigotmc:spigot-api", version.ref = "spigot" }
velocity = { module = "com.velocitypowered:velocity-api", version.ref = "velocity" }

Expand Down
1 change: 1 addition & 0 deletions platforms/spigot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repositories {
dependencies {
api(project(":shared"))
api(libs.adventure.bukkit)
api(libs.adventure.legacy)
compileOnly(libs.spigot)
}

Expand Down
1 change: 1 addition & 0 deletions platforms/universal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ repositories {
dependencies {
api(project(":shared"))
api(libs.adventure)
api(libs.adventure.legacy)
api(libs.snakeyaml)
}
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ plugins {
dependencies {
api(libs.jetbrains.annotations)
compileOnly(libs.adventure)
compileOnly(libs.adventure.legacy)
compileOnly(libs.snakeyaml)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -254,9 +255,11 @@ public static String stripEventPatterns(@NotNull String string) {
*/
@NotNull
public static Component applyEventPatterns(@NotNull String string) {
final LegacyComponentSerializer serializer = LegacyComponentSerializer.builder().
useUnusualXRepeatedCharacterHexFormat().build();
final TextComponent.Builder builder = Component.text();
searchEventPatterns(string,
txt -> builder.append(Component.text(txt)),
txt -> builder.append(serializer.deserialize(txt)),
(event, txt) -> applyEvents(builder, event, txt));
return builder.build();
}
Expand Down

0 comments on commit e370637

Please sign in to comment.