diff --git a/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java b/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java index 41c8193..d0136ff 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java @@ -32,32 +32,24 @@ public final class FormatBuilder { /** * Instantiates a new format builder * - * @param stringBuilder

The string builder to use output from

+ *

If the input is a list, it will be joined using the default delimiter: ",".

+ * + * @param input

The input to use as the initial string of this format builder

+ * @throws IllegalStateException

If the string formatter has not been set, and the input is a translatable message

*/ - public FormatBuilder(@NotNull StringBuilder stringBuilder) { - this.toFormat = stringBuilder.toString(); + public FormatBuilder(@NotNull K input) throws IllegalStateException { + this.toFormat = asString(input, LIST_DELIMITER); } /** * Instantiates a new format builder * - * @param translatableMessage

The translatable message to format

- * @throws IllegalStateException

If the string formatter has not been set

+ * @param input

The input to use as the initial string of this format builder

+ * @param delimiter

The delimiter used for joining if the input is some kind of list

+ * @throws IllegalStateException

If the string formatter has not been set, and the input is a translatable message

*/ - public FormatBuilder(@NotNull TranslatableMessage translatableMessage) throws IllegalStateException { - if (FormatBuilder.stringFormatter == null) { - throw NOT_SETUP_EXCEPTION; - } - this.toFormat = FormatBuilder.stringFormatter.getUnFormattedMessage(translatableMessage); - } - - /** - * Instantiates a new format builder - * - * @param toFormat

The string to format

- */ - public FormatBuilder(@NotNull String toFormat) { - this.toFormat = toFormat; + public FormatBuilder(@NotNull K input, @NotNull String delimiter) throws IllegalStateException { + this.toFormat = asString(input, delimiter); } /** @@ -97,7 +89,7 @@ public final class FormatBuilder { /** * Replaces placeholders for the current string - * + * *

If the placeholder or replacement is a list, it will be joined using the default delimiter: ",".

* * @param placeholder

The placeholder to replace

@@ -118,7 +110,7 @@ public final class FormatBuilder { * * @param placeholder

The placeholder to replace

* @param replacement

The replacement

- * @param delimiter

The delimiter used for joining if the replacement is some kind of list

+ * @param delimiter

The delimiter used for joining if the replacement is some kind of list

* @return

This format builder

* @throws IllegalStateException

If the string formatter has not been set, and the placeholder or replacement is * a translatable message

@@ -126,7 +118,7 @@ public final class FormatBuilder { @NotNull public FormatBuilder replace(@NotNull K placeholder, @NotNull L replacement, @NotNull String delimiter) throws IllegalStateException { - this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, asString(placeholder, LIST_DELIMITER), + this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, asString(placeholder, LIST_DELIMITER), asString(replacement, delimiter)); return this; } @@ -179,7 +171,7 @@ public final class FormatBuilder { * Appends the given string to this format builder * *

If the input is a list, it will be joined using the default delimiter: ",".

- * + * * @param input

The input to append

* @return

This format builder

* @throws IllegalStateException

If the string formatter has not been set, and the input is a translatable message

@@ -193,7 +185,7 @@ public final class FormatBuilder { /** * Appends the given string to this format builder * - * @param input

The input to append

+ * @param input

The input to append

* @param delimiter

The delimiter used for joining if the input is some kind of list

* @return

This format builder

* @throws IllegalStateException

If the string formatter has not been set, and the input is a translatable message

@@ -252,7 +244,7 @@ public final class FormatBuilder { /** * Converts the given input to a string * - * @param input

The input to convert

+ * @param input

The input to convert

* @param delimiter

The delimiter to use if the input is some kind of list

* @return

The corresponding string

* @throws IllegalStateException

If the string formatter has not been set, and the input is a translatable message.