Makes the format builder accept anything when creating a new format builder

This commit is contained in:
2025-09-13 16:09:38 +02:00
parent 50b515af1d
commit 28510fb0a3

View File

@@ -32,32 +32,24 @@ public final class FormatBuilder {
/** /**
* Instantiates a new format builder * Instantiates a new format builder
* *
* @param stringBuilder <p>The string builder to use output from</p> * <p>If the input is a list, it will be joined using the default delimiter: ",".</p>
*
* @param input <p>The input to use as the initial string of this format builder</p>
* @throws IllegalStateException <p>If the string formatter has not been set, and the input is a translatable message</p>
*/ */
public FormatBuilder(@NotNull StringBuilder stringBuilder) { public <K> FormatBuilder(@NotNull K input) throws IllegalStateException {
this.toFormat = stringBuilder.toString(); this.toFormat = asString(input, LIST_DELIMITER);
} }
/** /**
* Instantiates a new format builder * Instantiates a new format builder
* *
* @param translatableMessage <p>The translatable message to format</p> * @param input <p>The input to use as the initial string of this format builder</p>
* @throws IllegalStateException <p>If the string formatter has not been set</p> * @param delimiter <p>The delimiter used for joining if the input is some kind of list</p>
* @throws IllegalStateException <p>If the string formatter has not been set, and the input is a translatable message</p>
*/ */
public FormatBuilder(@NotNull TranslatableMessage translatableMessage) throws IllegalStateException { public <K> FormatBuilder(@NotNull K input, @NotNull String delimiter) throws IllegalStateException {
if (FormatBuilder.stringFormatter == null) { this.toFormat = asString(input, delimiter);
throw NOT_SETUP_EXCEPTION;
}
this.toFormat = FormatBuilder.stringFormatter.getUnFormattedMessage(translatableMessage);
}
/**
* Instantiates a new format builder
*
* @param toFormat <p>The string to format</p>
*/
public FormatBuilder(@NotNull String toFormat) {
this.toFormat = toFormat;
} }
/** /**
@@ -118,7 +110,7 @@ public final class FormatBuilder {
* *
* @param placeholder <p>The placeholder to replace</p> * @param placeholder <p>The placeholder to replace</p>
* @param replacement <p>The replacement</p> * @param replacement <p>The replacement</p>
* @param delimiter <p>The delimiter used for joining if the replacement is some kind of list</p> * @param delimiter <p>The delimiter used for joining if the replacement is some kind of list</p>
* @return <p>This format builder</p> * @return <p>This format builder</p>
* @throws IllegalStateException <p>If the string formatter has not been set, and the placeholder or replacement is * @throws IllegalStateException <p>If the string formatter has not been set, and the placeholder or replacement is
* a translatable message</p> * a translatable message</p>
@@ -193,7 +185,7 @@ public final class FormatBuilder {
/** /**
* Appends the given string to this format builder * Appends the given string to this format builder
* *
* @param input <p>The input to append</p> * @param input <p>The input to append</p>
* @param delimiter <p>The delimiter used for joining if the input is some kind of list</p> * @param delimiter <p>The delimiter used for joining if the input is some kind of list</p>
* @return <p>This format builder</p> * @return <p>This format builder</p>
* @throws IllegalStateException <p>If the string formatter has not been set, and the input is a translatable message</p> * @throws IllegalStateException <p>If the string formatter has not been set, and the input is a translatable message</p>
@@ -252,7 +244,7 @@ public final class FormatBuilder {
/** /**
* Converts the given input to a string * Converts the given input to a string
* *
* @param input <p>The input to convert</p> * @param input <p>The input to convert</p>
* @param delimiter <p>The delimiter to use if the input is some kind of list</p> * @param delimiter <p>The delimiter to use if the input is some kind of list</p>
* @return <p>The corresponding string</p> * @return <p>The corresponding string</p>
* @throws IllegalStateException <p>If the string formatter has not been set, and the input is a translatable message.</p> * @throws IllegalStateException <p>If the string formatter has not been set, and the input is a translatable message.</p>