From efc135f48a23e1bcbae0e6eb067d1bae5b38e978 Mon Sep 17 00:00:00 2001 From: TheMode Date: Tue, 20 Jul 2021 23:48:13 +0200 Subject: [PATCH] Handle empty list case, let the try-catch handle NPE --- .../net/minestom/server/instance/AnvilLoader.java | 12 ++---------- .../minestom/server/instance/block/BlockImpl.java | 3 +++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/AnvilLoader.java b/src/main/java/net/minestom/server/instance/AnvilLoader.java index 90262a9ce..18c339c34 100644 --- a/src/main/java/net/minestom/server/instance/AnvilLoader.java +++ b/src/main/java/net/minestom/server/instance/AnvilLoader.java @@ -125,16 +125,8 @@ public class AnvilLoader implements IChunkLoader { for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) { try { final BlockState blockState = section.get(x, y, z); - Block block = Block.fromNamespaceId(blockState.getName()); - if (block == null) { - // Invalid block - continue; - } - final var properties = blockState.getProperties(); - if (!properties.isEmpty()) { - block = block.withProperties(properties); - } - chunk.setBlock(x, y + yOffset, z, block); + chunk.setBlock(x, y + yOffset, z, + Block.fromNamespaceId(blockState.getName()).withProperties(blockState.getProperties())); } catch (Exception e) { EXCEPTION_MANAGER.handleException(e); } diff --git a/src/main/java/net/minestom/server/instance/block/BlockImpl.java b/src/main/java/net/minestom/server/instance/block/BlockImpl.java index a8344fb56..966a50428 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockImpl.java +++ b/src/main/java/net/minestom/server/instance/block/BlockImpl.java @@ -58,6 +58,9 @@ final class BlockImpl implements Block { @Override public @NotNull Block withProperties(@NotNull Map<@NotNull String, @NotNull String> properties) { + if (properties.isEmpty()) { + return this; + } Block block; if (this.properties.size() == properties.size()) { // Map should be complete