From f70557e3dac50d7796c0d24869275c84278378d4 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 25 Apr 2019 22:48:15 +1000 Subject: [PATCH] Provide a warning when an invalid property is entered rather than failing. Fixes WorldEdit entirely failing on new MC versions. --- .../bukkit/adapter/BukkitImplLoader.java | 2 +- .../factory/parser/DefaultBlockParser.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java index a03a9f229..612290995 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplLoader.java @@ -52,7 +52,7 @@ public class BukkitImplLoader { "**\n" + "** When working with blocks or undoing, chests will be empty, signs\n" + "** will be blank, and so on. There will be no support for entity\n" + - "** and biome-related functions.\n" + + "** and block property-related functions.\n" + "**\n" + "** Please see http://wiki.sk89q.com/wiki/WorldEdit/Bukkit_adapters\n" + "**********************************************\n"; 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 4f3793adb..72bf195da 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.extension.factory.parser; +import com.google.common.collect.Maps; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.WorldEdit; @@ -38,6 +39,7 @@ import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.HandSide; +import com.sk89q.worldedit.util.formatting.component.ErrorFormat; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -148,7 +150,7 @@ public class DefaultBlockParser extends InputParser { } } - private static Map, Object> parseProperties(BlockType type, String[] stateProperties) throws NoMatchException { + private static Map, Object> parseProperties(BlockType type, String[] stateProperties, ParserContext context) throws NoMatchException { Map, Object> blockStates = new HashMap<>(); if (stateProperties.length > 0) { // Block data not yet detected @@ -163,7 +165,14 @@ public class DefaultBlockParser extends InputParser { @SuppressWarnings("unchecked") Property propertyKey = (Property) type.getPropertyMap().get(parts[0]); if (propertyKey == null) { - throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getName()); + if (context.getActor() != null) { + context.getActor().print(ErrorFormat.wrap("Unknown property ", parts[0], " for block ", type.getName(), + ". Defaulting to base.")); + } else { + WorldEdit.logger.warn("Unknown property " + parts[0] + " for block " + type.getName()); +// throw new NoMatchException("Unknown property " + parts[0] + " for block " + type.getName()); + } + return Maps.newHashMap(); } if (blockStates.containsKey(propertyKey)) { throw new NoMatchException("Duplicate property " + parts[0]); @@ -222,7 +231,7 @@ public class DefaultBlockParser extends InputParser { typeString = blockAndExtraData[0].substring(0, stateStart); stateString = blockAndExtraData[0].substring(stateStart + 1, blockAndExtraData[0].length() - 1); } - if (typeString == null || typeString.isEmpty()) { + if (typeString.isEmpty()) { throw new InputParseException("Invalid format"); } String[] stateProperties = EMPTY_STRING_ARRAY; @@ -270,7 +279,7 @@ public class DefaultBlockParser extends InputParser { } } - blockStates.putAll(parseProperties(blockType, stateProperties)); + blockStates.putAll(parseProperties(blockType, stateProperties, context)); if (!context.isPreferringWildcard()) { // No wildcards allowed => eliminate them. (Start with default state)