mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 01:45:44 -05:00
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
|
||||
.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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue