diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/Items.java b/eco-api/src/main/java/com/willfp/eco/core/items/Items.java index 198edbe8..bc9cbdd0 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/items/Items.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/Items.java @@ -8,6 +8,7 @@ import com.willfp.eco.core.recipe.parts.EmptyTestableItem; import com.willfp.eco.core.recipe.parts.MaterialTestableItem; import com.willfp.eco.core.recipe.parts.ModifiedTestableItem; import com.willfp.eco.core.recipe.parts.TestableStack; +import com.willfp.eco.core.recipe.parts.UnrestrictedMaterialTestableItem; import com.willfp.eco.util.NamespacedKeyUtils; import com.willfp.eco.util.NumberUtils; import org.bukkit.Material; @@ -155,11 +156,16 @@ public final class Items { String[] split = args[0].toLowerCase().split(":"); if (split.length == 1) { - Material material = Material.getMaterial(args[0].toUpperCase()); + String itemType = args[0]; + boolean isWildcard = itemType.startsWith("*"); + if (isWildcard) { + itemType = itemType.substring(1); + } + Material material = Material.getMaterial(itemType.toUpperCase()); if (material == null || material == Material.AIR) { return new EmptyTestableItem(); } - item = new MaterialTestableItem(material); + item = isWildcard ? new UnrestrictedMaterialTestableItem(material) : new MaterialTestableItem(material); } if (split.length == 2) { @@ -183,11 +189,16 @@ public final class Items { This has been superseded by id amount */ if (part == null) { - Material material = Material.getMaterial(split[0].toUpperCase()); + String itemType = split[0]; + boolean isWildcard = itemType.startsWith("*"); + if (isWildcard) { + itemType = itemType.substring(1); + } + Material material = Material.getMaterial(itemType.toUpperCase()); if (material == null || material == Material.AIR) { return new EmptyTestableItem(); } - item = new MaterialTestableItem(material); + item = isWildcard ? new UnrestrictedMaterialTestableItem(material) : new MaterialTestableItem(material); stackAmount = Integer.parseInt(split[1]); } else { item = part; diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/UnrestrictedMaterialTestableItem.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/UnrestrictedMaterialTestableItem.java new file mode 100644 index 00000000..6b6106be --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/UnrestrictedMaterialTestableItem.java @@ -0,0 +1,32 @@ +package com.willfp.eco.core.recipe.parts; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Same as material testable items, but doesn't filter out custom items. + */ +public class UnrestrictedMaterialTestableItem extends MaterialTestableItem { + /** + * Create a new simple recipe part. + * + * @param material The material. + */ + public UnrestrictedMaterialTestableItem(@NotNull final Material material) { + super(material); + } + + /** + * If the item matches the material. + * + * @param itemStack The item to test. + * @return If the item is of the specified material. + */ + @Override + public boolean matches(@Nullable final ItemStack itemStack) { + return itemStack != null && itemStack.getType() == this.getMaterial(); + } +} +