From 5690221c27a439edf3fc876771b006dffa3c3cdb Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 5 Sep 2021 12:53:22 +0100 Subject: [PATCH] Fixed crafting --- .../main/java/com/willfp/eco/core/items/CustomItem.java | 8 +++++++- .../src/main/java/com/willfp/eco/core/items/Items.java | 5 ++++- .../willfp/eco/core/items/args/EnchantmentArgParser.java | 9 +++++++-- .../com/willfp/eco/core/items/args/LookupArgParser.java | 5 +++-- .../com/willfp/eco/core/items/args/TextureArgParser.java | 9 +++++++-- .../eco/core/recipe/parts/ModifiedTestableItem.java | 2 -- .../com/willfp/eco/core/recipe/parts/TestableStack.java | 2 -- .../eco/core/recipe/recipes/ShapedCraftingRecipe.java | 8 ++++++++ 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java index 3be68010..16b22113 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java @@ -1,7 +1,9 @@ package com.willfp.eco.core.items; +import com.willfp.eco.core.Eco; import lombok.Getter; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -49,7 +51,11 @@ public class CustomItem implements TestableItem { this.test = test; this.item = item; - Validate.isTrue(matches(getItem()), "The item must match the test!"); + Eco.getHandler().getEcoPlugin().getScheduler().runLater(() -> { + if (!matches(getItem())) { + Bukkit.getLogger().severe("Item with key " + key + " is invalid!"); + } + }, 1); } @Override 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 d9a31cc1..4eec68aa 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 @@ -178,7 +178,10 @@ public final class Items { List> predicates = new ArrayList<>(); for (LookupArgParser argParser : ARG_PARSERS) { - predicates.add(argParser.parseArguments(modifierArgs, meta)); + Predicate predicate = argParser.parseArguments(modifierArgs, meta); + if (predicate != null) { + predicates.add(argParser.parseArguments(modifierArgs, meta)); + } } example.setItemMeta(meta); diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/args/EnchantmentArgParser.java b/eco-api/src/main/java/com/willfp/eco/core/items/args/EnchantmentArgParser.java index 4ba16964..f9c9a2ce 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/items/args/EnchantmentArgParser.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/args/EnchantmentArgParser.java @@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -16,8 +17,8 @@ import java.util.function.Predicate; */ public class EnchantmentArgParser implements LookupArgParser { @Override - public Predicate parseArguments(@NotNull final String[] args, - @NotNull final ItemMeta meta) { + public @Nullable Predicate parseArguments(@NotNull final String[] args, + @NotNull final ItemMeta meta) { Map requiredEnchantments = new HashMap<>(); for (String enchantArg : args) { @@ -37,6 +38,10 @@ public class EnchantmentArgParser implements LookupArgParser { requiredEnchantments.put(enchantment, level); } + if (requiredEnchantments.isEmpty()) { + return null; + } + if (meta instanceof EnchantmentStorageMeta storageMeta) { requiredEnchantments.forEach((enchantment, integer) -> storageMeta.addStoredEnchant(enchantment, integer, true)); } else { diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/args/LookupArgParser.java b/eco-api/src/main/java/com/willfp/eco/core/items/args/LookupArgParser.java index 4675f678..2027d384 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/items/args/LookupArgParser.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/args/LookupArgParser.java @@ -4,6 +4,7 @@ import com.willfp.eco.core.items.TestableItem; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; @@ -19,6 +20,6 @@ public interface LookupArgParser { * @param meta The ItemMeta to modify. * @return The predicate test to apply to the modified item. */ - Predicate parseArguments(@NotNull String[] args, - @NotNull ItemMeta meta); + @Nullable Predicate parseArguments(@NotNull String[] args, + @NotNull ItemMeta meta); } diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/args/TextureArgParser.java b/eco-api/src/main/java/com/willfp/eco/core/items/args/TextureArgParser.java index afb91879..caa1084c 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/items/args/TextureArgParser.java +++ b/eco-api/src/main/java/com/willfp/eco/core/items/args/TextureArgParser.java @@ -5,6 +5,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; @@ -13,8 +14,8 @@ import java.util.function.Predicate; */ public class TextureArgParser implements LookupArgParser { @Override - public Predicate parseArguments(@NotNull final String[] args, - @NotNull final ItemMeta meta) { + public @Nullable Predicate parseArguments(@NotNull final String[] args, + @NotNull final ItemMeta meta) { String skullTexture = null; for (String arg : args) { @@ -34,6 +35,10 @@ public class TextureArgParser implements LookupArgParser { SkullUtils.setSkullTexture(skullMeta, skullTexture); } + if (skullTexture == null) { + return null; + } + String finalSkullTexture = skullTexture; return test -> { if (!test.hasItemMeta()) { diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ModifiedTestableItem.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ModifiedTestableItem.java index ecca5ee9..5f209654 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ModifiedTestableItem.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/ModifiedTestableItem.java @@ -45,8 +45,6 @@ public class ModifiedTestableItem implements TestableItem { this.handle = item; this.test = test; this.example = example; - - Validate.isTrue(matches(getItem()), "The example must match the test!"); } /** diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/TestableStack.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/TestableStack.java index 56325cf1..ae3154a1 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/TestableStack.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/parts/TestableStack.java @@ -36,8 +36,6 @@ public class TestableStack implements TestableItem { this.handle = item; this.amount = amount; - - Validate.isTrue(matches(getItem()), "The example must match the test!"); } /** diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java index 426a9a97..f33e024d 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java +++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java @@ -82,6 +82,10 @@ public final class ShapedCraftingRecipe extends PluginDependent imple ShapedRecipe shapedRecipe = new ShapedRecipe(this.getKey(), this.getOutput()); shapedRecipe.shape("012", "345", "678"); for (int i = 0; i < 9; i++) { + if (parts.get(i) instanceof EmptyTestableItem) { + continue; + } + char character = String.valueOf(i).toCharArray()[0]; shapedRecipe.setIngredient(character, parts.get(i).getItem().getType()); } @@ -89,6 +93,10 @@ public final class ShapedCraftingRecipe extends PluginDependent imple ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput()); displayedRecipe.shape("012", "345", "678"); for (int i = 0; i < 9; i++) { + if (parts.get(i) instanceof EmptyTestableItem) { + continue; + } + char character = String.valueOf(i).toCharArray()[0]; ItemStack item = parts.get(i).getItem();