@@ -47,8 +47,8 @@ public class TextFormatter {
47
47
/** A list of all the formatting options that should be applied to the text. */
48
48
private final @ NotNull ArrayList <FormatOption > formatOptions = new ArrayList <>(5 );
49
49
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 );
52
52
53
53
/** The parent formatter. Used when being concatenated to another formatter. */
54
54
private @ Nullable TextFormatter parent ;
@@ -179,30 +179,33 @@ public TextFormatter withConcatGap(@Nullable String gap) {
179
179
}
180
180
181
181
/**
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.
184
184
*/
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 ;
190
190
}
191
- formatter . parent = this ;
192
- this .concatList .add (formatter );
191
+
192
+ this .concatList .add (object );
193
193
}
194
+
194
195
return this ;
195
196
}
196
197
197
198
/**
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.
200
201
*/
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 );
206
209
}
207
210
208
211
/**
0 commit comments