From b75d5149ebf66af07ac2ee61be9d2ceab82f2414 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 23 Dec 2018 21:43:20 +1000 Subject: [PATCH] Fixed the bundle being directly used outside of the registry system. --- .../factory/parser/mask/BlocksMaskParser.java | 11 ++++++++--- .../com/sk89q/worldedit/world/block/BlockType.java | 6 +++--- .../com/sk89q/worldedit/world/item/ItemType.java | 9 +++++---- .../worldedit/world/registry/BlockRegistry.java | 9 +++++++++ .../world/registry/BundledBlockRegistry.java | 7 +++++++ .../world/registry/BundledItemRegistry.java | 10 ++++++++++ .../worldedit/world/registry/ItemRegistry.java | 13 +++++++++++++ .../sk89q/worldedit/forge/ForgeBlockRegistry.java | 9 +++++++++ .../sk89q/worldedit/forge/ForgeItemRegistry.java | 12 ++++++++++-- 9 files changed, 74 insertions(+), 12 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java index cd7e82b66..50907f077 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.factory.parser.mask; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; +import com.sk89q.worldedit.extension.input.NoMatchException; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BlockMask; @@ -46,11 +47,15 @@ public class BlocksMaskParser extends InputParser { ParserContext tempContext = new ParserContext(context); tempContext.setRestricted(false); tempContext.setPreferringWildcard(true); - Set holders = worldEdit.getBlockFactory().parseFromListInput(component, tempContext); - if (holders.isEmpty()) { + try { + Set holders = worldEdit.getBlockFactory().parseFromListInput(component, tempContext); + if (holders.isEmpty()) { + return null; + } + return new BlockMask(extent, holders); + } catch (NoMatchException e) { return null; } - return new BlockMask(extent, holders); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index feee8baed..56cf2820e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -101,11 +101,11 @@ public class BlockType { * @return The name, or ID */ public String getName() { - BundledBlockData.BlockEntry entry = BundledBlockData.getInstance().findById(this.id); - if (entry == null) { + String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this); + if (name == null) { return getId(); } else { - return entry.localizedName; + return name; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java index 90ccf072d..ab151729f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java @@ -19,10 +19,11 @@ package com.sk89q.worldedit.world.item; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.registry.NamespacedRegistry; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.registry.BundledItemData; import javax.annotation.Nullable; @@ -50,11 +51,11 @@ public class ItemType { * @return The name, or ID */ public String getName() { - BundledItemData.ItemEntry entry = BundledItemData.getInstance().findById(this.id); - if (entry == null) { + String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getName(this); + if (name == null) { return getId(); } else { - return entry.localizedName; + return name; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java index 0e87b084e..d4f0cd350 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java @@ -31,6 +31,15 @@ import javax.annotation.Nullable; */ public interface BlockRegistry { + /** + * Gets the name for the given block. + * + * @param blockType the block + * @return The name, or null if it's unknown + */ + @Nullable + String getName(BlockType blockType); + /** * Get the material for the given block. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java index 40e123959..1be08da87 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java @@ -33,6 +33,13 @@ import javax.annotation.Nullable; */ public class BundledBlockRegistry implements BlockRegistry { + @Nullable + @Override + public String getName(BlockType blockType) { + BundledBlockData.BlockEntry blockEntry = BundledBlockData.getInstance().findById(blockType.getId()); + return blockEntry != null ? blockEntry.localizedName : null; + } + @Nullable @Override public BlockMaterial getMaterial(BlockType blockType) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java index 31dc71e5d..3e0ae8800 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java @@ -19,10 +19,20 @@ package com.sk89q.worldedit.world.registry; +import com.sk89q.worldedit.world.item.ItemType; + +import javax.annotation.Nullable; + /** * A item registry that uses {@link BundledItemRegistry} to serve information * about items. */ public class BundledItemRegistry implements ItemRegistry { + @Nullable + @Override + public String getName(ItemType itemType) { + BundledItemData.ItemEntry itemEntry = BundledItemData.getInstance().findById(itemType.getId()); + return itemEntry != null ? itemEntry.localizedName : null; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java index 9d53db0c1..c44be9b8c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemRegistry.java @@ -19,6 +19,19 @@ package com.sk89q.worldedit.world.registry; +import com.sk89q.worldedit.world.item.ItemType; + +import javax.annotation.Nullable; + public interface ItemRegistry { + /** + * Gets the name for the given item. + * + * @param itemType the item + * @return The name, or null if it's unknown + */ + @Nullable + String getName(ItemType itemType); + } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java index a2d59715a..ddf3762bb 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeBlockRegistry.java @@ -27,16 +27,25 @@ import com.sk89q.worldedit.world.registry.BundledBlockRegistry; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; +import net.minecraft.util.ResourceLocation; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; +import javax.annotation.Nullable; + public class ForgeBlockRegistry extends BundledBlockRegistry { private Map materialMap = new HashMap<>(); + @Nullable + @Override + public String getName(BlockType blockType) { + return Block.REGISTRY.getObject(new ResourceLocation(blockType.getId())).getLocalizedName(); + } + @Override public BlockMaterial getMaterial(BlockType blockType) { return materialMap.computeIfAbsent(Block.getBlockFromName(blockType.getId()).getDefaultState().getMaterial(), diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java index 49ae97cb0..502c646fc 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java @@ -19,8 +19,16 @@ package com.sk89q.worldedit.forge; -import com.sk89q.worldedit.world.registry.ItemRegistry; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.registry.BundledItemRegistry; -public class ForgeItemRegistry implements ItemRegistry { +import javax.annotation.Nullable; +public class ForgeItemRegistry extends BundledItemRegistry { + + @Nullable + @Override + public String getName(ItemType itemType) { + return super.getName(itemType); // TODO + } }