44import java .util .Date ;
55import java .util .UUID ;
66
7- import com .jeremiahbl .bfcmod .BetterForgeChat ;
87import com .jeremiahbl .bfcmod .MarkdownFormatter ;
98import com .jeremiahbl .bfcmod .TextFormatter ;
109import com .jeremiahbl .bfcmod .config .ConfigHandler ;
1413import com .mojang .authlib .GameProfile ;
1514
1615import net .minecraft .ChatFormatting ;
17- import net .minecraft .network .chat .ChatType ;
18- import net .minecraft .network .chat .ClickEvent ;
19- import net .minecraft .network .chat .Component ;
20- import net .minecraft .network .chat .HoverEvent ;
21- import net .minecraft .network .chat .TextComponent ;
22- import net .minecraft .network .chat .TranslatableComponent ;
16+ import net .minecraft .network .chat .*;
2317import net .minecraft .server .level .ServerPlayer ;
2418import net .minecraftforge .event .ServerChatEvent ;
2519import net .minecraftforge .eventbus .api .SubscribeEvent ;
@@ -40,15 +34,19 @@ public void reloadConfigOptions() {
4034 loaded = true ;
4135 }
4236
43- public TextComponent getEventComponent (Component old ) {
37+ private Style getSpecialStyleComponents (Component old ) {
4438 if (old != null && old instanceof TranslatableComponent ) {
4539 TranslatableComponent tcmp = (TranslatableComponent ) old ;
4640 Object [] args = tcmp .getArgs ();
47- for (Object arg : args )
48- if (arg != null && arg instanceof TextComponent )
49- return (TextComponent ) arg ;
41+ for (Object arg : args ) {
42+ if (arg != null && arg instanceof TextComponent ) {
43+ Style sty = ((TextComponent ) arg ).getStyle ();
44+ if (sty != null && sty .getHoverEvent () != null )
45+ return sty ;
46+ }
47+ }
5048 }
51- return new TextComponent ( "" ) ;
49+ return null ;
5250 }
5351
5452 @ SubscribeEvent
@@ -81,7 +79,9 @@ public void onServerChat(ServerChatEvent e) {
8179 if (markdownEnabled && enableStyle && PermissionsHandler .playerHasPermission (uuid , PermissionsHandler .markdownChatNode ))
8280 msg = MarkdownFormatter .markdownStringToFormattedString (msg );
8381 TextComponent msgComp = TextFormatter .stringToFormattedText (msg , enableColor , enableStyle );
84- TextComponent eventComp = getEventComponent (e .getComponent ());
85- e .setComponent (eventComp .append (beforeMsg .append (msgComp .append (afterMsg ))));
82+ Style sty = getSpecialStyleComponents (e .getComponent ());
83+ TextComponent pfx = new TextComponent ("" );
84+ if (sty != null ) pfx .setStyle (sty );
85+ e .setComponent (pfx .append (beforeMsg .append (msgComp .append (afterMsg ))));
8686 }
8787}
0 commit comments