TranslatableComponent$Builder#addArgument
#1298
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Additions
TranslatableComponent$Builder#addArgument- adds a single translation argument, as opposed to the current methods which only allow setting the entire list.TranslatableComponentImpl#asArgument- converts a singleComponentLikeinto aTranslationArgument, with an optionalintindex for extra error info (ignored when-1, from e.g. the newaddArgument^).Changes
TranslatableComponentImpl$BuilderImpl.args- now defaults to null, with:TranslatableComponentImpl$BuilderImpl#args- acting as a getter that defaults it to a newArrayListif unset and returns its value (similarly to other builders around the API).TranslatableComponentImpl$BuilderImpl#arguments- now initializesargsto a newArrayListof the correct size and adds each argument manually using the newTranslatableComponentImpl#asArgument, so that the list is mutable (unlike the one returned byasArguments) .TranslatableComponentImpl$BuilderImpl#build- now defaultsargstoCollections.emptyList()ifnull.Note
TranslatableComponentImpl#asArgument's logic to include/exclude theint indexparam from errors may be a little messy? I don't think it's a very big problem as it's just an internal util method, but let me know if you'd prefer a different approach.Or maybe using the string supplier variants for
requireNonNullinstead of computing the error strings every time.