55import com .cleanroommc .modularui .api .drawable .IKey ;
66import org .apache .commons .lang3 .ArrayUtils ;
77
8+ import java .util .Arrays ;
89import java .util .function .LongSupplier ;
910import java .util .function .Supplier ;
1011
@@ -23,7 +24,7 @@ public static IKey string(String s) {
2324 }
2425
2526 public static IKey string (Supplier <String > s ) {
26- return string ( TextFormatting . RESET , s );
27+ return IKey . dynamic ( s );
2728 }
2829
2930 public static IKey string (TextFormatting formatting , String string ) {
@@ -36,31 +37,29 @@ public static IKey string(TextFormatting formatting, Supplier<String> stringSupp
3637 }
3738
3839 public static IKey string (Supplier <TextFormatting > formatting , String s ) {
39- return IKey .dynamic (() -> formatting .get () + s );
40+ return IKey .dynamic (() -> IKey . str ( s ). format ( formatting .get ()). getFormatted () );
4041 }
4142
4243 public static IKey string (Supplier <TextFormatting > formatting , Supplier <String > stringSupplier ) {
43- return IKey .dynamic (() -> formatting . get () + stringSupplier . get ());
44+ return IKey .dynamic (() -> IKey . str ( stringSupplier . get ()). format ( formatting . get ()). getFormatted ());
4445 }
4546
4647 public static IKey lang (String lang , Object ... args ) {
47- return lang (TextFormatting . RESET , lang , args );
48+ return IKey . lang (lang , args );
4849 }
4950
5051 public static IKey lang (TextFormatting formatting , String lang , Object ... args ) {
51- return IKey .lang (lang , args ).format (formatting );
52+ return IKey .lang (lang , checkFormatting ( formatting , args ) ).format (formatting );
5253 }
5354
5455 public static IKey lang (TextFormatting formatting , String lang , Supplier <?>... argSuppliers ) {
55- if (ArrayUtils .isEmpty (argSuppliers )) return colored ( formatting , IKey .lang (lang ));
56+ if (ArrayUtils .isEmpty (argSuppliers )) return IKey .lang (lang ). format ( formatting );
5657 if (argSuppliers .length == 1 )
57- return string ( formatting , () -> IKey .lang (lang , fixArg (formatting , argSuppliers [0 ].get ())).get ());
58- final Object [] fixedArgs = new Object [argSuppliers .length ];
58+ return IKey . dynamic ( () -> IKey .lang (lang , fixArg (formatting , argSuppliers [0 ].get ())).format ( formatting ). getFormatted ());
59+ final Object [] args = new Object [argSuppliers .length ];
5960 return IKey .dynamic (() -> {
60- for (int i = 0 ; i < fixedArgs .length ; i ++) {
61- fixedArgs [i ] = fixArg (formatting , argSuppliers [i ].get ());
62- }
63- return formatting + IKey .lang (lang , fixedArgs ).get ();
61+ Arrays .setAll (args , value -> fixArg (formatting , argSuppliers [value ].get ()));
62+ return IKey .lang (lang , args ).format (formatting ).getFormatted ();
6463 });
6564 }
6665
@@ -97,16 +96,13 @@ private static IKey wrap(TextFormatting formatting) {
9796 }
9897
9998 private static Object [] checkFormatting (TextFormatting formatting , Object [] args ) {
100- Object [] fixedArgs = new Object [args .length ];
101- for (int i = 0 ; i < args .length ; i ++) {
102- fixedArgs [i ] = fixArg (formatting , args [i ]);
103- }
104- return fixedArgs ;
99+ Arrays .setAll (args , value -> fixArg (formatting , args [value ]));
100+ return args ;
105101 }
106102
107103 private static Object fixArg (TextFormatting formatting , Object arg ) {
108104 if (arg instanceof IKey key ) {
109- if (hasFormatting (key .get ()))
105+ if (hasFormatting (key .getFormatted ()))
110106 return IKey .comp (key , wrap (formatting ));
111107 } else if (arg instanceof String s ) {
112108 if (hasFormatting (s ))
0 commit comments