Skip to content

Commit 127d718

Browse files
author
Gregory Mitchell
authored
Create LevelBuilder#scroll, Null Support
1 parent 03170e3 commit 127d718

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/main/java/me/gamercoder215/calcgames/levelz/builder/LevelBuilder.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import me.gamercoder215.calcgames.levelz.coord.Coordinate2D;
66
import me.gamercoder215.calcgames.levelz.coord.Coordinate3D;
77
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
89
import org.jetbrains.annotations.Unmodifiable;
910

1011
import java.util.HashMap;
@@ -71,15 +72,40 @@ public LevelBuilder spawn(int[] coords) {
7172
return spawn(Coordinate.fromArray(coords));
7273
}
7374

75+
/**
76+
* Sets the scroll direction for the level.
77+
* @param scroll Scroll Direction
78+
* @return this class, for chaining
79+
* @throws IllegalArgumentException If the level is not 2D
80+
*/
81+
@NotNull
82+
public LevelBuilder scroll(@Nullable Scroll scroll) throws IllegalArgumentException {
83+
if (!dimension.is2D())
84+
throw new IllegalArgumentException("Scroll is only supported for 2D levels");
85+
86+
if (scroll == null)
87+
headers.remove("scroll");
88+
else
89+
headers.put("scroll", scroll.name().toLowerCase());
90+
91+
return this;
92+
}
93+
7494
/**
7595
* Sets a header value.
7696
* @param key Header Key
77-
* @param value Header Value
97+
* @param value Header Value, can be null
7898
* @return this class, for chaining
99+
* @throws IllegalArgumentException If the key is null
79100
*/
80101
@NotNull
81-
public LevelBuilder header(@NotNull String key, @NotNull String value) {
82-
headers.put(key, value);
102+
public LevelBuilder header(@NotNull String key, @Nullable String value) throws IllegalArgumentException {
103+
if (key == null) throw new IllegalArgumentException("Key cannot be null");
104+
105+
if (value == null)
106+
headers.remove(key);
107+
else
108+
headers.put(key, value);
83109
return this;
84110
}
85111

0 commit comments

Comments
 (0)