Added wildcard material testable items
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user