From 26d4ea101e7b4b1ee039d8d7b6f924ba87081c55 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/DefaultItemParser.java | 6 +- .../factory/parser/mask/BlocksMaskParser.java | 61 +++++++++++++++++++ .../worldedit/world/block/BlockType.java | 6 +- .../world/registry/BlockRegistry.java | 9 +++ .../world/registry/BundledBlockRegistry.java | 7 +++ .../world/registry/BundledItemRegistry.java | 9 +++ .../world/registry/ItemRegistry.java | 9 +++ .../worldedit/forge/ForgeBlockRegistry.java | 9 +++ .../worldedit/forge/ForgeItemRegistry.java | 14 +++++ 9 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java index 8c087bfeb..b9951f701 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultItemParser.java @@ -64,8 +64,10 @@ public class DefaultItemParser extends InputParser { } if (item == null) { - item = WorldEdit.getInstance().getPlatformManager() - .queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().createFromId(input.toLowerCase()); + ItemType type = ItemTypes.get(input.toLowerCase()); + if (type != null) { + item = new BaseItem(type); + } } if (item == null) { 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 new file mode 100644 index 000000000..50907f077 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/mask/BlocksMaskParser.java @@ -0,0 +1,61 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +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; +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.BlockStateHolder; + +import java.util.Set; + +/** + * Parses mask input strings. + */ +public class BlocksMaskParser extends InputParser { + + public BlocksMaskParser(WorldEdit worldEdit) { + super(worldEdit); + } + + public Mask parseFromInput(String component, ParserContext context) throws InputParseException { + Extent extent = Request.request().getEditSession(); + + ParserContext tempContext = new ParserContext(context); + tempContext.setRestricted(false); + tempContext.setPreferringWildcard(true); + try { + Set holders = worldEdit.getBlockFactory().parseFromListInput(component, tempContext); + if (holders.isEmpty()) { + return null; + } + return new BlockMask(extent, holders); + } catch (NoMatchException e) { + return null; + } + } + +} 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 4f2f2e129..3e3f9b2e7 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 @@ -118,11 +118,11 @@ public class BlockType implements FawePattern { * @return The name, or ID */ public String getName() { - BundledBlockData.BlockEntry entry = BundledBlockData.getInstance().findById(this.getId()); - 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/registry/BlockRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockRegistry.java index ce0726d78..95ad60655 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 @@ -35,6 +35,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 9f0636daa..62c8b5c3a 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 4af6acaaf..01fd41ef1 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,6 +19,7 @@ package com.sk89q.worldedit.world.registry; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; @@ -26,6 +27,11 @@ import com.sk89q.worldedit.world.item.ItemTypes; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; +======= +import com.sk89q.worldedit.world.item.ItemType; + +import javax.annotation.Nullable; +>>>>>>> b75d5149... Fixed the bundle being directly used outside of the registry system. /** * A item registry that uses {@link BundledItemRegistry} to serve information @@ -35,6 +41,7 @@ public class BundledItemRegistry implements ItemRegistry { @Nullable @Override +<<<<<<< HEAD public BaseItem createFromId(String id) { ItemType itemType = ItemTypes.get(id); return itemType == null ? null : new BaseItem(itemType); @@ -47,6 +54,8 @@ public class BundledItemRegistry implements ItemRegistry { @Nullable @Override +======= +>>>>>>> b75d5149... Fixed the bundle being directly used outside of the registry system. 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 5e46af3fe..ea1613549 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,16 +19,23 @@ package com.sk89q.worldedit.world.registry; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.world.item.ItemType; import javax.annotation.Nullable; import java.util.Collection; import java.util.Collections; +======= +import com.sk89q.worldedit.world.item.ItemType; + +import javax.annotation.Nullable; +>>>>>>> b75d5149... Fixed the bundle being directly used outside of the registry system. public interface ItemRegistry { /** +<<<<<<< HEAD * Create a new item using its ID. * * @param id the id @@ -45,6 +52,8 @@ public interface ItemRegistry { } /** +======= +>>>>>>> b75d5149... Fixed the bundle being directly used outside of the registry system. * Gets the name for the given item. * * @param itemType the item 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 c87033075..b1ba36198 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,6 +19,7 @@ package com.sk89q.worldedit.forge; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.ItemRegistry; @@ -37,5 +38,18 @@ public class ForgeItemRegistry implements ItemRegistry { } else { return null; } +======= +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.registry.BundledItemRegistry; + +import javax.annotation.Nullable; + +public class ForgeItemRegistry extends BundledItemRegistry { + + @Nullable + @Override + public String getName(ItemType itemType) { + return super.getName(itemType); // TODO +>>>>>>> b75d5149... Fixed the bundle being directly used outside of the registry system. } }