diff --git a/pom.xml b/pom.xml index a32fde19..8a52c6a6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ fun.lewisdev DeluxeHub - 3.5.3 + 3.5.4 jar DeluxeHub @@ -115,7 +115,7 @@ org.spigotmc spigot-api - 1.16.5-R0.1-SNAPSHOT + 1.20.1-R0.1-SNAPSHOT provided @@ -161,7 +161,7 @@ de.tr7zw item-nbt-api - 2.10.0-SNAPSHOT + 2.11.3 com.github.shynixn.headdatabase diff --git a/src/main/java/fun/lewisdev/deluxehub/utility/universal/XMaterial.java b/src/main/java/fun/lewisdev/deluxehub/utility/universal/XMaterial.java index 563d9d47..9ac0a4bd 100644 --- a/src/main/java/fun/lewisdev/deluxehub/utility/universal/XMaterial.java +++ b/src/main/java/fun/lewisdev/deluxehub/utility/universal/XMaterial.java @@ -55,13 +55,13 @@ * Material Source Code: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java * XMaterial v1: https://www.spigotmc.org/threads/329630/ *

- * This class will throw a "unsupported material" error if someone tries to use an item with an invalid data value which can only happen in 1.12 servers and below or when the + * This class will throw an "unsupported material" error if someone tries to use an item with an invalid data value which can only happen in 1.12 servers and below or when the * utility is missing a new material in that specific version. * To get an invalid item, (aka Missing Texture Block) you can use the command * /give @p minecraft:dirt 1 10 where 1 is the item amount, and 10 is the data value. The material {@link #DIRT} with a data value of {@code 10} doesn't exist. * * @author Crypto Morin - * @version 11.3.0 + * @version 11.4.1 * @see Material * @see ItemStack */ @@ -87,7 +87,7 @@ public enum XMaterial { ACACIA_WOOD(0, "LOG_2"), ACTIVATOR_RAIL, /** - * https://minecraft.gamepedia.com/Air + * Air * {@link Material#isAir()} * * @see #VOID_AIR @@ -104,9 +104,12 @@ public enum XMaterial { ANDESITE_SLAB, ANDESITE_STAIRS, ANDESITE_WALL, + ANGLER_POTTERY_SHERD, ANVIL, APPLE, + ARCHER_POTTERY_SHERD, ARMOR_STAND, + ARMS_UP_POTTERY_SHERD, ARROW, ATTACHED_MELON_STEM(7, "MELON_STEM"), ATTACHED_PUMPKIN_STEM(7, "PUMPKIN_STEM"), @@ -198,6 +201,7 @@ public enum XMaterial { BLACK_TERRACOTTA(15, "STAINED_CLAY"), BLACK_WALL_BANNER("WALL_BANNER"), BLACK_WOOL(15, "WOOL"), + BLADE_POTTERY_SHERD, BLAST_FURNACE, BLAZE_POWDER, BLAZE_ROD, @@ -231,9 +235,10 @@ public enum XMaterial { BRAIN_CORAL_FAN, BRAIN_CORAL_WALL_FAN, BREAD, + BREWER_POTTERY_SHERD, BREWING_STAND("BREWING_STAND", "BREWING_STAND_ITEM"), BRICK("CLAY_BRICK"), - BRICKS("BRICKS", "BRICK"), + BRICKS("BRICK"), BRICK_SLAB(4, "STEP"), BRICK_STAIRS, BRICK_WALL, @@ -254,6 +259,7 @@ public enum XMaterial { BROWN_TERRACOTTA(12, "STAINED_CLAY"), BROWN_WALL_BANNER(3, "WALL_BANNER"), BROWN_WOOL(12, "WOOL"), + BRUSH, BUBBLE_COLUMN, BUBBLE_CORAL, BUBBLE_CORAL_BLOCK, @@ -262,9 +268,11 @@ public enum XMaterial { BUCKET, BUDDING_AMETHYST, BUNDLE, + BURN_POTTERY_SHERD, CACTUS, CAKE("CAKE_BLOCK"), CALCITE, + CALIBRATED_SCULK_SENSOR, CAMEL_SPAWN_EGG, CAMPFIRE, CANDLE, @@ -292,6 +300,25 @@ public enum XMaterial { CHAINMAIL_LEGGINGS, CHAIN_COMMAND_BLOCK("COMMAND", "COMMAND_CHAIN"), CHARCOAL(1, "COAL"), + CHERRY_BOAT, + CHERRY_BUTTON, + CHERRY_CHEST_BOAT, + CHERRY_DOOR, + CHERRY_FENCE, + CHERRY_FENCE_GATE, + CHERRY_HANGING_SIGN, + CHERRY_LEAVES, + CHERRY_LOG, + CHERRY_PLANKS, + CHERRY_PRESSURE_PLATE, + CHERRY_SAPLING, + CHERRY_SIGN, + CHERRY_SLAB, + CHERRY_STAIRS, + CHERRY_TRAPDOOR, + CHERRY_WALL_HANGING_SIGN, + CHERRY_WALL_SIGN, + CHERRY_WOOD, CHEST("LOCKED_CHEST"), CHEST_MINECART("STORAGE_MINECART"), CHICKEN("RAW_CHICKEN"), @@ -315,6 +342,7 @@ public enum XMaterial { COAL_BLOCK, COAL_ORE, COARSE_DIRT(1, "DIRT"), + COAST_ARMOR_TRIM_SMITHING_TEMPLATE, COBBLED_DEEPSLATE, COBBLED_DEEPSLATE_SLAB, COBBLED_DEEPSLATE_STAIRS, @@ -409,6 +437,7 @@ public enum XMaterial { CYAN_WOOL(9, "WOOL"), DAMAGED_ANVIL(2, "ANVIL"), DANDELION("YELLOW_FLOWER"), + DANGER_POTTERY_SHERD, DARK_OAK_BOAT("BOAT_DARK_OAK"), DARK_OAK_BUTTON("WOOD_BUTTON"), DARK_OAK_CHEST_BOAT, @@ -454,6 +483,7 @@ public enum XMaterial { DEAD_TUBE_CORAL_FAN, DEAD_TUBE_CORAL_WALL_FAN, DEBUG_STICK, + DECORATED_POT, DEEPSLATE, DEEPSLATE_BRICKS, DEEPSLATE_BRICK_SLAB, @@ -507,6 +537,7 @@ public enum XMaterial { DRIPSTONE_BLOCK, DROPPER, DROWNED_SPAWN_EGG, + DUNE_ARMOR_TRIM_SMITHING_TEMPLATE, ECHO_SHARD, EGG, ELDER_GUARDIAN_SPAWN_EGG(4, "MONSTER_EGG"), @@ -535,10 +566,12 @@ public enum XMaterial { END_STONE_BRICK_WALL, EVOKER_SPAWN_EGG(34, "MONSTER_EGG"), EXPERIENCE_BOTTLE("EXP_BOTTLE"), + EXPLORER_POTTERY_SHERD, EXPOSED_COPPER, EXPOSED_CUT_COPPER, EXPOSED_CUT_COPPER_SLAB, EXPOSED_CUT_COPPER_STAIRS, + EYE_ARMOR_TRIM_SMITHING_TEMPLATE, FARMLAND("SOIL"), FEATHER, FERMENTED_SPIDER_EYE, @@ -547,7 +580,7 @@ public enum XMaterial { * For some reasons filled map items are really special. * Their data value starts from 0 and every time a player * creates a new map that maps data value increases. - * https://github.com/CryptoMorin/XSeries/issues/91 + * GitHub Issue */ FILLED_MAP("MAP"), FIRE, @@ -567,6 +600,7 @@ public enum XMaterial { FLOWER_BANNER_PATTERN, FLOWER_POT("FLOWER_POT", "FLOWER_POT_ITEM"), FOX_SPAWN_EGG, + FRIEND_POTTERY_SHERD, FROGSPAWN, FROG_SPAWN_EGG, /** @@ -654,7 +688,9 @@ public enum XMaterial { GUNPOWDER("SULPHUR"), HANGING_ROOTS, HAY_BLOCK, + HEARTBREAK_POTTERY_SHERD, HEART_OF_THE_SEA, + HEART_POTTERY_SHERD, HEAVY_WEIGHTED_PRESSURE_PLATE("IRON_PLATE"), HOGLIN_SPAWN_EGG("MONSTER_EGG"), HONEYCOMB, @@ -668,6 +704,8 @@ public enum XMaterial { HORN_CORAL_FAN, HORN_CORAL_WALL_FAN, HORSE_SPAWN_EGG(100, "MONSTER_EGG"), + HOST_ARMOR_TRIM_SMITHING_TEMPLATE, + HOWL_POTTERY_SHERD, HUSK_SPAWN_EGG(23, "MONSTER_EGG"), ICE, INFESTED_CHISELED_STONE_BRICKS(5, "MONSTER_EGGS"), @@ -858,6 +896,7 @@ public enum XMaterial { MELON_STEM, MILK_BUCKET, MINECART, + MINER_POTTERY_SHERD, MOJANG_BANNER_PATTERN, MOOSHROOM_SPAWN_EGG(96, "MONSTER_EGG"), MOSSY_COBBLESTONE, @@ -870,6 +909,7 @@ public enum XMaterial { MOSSY_STONE_BRICK_WALL, MOSS_BLOCK, MOSS_CARPET, + MOURNER_POTTERY_SHERD, MOVING_PISTON("PISTON_MOVING_PIECE"), MUD, MUDDY_MANGROVE_ROOTS, @@ -891,6 +931,7 @@ public enum XMaterial { MUSIC_DISC_MELLOHI("RECORD_7"), MUSIC_DISC_OTHERSIDE, MUSIC_DISC_PIGSTEP, + MUSIC_DISC_RELIC, MUSIC_DISC_STAL("RECORD_8"), MUSIC_DISC_STRAD("RECORD_9"), MUSIC_DISC_WAIT("RECORD_12"), @@ -911,6 +952,7 @@ public enum XMaterial { NETHERITE_SCRAP, NETHERITE_SHOVEL, NETHERITE_SWORD, + NETHERITE_UPGRADE_SMITHING_TEMPLATE, NETHERRACK, NETHER_BRICK("NETHER_BRICK_ITEM"), NETHER_BRICKS("NETHER_BRICK"), @@ -924,7 +966,7 @@ public enum XMaterial { NETHER_SPROUTS, NETHER_STAR, /** - * Just like mentioned in https://minecraft.gamepedia.com/Nether_Wart + * Just like mentioned in Nether Wart * Nether wart is also known as nether stalk in the code. * NETHER_STALK is the planted state of nether warts. */ @@ -1002,6 +1044,7 @@ public enum XMaterial { PINK_CONCRETE_POWDER(6, "CONCRETE_POWDER"), PINK_DYE(9, "INK_SACK"), PINK_GLAZED_TERRACOTTA, + PINK_PETALS, PINK_SHULKER_BOX, PINK_STAINED_GLASS(6, "STAINED_GLASS"), PINK_STAINED_GLASS_PANE(6, "THIN_GLASS", "STAINED_GLASS_PANE"), @@ -1011,8 +1054,12 @@ public enum XMaterial { PINK_WOOL(6, "WOOL"), PISTON("PISTON_BASE"), PISTON_HEAD("PISTON_EXTENSION"), + PITCHER_CROP, + PITCHER_PLANT, + PITCHER_POD, PLAYER_HEAD(3, "SKULL", "SKULL_ITEM"), PLAYER_WALL_HEAD(3, "SKULL", "SKULL_ITEM"), + PLENTY_POTTERY_SHERD, PODZOL(2, "DIRT"), POINTED_DRIPSTONE, POISONOUS_POTATO, @@ -1056,6 +1103,7 @@ public enum XMaterial { POTTED_BLUE_ORCHID(1, "FLOWER_POT"), POTTED_BROWN_MUSHROOM("FLOWER_POT"), POTTED_CACTUS("FLOWER_POT"), + POTTED_CHERRY_SAPLING, POTTED_CORNFLOWER, POTTED_CRIMSON_FUNGUS, POTTED_CRIMSON_ROOTS, @@ -1075,10 +1123,15 @@ public enum XMaterial { POTTED_RED_MUSHROOM("FLOWER_POT"), POTTED_RED_TULIP(4, "FLOWER_POT"), POTTED_SPRUCE_SAPLING(1, "FLOWER_POT"), + POTTED_TORCHFLOWER, POTTED_WARPED_FUNGUS, POTTED_WARPED_ROOTS, POTTED_WHITE_TULIP(6, "FLOWER_POT"), POTTED_WITHER_ROSE, + POTTERY_SHARD_ARCHER, + POTTERY_SHARD_ARMS_UP, + POTTERY_SHARD_PRIZE, + POTTERY_SHARD_SKULL, POWDER_SNOW, POWDER_SNOW_BUCKET, POWDER_SNOW_CAULDRON, @@ -1092,6 +1145,7 @@ public enum XMaterial { PRISMARINE_SLAB, PRISMARINE_STAIRS, PRISMARINE_WALL, + PRIZE_POTTERY_SHERD, PUFFERFISH(3, "RAW_FISH"), PUFFERFISH_BUCKET, PUFFERFISH_SPAWN_EGG, @@ -1130,6 +1184,7 @@ public enum XMaterial { RABBIT_SPAWN_EGG(101, "MONSTER_EGG"), RABBIT_STEW, RAIL("RAILS"), + RAISER_ARMOR_TRIM_SMITHING_TEMPLATE, RAVAGER_SPAWN_EGG, RAW_COPPER, RAW_COPPER_BLOCK, @@ -1194,6 +1249,7 @@ public enum XMaterial { REPEATER("DIODE_BLOCK_ON", "DIODE_BLOCK_OFF", "DIODE"), REPEATING_COMMAND_BLOCK("COMMAND", "COMMAND_REPEATING"), RESPAWN_ANCHOR, + RIB_ARMOR_TRIM_SMITHING_TEMPLATE, ROOTED_DIRT, ROSE_BUSH(4, "DOUBLE_PLANT"), ROTTEN_FLESH, @@ -1216,19 +1272,25 @@ public enum XMaterial { SEAGRASS, SEA_LANTERN, SEA_PICKLE, + SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE, + SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE, + SHEAF_POTTERY_SHERD, SHEARS, SHEEP_SPAWN_EGG(91, "MONSTER_EGG"), + SHELTER_POTTERY_SHERD, SHIELD, SHROOMLIGHT, SHULKER_BOX("PURPLE_SHULKER_BOX"), SHULKER_SHELL, SHULKER_SPAWN_EGG(69, "MONSTER_EGG"), + SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE, SILVERFISH_SPAWN_EGG(60, "MONSTER_EGG"), SKELETON_HORSE_SPAWN_EGG(28, "MONSTER_EGG"), SKELETON_SKULL("SKULL", "SKULL_ITEM"), SKELETON_SPAWN_EGG(51, "MONSTER_EGG"), SKELETON_WALL_SKULL("SKULL", "SKULL_ITEM"), SKULL_BANNER_PATTERN, + SKULL_POTTERY_SHERD, SLIME_BALL, SLIME_BLOCK, SLIME_SPAWN_EGG(55, "MONSTER_EGG"), @@ -1248,6 +1310,10 @@ public enum XMaterial { SMOOTH_SANDSTONE_STAIRS, SMOOTH_STONE, SMOOTH_STONE_SLAB, + SNIFFER_EGG, + SNIFFER_SPAWN_EGG, + SNORT_POTTERY_SHERD, + SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE, SNOW, SNOWBALL("SNOW_BALL"), SNOW_BLOCK, @@ -1263,6 +1329,7 @@ public enum XMaterial { SPECTRAL_ARROW, SPIDER_EYE, SPIDER_SPAWN_EGG(52, "MONSTER_EGG"), + SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE, SPLASH_POTION, SPONGE, SPORE_BLOSSOM, @@ -1312,6 +1379,8 @@ public enum XMaterial { STRIPPED_BAMBOO_BLOCK, STRIPPED_BIRCH_LOG, STRIPPED_BIRCH_WOOD, + STRIPPED_CHERRY_LOG, + STRIPPED_CHERRY_WOOD, STRIPPED_CRIMSON_HYPHAE, STRIPPED_CRIMSON_STEM, STRIPPED_DARK_OAK_LOG, @@ -1338,6 +1407,8 @@ public enum XMaterial { */ SUGAR_CANE("SUGAR_CANE_BLOCK"), SUNFLOWER("DOUBLE_PLANT"), + SUSPICIOUS_GRAVEL, + SUSPICIOUS_SAND, SUSPICIOUS_STEW, SWEET_BERRIES, SWEET_BERRY_BUSH, @@ -1347,11 +1418,15 @@ public enum XMaterial { TALL_SEAGRASS, TARGET, TERRACOTTA("HARD_CLAY"), + TIDE_ARMOR_TRIM_SMITHING_TEMPLATE, TINTED_GLASS, TIPPED_ARROW, TNT, TNT_MINECART("EXPLOSIVE_MINECART"), TORCH, + TORCHFLOWER, + TORCHFLOWER_CROP, + TORCHFLOWER_SEEDS, TOTEM_OF_UNDYING("TOTEM"), TRADER_LLAMA_SPAWN_EGG, TRAPPED_CHEST, @@ -1372,6 +1447,7 @@ public enum XMaterial { TWISTING_VINES, TWISTING_VINES_PLANT, VERDANT_FROGLIGHT, + VEX_ARMOR_TRIM_SMITHING_TEMPLATE, VEX_SPAWN_EGG(35, "MONSTER_EGG"), VILLAGER_SPAWN_EGG(120, "MONSTER_EGG"), VINDICATOR_SPAWN_EGG(36, "MONSTER_EGG"), @@ -1385,6 +1461,7 @@ public enum XMaterial { WALL_TORCH("TORCH"), WANDERING_TRADER_SPAWN_EGG, WARDEN_SPAWN_EGG, + WARD_ARMOR_TRIM_SMITHING_TEMPLATE, WARPED_BUTTON, WARPED_DOOR, WARPED_FENCE, @@ -1409,7 +1486,7 @@ public enum XMaterial { * This is used for blocks only. * In 1.13- WATER will turn into STATIONARY_WATER after it finished spreading. * After 1.13+ this uses - * https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/Levelled.html water flowing system. + * Levelled water flowing system. */ WATER("STATIONARY_WATER"), WATER_BUCKET, @@ -1430,6 +1507,7 @@ public enum XMaterial { WAXED_WEATHERED_CUT_COPPER, WAXED_WEATHERED_CUT_COPPER_SLAB, WAXED_WEATHERED_CUT_COPPER_STAIRS, + WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE, WEATHERED_COPPER, WEATHERED_CUT_COPPER, WEATHERED_CUT_COPPER_SLAB, @@ -1458,6 +1536,7 @@ public enum XMaterial { WHITE_TULIP(6, "RED_ROSE"), WHITE_WALL_BANNER(15, "WALL_BANNER"), WHITE_WOOL("WOOL"), + WILD_ARMOR_TRIM_SMITHING_TEMPLATE, WITCH_SPAWN_EGG(66, "MONSTER_EGG"), WITHER_ROSE, WITHER_SKELETON_SKULL(1, "SKULL", "SKULL_ITEM"), @@ -1534,7 +1613,7 @@ public enum XMaterial { .build(); /** * The maximum data value in the pre-flattening update which belongs to {@link #VILLAGER_SPAWN_EGG}
- * https://minecraftitemids.com/types/spawn-egg + * Spawn Eggs * * @see #matchXMaterialWithData(String) * @since 8.0.0 @@ -1586,7 +1665,7 @@ public enum XMaterial { } /** - * The data value of this material https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening + * The data value of this material Pre-flattening * It's never a negative number. * * @see #getData() @@ -1622,14 +1701,15 @@ public enum XMaterial { this.material = mat; } - XMaterial(String... legacy) {this(0, legacy);} + XMaterial(String... legacy) { + this(0, legacy); + } /** * Gets the XMaterial with this name similar to {@link #valueOf(String)} * without throwing an exception. * * @param name the name of the material. - * * @return an optional that can be empty. * @since 5.1.0 */ @@ -1673,21 +1753,6 @@ private static XMaterial requestOldXMaterial(@Nonnull String name, byte data) { return null; } - /** - * Parses the given material name as an XMaterial with a given data - * value in the string if attached. Check {@link #matchXMaterialWithData(String)} for more info. - * - * @see #matchXMaterialWithData(String) - * @see #matchDefinedXMaterial(String, byte) - * @since 2.0.0 - */ - @Nonnull - public static Optional matchXMaterial(@Nonnull String name) { - if (name == null || name.isEmpty()) throw new IllegalArgumentException("Cannot match a material with null or empty material name"); - Optional oldMatch = matchXMaterialWithData(name); - return oldMatch.isPresent() ? oldMatch : matchDefinedXMaterial(format(name), UNKNOWN_DATA_VALUE); - } - /** * Parses material name and data value from the specified string. * The separator for the material name and its data value is {@code :} @@ -1700,7 +1765,6 @@ public static Optional matchXMaterial(@Nonnull String name) { * * * @param name the material string that consists of the material name, data and separator character. - * * @return the parsed XMaterial. * @see #matchXMaterial(String) * @since 3.0.0 @@ -1722,6 +1786,22 @@ private static Optional matchXMaterialWithData(@Nonnull String name) return Optional.empty(); } + /** + * Parses the given material name as an XMaterial with a given data + * value in the string if attached. Check {@link #matchXMaterialWithData(String)} for more info. + * + * @see #matchXMaterialWithData(String) + * @see #matchDefinedXMaterial(String, byte) + * @since 2.0.0 + */ + @Nonnull + public static Optional matchXMaterial(@Nonnull String name) { + if (name == null || name.isEmpty()) + throw new IllegalArgumentException("Cannot match a material with null or empty material name"); + Optional oldMatch = matchXMaterialWithData(name); + return oldMatch.isPresent() ? oldMatch : matchDefinedXMaterial(format(name), UNKNOWN_DATA_VALUE); + } + /** * Parses the given material as an XMaterial. * @@ -1742,7 +1822,6 @@ public static XMaterial matchXMaterial(@Nonnull Material material) { * if not a damageable item {@link ItemStack#getDurability()}. * * @param item the ItemStack to match. - * * @return an XMaterial if matched any. * @throws IllegalArgumentException may be thrown as an unexpected exception. * @see #matchXMaterial(Material) @@ -1753,7 +1832,11 @@ public static XMaterial matchXMaterial(@Nonnull Material material) { public static XMaterial matchXMaterial(@Nonnull ItemStack item) { Objects.requireNonNull(item, "Cannot match null ItemStack"); String material = item.getType().name(); - byte data = (byte) (Data.ISFLAT || item.getType().getMaxDurability() > 0 ? 0 : item.getDurability()); + + // 1.13+ doesn't use data values at all. + // Maps are given different data values for different parts of the map also some plugins use negative values for custom images. + // Items that have durability, such as armor and tools don't use the data value to distinguish their material. + byte data = (byte) (Data.ISFLAT || material.equals("MAP") || item.getType().getMaxDurability() > 0 ? 0 : item.getDurability()); // Versions 1.9-1.12 didn't really use the items data value. if (supports(9) && !supports(13) && item.hasItemMeta() && material.equals("MONSTER_EGG")) { @@ -1791,19 +1874,42 @@ public static XMaterial matchXMaterial(@Nonnull ItemStack item) { throw new IllegalArgumentException("Unsupported material from item: " + material + " (" + data + ')'); } + /** + * Gets the XMaterial based on the material's ID (Magic Value) and data value.
+ * You should avoid using this for performance issues. + * + * @param id the ID (Magic value) of the material. + * @param data the data value of the material. + * @return a parsed XMaterial with the same ID and data value. + * @see #matchXMaterial(ItemStack) + * @since 2.0.0 + * @deprecated this method loops through all the available materials and matches their ID using {@link #getId()} + * which takes a really long time. Plugins should no longer support IDs. If you want, you can make a {@link Map} cache yourself. + * This method obviously doesn't work for 1.13+ and will not be supported. This is only here for debugging purposes. + */ + @Nonnull + @Deprecated + public static Optional matchXMaterial(int id, byte data) { + if (id < 0 || id > MAX_ID || data < 0) return Optional.empty(); + for (XMaterial materials : VALUES) { + if (materials.data == data && materials.getId() == id) return Optional.of(materials); + } + return Optional.empty(); + } + /** * The main method that parses the given material name and data value as an XMaterial. * All the values passed to this method will not be null or empty and are formatted correctly. * * @param name the formatted name of the material. * @param data the data value of the material. Is always 0 or {@link #UNKNOWN_DATA_VALUE} when {@link Data#ISFLAT} - * * @return an XMaterial (with the same data value if specified) * @see #matchXMaterial(Material) * @see #matchXMaterial(int, byte) * @see #matchXMaterial(ItemStack) * @since 3.0.0 */ + @SuppressWarnings({"DanglingJavadoc", "JavadocBlankLines"}) @Nonnull protected static Optional matchDefinedXMaterial(@Nonnull String name, byte data) { // if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null; @@ -1823,49 +1929,26 @@ protected static Optional matchDefinedXMaterial(@Nonnull String name, return (data >= 0 && isAMap) ? Optional.of(FILLED_MAP) : Optional.empty(); } - if (!Data.ISFLAT && oldXMaterial.isPlural() && (duplicated == null ? isDuplicated(name) : duplicated)) return getIfPresent(name); - return Optional.of(oldXMaterial); - } - - /** - * XMaterial Paradox (Duplication Check) - * Checks if the material has any duplicates. - *

- * Example: - *

{@code MELON, CARROT, POTATO, BEETROOT -> true} - * - * @param name the name of the material to check. - * - * @return true if there's a duplicated material for this material, otherwise false. - * @since 2.0.0 - */ - private static boolean isDuplicated(@Nonnull String name) { - // Don't use matchXMaterial() since this method is being called from matchXMaterial() itself and will cause a StackOverflowError. - return DUPLICATED.contains(name); - } + /** + * XMaterial Paradox (Duplication Check) + * I've concluded that this is just an infinite loop that keeps + * going around the Singular Form and the Plural Form materials. A waste of brain cells and a waste of time. + * This solution works just fine anyway. + * + * A solution for XMaterial Paradox. + * Manually parses the duplicated materials to find the exact material based on the server version. + * If the name ends with "S" -> Plural Form Material. + * Plural methods are only plural if they're also {@link #DUPLICATED} + * + * The only special exceptions are {@link #BRICKS} (??) and {@link #NETHER_BRICKS} + * Note: BRICKS was added because + * {@code XMaterial.matchXMaterial("BRICK")} would match {@link #BRICKS} instead in 1.8. + */ + boolean isPlural = oldXMaterial == CARROTS || oldXMaterial == POTATOES || oldXMaterial == BRICKS; - /** - * Gets the XMaterial based on the material's ID (Magic Value) and data value.
- * You should avoid using this for performance issues. - * - * @param id the ID (Magic value) of the material. - * @param data the data value of the material. - * - * @return a parsed XMaterial with the same ID and data value. - * @see #matchXMaterial(ItemStack) - * @since 2.0.0 - * @deprecated this method loops through all the available materials and matches their ID using {@link #getId()} - * which takes a really long time. Plugins should no longer support IDs. If you want, you can make a {@link Map} cache yourself. - * This method obviously doesn't work for 1.13+ and will not be supported. This is only here for debugging purposes. - */ - @Nonnull - @Deprecated - public static Optional matchXMaterial(int id, byte data) { - if (id < 0 || id > MAX_ID || data < 0) return Optional.empty(); - for (XMaterial materials : VALUES) { - if (materials.data == data && materials.getId() == id) return Optional.of(materials); - } - return Optional.empty(); + if (!Data.ISFLAT && isPlural && (duplicated == null ? isDuplicated(name) : duplicated)) + return getIfPresent(name); + return Optional.of(oldXMaterial); } /** @@ -1875,7 +1958,6 @@ public static Optional matchXMaterial(int id, byte data) { * the normal RegEx + String Methods approach for both formatted and unformatted material names. * * @param name the material name to modify. - * * @return an enum name. * @since 2.0.0 */ @@ -1913,7 +1995,6 @@ protected static String format(@Nonnull String name) { * Checks if the specified version is the same version or higher than the current server version. * * @param version the major version to be checked. "1." is ignored. E.g. 1.12 = 12 | 1.9 = 9 - * * @return true of the version is equal or higher than the current version. * @since 2.0.0 */ @@ -1925,27 +2006,6 @@ public String[] getLegacy() { return this.legacy; } - /** - * XMaterial Paradox (Duplication Check) - * I've concluded that this is just an infinite loop that keeps - * going around the Singular Form and the Plural Form materials. A waste of brain cells and a waste of time. - * This solution works just fine anyway. - *

- * A solution for XMaterial Paradox. - * Manually parses the duplicated materials to find the exact material based on the server version. - * If the name ends with "S" -> Plural Form Material. - * Plural methods are only plural if they're also {@link #DUPLICATED} - *

- * The only special exceptions are {@link #BRICKS} and {@link #NETHER_BRICKS} - * - * @return true if this material is a plural form material, otherwise false. - * @since 8.0.0 - */ - private boolean isPlural() { - // this.name().charAt(this.name().length() - 1) == 'S' - return this == CARROTS || this == POTATOES; - } - /** * Checks if the list of given material names matches the given base material. * Mostly used for configs. @@ -1980,7 +2040,6 @@ private boolean isPlural() { * Want to learn RegEx? You can mess around in RegExr website. * * @param materials the material names to check base material on. - * * @return true if one of the given material names is similar to the base material. * @since 3.1.1 */ @@ -2024,7 +2083,6 @@ public boolean isOneOf(@Nullable Collection materials) { * Use {@link #parseItem()} instead when creating new ItemStacks. * * @param item the item to change its type. - * * @see #parseItem() * @since 3.0.0 */ @@ -2045,7 +2103,6 @@ public ItemStack setType(@Nonnull ItemStack item) { * All the values passed to this method will not be null or empty and are formatted correctly. * * @param name the material name to check. - * * @return true if it's one of the legacy names, otherwise false. * @since 2.0.0 */ @@ -2080,7 +2137,7 @@ public String toString() { /** * Gets the ID (Magic value) of the material. - * https://www.minecraftinfo.com/idlist.htm + * ID List *

* Spigot added material ID support back in 1.16+ * @@ -2146,7 +2203,6 @@ public Material parseMaterial() { * Checks if an item has the same material (and data value on older versions). * * @param item item to check. - * * @return true if the material is the same as the item's material (and data value if on older versions), otherwise false. * @since 1.0.0 */ @@ -2179,7 +2235,6 @@ public boolean isSupported() { * no matter if it is supported or not. * * @param alternateMaterial the material to get if this one is not supported. - * * @return this material or the {@code alternateMaterial} if not supported. */ @Nullable @@ -2187,6 +2242,22 @@ public XMaterial or(@Nullable XMaterial alternateMaterial) { return isSupported() ? this : alternateMaterial; } + /** + * XMaterial Paradox (Duplication Check) + * Checks if the material has any duplicates. + *

+ * Example: + *

{@code MELON, CARROT, POTATO, BEETROOT -> true} + * + * @param name the name of the material to check. + * @return true if there's a duplicated material for this material, otherwise false. + * @since 2.0.0 + */ + private static boolean isDuplicated(@Nonnull String name) { + // Don't use matchXMaterial() since this method is being called from matchXMaterial() itself and will cause a StackOverflowError. + return DUPLICATED.contains(name); + } + /** * This method is needed due to Java enum initialization limitations. * It's really inefficient yes, but it's only used for initialization.