From 83c42080d65fb28e39cf9789635d69e32617e3c9 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Fri, 13 Dec 2024 21:49:47 +0100 Subject: [PATCH] chat/contents --- .../chat/contents/NbtContents.java.patch | 20 +++++++++++++ .../chat/contents/SelectorContents.java.patch | 10 +++---- .../contents/TranslatableContents.java.patch | 30 ++++++++++--------- .../chat/contents/NbtContents.java.patch | 20 ------------- 4 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 paper-server/patches/sources/net/minecraft/network/chat/contents/NbtContents.java.patch rename paper-server/patches/{unapplied => sources}/net/minecraft/network/chat/contents/SelectorContents.java.patch (55%) rename paper-server/patches/{unapplied => sources}/net/minecraft/network/chat/contents/TranslatableContents.java.patch (69%) delete mode 100644 paper-server/patches/unapplied/net/minecraft/network/chat/contents/NbtContents.java.patch diff --git a/paper-server/patches/sources/net/minecraft/network/chat/contents/NbtContents.java.patch b/paper-server/patches/sources/net/minecraft/network/chat/contents/NbtContents.java.patch new file mode 100644 index 0000000000..ee118dfd02 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/network/chat/contents/NbtContents.java.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/network/chat/contents/NbtContents.java ++++ b/net/minecraft/network/chat/contents/NbtContents.java +@@ -115,7 +_,7 @@ + }).map(Tag::getAsString); + if (this.interpreting) { + Component component = DataFixUtils.orElse( +- ComponentUtils.updateForEntity(nbtPathPattern, this.separator, entity, recursionDepth), ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR ++ ComponentUtils.updateSeparatorForEntity(nbtPathPattern, this.separator, entity, recursionDepth), ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR // Paper - validate separator + ); + return stream.flatMap(text -> { + try { +@@ -127,7 +_,7 @@ + } + }).reduce((mutableComponent, component1) -> mutableComponent.append(component).append(component1)).orElseGet(Component::empty); + } else { +- return ComponentUtils.updateForEntity(nbtPathPattern, this.separator, entity, recursionDepth) ++ return ComponentUtils.updateSeparatorForEntity(nbtPathPattern, this.separator, entity, recursionDepth) // Paper - validate separator + .map( + mutableComponent -> stream.map(Component::literal) + .reduce((mutableComponent1, otherMutableComponent) -> mutableComponent1.append(mutableComponent).append(otherMutableComponent)) diff --git a/paper-server/patches/unapplied/net/minecraft/network/chat/contents/SelectorContents.java.patch b/paper-server/patches/sources/net/minecraft/network/chat/contents/SelectorContents.java.patch similarity index 55% rename from paper-server/patches/unapplied/net/minecraft/network/chat/contents/SelectorContents.java.patch rename to paper-server/patches/sources/net/minecraft/network/chat/contents/SelectorContents.java.patch index aff540bbdc..16c49dcbd5 100644 --- a/paper-server/patches/unapplied/net/minecraft/network/chat/contents/SelectorContents.java.patch +++ b/paper-server/patches/sources/net/minecraft/network/chat/contents/SelectorContents.java.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/network/chat/contents/SelectorContents.java +++ b/net/minecraft/network/chat/contents/SelectorContents.java -@@ -36,7 +36,7 @@ - if (source == null) { +@@ -36,7 +_,7 @@ + if (nbtPathPattern == null) { return Component.empty(); } else { -- Optional optional = ComponentUtils.updateForEntity(source, this.separator, sender, depth); -+ Optional optional = ComponentUtils.updateSeparatorForEntity(source, this.separator, sender, depth); // Paper - validate separator - return ComponentUtils.formatList(this.selector.resolved().findEntities(source), optional, Entity::getDisplayName); +- Optional optional = ComponentUtils.updateForEntity(nbtPathPattern, this.separator, entity, recursionDepth); ++ Optional optional = ComponentUtils.updateSeparatorForEntity(nbtPathPattern, this.separator, entity, recursionDepth); // Paper - validate separator + return ComponentUtils.formatList(this.selector.resolved().findEntities(nbtPathPattern), optional, Entity::getDisplayName); } } diff --git a/paper-server/patches/unapplied/net/minecraft/network/chat/contents/TranslatableContents.java.patch b/paper-server/patches/sources/net/minecraft/network/chat/contents/TranslatableContents.java.patch similarity index 69% rename from paper-server/patches/unapplied/net/minecraft/network/chat/contents/TranslatableContents.java.patch rename to paper-server/patches/sources/net/minecraft/network/chat/contents/TranslatableContents.java.patch index 88b91fae6d..6240ecc49b 100644 --- a/paper-server/patches/unapplied/net/minecraft/network/chat/contents/TranslatableContents.java.patch +++ b/paper-server/patches/sources/net/minecraft/network/chat/contents/TranslatableContents.java.patch @@ -1,45 +1,47 @@ --- a/net/minecraft/network/chat/contents/TranslatableContents.java +++ b/net/minecraft/network/chat/contents/TranslatableContents.java -@@ -181,6 +181,15 @@ +@@ -181,6 +_,16 @@ @Override - public Optional visit(FormattedText.ContentConsumer visitor) { + public Optional visit(FormattedText.ContentConsumer contentConsumer) { + // Paper start - Count visited parts + try { -+ return this.visit(new TranslatableContentConsumer<>(visitor)); ++ return this.visit(new TranslatableContentConsumer<>(contentConsumer)); + } catch (IllegalArgumentException ignored) { -+ return visitor.accept("..."); ++ return contentConsumer.accept("..."); + } + } -+ private Optional visit(TranslatableContentConsumer visitor) { ++ ++ private Optional visit(TranslatableContentConsumer contentConsumer) { + // Paper end - Count visited parts this.decompose(); for (FormattedText formattedText : this.decomposedParts) { -@@ -191,7 +200,26 @@ - } +@@ -192,6 +_,27 @@ return Optional.empty(); -+ } + } ++ + // Paper start - Count visited parts + private static final class TranslatableContentConsumer implements FormattedText.ContentConsumer { -+ private static final IllegalArgumentException EX = new IllegalArgumentException("Too long"); ++ private static final IllegalArgumentException NESTED_TOO_LONG = new IllegalArgumentException("Too long"); ++ + private final FormattedText.ContentConsumer visitor; + private int visited; + -+ private TranslatableContentConsumer(FormattedText.ContentConsumer visitor) { ++ private TranslatableContentConsumer(final FormattedText.ContentConsumer visitor) { + this.visitor = visitor; + } + + @Override + public Optional accept(final String asString) { -+ if (visited++ > 32) { -+ throw EX; ++ if (this.visited++ > 32) { ++ throw NESTED_TOO_LONG; + } + return this.visitor.accept(asString); + } - } ++ } + // Paper end - Count visited parts @Override - public MutableComponent resolve(@Nullable CommandSourceStack source, @Nullable Entity sender, int depth) throws CommandSyntaxException { + public MutableComponent resolve(@Nullable CommandSourceStack nbtPathPattern, @Nullable Entity entity, int recursionDepth) throws CommandSyntaxException { diff --git a/paper-server/patches/unapplied/net/minecraft/network/chat/contents/NbtContents.java.patch b/paper-server/patches/unapplied/net/minecraft/network/chat/contents/NbtContents.java.patch deleted file mode 100644 index f30203349e..0000000000 --- a/paper-server/patches/unapplied/net/minecraft/network/chat/contents/NbtContents.java.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- a/net/minecraft/network/chat/contents/NbtContents.java -+++ b/net/minecraft/network/chat/contents/NbtContents.java -@@ -120,7 +120,7 @@ - }).map(Tag::getAsString); - if (this.interpreting) { - Component component = DataFixUtils.orElse( -- ComponentUtils.updateForEntity(source, this.separator, sender, depth), ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR -+ ComponentUtils.updateSeparatorForEntity(source, this.separator, sender, depth), ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR // Paper - validate separator - ); - return stream.flatMap(text -> { - try { -@@ -132,7 +132,7 @@ - } - }).reduce((accumulator, current) -> accumulator.append(component).append(current)).orElseGet(Component::empty); - } else { -- return ComponentUtils.updateForEntity(source, this.separator, sender, depth) -+ return ComponentUtils.updateSeparatorForEntity(source, this.separator, sender, depth) // Paper - validate separator - .map( - text -> stream.map(Component::literal) - .reduce((accumulator, current) -> accumulator.append(text).append(current))