diff --git a/leaves-server/minecraft-patches/features/0115-Vanilla-player-display-name.patch b/leaves-server/minecraft-patches/features/0115-Vanilla-player-display-name.patch index 2e5c4846..9664d114 100644 --- a/leaves-server/minecraft-patches/features/0115-Vanilla-player-display-name.patch +++ b/leaves-server/minecraft-patches/features/0115-Vanilla-player-display-name.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Vanilla player display name diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java -index 5e74fdf09d5063b955d9c5ed63775b38f562687e..d92c018de29cc377cc8e7188fc2d316e96b1f369 100644 +index 7cbd70c17369f3578f1a50c553dd25bfb189af11..70b35fa479bdfcda2f404b3b86547552f7d6da8e 100644 --- a/net/minecraft/server/level/ServerPlayer.java +++ b/net/minecraft/server/level/ServerPlayer.java @@ -476,7 +476,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc @@ -13,7 +13,43 @@ index 5e74fdf09d5063b955d9c5ed63775b38f562687e..d92c018de29cc377cc8e7188fc2d316e // CraftBukkit start this.displayName = this.getScoreboardName(); - this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper -+ this.adventure$displayName = org.leavesmc.leaves.LeavesConfig.fix.vanillaDisplayName ? io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getDisplayName()) : net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper // Leaves - Vanilla display name ++ this.adventure$displayName = org.leavesmc.leaves.LeavesConfig.fix.vanillaDisplayName ? io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getDisplayName()) : net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper // Leaves - vanilla display name this.bukkitPickUpLoot = true; this.maxHealthCache = this.getMaxHealth(); // CraftBukkit end +diff --git a/net/minecraft/world/scores/Scoreboard.java b/net/minecraft/world/scores/Scoreboard.java +index 4275d048a8f5e98c7436f5bf2d55a9b68f7ba818..c68399f1ada71f6b301b41bdc83af024a9d2f1d3 100644 +--- a/net/minecraft/world/scores/Scoreboard.java ++++ b/net/minecraft/world/scores/Scoreboard.java +@@ -282,6 +282,16 @@ public class Scoreboard { + } + + this.teamsByPlayer.put(playerName, team); ++ // Leaves start - vanilla display name ++ if (org.leavesmc.leaves.LeavesConfig.fix.vanillaDisplayName) { ++ boolean result = team.getPlayers().add(playerName); ++ net.minecraft.server.level.ServerPlayer player = net.minecraft.server.MinecraftServer.getServer().getPlayerList().getPlayerByName(playerName); ++ if (player != null) { ++ player.adventure$displayName = io.papermc.paper.adventure.PaperAdventure.asAdventure(player.getDisplayName()); ++ } ++ return result; ++ } ++ // Leaves end - vanilla display name + return team.getPlayers().add(playerName); + } + +@@ -301,6 +311,14 @@ public class Scoreboard { + } else { + this.teamsByPlayer.remove(username); + playerTeam.getPlayers().remove(username); ++ // Leaves start - vanilla display name ++ if (org.leavesmc.leaves.LeavesConfig.fix.vanillaDisplayName) { ++ net.minecraft.server.level.ServerPlayer player = net.minecraft.server.MinecraftServer.getServer().getPlayerList().getPlayerByName(username); ++ if (player != null) { ++ player.adventure$displayName = io.papermc.paper.adventure.PaperAdventure.asAdventure(player.getDisplayName()); ++ } ++ } ++ // Leaves end - vanilla display name + } + } + diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java index f76ab49b..8385b86e 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/LeavesConfig.java @@ -1,7 +1,9 @@ package org.leavesmc.leaves; import com.destroystokyo.paper.util.SneakyThrow; +import io.papermc.paper.adventure.PaperAdventure; import io.papermc.paper.configuration.GlobalConfiguration; +import net.kyori.adventure.text.Component; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; @@ -1206,8 +1208,20 @@ public final class LeavesConfig { @GlobalConfig("vanilla-hopper") public boolean vanillaHopper = false; - @GlobalConfig("vanilla-display-name") - public boolean vanillaDisplayName = false; + @GlobalConfig(value = "vanilla-display-name", validator = DisplayNameValidator.class) + public boolean vanillaDisplayName = true; + + private static class DisplayNameValidator extends BooleanConfigValidator { + @Override + public void verify(Boolean old, Boolean value) throws IllegalArgumentException { + if (value == old) { + return; + } + for (ServerPlayer player : MinecraftServer.getServer().getPlayerList().getPlayers()) { + player.adventure$displayName = value ? PaperAdventure.asAdventure(player.getDisplayName()) : Component.text(player.getScoreboardName()); + } + } + } @GlobalConfig("vanilla-portal-handle") public boolean vanillaPortalHandle = false;