Compare commits

..

3 Commits
6.7.1 ... 6.7.2

Author SHA1 Message Date
Auxilor
874a9b4f32 Updated to 6.7.2 2021-09-05 12:53:33 +01:00
Auxilor
5690221c27 Fixed crafting 2021-09-05 12:53:22 +01:00
Auxilor
f19b143804 Added validation to testable items 2021-09-05 12:02:35 +01:00
8 changed files with 40 additions and 8 deletions

View File

@@ -1,6 +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;
@@ -47,6 +50,12 @@ public class CustomItem implements TestableItem {
this.key = key;
this.test = test;
this.item = item;
Eco.getHandler().getEcoPlugin().getScheduler().runLater(() -> {
if (!matches(getItem())) {
Bukkit.getLogger().severe("Item with key " + key + " is invalid!");
}
}, 1);
}
@Override

View File

@@ -178,7 +178,10 @@ public final class Items {
List<Predicate<ItemStack>> predicates = new ArrayList<>();
for (LookupArgParser argParser : ARG_PARSERS) {
predicates.add(argParser.parseArguments(modifierArgs, meta));
Predicate<ItemStack> predicate = argParser.parseArguments(modifierArgs, meta);
if (predicate != null) {
predicates.add(argParser.parseArguments(modifierArgs, meta));
}
}
example.setItemMeta(meta);

View File

@@ -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<ItemStack> parseArguments(@NotNull final String[] args,
@NotNull final ItemMeta meta) {
public @Nullable Predicate<ItemStack> parseArguments(@NotNull final String[] args,
@NotNull final ItemMeta meta) {
Map<Enchantment, Integer> 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 {

View File

@@ -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<ItemStack> parseArguments(@NotNull String[] args,
@NotNull ItemMeta meta);
@Nullable Predicate<ItemStack> parseArguments(@NotNull String[] args,
@NotNull ItemMeta meta);
}

View File

@@ -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<ItemStack> parseArguments(@NotNull final String[] args,
@NotNull final ItemMeta meta) {
public @Nullable Predicate<ItemStack> 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()) {

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.core.recipe.parts;
import com.willfp.eco.core.items.TestableItem;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@@ -82,6 +82,10 @@ public final class ShapedCraftingRecipe extends PluginDependent<EcoPlugin> 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<EcoPlugin> 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();

View File

@@ -1,2 +1,2 @@
version = 6.7.1
version = 6.7.2
plugin-name = eco