From 5de8e0852c92aa9b870fb2ff1fd5705914511729 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 18 Feb 2019 21:17:36 +1000 Subject: [PATCH] Treat categories as empty when missing --- .../factory/parser/mask/BlockCategoryMaskParser.java | 3 +-- .../parser/pattern/BlockCategoryPatternParser.java | 4 +--- .../sk89q/worldedit/world/block/BlockCategories.java | 10 ++++++---- .../com/sk89q/worldedit/world/item/ItemCategories.java | 10 ++++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java index 0ef1a1730..aceba782a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlockCategoryMaskParser.java @@ -27,7 +27,6 @@ import com.sk89q.worldedit.function.mask.BlockCategoryMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.session.request.Request; -import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockCategory; public class BlockCategoryMaskParser extends InputParser { @@ -45,7 +44,7 @@ public class BlockCategoryMaskParser extends InputParser { Extent extent = Request.request().getEditSession(); // This means it's a tag mask. - BlockCategory category = BlockCategories.get(input.substring(2).toLowerCase()); + BlockCategory category = BlockCategory.REGISTRY.get(input.substring(2).toLowerCase()); if (category == null) { throw new InputParseException("Unrecognised tag '" + input.substring(2) + '\''); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java index 5b08053b0..b2e9672f5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java @@ -26,9 +26,7 @@ import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.internal.registry.InputParser; -import com.sk89q.worldedit.world.block.BlockCategories; import com.sk89q.worldedit.world.block.BlockCategory; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import java.util.List; @@ -58,7 +56,7 @@ public class BlockCategoryPatternParser extends InputParser { anyState = true; } - BlockCategory category = BlockCategories.get(tag); + BlockCategory category = BlockCategory.REGISTRY.get(tag); if (category == null) { throw new InputParseException("Unknown block tag: " + tag); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategories.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategories.java index 5d5304f5b..28c3385d5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategories.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategories.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.world.block; -import javax.annotation.Nullable; - /** * Stores a list of categories of Block Types. */ @@ -62,7 +60,11 @@ public final class BlockCategories { private BlockCategories() { } - public static @Nullable BlockCategory get(final String id) { - return BlockCategory.REGISTRY.get(id); + private static BlockCategory get(final String id) { + BlockCategory blockCategory = BlockCategory.REGISTRY.get(id); + if (blockCategory == null) { + return new BlockCategory(id); + } + return blockCategory; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategories.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategories.java index 460473d22..021d6834c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategories.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategories.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.world.item; -import javax.annotation.Nullable; - /** * Stores a list of categories of Item Types. */ @@ -60,7 +58,11 @@ public final class ItemCategories { private ItemCategories() { } - public static @Nullable ItemCategory get(final String id) { - return ItemCategory.REGISTRY.get(id); + private static ItemCategory get(final String id) { + ItemCategory itemCategory = ItemCategory.REGISTRY.get(id); + if (itemCategory == null) { + return new ItemCategory(id); + } + return itemCategory; } }