From 8fe96bcc2b2a3cd4689da0a62e0bd07e5c714262 Mon Sep 17 00:00:00 2001 From: OptimisticDev <173472493+OptimisticDeving@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:35:37 +0000 Subject: [PATCH] Allow players to select the vanilla chat format (#356) * Allow players to select the vanilla chat format * Fix URL replacement in vanilla format --- .../pw/kaboom/extras/modules/player/PlayerChat.java | 13 +++++++++++++ .../kaboom/extras/modules/player/PlayerPrefix.java | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java index 89052d3..62747cb 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java @@ -83,11 +83,24 @@ public final class PlayerChat implements Listener { LegacyComponentSerializer .legacyAmpersand(); + private Component renderVanilla(@Nonnull Component displayName, + @Nonnull Component component) { + return Component.translatable( + "chat.type.text", + displayName, + component.replaceText(URL_REPLACEMENT_CONFIG) + ); + } + @Override public @Nonnull Component render(@Nonnull Player player, @Nonnull Component displayName, @Nonnull Component component, @Nonnull Audience audience) { + if (PlayerPrefix.isUsingVanillaFormat(player)) { + return renderVanilla(displayName, component); + } + Component newComponent = Component.empty(); final Component prefix; Component prefix1; diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java index d67e59b..1e5a7fd 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java @@ -74,6 +74,14 @@ public final class PlayerPrefix implements Listener { return prefix; } + public static boolean isUsingVanillaFormat(Player player) { + final UUID playerUUID = player.getUniqueId(); + final String stringifiedUUID = playerUUID.toString(); + final String legacyPrefix = PREFIX_CONFIG.getString(stringifiedUUID); + + return legacyPrefix != null && legacyPrefix.equals("%"); + } + public static Component getPrefix(Player player) throws IOException { final UUID playerUUID = player.getUniqueId(); final String stringifiedUUID = playerUUID.toString(); @@ -94,7 +102,10 @@ public final class PlayerPrefix implements Listener { private static void onUpdate(Player player) throws IOException { final Component component = Component.empty() - .append(getPrefix(player)) + .append( + isUsingVanillaFormat(player) ? + Component.empty() : getPrefix(player) + ) .append(player.displayName()); player.playerListName(component);