From 4ef1d13622f2af7f761de27df08378824fa2cb82 Mon Sep 17 00:00:00 2001 From: Riley Park Date: Tue, 9 Mar 2021 10:03:27 -0800 Subject: [PATCH] legacy formatting will be the death of me --- Spigot-Server-Patches/Adventure.patch | 33 +++++++++++++++++-- .../Player-Tab-List-and-Title-APIs.patch | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Spigot-Server-Patches/Adventure.patch b/Spigot-Server-Patches/Adventure.patch index 2840ae1526..f5fac57c04 100644 --- a/Spigot-Server-Patches/Adventure.patch +++ b/Spigot-Server-Patches/Adventure.patch @@ -216,7 +216,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + private static String legacyDisplayName(final CraftPlayer player) { -+ return PaperAdventure.LEGACY_SECTION_UXRC.serialize(Component.empty().append(displayName(player))); ++ return player.getDisplayName(); + } + + private static Component displayName(final CraftPlayer player) { @@ -328,6 +328,34 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return handlers.getRegisteredListeners().length > 0; + } +} +diff --git a/src/main/java/io/papermc/paper/adventure/DisplayNames.java b/src/main/java/io/papermc/paper/adventure/DisplayNames.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/adventure/DisplayNames.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.adventure; ++ ++import net.minecraft.server.EntityPlayer; ++import org.bukkit.ChatColor; ++import org.bukkit.craftbukkit.entity.CraftPlayer; ++ ++public final class DisplayNames { ++ private DisplayNames() { ++ } ++ ++ public static String getLegacy(final CraftPlayer player) { ++ return getLegacy(player.getHandle()); ++ } ++ ++ public static String getLegacy(final EntityPlayer player) { ++ final String legacy = player.displayName; ++ if (legacy != null) { ++ return PaperAdventure.LEGACY_SECTION_UXRC.serialize(player.adventure$displayName) + ChatColor.getLastColors(player.displayName); ++ } ++ return PaperAdventure.LEGACY_SECTION_UXRC.serialize(player.adventure$displayName); ++ } ++} diff --git a/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java b/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 @@ -2045,7 +2073,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public String getDisplayName() { -+ if(true) return io.papermc.paper.adventure.PaperAdventure.superHackyLegacyRepresentationOfComponent(this.getHandle().adventure$displayName, this.getHandle().displayName); // Paper ++ if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper return getHandle().displayName; } @@ -2236,6 +2264,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @Override + public void displayName(final net.kyori.adventure.text.Component displayName) { + this.getHandle().adventure$displayName = displayName != null ? displayName : net.kyori.adventure.text.Component.text(this.getName()); ++ this.getHandle().displayName = null; + } + + @Override diff --git a/Spigot-Server-Patches/Player-Tab-List-and-Title-APIs.patch b/Spigot-Server-Patches/Player-Tab-List-and-Title-APIs.patch index c552ff3860..aca7ed3b94 100644 --- a/Spigot-Server-Patches/Player-Tab-List-and-Title-APIs.patch +++ b/Spigot-Server-Patches/Player-Tab-List-and-Title-APIs.patch @@ -170,4 +170,4 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @Override public String getDisplayName() { - if(true) return io.papermc.paper.adventure.PaperAdventure.superHackyLegacyRepresentationOfComponent(this.getHandle().adventure$displayName, this.getHandle().displayName); // Paper + if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper