mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-22 18:16:14 +01:00
Code cleanup
This commit is contained in:
parent
6bd1e9d3f9
commit
7410d89f3c
@ -20,7 +20,6 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class MaterialsRegistry {
|
||||
|
||||
// Material names have been changed in 1.13, when dolphins were added
|
||||
@ -30,25 +29,93 @@ public final class MaterialsRegistry {
|
||||
private static final char[] IGNORE_CHARS = {'-', '_', ' '};
|
||||
|
||||
// Default material names are ugly
|
||||
private static final Map<String, Material> MATERIALS_BY_ALIAS = new HashMap<>();
|
||||
private static final Map<String, Material> MATERIALS_BY_ALIAS = initMaterialsByAlias();
|
||||
|
||||
// Materials that are considered air (with 1.13+ compatibility)
|
||||
private static final Collection<Material> AIR_MATERIALS = getExistingMaterials("AIR", "CAVE_AIR", "VOID_AIR");
|
||||
|
||||
private MaterialsRegistry() {
|
||||
private MaterialsRegistry() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Map<String, Material> initMaterialsByAlias() {
|
||||
Map<String, Material> materialsByAlias = new HashMap<>();
|
||||
|
||||
for (Material material : Material.values()) {
|
||||
addMaterialAlias(materialsByAlias, material.toString(), material);
|
||||
|
||||
if (!USE_NEW_MATERIAL_NAMES) {
|
||||
// Add numerical IDs in versions before 1.13
|
||||
addMaterialAlias(materialsByAlias, String.valueOf(material.getId()), material);
|
||||
}
|
||||
}
|
||||
|
||||
// Add some default useful aliases (when present)
|
||||
tryAddMaterialAlias(materialsByAlias, "iron bar", "IRON_FENCE");
|
||||
tryAddMaterialAlias(materialsByAlias, "iron bars", "IRON_FENCE");
|
||||
tryAddMaterialAlias(materialsByAlias, "glass pane", "THIN_GLASS");
|
||||
tryAddMaterialAlias(materialsByAlias, "nether wart", "NETHER_STALK");
|
||||
tryAddMaterialAlias(materialsByAlias, "nether warts", "NETHER_STALK");
|
||||
tryAddMaterialAlias(materialsByAlias, "slab", "STEP");
|
||||
tryAddMaterialAlias(materialsByAlias, "double slab", "DOUBLE_STEP");
|
||||
tryAddMaterialAlias(materialsByAlias, "stone brick", "SMOOTH_BRICK");
|
||||
tryAddMaterialAlias(materialsByAlias, "stone bricks", "SMOOTH_BRICK");
|
||||
tryAddMaterialAlias(materialsByAlias, "stone stair", "SMOOTH_STAIRS");
|
||||
tryAddMaterialAlias(materialsByAlias, "stone stairs", "SMOOTH_STAIRS");
|
||||
tryAddMaterialAlias(materialsByAlias, "potato", "POTATO_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "carrot", "CARROT_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "brewing stand", "BREWING_STAND_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "cauldron", "CAULDRON_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "carrot on stick", "CARROT_STICK");
|
||||
tryAddMaterialAlias(materialsByAlias, "carrot on a stick", "CARROT_STICK");
|
||||
tryAddMaterialAlias(materialsByAlias, "cobblestone wall", "COBBLE_WALL");
|
||||
tryAddMaterialAlias(materialsByAlias, "acacia wood stairs", "ACACIA_STAIRS");
|
||||
tryAddMaterialAlias(materialsByAlias, "dark oak wood stairs", "DARK_OAK_STAIRS");
|
||||
tryAddMaterialAlias(materialsByAlias, "wood slab", "WOOD_STEP");
|
||||
tryAddMaterialAlias(materialsByAlias, "double wood slab", "WOOD_DOUBLE_STEP");
|
||||
tryAddMaterialAlias(materialsByAlias, "repeater", "DIODE");
|
||||
tryAddMaterialAlias(materialsByAlias, "piston", "PISTON_BASE");
|
||||
tryAddMaterialAlias(materialsByAlias, "sticky piston", "PISTON_STICKY_BASE");
|
||||
tryAddMaterialAlias(materialsByAlias, "flower pot", "FLOWER_POT_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "wood showel", "WOOD_SPADE");
|
||||
tryAddMaterialAlias(materialsByAlias, "stone showel", "STONE_SPADE");
|
||||
tryAddMaterialAlias(materialsByAlias, "gold showel", "GOLD_SPADE");
|
||||
tryAddMaterialAlias(materialsByAlias, "iron showel", "IRON_SPADE");
|
||||
tryAddMaterialAlias(materialsByAlias, "diamond showel", "DIAMOND_SPADE");
|
||||
tryAddMaterialAlias(materialsByAlias, "steak", "COOKED_BEEF");
|
||||
tryAddMaterialAlias(materialsByAlias, "cooked porkchop", "GRILLED_PORK");
|
||||
tryAddMaterialAlias(materialsByAlias, "raw porkchop", "PORK");
|
||||
tryAddMaterialAlias(materialsByAlias, "hardened clay", "HARD_CLAY");
|
||||
tryAddMaterialAlias(materialsByAlias, "huge brown mushroom", "HUGE_MUSHROOM_1");
|
||||
tryAddMaterialAlias(materialsByAlias, "huge red mushroom", "HUGE_MUSHROOM_2");
|
||||
tryAddMaterialAlias(materialsByAlias, "mycelium", "MYCEL");
|
||||
tryAddMaterialAlias(materialsByAlias, "poppy", "RED_ROSE");
|
||||
tryAddMaterialAlias(materialsByAlias, "comparator", "REDSTONE_COMPARATOR");
|
||||
tryAddMaterialAlias(materialsByAlias, "skull", "SKULL_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "head", "SKULL_ITEM");
|
||||
tryAddMaterialAlias(materialsByAlias, "redstone torch", "REDSTONE_TORCH_ON");
|
||||
tryAddMaterialAlias(materialsByAlias, "redstone lamp", "REDSTONE_LAMP_OFF");
|
||||
tryAddMaterialAlias(materialsByAlias, "glistering melon", "SPECKLED_MELON");
|
||||
tryAddMaterialAlias(materialsByAlias, "acacia leaves", "LEAVES_2");
|
||||
tryAddMaterialAlias(materialsByAlias, "acacia log", "LOG_2");
|
||||
tryAddMaterialAlias(materialsByAlias, "gunpowder", "SULPHUR");
|
||||
tryAddMaterialAlias(materialsByAlias, "lilypad", "WATER_LILY");
|
||||
tryAddMaterialAlias(materialsByAlias, "command block", "COMMAND");
|
||||
tryAddMaterialAlias(materialsByAlias, "dye", "INK_SACK");
|
||||
|
||||
return materialsByAlias;
|
||||
}
|
||||
|
||||
private static void addMaterialAlias(String name, Material material) {
|
||||
MATERIALS_BY_ALIAS.put(StringUtils.stripChars(name, IGNORE_CHARS).toLowerCase(), material);
|
||||
}
|
||||
|
||||
private static void tryAddMaterialAlias(String name, String materialEnumName) {
|
||||
private static void tryAddMaterialAlias(Map<String, Material> materialsByAlias, String name, String materialEnumName) {
|
||||
try {
|
||||
addMaterialAlias(name, Material.valueOf(materialEnumName));
|
||||
addMaterialAlias(materialsByAlias, name, Material.valueOf(materialEnumName));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Ignore, do not add a new alias
|
||||
}
|
||||
}
|
||||
|
||||
private static void addMaterialAlias(Map<String, Material> materialsByAlias, String name, Material material) {
|
||||
materialsByAlias.put(StringUtils.stripChars(name, IGNORE_CHARS).toLowerCase(), material);
|
||||
}
|
||||
|
||||
public static Material matchMaterial(String alias) {
|
||||
if (alias == null) {
|
||||
@ -63,7 +130,7 @@ public final class MaterialsRegistry {
|
||||
}
|
||||
|
||||
private static Collection<Material> getExistingMaterials(String... materialEnumNames) {
|
||||
Collection<Material> existingMaterials = new HashSet<Material>();
|
||||
Collection<Material> existingMaterials = new HashSet<>();
|
||||
|
||||
for (String materialEnumName : materialEnumNames) {
|
||||
try {
|
||||
@ -79,69 +146,5 @@ public final class MaterialsRegistry {
|
||||
public static boolean isAir(Material material) {
|
||||
return AIR_MATERIALS.contains(material);
|
||||
}
|
||||
|
||||
static {
|
||||
for (Material material : Material.values()) {
|
||||
addMaterialAlias(material.toString(), material);
|
||||
|
||||
if (!USE_NEW_MATERIAL_NAMES) {
|
||||
// Add numerical IDs in versions before 1.13
|
||||
addMaterialAlias(String.valueOf(material.getId()), material);
|
||||
}
|
||||
}
|
||||
|
||||
// Add some default useful aliases (when present)
|
||||
tryAddMaterialAlias("iron bar", "IRON_FENCE");
|
||||
tryAddMaterialAlias("iron bars", "IRON_FENCE");
|
||||
tryAddMaterialAlias("glass pane", "THIN_GLASS");
|
||||
tryAddMaterialAlias("nether wart", "NETHER_STALK");
|
||||
tryAddMaterialAlias("nether warts", "NETHER_STALK");
|
||||
tryAddMaterialAlias("slab", "STEP");
|
||||
tryAddMaterialAlias("double slab", "DOUBLE_STEP");
|
||||
tryAddMaterialAlias("stone brick", "SMOOTH_BRICK");
|
||||
tryAddMaterialAlias("stone bricks", "SMOOTH_BRICK");
|
||||
tryAddMaterialAlias("stone stair", "SMOOTH_STAIRS");
|
||||
tryAddMaterialAlias("stone stairs", "SMOOTH_STAIRS");
|
||||
tryAddMaterialAlias("potato", "POTATO_ITEM");
|
||||
tryAddMaterialAlias("carrot", "CARROT_ITEM");
|
||||
tryAddMaterialAlias("brewing stand", "BREWING_STAND_ITEM");
|
||||
tryAddMaterialAlias("cauldron", "CAULDRON_ITEM");
|
||||
tryAddMaterialAlias("carrot on stick", "CARROT_STICK");
|
||||
tryAddMaterialAlias("carrot on a stick", "CARROT_STICK");
|
||||
tryAddMaterialAlias("cobblestone wall", "COBBLE_WALL");
|
||||
tryAddMaterialAlias("acacia wood stairs", "ACACIA_STAIRS");
|
||||
tryAddMaterialAlias("dark oak wood stairs", "DARK_OAK_STAIRS");
|
||||
tryAddMaterialAlias("wood slab", "WOOD_STEP");
|
||||
tryAddMaterialAlias("double wood slab", "WOOD_DOUBLE_STEP");
|
||||
tryAddMaterialAlias("repeater", "DIODE");
|
||||
tryAddMaterialAlias("piston", "PISTON_BASE");
|
||||
tryAddMaterialAlias("sticky piston", "PISTON_STICKY_BASE");
|
||||
tryAddMaterialAlias("flower pot", "FLOWER_POT_ITEM");
|
||||
tryAddMaterialAlias("wood showel", "WOOD_SPADE");
|
||||
tryAddMaterialAlias("stone showel", "STONE_SPADE");
|
||||
tryAddMaterialAlias("gold showel", "GOLD_SPADE");
|
||||
tryAddMaterialAlias("iron showel", "IRON_SPADE");
|
||||
tryAddMaterialAlias("diamond showel", "DIAMOND_SPADE");
|
||||
tryAddMaterialAlias("steak", "COOKED_BEEF");
|
||||
tryAddMaterialAlias("cooked porkchop", "GRILLED_PORK");
|
||||
tryAddMaterialAlias("raw porkchop", "PORK");
|
||||
tryAddMaterialAlias("hardened clay", "HARD_CLAY");
|
||||
tryAddMaterialAlias("huge brown mushroom", "HUGE_MUSHROOM_1");
|
||||
tryAddMaterialAlias("huge red mushroom", "HUGE_MUSHROOM_2");
|
||||
tryAddMaterialAlias("mycelium", "MYCEL");
|
||||
tryAddMaterialAlias("poppy", "RED_ROSE");
|
||||
tryAddMaterialAlias("comparator", "REDSTONE_COMPARATOR");
|
||||
tryAddMaterialAlias("skull", "SKULL_ITEM");
|
||||
tryAddMaterialAlias("head", "SKULL_ITEM");
|
||||
tryAddMaterialAlias("redstone torch", "REDSTONE_TORCH_ON");
|
||||
tryAddMaterialAlias("redstone lamp", "REDSTONE_LAMP_OFF");
|
||||
tryAddMaterialAlias("glistering melon", "SPECKLED_MELON");
|
||||
tryAddMaterialAlias("acacia leaves", "LEAVES_2");
|
||||
tryAddMaterialAlias("acacia log", "LOG_2");
|
||||
tryAddMaterialAlias("gunpowder", "SULPHUR");
|
||||
tryAddMaterialAlias("lilypad", "WATER_LILY");
|
||||
tryAddMaterialAlias("command block", "COMMAND");
|
||||
tryAddMaterialAlias("dye", "INK_SACK");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,8 +14,6 @@
|
||||
*/
|
||||
package me.filoghost.chestcommands.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {
|
||||
|
Loading…
Reference in New Issue
Block a user