From 930599fcbfe0baaf1d1812b7bddbb579ced0cb2f Mon Sep 17 00:00:00 2001
From: Mariell Hoversholm <proximyst@proximyst.com>
Date: Tue, 9 Mar 2021 00:14:49 +0100
Subject: [PATCH] Respect teams in legacy chat name if configured (#5321)

---
 Spigot-Server-Patches/Adventure.patch                  | 10 ++++++++--
 ...to-use-vanilla-per-world-scoreboard-coloring-.patch |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Spigot-Server-Patches/Adventure.patch b/Spigot-Server-Patches/Adventure.patch
index cb9431f2a8..a29361f1db 100644
--- a/Spigot-Server-Patches/Adventure.patch
+++ b/Spigot-Server-Patches/Adventure.patch
@@ -123,6 +123,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +import net.kyori.adventure.text.Component;
 +import net.kyori.adventure.text.TextReplacementConfig;
 +import net.kyori.adventure.text.event.ClickEvent;
++import net.kyori.adventure.text.format.Style;
++import net.kyori.adventure.text.format.TextDecoration;
 +import net.minecraft.server.EntityPlayer;
 +import net.minecraft.server.IChatBaseComponent;
 +import net.minecraft.server.MinecraftServer;
@@ -171,7 +173,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +            // continuing from AsyncPlayerChatEvent (without PlayerChatEvent)
 +            event -> {
 +                final AsyncChatEvent ae = this.createAsync(
-+                    legacyFormatter(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()),
++                    legacyFormatter(event.getFormat(), legacyDisplayName((CraftPlayer) event.getPlayer()), event.getMessage()),
 +                    event.getRecipients(),
 +                    PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage())
 +                );
@@ -189,7 +191,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +                    @Override
 +                    protected Void evaluate() {
 +                        final ChatEvent se = ChatProcessor.this.createSync(
-+                            legacyFormatter(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()),
++                            legacyFormatter(event.getFormat(), legacyDisplayName((CraftPlayer) event.getPlayer()), event.getMessage()),
 +                            event.getRecipients(),
 +                            PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage())
 +                        );
@@ -213,6 +215,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
 +        );
 +    }
 +
++    private static String legacyDisplayName(final CraftPlayer player) {
++        return PaperAdventure.LEGACY_SECTION_UXRC.serialize(Component.empty().append(displayName(player)));
++    }
++
 +    private static Component displayName(final CraftPlayer player) {
 +        return player.displayName();
 +    }
diff --git a/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch
index 07b2e77e22..c6966768ac 100644
--- a/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch
+++ b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch
@@ -29,7 +29,7 @@ diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/m
 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
 --- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
 +++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
-@@ -0,0 +0,0 @@ import net.kyori.adventure.text.event.ClickEvent;
+@@ -0,0 +0,0 @@ import net.kyori.adventure.text.format.TextDecoration;
  import net.minecraft.server.EntityPlayer;
  import net.minecraft.server.IChatBaseComponent;
  import net.minecraft.server.MinecraftServer;