category changes

Dieser Commit ist enthalten in:
kashike 2018-07-05 11:09:45 -07:00 committet von Matthew Miller
Ursprung e1c2ea3a3b
Commit 70208c38fd
19 geänderte Dateien mit 159 neuen und 166 gelöschten Zeilen

Datei anzeigen

@ -41,13 +41,13 @@ public final class Blocks {
*/
private static final Set<BlockType> shouldPlaceLast = new HashSet<>();
static {
shouldPlaceLast.addAll(BlockCategories.SAPLINGS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.FLOWER_POTS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.BUTTONS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.ANVIL.getBlockTypes()); // becomes relevant with asynchronous placement
shouldPlaceLast.addAll(BlockCategories.WOODEN_PRESSURE_PLATES.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.CARPETS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.RAILS.getBlockTypes());
shouldPlaceLast.addAll(BlockCategories.SAPLINGS.getAll());
shouldPlaceLast.addAll(BlockCategories.FLOWER_POTS.getAll());
shouldPlaceLast.addAll(BlockCategories.BUTTONS.getAll());
shouldPlaceLast.addAll(BlockCategories.ANVIL.getAll()); // becomes relevant with asynchronous placement
shouldPlaceLast.addAll(BlockCategories.WOODEN_PRESSURE_PLATES.getAll());
shouldPlaceLast.addAll(BlockCategories.CARPETS.getAll());
shouldPlaceLast.addAll(BlockCategories.RAILS.getAll());
shouldPlaceLast.add(BlockTypes.BLACK_BED);
shouldPlaceLast.add(BlockTypes.BLUE_BED);
shouldPlaceLast.add(BlockTypes.BROWN_BED);
@ -128,8 +128,8 @@ public final class Blocks {
*/
private static final Set<BlockType> shouldPlaceFinal = new HashSet<>();
static {
shouldPlaceFinal.addAll(BlockCategories.DOORS.getBlockTypes());
shouldPlaceFinal.addAll(BlockCategories.BANNERS.getBlockTypes());
shouldPlaceFinal.addAll(BlockCategories.DOORS.getAll());
shouldPlaceFinal.addAll(BlockCategories.BANNERS.getAll());
shouldPlaceFinal.add(BlockTypes.SIGN);
shouldPlaceFinal.add(BlockTypes.WALL_SIGN);
shouldPlaceFinal.add(BlockTypes.CACTUS);

Datei anzeigen

@ -186,7 +186,7 @@ public class GeneralCommands {
int found = 0;
for (ItemType searchType : ItemTypes.values()) {
for (ItemType searchType : ItemType.REGISTRY) {
if (found >= 15) {
actor.print("Too many results!");
break;

Datei anzeigen

@ -0,0 +1,62 @@
/*
* 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.HashSet;
import java.util.Set;
public abstract class Category<T> {
private final Set<T> set = new HashSet<>();
protected final String id;
private boolean empty = true;
protected Category(final String id) {
this.id = id;
}
public final String getId() {
return this.id;
}
public final Set<T> getAll() {
if (this.empty) {
this.set.addAll(this.load());
this.empty = false;
}
return this.set;
}
protected abstract Set<T> load();
/**
* Checks if this category contains {@code object}.
*
* @param object the object
* @return {@code true} if this category contains the object
*/
public boolean contains(final T object) {
return this.getAll().contains(object);
}
public void invalidateCache() {
this.set.clear();
this.empty = true;
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.registry;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ -30,9 +31,14 @@ import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
public final class NamespacedRegistry<V> {
public final class NamespacedRegistry<V> implements Iterable<V> {
private static final String MINECRAFT_NAMESPACE = "minecraft";
private final Map<String, V> map = new HashMap<>();
private final String name;
public NamespacedRegistry(final String name) {
this.name = name;
}
public @Nullable V get(final String key) {
checkState(key.equals(key.toLowerCase()), "key must be lowercase");
@ -44,7 +50,7 @@ public final class NamespacedRegistry<V> {
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);
checkState(!this.map.containsKey(key), "key '%s' already has an associated %s", key, this.name);
this.map.put(key, value);
return value;
}
@ -63,4 +69,9 @@ public final class NamespacedRegistry<V> {
}
return key;
}
@Override
public Iterator<V> iterator() {
return this.map.values().iterator();
}
}

Datei anzeigen

@ -19,20 +19,12 @@
package com.sk89q.worldedit.world.block;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
/**
* Stores a list of categories of Block Types.
*/
public class BlockCategories {
private BlockCategories() {
}
public final class BlockCategories {
public static final BlockCategory ACACIA_LOGS = register("minecraft:acacia_logs");
public static final BlockCategory ANVIL = register("minecraft:anvil");
@ -67,6 +59,9 @@ public class BlockCategories {
public static final BlockCategory WOODEN_STAIRS = register("minecraft:wooden_stairs");
public static final BlockCategory WOOL = register("minecraft:wool");
private BlockCategories() {
}
private static BlockCategory register(final String id) {
return register(new BlockCategory(id));
}
@ -75,12 +70,7 @@ public class BlockCategories {
return BlockCategory.REGISTRY.register(tag.getId(), tag);
}
@Nullable
public static BlockCategory get(final String id) {
public static @Nullable BlockCategory get(final String id) {
return BlockCategory.REGISTRY.get(id);
}
public static Collection<BlockCategory> values() {
return BlockCategory.REGISTRY.values();
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.Category;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import java.util.Set;
@ -29,35 +30,19 @@ import java.util.Set;
* A category of blocks. This is due to the splitting up of
* blocks such as wool into separate ids.
*/
public class BlockCategory {
public class BlockCategory extends Category<BlockType> {
public static final NamespacedRegistry<BlockCategory> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<BlockCategory> REGISTRY = new NamespacedRegistry<>("block tag");
private final String id;
public BlockCategory(String id) {
this.id = id;
public BlockCategory(final String id) {
super(id);
}
public String getId() {
return this.id;
}
public Set<BlockType> getBlockTypes() {
@Override
protected Set<BlockType> load() {
return WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries()
.getBlockCategoryRegistry().getCategorisedByName(this.id);
}
/**
* Checks whether the BlocKType is contained within
* this category.
*
* @param blockType The blocktype
* @return If it's a part of this category
*/
public boolean contains(BlockType blockType) {
return getBlockTypes().contains(blockType);
.getBlockCategoryRegistry().getAll(this);
}
/**
@ -68,6 +53,6 @@ public class BlockCategory {
* @return If it's a part of this category
*/
public boolean contains(BlockStateHolder blockStateHolder) {
return getBlockTypes().contains(blockStateHolder.getBlockType());
return this.getAll().contains(blockStateHolder.getBlockType());
}
}

Datei anzeigen

@ -34,7 +34,7 @@ import javax.annotation.Nullable;
public class BlockType {
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<BlockType> REGISTRY = new NamespacedRegistry<>("block type");
private String id;
private BlockState defaultState;

Datei anzeigen

@ -19,17 +19,12 @@
package com.sk89q.worldedit.world.block;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* Stores a list of common Block String IDs.
*/
public class BlockTypes {
private BlockTypes() {
}
public final class BlockTypes {
public static final BlockType ACACIA_BARK = register("minecraft:acacia_bark");
public static final BlockType ACACIA_BUTTON = register("minecraft:acacia_button");
@ -604,6 +599,9 @@ public class BlockTypes {
public static final BlockType ZOMBIE_HEAD = register("minecraft:zombie_head");
public static final BlockType ZOMBIE_WALL_HEAD = register("minecraft:zombie_wall_head");
private BlockTypes() {
}
private static BlockType register(final String id) {
return register(new BlockType(id));
}
@ -612,12 +610,7 @@ public class BlockTypes {
return BlockType.REGISTRY.register(block.getId(), block);
}
@Nullable
public static BlockType get(final String id) {
public static @Nullable BlockType get(final String id) {
return BlockType.REGISTRY.get(id);
}
public static Collection<BlockType> values() {
return BlockType.REGISTRY.values();
}
}

Datei anzeigen

@ -19,21 +19,19 @@
package com.sk89q.worldedit.world.fluid;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* Stores a list of categories of Block Types.
*/
public class FluidCategories {
private FluidCategories() {
}
public final class FluidCategories {
public static final FluidCategory LAVA = register("minecraft:lava");
public static final FluidCategory WATER = register("minecraft:water");
private FluidCategories() {
}
private static FluidCategory register(final String id) {
return register(new FluidCategory(id));
}
@ -42,12 +40,7 @@ public class FluidCategories {
return FluidCategory.REGISTRY.register(tag.getId(), tag);
}
@Nullable
public static FluidCategory get(final String id) {
public static @Nullable FluidCategory get(final String id) {
return FluidCategory.REGISTRY.get(id);
}
public static Collection<FluidCategory> values() {
return FluidCategory.REGISTRY.values();
}
}

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.fluid;
import com.sk89q.worldedit.registry.Category;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import java.util.Collections;
@ -28,35 +29,19 @@ import java.util.Set;
* A category of fluids. This is due to the splitting up of
* blocks such as wool into separate ids.
*/
public class FluidCategory {
public class FluidCategory extends Category<FluidType> {
public static final NamespacedRegistry<FluidCategory> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<FluidCategory> REGISTRY = new NamespacedRegistry<>("fluid tag");
private final String id;
public FluidCategory(String id) {
this.id = id;
public FluidCategory(final String id) {
super(id);
}
public String getId() {
return this.id;
}
public Set<FluidType> getFluidTypes() {
@Override
protected Set<FluidType> load() {
return Collections.emptySet(); // TODO Make this work.
// return WorldEdit.getInstance().getPlatformManager()
// .queryCapability(Capability.GAME_HOOKS).getRegistries()
// .getBlockCategoryRegistry().getCategorisedByName(this.id);
}
/**
* Checks whether the FluidType is contained within
* this category.
*
* @param fluidType The fluidType
* @return If it's a part of this category
*/
public boolean contains(FluidType fluidType) {
return getFluidTypes().contains(fluidType);
}
}

Datei anzeigen

@ -27,7 +27,7 @@ import com.sk89q.worldedit.registry.NamespacedRegistry;
*/
public class FluidType {
public static final NamespacedRegistry<FluidType> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<FluidType> REGISTRY = new NamespacedRegistry<>("fluid type");
private String id;

Datei anzeigen

@ -19,17 +19,12 @@
package com.sk89q.worldedit.world.fluid;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* Stores a list of common Fluid String IDs.
*/
public class FluidTypes {
private FluidTypes() {
}
public final class FluidTypes {
public static final FluidType EMPTY = register("minecraft:empty");
public static final FluidType FLOWING_LAVA = register("minecraft:flowing_lava");
@ -37,6 +32,9 @@ public class FluidTypes {
public static final FluidType LAVA = register("minecraft:lava");
public static final FluidType WATER = register("minecraft:water");
private FluidTypes() {
}
private static FluidType register(final String id) {
return register(new FluidType(id));
}
@ -45,12 +43,7 @@ public class FluidTypes {
return FluidType.REGISTRY.register(fluid.getId(), fluid);
}
@Nullable
public static FluidType getFluidType(final String id) {
public static @Nullable FluidType get(final String id) {
return FluidType.REGISTRY.get(id);
}
public static Collection<FluidType> values() {
return FluidType.REGISTRY.values();
}
}

Datei anzeigen

@ -19,20 +19,12 @@
package com.sk89q.worldedit.world.item;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
/**
* Stores a list of categories of Item Types.
*/
public class ItemCategories {
private ItemCategories() {
}
public final class ItemCategories {
public static final ItemCategory ACACIA_LOGS = register("minecraft:acacia_logs");
public static final ItemCategory ANVIL = register("minecraft:anvil");
@ -65,6 +57,9 @@ public class ItemCategories {
public static final ItemCategory WOODEN_STAIRS = register("minecraft:wooden_stairs");
public static final ItemCategory WOOL = register("minecraft:wool");
private ItemCategories() {
}
private static ItemCategory register(final String id) {
return register(new ItemCategory(id));
}
@ -73,12 +68,7 @@ public class ItemCategories {
return ItemCategory.REGISTRY.register(tag.getId(), tag);
}
@Nullable
public static ItemCategory get(final String id) {
public static @Nullable ItemCategory get(final String id) {
return ItemCategory.REGISTRY.get(id);
}
public static Collection<ItemCategory> values() {
return ItemCategory.REGISTRY.values();
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.item;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.Category;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import java.util.Set;
@ -30,35 +31,19 @@ import java.util.Set;
* A category of items. This is due to the splitting up of
* items such as wool into separate ids.
*/
public class ItemCategory {
public class ItemCategory extends Category<ItemType> {
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<ItemCategory> REGISTRY = new NamespacedRegistry<>("item tag");
private final String id;
public ItemCategory(String id) {
this.id = id;
public ItemCategory(final String id) {
super(id);
}
public String getId() {
return this.id;
}
public Set<ItemType> getItemTypes() {
@Override
protected Set<ItemType> load() {
return WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries()
.getItemCategoryRegistry().getCategorisedByName(this.id);
}
/**
* Checks whether the ItemType is contained within
* this category.
*
* @param itemType The itemType
* @return If it's a part of this category
*/
public boolean contains(ItemType itemType) {
return getItemTypes().contains(itemType);
.getItemCategoryRegistry().getAll(this);
}
/**
@ -69,6 +54,6 @@ public class ItemCategory {
* @return If it's a part of this category
*/
public boolean contains(BaseItem baseItem) {
return getItemTypes().contains(baseItem.getType());
return this.getAll().contains(baseItem.getType());
}
}

Datei anzeigen

@ -29,7 +29,7 @@ import javax.annotation.Nullable;
public class ItemType {
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>();
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
private String id;

Datei anzeigen

@ -19,17 +19,9 @@
package com.sk89q.worldedit.world.item;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
public class ItemTypes {
private ItemTypes() {
}
public final class ItemTypes {
public static final ItemType ACACIA_BARK = register("minecraft:acacia_bark");
public static final ItemType ACACIA_BOAT = register("minecraft:acacia_boat");
@ -743,6 +735,9 @@ public class ItemTypes {
public static final ItemType ZOMBIE_SPAWN_EGG = register("minecraft:zombie_spawn_egg");
public static final ItemType ZOMBIE_VILLAGER_SPAWN_EGG = register("minecraft:zombie_villager_spawn_egg");
private ItemTypes() {
}
private static ItemType register(final String id) {
return register(new ItemType(id));
}
@ -751,12 +746,7 @@ public class ItemTypes {
return ItemType.REGISTRY.register(item.getId(), item);
}
@Nullable
public static ItemType get(final String id) {
public static @Nullable ItemType get(final String id) {
return ItemType.REGISTRY.get(id);
}
public static Collection<ItemType> values() {
return ItemType.REGISTRY.values();
}
}

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.Category;
import java.util.Set;
/**
@ -34,6 +36,8 @@ public interface CategoryRegistry<T> {
*/
Set<T> getCategorisedByName(String category);
Set<T> getAll(final Category<T> category);
/**
* Gets a list of categories given to a value.
*

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.Category;
import com.sk89q.worldedit.world.block.BlockType;
import java.util.Collections;
@ -31,6 +32,11 @@ public class NullBlockCategoryRegistry implements BlockCategoryRegistry {
return Collections.emptySet();
}
@Override
public Set<BlockType> getAll(final Category<BlockType> category) {
return Collections.emptySet();
}
@Override
public Set<String> getCategories(BlockType categorised) {
return Collections.emptySet();

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.registry.Category;
import com.sk89q.worldedit.world.item.ItemType;
import java.util.Collections;
@ -31,6 +32,11 @@ public class NullItemCategoryRegistry implements ItemCategoryRegistry {
return Collections.emptySet();
}
@Override
public Set<ItemType> getAll(final Category<ItemType> category) {
return Collections.emptySet();
}
@Override
public Set<String> getCategories(ItemType categorised) {
return Collections.emptySet();