From 27a8d99ec4f11d1facccb6d68b120b67b74b16a2 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Mon, 8 Mar 2021 16:44:40 -0800 Subject: [PATCH] Adventure 4.7.0 --- Spigot-API-Patches/0005-Adventure.patch | 12 ++--- Spigot-Server-Patches/0010-Adventure.patch | 54 ++++++++++++++++++++-- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Spigot-API-Patches/0005-Adventure.patch b/Spigot-API-Patches/0005-Adventure.patch index c95924a3b..999222b3c 100644 --- a/Spigot-API-Patches/0005-Adventure.patch +++ b/Spigot-API-Patches/0005-Adventure.patch @@ -7,7 +7,7 @@ Co-authored-by: zml Co-authored-by: Jake Potrebic diff --git a/pom.xml b/pom.xml -index 58fc279186e01a4703102227f387e96272fcf0a7..6397486ac7027a679d70d388066e4dac55936f5c 100644 +index 58fc279186e01a4703102227f387e96272fcf0a7..06f294ca94709b39f9f1e56fe32b44524b651c13 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,39 @@ @@ -20,7 +20,7 @@ index 58fc279186e01a4703102227f387e96272fcf0a7..6397486ac7027a679d70d388066e4dac + + net.kyori + adventure-bom -+ 4.6.0 ++ 4.7.0 + pom + import + @@ -55,10 +55,10 @@ index 58fc279186e01a4703102227f387e96272fcf0a7..6397486ac7027a679d70d388066e4dac https://javadoc.io/doc/org.jetbrains/annotations-java5/20.1.0/ https://javadoc.io/doc/net.md-5/bungeecord-chat/1.16-R0.4/ + -+ https://jd.adventure.kyori.net/api/4.6.0/ -+ https://jd.adventure.kyori.net/text-serializer-gson/4.6.0/ -+ https://jd.adventure.kyori.net/text-serializer-legacy/4.6.0/ -+ https://jd.adventure.kyori.net/text-serializer-plain/4.6.0/ ++ https://jd.adventure.kyori.net/api/4.7.0/ ++ https://jd.adventure.kyori.net/text-serializer-gson/4.7.0/ ++ https://jd.adventure.kyori.net/text-serializer-legacy/4.7.0/ ++ https://jd.adventure.kyori.net/text-serializer-plain/4.7.0/ + diff --git a/Spigot-Server-Patches/0010-Adventure.patch b/Spigot-Server-Patches/0010-Adventure.patch index 15cbec6e0..5a68d1c97 100644 --- a/Spigot-Server-Patches/0010-Adventure.patch +++ b/Spigot-Server-Patches/0010-Adventure.patch @@ -424,10 +424,10 @@ index 0000000000000000000000000000000000000000..64fcc77eb2ce8979ae756696d98f1d3a +} diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java new file mode 100644 -index 0000000000000000000000000000000000000000..23e6a033612d964f1185dd09a10b470f46685568 +index 0000000000000000000000000000000000000000..3c6de21ffa90c644760a412eb6624d18510e0a53 --- /dev/null +++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java -@@ -0,0 +1,286 @@ +@@ -0,0 +1,334 @@ +package io.papermc.paper.adventure; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -436,21 +436,27 @@ index 0000000000000000000000000000000000000000..23e6a033612d964f1185dd09a10b470f +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; ++import java.util.regex.Matcher; ++import java.util.regex.Pattern; +import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.inventory.Book; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.nbt.api.BinaryTagHolder; +import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.TranslatableComponent; ++import net.kyori.adventure.text.flattener.ComponentFlattener; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; ++import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.translation.GlobalTranslator; +import net.kyori.adventure.util.Codec; +import net.minecraft.server.BossBattle; +import net.minecraft.server.EnumChatFormat; +import net.minecraft.server.IChatBaseComponent; +import net.minecraft.server.ItemStack; ++import net.minecraft.server.LocaleLanguage; +import net.minecraft.server.MinecraftKey; +import net.minecraft.server.MojangsonParser; +import net.minecraft.server.NBTTagCompound; @@ -462,7 +468,49 @@ index 0000000000000000000000000000000000000000..23e6a033612d964f1185dd09a10b470f + +public final class PaperAdventure { + public static final AttributeKey LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale"); -+ public static final LegacyComponentSerializer LEGACY_SECTION_UXRC = LegacyComponentSerializer.builder().hexColors().useUnusualXRepeatedCharacterHexFormat().build(); ++ private static final Pattern LOCALIZATION_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?s"); ++ public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder() ++ .complexMapper(TranslatableComponent.class, (translatable, consumer) -> { ++ final @NonNull String translated = LocaleLanguage.a().a(translatable.key()); ++ ++ final Matcher matcher = LOCALIZATION_PATTERN.matcher(translated); ++ final List args = translatable.args(); ++ int argPosition = 0; ++ int lastIdx = 0; ++ while (matcher.find()) { ++ // append prior ++ if (lastIdx < matcher.start()) { ++ consumer.accept(Component.text(translated.substring(lastIdx, matcher.start()))); ++ } ++ lastIdx = matcher.end(); ++ ++ final @Nullable String argIdx = matcher.group(1); ++ // calculate argument position ++ if (argIdx != null) { ++ try { ++ final int idx = Integer.parseInt(argIdx); ++ if (idx < args.size()) { ++ consumer.accept(args.get(idx)); ++ } ++ } catch (final NumberFormatException ex) { ++ // ignore, drop the format placeholder ++ } ++ } else { ++ final int idx = argPosition++; ++ if (idx < args.size()) { ++ consumer.accept(args.get(idx)); ++ } ++ } ++ } ++ ++ // append tail ++ if (lastIdx < translated.length()) { ++ consumer.accept(Component.text(translated.substring(lastIdx))); ++ } ++ }) ++ .build(); ++ public static final LegacyComponentSerializer LEGACY_SECTION_UXRC = LegacyComponentSerializer.builder().flattener(FLATTENER).hexColors().useUnusualXRepeatedCharacterHexFormat().build(); ++ public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build(); + static final GsonComponentSerializer GSON = GsonComponentSerializer.builder() + .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE) + .build();