[ci skip] add more comments & move 1 hunk to correct patch

This commit is contained in:
Jake Potrebic
2024-01-13 12:31:02 -08:00
parent 393db207da
commit a5eaf39caf
24 changed files with 130 additions and 143 deletions

View File

@@ -2084,7 +2084,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return name == null ? null : FORMATTING_BY_NAME.get(cleanName(name));
}
+ // Paper start
+ // Paper start - add method to get by hex value
+ @Nullable public static ChatFormatting getByHexValue(int i) {
+ for (ChatFormatting value : values()) {
+ if (value.getColor() != null && value.getColor() == i) {
@@ -2094,7 +2094,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ return null;
+ }
+ // Paper end
+ // Paper end - add method to get by hex value
+
@Nullable
public static ChatFormatting getById(int colorIndex) {
@@ -2107,7 +2107,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private final CommandSigningContext signingContext;
private final TaskChainer chatMessageChainer;
public volatile CommandNode currentCommand; // CraftBukkit
+ public boolean bypassSelectorPermissions = false; // Paper
+ public boolean bypassSelectorPermissions = false; // Paper - add bypass for selector permissions
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
@@ -2122,11 +2122,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- Component component = minecraftServer.getChatDecorator().decorate(source.getPlayer(), message.decoratedContent());
- source.getChatMessageChainer().append(completableFuture, (filtered) -> {
- PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(component).filter(filtered.mask());
+ // Paper start
+ // Paper start - support asynchronous chat decoration
+ CompletableFuture<ChatDecorator.Result> componentFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent());
+ source.getChatMessageChainer().append(CompletableFuture.allOf(completableFuture, componentFuture), (filtered) -> {
+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(componentFuture.join().component()).filter(completableFuture.join().mask()); // Paper
+ // Paper end
+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(componentFuture.join().component()).filter(completableFuture.join().mask());
+ // Paper end - support asynchronous chat decoration
callback.accept(playerChatMessage2);
});
}
@@ -2135,10 +2135,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
ChatDecorator chatDecorator = source.getServer().getChatDecorator();
- Component component = chatDecorator.decorate(source.getPlayer(), message.decoratedContent());
- callback.accept(message.withUnsignedContent(component));
+ // Paper start
+ // Paper start - support asynchronous chat decoration
+ CompletableFuture<ChatDecorator.Result> componentFuture = chatDecorator.decorate(source.getPlayer(), source, message.decoratedContent());
+ source.getChatMessageChainer().append(componentFuture, (result) -> callback.accept(message.withUnsignedContent(result.component())));
+ // Paper end
+ // Paper end - support asynchronous chat decoration
}
private static CompletableFuture<FilteredText> filterPlainText(CommandSourceStack source, PlayerChatMessage message) {
@@ -2151,7 +2151,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private void checkPermissions(CommandSourceStack source) throws CommandSyntaxException {
- if (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector")) { // CraftBukkit
+ if (source.bypassSelectorPermissions || (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector"))) { // CraftBukkit // Paper
+ if (source.bypassSelectorPermissions || (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector"))) { // CraftBukkit // Paper - add bypass for selector perms
throw EntityArgument.ERROR_SELECTORS_NOT_ALLOWED.create();
}
}
@@ -2163,7 +2163,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public static final int DEFAULT_NBT_QUOTA = 2097152;
private final ByteBuf source;
+ public java.util.Locale adventure$locale; // Paper
+ public java.util.Locale adventure$locale; // Paper - track player's locale for server-side translations
public static final short MAX_STRING_LENGTH = 32767;
public static final int MAX_COMPONENT_STRING_LENGTH = 262144;
private static final int PUBLIC_KEY_SIZE = 256;
@@ -2171,17 +2171,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
public <T> void writeJsonWithCodec(Codec<T> codec, T value) {
+ // Paper start - Adventure
+ // Paper start - Adventure; add max length parameter
+ this.writeJsonWithCodec(codec, value, MAX_STRING_LENGTH);
+ }
+ public <T> void writeJsonWithCodec(Codec<T> codec, T value, int maxLength) {
+ // Paper end - Adventure
+ // Paper end - Adventure; add max length parameter
DataResult<JsonElement> dataresult = codec.encodeStart(JsonOps.INSTANCE, value);
this.writeUtf(FriendlyByteBuf.GSON.toJson((JsonElement) Util.getOrThrow(dataresult, (s) -> {
return new EncoderException("Failed to encode: " + s + " " + value);
- })));
+ })), maxLength); // Paper - Adventure
+ })), maxLength); // Paper - Adventure; add max length parameter
}
public <T> void writeId(IdMap<T> registry, T value) {
@@ -2189,7 +2189,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return (Component) this.readWithCodecTrusted(NbtOps.INSTANCE, ComponentSerialization.CODEC);
}
+ // Paper start - adventure
+ // Paper start - adventure; support writing adventure components directly and server-side translations
+ public FriendlyByteBuf writeComponent(final net.kyori.adventure.text.Component component) {
+ return this.writeWithCodec(NbtOps.INSTANCE, io.papermc.paper.adventure.PaperAdventure.localizedCodec(this.adventure$locale), component);
+ }
@@ -2201,7 +2201,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ return this.writeWithCodec(NbtOps.INSTANCE, ComponentSerialization.localizedCodec(this.adventure$locale), text);
+ // Paper end - adventure
+ // Paper end - adventure; support writing adventure components directly and server-side translations
}
public <T extends Enum<T>> T readEnum(Class<T> enumClass) {
@@ -2213,7 +2213,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} else {
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(byteBuf);
friendlyByteBuf.writeVarInt(i);
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper - adventure; set player's locale
try {
int j = friendlyByteBuf.writerIndex();
@@ -2231,14 +2231,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public interface ChatDecorator {
ChatDecorator PLAIN = (sender, message) -> {
- return message;
+ return CompletableFuture.completedFuture(message); // Paper
+ return CompletableFuture.completedFuture(message); // Paper - adventure; support async chat decoration events
};
- Component decorate(@Nullable ServerPlayer sender, Component message);
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper
+ CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message); // Paper - make a completable future again
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - adventure; support chat decoration events
+ CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message); // Paper - adventure; support async chat decoration events
+
+ // Paper start
+ // Paper start - adventure; support async chat decoration events
+ default CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
+ throw new UnsupportedOperationException("Must override this implementation");
+ }
@@ -2294,7 +2294,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return new MessagePair(adventureComponent, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(adventureComponent));
+ }
+ }
+ // Paper end
+ // Paper end - adventure; support async chat decoration events
}
diff --git a/src/main/java/net/minecraft/network/chat/ComponentSerialization.java b/src/main/java/net/minecraft/network/chat/ComponentSerialization.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
@@ -2304,7 +2304,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return ExtraCodecs.orCompressed(mapCodec3, mapCodec2);
}
+ // Paper start - adventure
+ // Paper start - adventure; create separate codec for each locale
+ private static final java.util.Map<java.util.Locale, Codec<Component>> LOCALIZED_CODECS = new java.util.concurrent.ConcurrentHashMap<>();
+
+ public static Codec<Component> localizedCodec(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Locale locale) {
@@ -2314,21 +2314,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return LOCALIZED_CODECS.computeIfAbsent(locale,
+ loc -> ExtraCodecs.recursive("Component", selfCodec -> createCodec(selfCodec, loc)));
+ }
+ // Paper end
+ // Paper end - adventure; create separate codec for each locale
+
private static Codec<Component> createCodec(Codec<Component> selfCodec) {
+ // Paper start - adventure
+ // Paper start - adventure; create separate codec for each locale
+ return createCodec(selfCodec, null);
+ }
+
+ private static Codec<Component> createCodec(Codec<Component> selfCodec, @javax.annotation.Nullable java.util.Locale locale) {
+ // Paper end
+ // Paper end - adventure; create separate codec for each locale
ComponentContents.Type<?>[] types = new ComponentContents.Type[]{PlainTextContents.TYPE, TranslatableContents.TYPE, KeybindContents.TYPE, ScoreContents.TYPE, SelectorContents.TYPE, NbtContents.TYPE};
MapCodec<ComponentContents> mapCodec = createLegacyComponentMatcher(types, ComponentContents.Type::codec, ComponentContents::type, "type");
Codec<Component> codec = RecordCodecBuilder.create((instance) -> {
return instance.group(mapCodec.forGetter(Component::getContents), ExtraCodecs.strictOptionalField(ExtraCodecs.nonEmptyList(selfCodec.listOf()), "extra", List.of()).forGetter(Component::getSiblings), Style.Serializer.MAP_CODEC.forGetter(Component::getStyle)).apply(instance, MutableComponent::new);
});
+ // Paper start - adventure
+ // Paper start - adventure; create separate codec for each locale
+ final Codec<Component> origCodec = codec;
+ codec = new Codec<>() {
+ @Override
@@ -2355,7 +2355,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return origCodec.toString() + "[AdventureComponentAware]";
+ }
+ };
+ // Paper end
+ // Paper end - adventure; create separate codec for each locale
return Codec.either(Codec.either(Codec.STRING, ExtraCodecs.nonEmptyList(selfCodec.listOf())), codec).xmap((either) -> {
return either.map((either2) -> {
return either2.map(Component::literal, ComponentSerialization::createFromList);
@@ -2367,11 +2367,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (depth > 100) {
return text.copy();
} else {
+ // Paper start
+ // Paper start - adventure; pass actual vanilla component
+ if (text instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent) {
+ text = adventureComponent.deepConverted();
+ }
+ // Paper end
+ // Paper end - adventure; pass actual vanilla component
MutableComponent mutableComponent = text.getContents().resolve(source, sender, depth + 1);
for(Component component : text.getSiblings()) {
@@ -2383,7 +2383,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
import net.minecraft.util.SignatureValidator;
public record MessageSignature(byte[] bytes) {
+ public net.kyori.adventure.chat.SignedMessage.Signature adventure() { return () -> this.bytes; } // Paper
+ public net.kyori.adventure.chat.SignedMessage.Signature adventure() { return () -> this.bytes; } // Paper - adventure; support signed messages
public static final Codec<MessageSignature> CODEC = ExtraCodecs.BASE64_STRING.xmap(MessageSignature::new, MessageSignature::bytes);
public static final int BYTES = 256;
@@ -2447,7 +2447,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
import net.minecraft.util.SignatureValidator;
-public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask) {
+// Paper start
+// Paper start - adventure; support signed messages
+public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask, @Nullable net.minecraft.network.chat.ChatDecorator.Result result) {
+ public PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask) {
+ this(link, signature, signedBody, unsignedContent, filterMask, null);
@@ -2493,7 +2493,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public AdventureView adventureView() {
+ return new AdventureView();
+ }
+ // Paper end
+ // Paper end - adventure; support signed messages
public static final MapCodec<PlayerChatMessage> MAP_CODEC = RecordCodecBuilder.mapCodec((instance) -> {
return instance.group(SignedMessageLink.CODEC.fieldOf("link").forGetter(PlayerChatMessage::link), MessageSignature.CODEC.optionalFieldOf("signature").forGetter((message) -> {
return Optional.ofNullable(message.signature);
@@ -2502,7 +2502,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public PlayerChatMessage withUnsignedContent(Component unsignedContent) {
- Component component = !unsignedContent.equals(Component.literal(this.signedContent())) ? unsignedContent : null;
+ Component component = !(unsignedContent instanceof io.papermc.paper.adventure.AdventureComponent advComponent ? advComponent.deepConverted() : unsignedContent).equals(Component.literal(this.signedContent())) ? unsignedContent : null; // Paper
+ Component component = !(unsignedContent instanceof io.papermc.paper.adventure.AdventureComponent advComponent ? advComponent.deepConverted() : unsignedContent).equals(Component.literal(this.signedContent())) ? unsignedContent : null; // Paper - adventure; convert adventure component wraps
return new PlayerChatMessage(this.link, this.signature, this.signedBody, component, this.filterMask);
}