Skip to content

Commit

Permalink
Fix script writer NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Dec 16, 2024
1 parent 0b34488 commit 762036a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/net/neoforged/camelot/script/ScriptWriter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.neoforged.camelot.script;

import com.google.errorprone.annotations.CanIgnoreReturnValue;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import org.jetbrains.annotations.Nullable;

import java.io.StringWriter;
import java.util.List;
Expand All @@ -11,6 +11,7 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

@CanIgnoreReturnValue
public class ScriptWriter {
private final StringWriter writer;
private int indentAmount;
Expand Down Expand Up @@ -71,12 +72,12 @@ public ScriptWriter decreaseIndent(int amount) {
return this;
}

public <T> ScriptWriter writeKeyValueIfNot(String key, T value, Predicate<T> predicate) {
public <T> ScriptWriter writeKeyValueIfNot(String key, @Nullable T value, Predicate<T> predicate) {
return writeKeyValueIf(key, value, Predicate.not(predicate));
}

public <T> ScriptWriter writeKeyValueIf(String key, T value, Predicate<T> predicate) {
if (predicate.test(value)) {
public <T> ScriptWriter writeKeyValueIf(String key, @Nullable T value, Predicate<T> predicate) {
if (value != null && predicate.test(value)) {
writeKeyValue(key, _ -> {
switch (value) {
case Integer number -> writeInt(number);
Expand All @@ -88,7 +89,6 @@ public <T> ScriptWriter writeKeyValueIf(String key, T value, Predicate<T> predic
return this;
}

@CanIgnoreReturnValue
public ScriptWriter writeKeyValue(String key, Consumer<ScriptWriter> value) {
writeLineStart().write("'").write(key).write("'").write(": ");
value.accept(this);
Expand Down

0 comments on commit 762036a

Please sign in to comment.