add playerNameComponent support in Chat API

This commit is contained in:
Marc Baloup 2021-07-18 22:56:21 +02:00
parent 316894dbe0
commit 6b7098eacd
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
2 changed files with 9 additions and 0 deletions

View File

@ -101,6 +101,8 @@ public abstract class Chat extends ChatStatic implements HoverEventSource<Compon
public Chat thenPlayerName(String legacyText) { return then(playerNameText(legacyText)); } public Chat thenPlayerName(String legacyText) { return then(playerNameText(legacyText)); }
public Chat thenPlayerName(Component comp) { return then(playerNameComponent(comp)); }
public Chat thenNewLine() { return then(Component.newline()); } public Chat thenNewLine() { return then(Component.newline()); }
public Chat thenLegacyText(Object legacyText) { return then(legacyText(legacyText)); } public Chat thenLegacyText(Object legacyText) { return then(legacyText(legacyText)); }

View File

@ -59,6 +59,13 @@ public abstract class ChatStatic {
return legacyText(legacyText).white(); return legacyText(legacyText).white();
} }
public static FormatableChat playerNameComponent(Component c) {
FormatableChat fc = chatComponent(c);
if (c.color() == null)
fc.white();
return fc;
}
public static FormatableChat translation(String key, Object... with) { public static FormatableChat translation(String key, Object... with) {
return chatComponent(Component.translatable(key, Chat.filterObjToComponentLike(with))); return chatComponent(Component.translatable(key, Chat.filterObjToComponentLike(with)));
} }