From f8bf547c9e6d146881b30744f19f436035a2406f Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 14 Oct 2018 17:55:57 +1000 Subject: [PATCH] Added some missing bukkit registries --- .../bukkit/BukkitBlockCategoryRegistry.java | 52 +++++++++++++++++++ .../bukkit/BukkitItemCategoryRegistry.java | 52 +++++++++++++++++++ .../worldedit/bukkit/BukkitRegistries.java | 14 +++++ .../world/registry/CategoryRegistry.java | 8 --- .../registry/NullBlockCategoryRegistry.java | 5 -- .../registry/NullItemCategoryRegistry.java | 5 -- 6 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCategoryRegistry.java create mode 100644 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemCategoryRegistry.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCategoryRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCategoryRegistry.java new file mode 100644 index 000000000..cecec0691 --- /dev/null +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCategoryRegistry.java @@ -0,0 +1,52 @@ +/* + * 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.bukkit; + +import com.sk89q.worldedit.registry.Category; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.registry.BlockCategoryRegistry; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; + +import java.util.Set; +import java.util.stream.Collectors; + +public class BukkitBlockCategoryRegistry implements BlockCategoryRegistry { + + private Set getFromBukkitTag(Tag tag) { + return tag.getValues().stream().map(BukkitAdapter::asBlockType).collect(Collectors.toSet()); + } + + @Override + public Set getCategorisedByName(String category) { + String[] split = category.split(":"); + String namespace = split.length > 1 ? split[0] : "minecraft"; + String key = split.length > 1 ? split[1] : category; + Tag tag = Bukkit.getTag(Tag.REGISTRY_BLOCKS, new NamespacedKey(namespace, key), Material.class); + return getFromBukkitTag(tag); + } + + @Override + public Set getAll(Category category) { + return getCategorisedByName(category.getId()); + } +} diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemCategoryRegistry.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemCategoryRegistry.java new file mode 100644 index 000000000..c75c56eb2 --- /dev/null +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitItemCategoryRegistry.java @@ -0,0 +1,52 @@ +/* + * 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.bukkit; + +import com.sk89q.worldedit.registry.Category; +import com.sk89q.worldedit.world.item.ItemType; +import com.sk89q.worldedit.world.registry.ItemCategoryRegistry; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; + +import java.util.Set; +import java.util.stream.Collectors; + +public class BukkitItemCategoryRegistry implements ItemCategoryRegistry { + + private Set getFromBukkitTag(Tag tag) { + return tag.getValues().stream().map(BukkitAdapter::asItemType).collect(Collectors.toSet()); + } + + @Override + public Set getCategorisedByName(String category) { + String[] split = category.split(":"); + String namespace = split.length > 1 ? split[0] : "minecraft"; + String key = split.length > 1 ? split[1] : category; + Tag tag = Bukkit.getTag(Tag.REGISTRY_ITEMS, new NamespacedKey(namespace, key), Material.class); + return getFromBukkitTag(tag); + } + + @Override + public Set getAll(Category category) { + return getCategorisedByName(category.getId()); + } +} diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java index 6ed0999c7..5c93a8422 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitRegistries.java @@ -20,8 +20,10 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.world.registry.BiomeRegistry; +import com.sk89q.worldedit.world.registry.BlockCategoryRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.BundledRegistries; +import com.sk89q.worldedit.world.registry.ItemCategoryRegistry; /** * World data for the Bukkit platform. @@ -31,6 +33,8 @@ class BukkitRegistries extends BundledRegistries { private static final BukkitRegistries INSTANCE = new BukkitRegistries(); private final BlockRegistry blockRegistry = new BukkitBlockRegistry(); private final BiomeRegistry biomeRegistry = new BukkitBiomeRegistry(); + private final BlockCategoryRegistry blockCategoryRegistry = new BukkitBlockCategoryRegistry(); + private final ItemCategoryRegistry itemCategoryRegistry = new BukkitItemCategoryRegistry(); /** * Create a new instance. @@ -48,6 +52,16 @@ class BukkitRegistries extends BundledRegistries { return biomeRegistry; } + @Override + public BlockCategoryRegistry getBlockCategoryRegistry() { + return blockCategoryRegistry; + } + + @Override + public ItemCategoryRegistry getItemCategoryRegistry() { + return itemCategoryRegistry; + } + /** * Get a static instance. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java index 1a54c7961..496893821 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/CategoryRegistry.java @@ -37,12 +37,4 @@ public interface CategoryRegistry { Set getCategorisedByName(String category); Set getAll(final Category category); - - /** - * Gets a list of categories given to a value. - * - * @param categorised The value - * @return A set of categories - */ - Set getCategories(T categorised); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java index b26286498..4484d67d2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullBlockCategoryRegistry.java @@ -36,9 +36,4 @@ public class NullBlockCategoryRegistry implements BlockCategoryRegistry { public Set getAll(final Category category) { return Collections.emptySet(); } - - @Override - public Set getCategories(BlockType categorised) { - return Collections.emptySet(); - } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java index d047706c2..8eb5d9ee6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/NullItemCategoryRegistry.java @@ -36,9 +36,4 @@ public class NullItemCategoryRegistry implements ItemCategoryRegistry { public Set getAll(final Category category) { return Collections.emptySet(); } - - @Override - public Set getCategories(ItemType categorised) { - return Collections.emptySet(); - } }