|
5 | 5 | import me.gamercoder215.calcgames.levelz.coord.Coordinate2D;
|
6 | 6 | import me.gamercoder215.calcgames.levelz.coord.Coordinate3D;
|
7 | 7 | import org.jetbrains.annotations.NotNull;
|
| 8 | +import org.jetbrains.annotations.Nullable; |
8 | 9 | import org.jetbrains.annotations.Unmodifiable;
|
9 | 10 |
|
10 | 11 | import java.util.HashMap;
|
@@ -71,15 +72,40 @@ public LevelBuilder spawn(int[] coords) {
|
71 | 72 | return spawn(Coordinate.fromArray(coords));
|
72 | 73 | }
|
73 | 74 |
|
| 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 | + |
74 | 94 | /**
|
75 | 95 | * Sets a header value.
|
76 | 96 | * @param key Header Key
|
77 |
| - * @param value Header Value |
| 97 | + * @param value Header Value, can be null |
78 | 98 | * @return this class, for chaining
|
| 99 | + * @throws IllegalArgumentException If the key is null |
79 | 100 | */
|
80 | 101 | @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); |
83 | 109 | return this;
|
84 | 110 | }
|
85 | 111 |
|
|
0 commit comments