Permalink
Browse files

registry changes

  • Loading branch information...
kashike committed Jul 5, 2018
1 parent 61c6740 commit f5227f3f06aefed50f4fe216ab7e19763c76ddec
Showing with 1,496 additions and 1,528 deletions.
  1. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java
  2. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java
  3. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java
  4. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java
  5. +66 −0 worldedit-core/src/main/java/com/sk89q/worldedit/registry/NamespacedRegistry.java
  6. +39 −57 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategories.java
  7. +3 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockCategory.java
  8. +4 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java
  9. +579 −600 worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java
  10. +9 −30 worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidCategories.java
  11. +4 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidCategory.java
  12. +4 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java
  13. +12 −34 worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidTypes.java
  14. +37 −55 worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategories.java
  15. +3 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemCategory.java
  16. +4 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemType.java
  17. +718 −736 worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java
  18. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockRegistry.java
  19. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemRegistry.java
  20. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java
  21. +1 −1 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeItemRegistry.java
  22. +1 −1 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java
  23. +1 −1 worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java
  24. +1 −1 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java
  25. +2 −2 worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java
@@ -557,9 +557,9 @@ public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException {
public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException {
if (item.hasBlockType()) {
throw new InvalidToolBindException(item, "Blocks can't be used");
} else if (item == ItemTypes.getItemType(config.wandItem)) {
} else if (item == ItemTypes.get(config.wandItem)) {
throw new InvalidToolBindException(item, "Already used for the wand");
} else if (item == ItemTypes.getItemType(config.navigationWand)) {
} else if (item == ItemTypes.get(config.navigationWand)) {
throw new InvalidToolBindException(item, "Already used for the navigation wand");
}
@@ -163,7 +163,7 @@ public void searchItem(Actor actor, CommandContext args) throws WorldEditExcepti
boolean blocksOnly = args.hasFlag('b');
boolean itemsOnly = args.hasFlag('i');
ItemType type = ItemTypes.getItemType(query);
ItemType type = ItemTypes.get(query);
if (type != null) {
actor.print(type.getId() + " (" + type.getName() + ")");
@@ -278,7 +278,7 @@ public void chunk(Player player, LocalSession session, EditSession editSession,
@CommandPermissions("worldedit.wand")
public void wand(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
player.giveItem(new BaseItemStack(ItemTypes.getItemType(we.getConfiguration().wandItem), 1));
player.giveItem(new BaseItemStack(ItemTypes.get(we.getConfiguration().wandItem), 1));
player.print("Left click: select pos #1; Right click: select pos #2");
}
@@ -232,7 +232,7 @@ private BlockStateHolder parseLogic(String input, ParserContext context) throws
blockStates = blockInHand.getStates();
} else {
// Attempt to lookup a block from ID or name.
blockType = BlockTypes.getBlockType(typeString);
blockType = BlockTypes.get(typeString);
if (blockType == null) {
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
@@ -0,0 +1,66 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.registry;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
public final class NamespacedRegistry<V> {
private static final String MINECRAFT_NAMESPACE = "minecraft";
private final Map<String, V> map = new HashMap<>();
public @Nullable V get(final String key) {
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
return this.map.get(this.orDefaultNamespace(key));
}
public V register(final String key, final V value) {
requireNonNull(key, "key");
requireNonNull(value, "value");
checkState(key.indexOf(':') > -1, "key is not namespaced");
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
checkState(!this.map.containsKey(key), "key %s already has an entry", key);
this.map.put(key, value);
return value;
}
public Set<String> keySet() {
return Collections.unmodifiableSet(this.map.keySet());
}
public Collection<V> values() {
return Collections.unmodifiableCollection(this.map.values());
}
private String orDefaultNamespace(final String key) {
if (key.indexOf(':') == -1) {
return MINECRAFT_NAMESPACE + ':' + key;
}
return key;
}
}
@@ -34,71 +34,53 @@
private BlockCategories() {
}
public static final BlockCategory ACACIA_LOGS = new BlockCategory("minecraft:acacia_logs");
public static final BlockCategory ANVIL = new BlockCategory("minecraft:anvil");
public static final BlockCategory BANNERS = new BlockCategory("minecraft:banners");
public static final BlockCategory BIRCH_LOGS = new BlockCategory("minecraft:birch_logs");
public static final BlockCategory BUTTONS = new BlockCategory("minecraft:buttons");
public static final BlockCategory CARPETS = new BlockCategory("minecraft:carpets");
public static final BlockCategory CORAL = new BlockCategory("minecraft:coral");
public static final BlockCategory CORAL_PLANTS = new BlockCategory("minecraft:coral_plants");
public static final BlockCategory DARK_OAK_LOGS = new BlockCategory("minecraft:dark_oak_logs");
public static final BlockCategory DOORS = new BlockCategory("minecraft:doors");
public static final BlockCategory ENDERMAN_HOLDABLE = new BlockCategory("minecraft:enderman_holdable");
public static final BlockCategory FLOWER_POTS = new BlockCategory("minecraft:flower_pots");
public static final BlockCategory ICE = new BlockCategory("minecraft:ice");
public static final BlockCategory JUNGLE_LOGS = new BlockCategory("minecraft:jungle_logs");
public static final BlockCategory LEAVES = new BlockCategory("minecraft:leaves");
public static final BlockCategory LOGS = new BlockCategory("minecraft:logs");
public static final BlockCategory OAK_LOGS = new BlockCategory("minecraft:oak_logs");
public static final BlockCategory PLANKS = new BlockCategory("minecraft:planks");
public static final BlockCategory RAILS = new BlockCategory("minecraft:rails");
public static final BlockCategory SAND = new BlockCategory("minecraft:sand");
public static final BlockCategory SAPLINGS = new BlockCategory("minecraft:saplings");
public static final BlockCategory SLABS = new BlockCategory("minecraft:slabs");
public static final BlockCategory SPRUCE_LOGS = new BlockCategory("minecraft:spruce_logs");
public static final BlockCategory STAIRS = new BlockCategory("minecraft:stairs");
public static final BlockCategory STONE_BRICKS = new BlockCategory("minecraft:stone_bricks");
public static final BlockCategory VALID_SPAWN = new BlockCategory("minecraft:valid_spawn");
public static final BlockCategory WOODEN_BUTTONS = new BlockCategory("minecraft:wooden_buttons");
public static final BlockCategory WOODEN_DOORS = new BlockCategory("minecraft:wooden_doors");
public static final BlockCategory WOODEN_PRESSURE_PLATES = new BlockCategory("minecraft:wooden_pressure_plates");
public static final BlockCategory WOODEN_SLABS = new BlockCategory("minecraft:wooden_slabs");
public static final BlockCategory WOODEN_STAIRS = new BlockCategory("minecraft:wooden_stairs");
public static final BlockCategory WOOL = new BlockCategory("minecraft:wool");
public static final BlockCategory ACACIA_LOGS = register("minecraft:acacia_logs");
public static final BlockCategory ANVIL = register("minecraft:anvil");
public static final BlockCategory BANNERS = register("minecraft:banners");
public static final BlockCategory BIRCH_LOGS = register("minecraft:birch_logs");
public static final BlockCategory BUTTONS = register("minecraft:buttons");
public static final BlockCategory CARPETS = register("minecraft:carpets");
public static final BlockCategory CORAL = register("minecraft:coral");
public static final BlockCategory CORAL_PLANTS = register("minecraft:coral_plants");
public static final BlockCategory DARK_OAK_LOGS = register("minecraft:dark_oak_logs");
public static final BlockCategory DOORS = register("minecraft:doors");
public static final BlockCategory ENDERMAN_HOLDABLE = register("minecraft:enderman_holdable");
public static final BlockCategory FLOWER_POTS = register("minecraft:flower_pots");
public static final BlockCategory ICE = register("minecraft:ice");
public static final BlockCategory JUNGLE_LOGS = register("minecraft:jungle_logs");
public static final BlockCategory LEAVES = register("minecraft:leaves");
public static final BlockCategory LOGS = register("minecraft:logs");
public static final BlockCategory OAK_LOGS = register("minecraft:oak_logs");
public static final BlockCategory PLANKS = register("minecraft:planks");
public static final BlockCategory RAILS = register("minecraft:rails");
public static final BlockCategory SAND = register("minecraft:sand");
public static final BlockCategory SAPLINGS = register("minecraft:saplings");
public static final BlockCategory SLABS = register("minecraft:slabs");
public static final BlockCategory SPRUCE_LOGS = register("minecraft:spruce_logs");
public static final BlockCategory STAIRS = register("minecraft:stairs");
public static final BlockCategory STONE_BRICKS = register("minecraft:stone_bricks");
public static final BlockCategory VALID_SPAWN = register("minecraft:valid_spawn");
public static final BlockCategory WOODEN_BUTTONS = register("minecraft:wooden_buttons");
public static final BlockCategory WOODEN_DOORS = register("minecraft:wooden_doors");
public static final BlockCategory WOODEN_PRESSURE_PLATES = register("minecraft:wooden_pressure_plates");
public static final BlockCategory WOODEN_SLABS = register("minecraft:wooden_slabs");
public static final BlockCategory WOODEN_STAIRS = register("minecraft:wooden_stairs");
public static final BlockCategory WOOL = register("minecraft:wool");
private static final Map<String, BlockCategory> categoryMapping = new HashMap<>();
static {
for (Field field : BlockCategories.class.getFields()) {
if (field.getType() == BlockCategory.class) {
try {
registerCategory((BlockCategory) field.get(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
private static BlockCategory register(final String id) {
return register(new BlockCategory(id));
}
public static void registerCategory(BlockCategory blockCategory) {
if (categoryMapping.containsKey(blockCategory.getId()) && !blockCategory.getId().startsWith("minecraft:")) {
throw new IllegalArgumentException("Existing category with this ID already registered");
}
categoryMapping.put(blockCategory.getId(), blockCategory);
public static BlockCategory register(final BlockCategory tag) {
return BlockCategory.REGISTRY.register(tag.getId(), tag);
}
@Nullable
public static BlockCategory getBlockCategory(String id) {
// If it has no namespace, assume minecraft.
if (id != null && !id.contains(":")) {
id = "minecraft:" + id;
}
return categoryMapping.get(id);
public static BlockCategory get(final String id) {
return BlockCategory.REGISTRY.get(id);
}
public static Collection<BlockCategory> values() {
return categoryMapping.values();
return BlockCategory.REGISTRY.values();
}
}
@@ -21,6 +21,7 @@
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import java.util.Set;
@@ -30,6 +31,8 @@
*/
public class BlockCategory {
public static final NamespacedRegistry<BlockCategory> REGISTRY = new NamespacedRegistry<>();
private final String id;
public BlockCategory(String id) {
@@ -22,6 +22,7 @@
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BlockMaterial;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BundledBlockData;
@@ -33,6 +34,8 @@
public class BlockType {
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>();
private String id;
private BlockState defaultState;
@@ -100,7 +103,7 @@ public boolean hasItemType() {
*/
@Nullable
public ItemType getItemType() {
return ItemTypes.getItemType(this.id);
return ItemTypes.get(this.id);
}
/**
Oops, something went wrong.

0 comments on commit f5227f3

Please sign in to comment.