@@ -47,8 +47,8 @@ public class TextFormatter {
4747 /** A list of all the formatting options that should be applied to the text. */
4848 private final @ NotNull ArrayList <FormatOption > formatOptions = new ArrayList <>(5 );
4949
50- /** A list of all the formatters that should be concatenated to this formatter. */
51- private final @ NotNull List <TextFormatter > concatList = new ArrayList <>(0 );
50+ /** A list of all the values that should be concatenated to this formatter. */
51+ private final @ NotNull List <Object > concatList = new ArrayList <>(0 );
5252
5353 /** The parent formatter. Used when being concatenated to another formatter. */
5454 private @ Nullable TextFormatter parent ;
@@ -179,30 +179,33 @@ public TextFormatter withConcatGap(@Nullable String gap) {
179179 }
180180
181181 /**
182- * Concatenates the specified formatters to this formatter.
183- * @param formatters The formatters to concatenate.
182+ * Concatenates the specified values to the formatter. Another {@link TextFormatter} may also be concatenated .
183+ * @param objects The values to concatenate.
184184 */
185- public TextFormatter concat (@ NotNull TextFormatter ... formatters ) {
186- for (TextFormatter formatter : formatters ) {
187- // if it was already added to another formatter, throw an exception
188- if ( formatter . parent != null ) {
189- throw new IllegalArgumentException ( "Cannot concatenate a formatter that is already concatenated to another formatter." ) ;
185+ public TextFormatter concat (@ NotNull Object ... objects ) {
186+ for (var object : objects ) {
187+ if ( object instanceof TextFormatter tf ) {
188+ this . concatFormatter ( tf );
189+ continue ;
190190 }
191- formatter . parent = this ;
192- this .concatList .add (formatter );
191+
192+ this .concatList .add (object );
193193 }
194+
194195 return this ;
195196 }
196197
197198 /**
198- * Concatenates the specified strings to this formatter.
199- * @param strings The strings to concatenate.
199+ * Properly concatenates the specified formatter to this formatter by also linking both formatters together .
200+ * @param formatter The formatter to concatenate.
200201 */
201- public TextFormatter concat (@ NotNull String ... strings ) {
202- for (var str : strings ) {
203- this .concatList .add (TextFormatter .of (str ));
204- }
205- return this ;
202+ private void concatFormatter (@ NotNull TextFormatter formatter ) {
203+ // if it was already added to another formatter, throw an exception
204+ if (formatter .parent != null )
205+ throw new IllegalArgumentException ("Cannot concatenate a formatter that is already concatenated to another formatter." );
206+
207+ formatter .parent = this ;
208+ this .concatList .add (formatter );
206209 }
207210
208211 /**
0 commit comments