From 3e988e7ffe08a3edc44c35d5c4e02f9ae696a476 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 11 Feb 2019 20:30:42 +1000 Subject: [PATCH] Fixed parsing fuzzy blocks failing. --- .../factory/parser/DefaultBlockParser.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index 1088c3695..d6c62b4d1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -148,7 +148,9 @@ public class DefaultBlockParser extends InputParser { } } - private static BlockState applyProperties(BlockState state, String[] stateProperties) throws NoMatchException { + private static Map, Object> parseProperties(BlockType type, String[] stateProperties) throws NoMatchException { + Map, Object> blockStates = new HashMap<>(); + if (stateProperties.length > 0) { // Block data not yet detected // Parse the block data (optional) for (String parseableData : stateProperties) { @@ -159,9 +161,12 @@ public class DefaultBlockParser extends InputParser { } @SuppressWarnings("unchecked") - Property propertyKey = (Property) state.getBlockType().getPropertyMap().get(parts[0]); + Property propertyKey = (Property) type.getPropertyMap().get(parts[0]); if (propertyKey == null) { - throw new NoMatchException("Unknown state " + parts[0] + " for block " + state.getBlockType().getName()); + throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getName()); + } + if (blockStates.containsKey(propertyKey)) { + throw new NoMatchException("Duplicate property " + parts[0]); } Object value; try { @@ -170,7 +175,7 @@ public class DefaultBlockParser extends InputParser { throw new NoMatchException("Unknown value " + parts[1] + " for state " + parts[0]); } - state = state.with(propertyKey, value); + blockStates.put(propertyKey, value); } catch (NoMatchException e) { throw e; // Pass-through } catch (Exception e) { @@ -180,7 +185,7 @@ public class DefaultBlockParser extends InputParser { } } - return state; + return blockStates; } private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException { @@ -265,9 +270,16 @@ public class DefaultBlockParser extends InputParser { } } + blockStates.putAll(parseProperties(blockType, stateProperties)); + if (!context.isPreferringWildcard()) { // No wildcards allowed => eliminate them. (Start with default state) state = blockType.getDefaultState(); + for (Map.Entry, Object> blockState : blockStates.entrySet()) { + @SuppressWarnings("unchecked") + Property objProp = (Property) blockState.getKey(); + state = state.with(objProp, blockState.getValue()); + } } else { FuzzyBlockState.Builder fuzzyBuilder = FuzzyBlockState.builder(); fuzzyBuilder.type(blockType); @@ -278,8 +290,6 @@ public class DefaultBlockParser extends InputParser { } state = fuzzyBuilder.build(); } - - state = applyProperties(state, stateProperties); } // Check if the item is allowed