3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00

Prevent an infinite recursion error while rendering translatables (Fixes #6551) (#6555)

Dieser Commit ist enthalten in:
Jake Potrebic 2021-09-03 10:01:05 -07:00 committet von GitHub
Ursprung f6a1cb21c5
Commit 5c7da5536b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -498,10 +498,10 @@ index 0000000000000000000000000000000000000000..eeedc30a45d9637d68f04f185b3dd90d
+}
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..41762b5ed19b17ee524f79726eaa4cf38479ba96
index 0000000000000000000000000000000000000000..f763a3ea5796737304e0c1f41349622e1d7adadf
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
@@ -0,0 +1,375 @@
@@ -0,0 +1,381 @@
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
@ -525,6 +525,8 @@ index 0000000000000000000000000000000000000000..41762b5ed19b17ee524f79726eaa4cf3
+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.translation.TranslationRegistry;
+import net.kyori.adventure.translation.Translator;
+import net.kyori.adventure.util.Codec;
+import net.minecraft.ChatFormatting;
+import net.minecraft.locale.Language;
@ -547,8 +549,12 @@ index 0000000000000000000000000000000000000000..41762b5ed19b17ee524f79726eaa4cf3
+ public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
+ .complexMapper(TranslatableComponent.class, (translatable, consumer) -> {
+ if (!Language.getInstance().has(translatable.key())) {
+ consumer.accept(GlobalTranslator.render(translatable, Locale.US));
+ return;
+ for (final Translator source : GlobalTranslator.get().sources()) {
+ if (source instanceof TranslationRegistry registry && registry.contains(translatable.key())) {
+ consumer.accept(GlobalTranslator.render(translatable, Locale.US));
+ return;
+ }
+ }
+ }
+ final @NonNull String translated = Language.getInstance().getOrDefault(translatable.key());
+