Allow players to select the vanilla chat format (#356)

* Allow players to select the vanilla chat format

* Fix URL replacement in vanilla format
This commit is contained in:
OptimisticDev 2024-08-19 15:35:37 +00:00 committed by GitHub
parent 2e79421d49
commit 8fe96bcc2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -83,11 +83,24 @@ public final class PlayerChat implements Listener {
LegacyComponentSerializer LegacyComponentSerializer
.legacyAmpersand(); .legacyAmpersand();
private Component renderVanilla(@Nonnull Component displayName,
@Nonnull Component component) {
return Component.translatable(
"chat.type.text",
displayName,
component.replaceText(URL_REPLACEMENT_CONFIG)
);
}
@Override @Override
public @Nonnull Component render(@Nonnull Player player, public @Nonnull Component render(@Nonnull Player player,
@Nonnull Component displayName, @Nonnull Component displayName,
@Nonnull Component component, @Nonnull Component component,
@Nonnull Audience audience) { @Nonnull Audience audience) {
if (PlayerPrefix.isUsingVanillaFormat(player)) {
return renderVanilla(displayName, component);
}
Component newComponent = Component.empty(); Component newComponent = Component.empty();
final Component prefix; final Component prefix;
Component prefix1; Component prefix1;

View file

@ -74,6 +74,14 @@ public final class PlayerPrefix implements Listener {
return prefix; 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 { public static Component getPrefix(Player player) throws IOException {
final UUID playerUUID = player.getUniqueId(); final UUID playerUUID = player.getUniqueId();
final String stringifiedUUID = playerUUID.toString(); final String stringifiedUUID = playerUUID.toString();
@ -94,7 +102,10 @@ public final class PlayerPrefix implements Listener {
private static void onUpdate(Player player) throws IOException { private static void onUpdate(Player player) throws IOException {
final Component component = Component.empty() final Component component = Component.empty()
.append(getPrefix(player)) .append(
isUsingVanillaFormat(player) ?
Component.empty() : getPrefix(player)
)
.append(player.displayName()); .append(player.displayName());
player.playerListName(component); player.playerListName(component);