From a6a0b5eb6609b376cbcafa4bf86117dff60e7d41 Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Sat, 27 Aug 2022 16:48:54 +0200 Subject: [PATCH] fix: avoid recursive LegacyMapper initialization (#1922) --- .../factory/parser/DefaultBlockParser.java | 2 +- .../sk89q/worldedit/world/block/BlockTypes.java | 17 +++++++++++------ 2 files changed, 12 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 e37e5b0fa..4d8523f84 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 @@ -455,7 +455,7 @@ public class DefaultBlockParser extends InputParser { state = item.getType().getBlockType().getDefaultState(); nbt = item.getNbtData(); } else { - BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT)); + BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT), context); if (type != null) { state = type.getDefaultState(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index 152c4df9b..47e083809 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -23,6 +23,7 @@ import com.fastasyncworldedit.core.command.SuggestInputParseException; import com.fastasyncworldedit.core.util.JoinedCharSequence; import com.fastasyncworldedit.core.util.StringMan; import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.world.registry.LegacyMapper; import javax.annotation.Nullable; @@ -1948,6 +1949,9 @@ public final class BlockTypes { */ public static BlockType parse(final String type) throws InputParseException { + return parse(type, new ParserContext()); + } + public static BlockType parse(final String type, final ParserContext context) throws InputParseException { final String inputLower = type.toLowerCase(Locale.ROOT); String input = inputLower; @@ -1958,13 +1962,14 @@ public final class BlockTypes { if (result != null) { return result; } - - try { - BlockStateHolder block = LegacyMapper.getInstance().getBlockFromLegacy(input); - if (block != null) { - return block.getBlockType(); + if (context.isTryingLegacy()) { + try { + BlockStateHolder block = LegacyMapper.getInstance().getBlockFromLegacy(input); + if (block != null) { + return block.getBlockType(); + } + } catch (NumberFormatException | IndexOutOfBoundsException ignored) { } - } catch (NumberFormatException | IndexOutOfBoundsException ignored) { } throw new SuggestInputParseException("Does not match a valid block type: " + inputLower, inputLower, () -> Stream.of(