mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 09:42:06 -07:00
Attempt to patch edge cases in component serialization roundtrip.
This is a bandaid fix, but vanilla shouldn't really be creating illegal components like this.
This commit is contained in:
@@ -118,7 +118,7 @@
|
|||||||
+ // source.sendFailure(mutableComponent);
|
+ // source.sendFailure(mutableComponent);
|
||||||
+ builder
|
+ builder
|
||||||
+ .append(net.kyori.adventure.text.Component.newline())
|
+ .append(net.kyori.adventure.text.Component.newline())
|
||||||
+ .append(io.papermc.paper.adventure.PaperAdventure.asAdventure(mutableComponent));
|
+ .append(io.papermc.paper.adventure.PaperAdventure.asAdventureSafe(mutableComponent)); // Console output can cause section characters
|
||||||
+ }
|
+ }
|
||||||
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build());
|
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(source.getBukkitSender(), command, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build());
|
||||||
+ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
|
+ org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
@@ -27,6 +27,7 @@ import net.kyori.adventure.text.TranslationArgument;
|
|||||||
import net.kyori.adventure.text.event.DataComponentValue;
|
import net.kyori.adventure.text.event.DataComponentValue;
|
||||||
import net.kyori.adventure.text.event.DataComponentValueConverterRegistry;
|
import net.kyori.adventure.text.event.DataComponentValueConverterRegistry;
|
||||||
import net.kyori.adventure.text.flattener.ComponentFlattener;
|
import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.Style;
|
import net.kyori.adventure.text.format.Style;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||||
@@ -187,6 +188,18 @@ public final class PaperAdventure {
|
|||||||
|
|
||||||
// Component
|
// Component
|
||||||
|
|
||||||
|
// There are edge cases where vanilla can create illegal components that fail the adventure codec roundtrips.
|
||||||
|
// Handle those "safely"
|
||||||
|
// Currently this is needed for command related click events that may have section characters in NMS.
|
||||||
|
public static @NotNull Component asAdventureSafe(@Nullable final net.minecraft.network.chat.Component component) {
|
||||||
|
try {
|
||||||
|
return asAdventure(component);
|
||||||
|
} catch (RuntimeException runtimeException) {
|
||||||
|
runtimeException.printStackTrace();
|
||||||
|
return Component.translatable("multiplayer.message_not_delivered", "Adventure roundtrip").color(NamedTextColor.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static @NotNull Component asAdventure(@Nullable final net.minecraft.network.chat.Component component) {
|
public static @NotNull Component asAdventure(@Nullable final net.minecraft.network.chat.Component component) {
|
||||||
return component == null ? Component.empty() : WRAPPER_AWARE_SERIALIZER.deserialize(component);
|
return component == null ? Component.empty() : WRAPPER_AWARE_SERIALIZER.deserialize(component);
|
||||||
}
|
}
|
||||||
|
@@ -797,7 +797,9 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component teamDisplayName() {
|
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component teamDisplayName() {
|
||||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getDisplayName());
|
// Player entities could possibly create a section character in the click event
|
||||||
|
// due to their game profile having an illegal name
|
||||||
|
return io.papermc.paper.adventure.PaperAdventure.asAdventureSafe(this.getHandle().getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user