diff --git a/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java b/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java index 4fbec2e..6680199 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/FormatBuilder.java @@ -183,6 +183,81 @@ public final class FormatBuilder { return this; } + /** + * Replaces placeholders for the current string + * + * @param placeholder
The placeholder to replace
+ * @param replacementThe replacement
+ * @returnThis format builder
+ */ + @NotNull + public FormatBuilder replace(@NotNull String placeholder, @NotNull FormatBuilder replacement) { + this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, placeholder, replacement.toString()); + return this; + } + + /** + * Replaces placeholders for the current string + * + * @param placeholderThe placeholder to replace
+ * @param replacementThe replacement
+ * @returnThis format builder
+ */ + @NotNull + public FormatBuilder replace(@NotNull FormatBuilder placeholder, @NotNull String replacement) { + this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, placeholder.toString(), replacement); + return this; + } + + /** + * Replaces placeholders for the current string + * + * @param placeholderThe placeholder to replace
+ * @param replacementThe replacement
+ * @returnThis format builder
+ */ + @NotNull + public FormatBuilder replace(@NotNull FormatBuilder placeholder, @NotNull FormatBuilder replacement) { + this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, placeholder.toString(), replacement.toString()); + return this; + } + + /** + * Replaces placeholders for the current string + * + * @param placeholderThe placeholder to replace
+ * @param replacementThe replacement
+ * @returnThis format builder
+ * @throws IllegalStateExceptionIf the string formatter has not been set
+ */ + @NotNull + public FormatBuilder replace(@NotNull TranslatableMessage placeholder, @NotNull FormatBuilder replacement) { + if (FormatBuilder.stringFormatter == null) { + throw NOT_SETUP_EXCEPTION; + } + this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, + FormatBuilder.stringFormatter.getUnFormattedMessage(placeholder), replacement.toString()); + return this; + } + + /** + * Replaces placeholders for the current string + * + * @param placeholderThe placeholder to replace
+ * @param replacementThe replacement
+ * @returnThis format builder
+ * @throws IllegalStateExceptionIf the string formatter has not been set
+ */ + @NotNull + public FormatBuilder replace(@NotNull FormatBuilder placeholder, @NotNull TranslatableMessage replacement) { + if (FormatBuilder.stringFormatter == null) { + throw NOT_SETUP_EXCEPTION; + } + this.toFormat = StringFormatter.replacePlaceholder(this.toFormat, placeholder.toString(), + FormatBuilder.stringFormatter.getUnFormattedMessage(replacement)); + return this; + } + /** * Converts color codes in the current string * @@ -235,11 +310,24 @@ public final class FormatBuilder { * @param stringBuilderThe string builder to append
* @returnThis format builder
*/ + @NotNull public FormatBuilder append(@NotNull StringBuilder stringBuilder) { this.toFormat += stringBuilder.toString(); return this; } + /** + * Appends the given format builder's output to this format builder + * + * @param formatBuilderThe format builder to append
+ * @returnThis format builder
+ */ + @NotNull + public FormatBuilder append(@NotNull FormatBuilder formatBuilder) { + this.toFormat += formatBuilder.toString(); + return this; + } + /** * Displays the result to the specified command sender as a success message *