forked from kaboomserver/extras
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:
parent
2e79421d49
commit
8fe96bcc2b
2 changed files with 25 additions and 1 deletions
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue