From a4b99c60dc47545d81e0632b2aced6c5ed13ec48 Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 16 Jun 2021 14:49:56 +0200 Subject: [PATCH] Fix property parsing --- .../server/instance/block/BlockRegistry.java | 55 ++++++++++--------- .../server/instance/block/BlockTest.java | 3 +- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/block/BlockRegistry.java b/src/main/java/net/minestom/server/instance/block/BlockRegistry.java index 542bed477..dc49bd73f 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockRegistry.java +++ b/src/main/java/net/minestom/server/instance/block/BlockRegistry.java @@ -20,14 +20,29 @@ class BlockRegistry { // Block namespace -> properties map to block access private static final Map BLOCK_PROPERTY_MAP = new ConcurrentHashMap<>(); - private static class PropertyEntry { - private final Map, Block> propertyMap = new ConcurrentHashMap<>(); + static @Nullable Block get(@NotNull String namespace) { + return NAMESPACE_MAP.get(namespace); + } + + static @Nullable Block getId(int id) { + return BLOCK_ID_MAP.get(id); + } + + static @Nullable Block getState(int stateId) { + return BLOCK_STATE_MAP.get(stateId); + } + + static @Nullable Block getProperties(String namespace, Map properties) { + final var entry = BLOCK_PROPERTY_MAP.get(namespace); + return entry.propertyMap.get(properties); + } + + static @Nullable Block getProperties(Block block, Map properties) { + return getProperties(block.getNamespaceId().asString(), properties); } static { // Load data from file - - // Blocks JsonObject blocks = Registry.load(Registry.Resource.BLOCK); blocks.entrySet().forEach(entry -> { final String blockNamespace = entry.getKey(); @@ -46,6 +61,10 @@ class BlockRegistry { }); } + private static class PropertyEntry { + private final Map, Block> propertyMap = new ConcurrentHashMap<>(); + } + private static void retrieveState(String namespace, JsonObject object, JsonObject stateObject) { PropertyEntry propertyEntry = new PropertyEntry(); stateObject.entrySet().forEach(stateEntry -> { @@ -81,27 +100,13 @@ class BlockRegistry { builder.append(c); } } + // Add last property if present + { + final String key = keyBuilder.toString(); + if (!key.isEmpty()) { + result.put(key, valueBuilder.toString()); + } + } return result; } - - public static @Nullable Block get(@NotNull String namespace) { - return NAMESPACE_MAP.get(namespace); - } - - public static @Nullable Block getId(int id) { - return BLOCK_ID_MAP.get(id); - } - - public static @Nullable Block getState(int stateId) { - return BLOCK_STATE_MAP.get(stateId); - } - - public static @Nullable Block getProperties(String namespace, Map properties) { - final var entry = BLOCK_PROPERTY_MAP.get(namespace); - return entry.propertyMap.get(properties); - } - - public static @Nullable Block getProperties(Block block, Map properties) { - return getProperties(block.getNamespaceId().asString(), properties); - } } diff --git a/src/main/java/net/minestom/server/instance/block/BlockTest.java b/src/main/java/net/minestom/server/instance/block/BlockTest.java index 8708de7a5..586651fb7 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockTest.java +++ b/src/main/java/net/minestom/server/instance/block/BlockTest.java @@ -38,7 +38,8 @@ class BlockTest implements Block { public @NotNull Block withProperty(@NotNull String property, @NotNull String value) { var properties = new HashMap<>(this.properties); properties.put(property, value); - return Objects.requireNonNull(BlockRegistry.getProperties(this, properties)); + final Block block = BlockRegistry.getProperties(this, properties); + return Objects.requireNonNull(block); } @Override