mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 11:24:11 +01:00
42 lines
2.5 KiB
Diff
42 lines
2.5 KiB
Diff
--- a/net/minecraft/network/chat/ComponentUtils.java
|
|
+++ b/net/minecraft/network/chat/ComponentUtils.java
|
|
@@ -33,14 +33,39 @@
|
|
}
|
|
}
|
|
|
|
+ @io.papermc.paper.annotation.DoNotUse // Paper - validate separators - right now this method is only used for separator evaluation. Error on build if this changes to re-evaluate.
|
|
public static Optional<MutableComponent> updateForEntity(@Nullable CommandSourceStack source, Optional<Component> text, @Nullable Entity sender, int depth) throws CommandSyntaxException {
|
|
return text.isPresent() ? Optional.of(updateForEntity(source, text.get(), sender, depth)) : Optional.empty();
|
|
}
|
|
|
|
+ // Paper start - validate separator
|
|
+ public static Optional<MutableComponent> updateSeparatorForEntity(@Nullable CommandSourceStack source, Optional<Component> text, @Nullable Entity sender, int depth) throws CommandSyntaxException {
|
|
+ if (text.isEmpty() || !isValidSelector(text.get())) return Optional.empty();
|
|
+ return Optional.of(updateForEntity(source, text.get(), sender, depth));
|
|
+ }
|
|
+ public static boolean isValidSelector(final Component component) {
|
|
+ final ComponentContents contents = component.getContents();
|
|
+
|
|
+ if (contents instanceof net.minecraft.network.chat.contents.NbtContents || contents instanceof net.minecraft.network.chat.contents.SelectorContents) return false;
|
|
+ if (contents instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents) {
|
|
+ for (final Object arg : translatableContents.getArgs()) {
|
|
+ if (arg instanceof final Component argumentAsComponent && !isValidSelector(argumentAsComponent)) return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+ // Paper end - validate separator
|
|
+
|
|
public static MutableComponent updateForEntity(@Nullable CommandSourceStack source, Component text, @Nullable Entity sender, int depth) throws CommandSyntaxException {
|
|
if (depth > 100) {
|
|
return text.copy();
|
|
} else {
|
|
+ // Paper start - adventure; pass actual vanilla component
|
|
+ if (text instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent) {
|
|
+ text = adventureComponent.deepConverted();
|
|
+ }
|
|
+ // Paper end - adventure; pass actual vanilla component
|
|
MutableComponent mutableComponent = text.getContents().resolve(source, sender, depth + 1);
|
|
|
|
for (Component component : text.getSiblings()) {
|