Makes the format builder accept format builders for replacement and appending
All checks were successful
KnarCraft/KnarLib/pipeline/head This commit looks good

This commit is contained in:
2025-09-06 14:40:02 +02:00
parent 869a47c04a
commit 0ac76f28c3

View File

@@ -183,6 +183,81 @@ public final class FormatBuilder {
return this;
}
/**
* Replaces placeholders for the current string
*
* @param placeholder <p>The placeholder to replace</p>
* @param replacement <p>The replacement</p>
* @return <p>This format builder</p>
*/
@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 placeholder <p>The placeholder to replace</p>
* @param replacement <p>The replacement</p>
* @return <p>This format builder</p>
*/
@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 placeholder <p>The placeholder to replace</p>
* @param replacement <p>The replacement</p>
* @return <p>This format builder</p>
*/
@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 placeholder <p>The placeholder to replace</p>
* @param replacement <p>The replacement</p>
* @return <p>This format builder</p>
* @throws IllegalStateException <p>If the string formatter has not been set</p>
*/
@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 placeholder <p>The placeholder to replace</p>
* @param replacement <p>The replacement</p>
* @return <p>This format builder</p>
* @throws IllegalStateException <p>If the string formatter has not been set</p>
*/
@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 stringBuilder <p>The string builder to append</p>
* @return <p>This format builder</p>
*/
@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 formatBuilder <p>The format builder to append</p>
* @return <p>This format builder</p>
*/
@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
*