@@ -99,7 +99,8 @@ object BlockStorage : Listener {
9999 * @throws IllegalArgumentException if the chunk containing the block is not loaded
100100 */
101101 @JvmStatic
102- fun get (blockPosition : BlockPosition ): RebarBlock ? {
102+ fun get (blockPosition : BlockPosition ? ): RebarBlock ? {
103+ if (blockPosition == null ) return null
103104 require(blockPosition.chunk.isLoaded) { " You can only get Rebar blocks in loaded chunks" }
104105 return lockBlockRead { blocks[blockPosition] }
105106 }
@@ -110,15 +111,15 @@ object BlockStorage : Listener {
110111 * @throws IllegalArgumentException if the chunk containing the block is not loaded
111112 */
112113 @JvmStatic
113- fun get (block : Block ): RebarBlock ? = get(block .position)
114+ fun get (block : Block ? ): RebarBlock ? = block?. let { get(it .position) }
114115
115116 /* *
116117 * Returns the Rebar block at the given [location], or null if the block does not exist.
117118 *
118119 * @throws IllegalArgumentException if the chunk containing the block is not loaded
119120 */
120121 @JvmStatic
121- fun get (location : Location ): RebarBlock ? = get(location .block)
122+ fun get (location : Location ? ): RebarBlock ? = location?. let { get(it .block) }
122123
123124 /* *
124125 * Returns the Rebar block (of type [T]) at the given [blockPosition], or null if the block
@@ -127,7 +128,7 @@ object BlockStorage : Listener {
127128 * @throws IllegalArgumentException if the chunk containing the block is not loaded
128129 */
129130 @JvmStatic
130- fun <T > getAs (clazz : Class <T >, blockPosition : BlockPosition ): T ? {
131+ fun <T > getAs (clazz : Class <T >, blockPosition : BlockPosition ? ): T ? {
131132 val block = get(blockPosition) ? : return null
132133 if (! clazz.isInstance(block)) {
133134 return null
@@ -142,7 +143,7 @@ object BlockStorage : Listener {
142143 * @throws IllegalArgumentException if the chunk containing the block is not loaded
143144 */
144145 @JvmStatic
145- fun <T > getAs (clazz : Class <T >, block : Block ): T ? = getAs(clazz, block .position)
146+ fun <T > getAs (clazz : Class <T >, block : Block ? ): T ? = block?. let { getAs(clazz, it .position) }
146147
147148 /* *
148149 * Returns the Rebar block (of type [T]) at the given [location], or null if the block
@@ -151,8 +152,7 @@ object BlockStorage : Listener {
151152 * @throws IllegalArgumentException if the chunk containing the block is not loaded
152153 */
153154 @JvmStatic
154- fun <T > getAs (clazz : Class <T >, location : Location ): T ? =
155- getAs(clazz, BlockPosition (location))
155+ fun <T > getAs (clazz : Class <T >, location : Location ? ): T ? = location?.let { getAs(clazz, BlockPosition (it)) }
156156
157157 /* *
158158 * Gets the Rebar block (of type [T]) at the given [blockPosition].
@@ -161,7 +161,7 @@ object BlockStorage : Listener {
161161 *
162162 * @throws IllegalArgumentException if the chunk containing the block is not loaded
163163 */
164- inline fun <reified T > getAs (blockPosition : BlockPosition ): T ? =
164+ inline fun <reified T > getAs (blockPosition : BlockPosition ? ): T ? =
165165 getAs(T ::class .java, blockPosition)
166166
167167 /* *
@@ -171,7 +171,7 @@ object BlockStorage : Listener {
171171 *
172172 * @throws IllegalArgumentException if the chunk containing the block is not loaded
173173 */
174- inline fun <reified T > getAs (block : Block ): T ? = getAs(T ::class .java, block)
174+ inline fun <reified T > getAs (block : Block ? ): T ? = getAs(T ::class .java, block)
175175
176176 /* *
177177 * Returns the Rebar block (of type [T]) at the given [location].
@@ -180,7 +180,7 @@ object BlockStorage : Listener {
180180 *
181181 * @throws IllegalArgumentException if the chunk containing the block is not loaded
182182 */
183- inline fun <reified T > getAs (location : Location ): T ? = getAs(T ::class .java, location)
183+ inline fun <reified T > getAs (location : Location ? ): T ? = getAs(T ::class .java, location)
184184
185185 /* *
186186 * Returns all the Plyon blocks in the chunk at [chunkPosition].
0 commit comments