Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/ch/njol/skript/lang/SyntaxStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public SyntaxStringBuilder(@Nullable Event event, boolean debug) {
*
* @param object The object to add.
* @return The builder.
* @see #appendIf(boolean, Object)
*/
public SyntaxStringBuilder append(@NotNull Object object) {
Preconditions.checkNotNull(object);
Expand All @@ -54,6 +55,7 @@ public SyntaxStringBuilder append(@NotNull Object object) {
*
* @param objects The objects to add.
* @return The builder.
* @see #appendIf(boolean, Object...)
*/
public SyntaxStringBuilder append(@NotNull Object... objects) {
for (Object object : objects) {
Expand All @@ -62,6 +64,40 @@ public SyntaxStringBuilder append(@NotNull Object... objects) {
return this;
}

/**
* Adds an object to the string and returns the builder, if the given condition is true.
* Spaces are automatically added between the provided objects.
* If the object is a {@link Debuggable} it will be formatted using
* {@link Debuggable#toString(Event, boolean)}.
*
* @param condition The condition.
* @param object The object to add.
* @return The builder.
* @see #append(Object)
*/
public SyntaxStringBuilder appendIf(boolean condition, @NotNull Object object) {
if (condition) {
append(object);
}
return this;
}

/**
* Adds multiple objects to the string and returns the builder, if the given condition is true.
* Spaces are automatically added between the provided objects.
*
* @param condition The condition.
* @param objects The objects to add.
* @return The builder.
* @see #append(Object...)
*/
public SyntaxStringBuilder appendIf(boolean condition, @NotNull Object... objects) {
if (condition) {
append(objects);
}
return this;
}

@Override
public String toString() {
return joiner.toString();
Expand Down