Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 19:10:09 +01:00
Adventure 4.7.0
Dieser Commit ist enthalten in:
Ursprung
e65bd35a12
Commit
27a8d99ec4
@ -7,7 +7,7 @@ Co-authored-by: zml <zml@stellardrift.ca>
|
||||
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
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
|
||||
+ <dependency>
|
||||
+ <groupId>net.kyori</groupId>
|
||||
+ <artifactId>adventure-bom</artifactId>
|
||||
+ <version>4.6.0</version> <!-- keep this version in synch with javadoc section below! -->
|
||||
+ <version>4.7.0</version> <!-- keep this version in synch with javadoc section below! -->
|
||||
+ <type>pom</type>
|
||||
+ <scope>import</scope>
|
||||
+ </dependency>
|
||||
@ -55,10 +55,10 @@ index 58fc279186e01a4703102227f387e96272fcf0a7..6397486ac7027a679d70d388066e4dac
|
||||
<link>https://javadoc.io/doc/org.jetbrains/annotations-java5/20.1.0/</link>
|
||||
<link>https://javadoc.io/doc/net.md-5/bungeecord-chat/1.16-R0.4/</link>
|
||||
+ <!-- Paper start -->
|
||||
+ <link>https://jd.adventure.kyori.net/api/4.6.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/text-serializer-gson/4.6.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/text-serializer-legacy/4.6.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/text-serializer-plain/4.6.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/api/4.7.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/text-serializer-gson/4.7.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/text-serializer-legacy/4.7.0/</link>
|
||||
+ <link>https://jd.adventure.kyori.net/text-serializer-plain/4.7.0/</link>
|
||||
+ <!-- Paper end -->
|
||||
</links>
|
||||
</configuration>
|
||||
|
@ -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> 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<Component> 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();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren