chat/contents

This commit is contained in:
Lulu13022002 2024-12-13 21:49:47 +01:00
parent c6a426beda
commit 83c42080d6
No known key found for this signature in database
GPG key ID: 491C8F0B8ACDEB01
4 changed files with 41 additions and 39 deletions

View file

@ -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))

View file

@ -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<? extends Component> optional = ComponentUtils.updateForEntity(source, this.separator, sender, depth);
+ Optional<? extends Component> optional = ComponentUtils.updateSeparatorForEntity(source, this.separator, sender, depth); // Paper - validate separator
return ComponentUtils.formatList(this.selector.resolved().findEntities(source), optional, Entity::getDisplayName);
- Optional<? extends Component> optional = ComponentUtils.updateForEntity(nbtPathPattern, this.separator, entity, recursionDepth);
+ Optional<? extends Component> optional = ComponentUtils.updateSeparatorForEntity(nbtPathPattern, this.separator, entity, recursionDepth); // Paper - validate separator
return ComponentUtils.formatList(this.selector.resolved().findEntities(nbtPathPattern), optional, Entity::getDisplayName);
}
}

View file

@ -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 <T> Optional<T> visit(FormattedText.ContentConsumer<T> visitor) {
public <T> Optional<T> visit(FormattedText.ContentConsumer<T> 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 <T> Optional<T> visit(TranslatableContentConsumer<T> visitor) {
+
+ private <T> Optional<T> visit(TranslatableContentConsumer<T> 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<T> implements FormattedText.ContentConsumer<T> {
+ private static final IllegalArgumentException EX = new IllegalArgumentException("Too long");
+ private static final IllegalArgumentException NESTED_TOO_LONG = new IllegalArgumentException("Too long");
+
+ private final FormattedText.ContentConsumer<T> visitor;
+ private int visited;
+
+ private TranslatableContentConsumer(FormattedText.ContentConsumer<T> visitor) {
+ private TranslatableContentConsumer(final FormattedText.ContentConsumer<T> visitor) {
+ this.visitor = visitor;
+ }
+
+ @Override
+ public Optional<T> 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 {

View file

@ -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))