33import com .google .common .collect .ImmutableList ;
44import com .google .common .collect .ImmutableSet ;
55import dev .isxander .yacl .api .*;
6+ import dev .isxander .yacl .impl .utils .YACLConstants ;
67import net .minecraft .network .chat .Component ;
7- import net .minecraft .network .chat .MutableComponent ;
88import org .apache .commons .lang3 .Validate ;
99import org .jetbrains .annotations .ApiStatus ;
1010import org .jetbrains .annotations .NotNull ;
@@ -218,7 +218,8 @@ public ListOptionEntry<T> create(T initialValue) {
218218 @ ApiStatus .Internal
219219 public static final class BuilderImpl <T > implements Builder <T > {
220220 private Component name = Component .empty ();
221- private final List <Component > tooltipLines = new ArrayList <>();
221+ private OptionDescription description = null ;
222+ private OptionDescription .Builder legacyBuilder = null ;
222223 private Function <ListOptionEntry <T >, Controller <T >> controllerFunction ;
223224 private Binding <List <T >> binding = null ;
224225 private final Set <OptionFlag > flags = new HashSet <>();
@@ -240,11 +241,23 @@ public Builder<T> name(@NotNull Component name) {
240241 return this ;
241242 }
242243
244+ @ Override
245+ public Builder <T > description (@ NotNull OptionDescription description ) {
246+ Validate .isTrue (legacyBuilder == null , "Cannot set description when deprecated `tooltip` method is used" );
247+ Validate .notNull (description , "`description` must not be null" );
248+
249+ this .description = description ;
250+ return this ;
251+ }
252+
243253 @ Override
244254 public Builder <T > tooltip (@ NotNull Component ... tooltips ) {
255+ Validate .isTrue (description == null , "Cannot use deprecated `tooltip` method when `description` in use." );
245256 Validate .notEmpty (tooltips , "`tooltips` cannot be empty" );
246257
247- tooltipLines .addAll (List .of (tooltips ));
258+ ensureLegacyDescriptionBuilder ();
259+
260+ legacyBuilder .description (tooltips );
248261 return this ;
249262 }
250263
@@ -328,16 +341,23 @@ public ListOption<T> build() {
328341 Validate .notNull (binding , "`binding` must not be null" );
329342 Validate .notNull (initialValue , "`initialValue` must not be null" );
330343
331- MutableComponent concatenatedTooltip = Component .empty ();
332- boolean first = true ;
333- for (Component line : tooltipLines ) {
334- if (!first ) concatenatedTooltip .append ("\n " );
335- first = false ;
344+ if (description == null ) {
345+ if (ensureLegacyDescriptionBuilder ())
346+ YACLConstants .LOGGER .warn ("Using deprecated `tooltip` method in list option {}. Use `description` instead." , name .getString ());
336347
337- concatenatedTooltip . append ( line );
348+ description = legacyBuilder . name ( name ). build ( );
338349 }
339350
340- return new ListOptionImpl <>(name , OptionDescription .createBuilder ().name (name ).description (concatenatedTooltip ).build (), binding , initialValue , typeClass , controllerFunction , ImmutableSet .copyOf (flags ), collapsed , available , listeners );
351+ return new ListOptionImpl <>(name , description , binding , initialValue , typeClass , controllerFunction , ImmutableSet .copyOf (flags ), collapsed , available , listeners );
352+ }
353+
354+ private boolean ensureLegacyDescriptionBuilder () {
355+ if (legacyBuilder == null ) {
356+ legacyBuilder = OptionDescription .createBuilder ();
357+ return false ;
358+ } else {
359+ return true ;
360+ }
341361 }
342362 }
343363}
0 commit comments