From ad442e4bd3088881b2f63762ea72a8c85723b381 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 19 Jun 2023 01:44:29 +0800 Subject: [PATCH] ItemAction tweak --- .../citizensnpcs/trait/shop/ItemAction.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java b/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java index eb047f6ac..edd1b6fad 100644 --- a/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java +++ b/main/src/main/java/net/citizensnpcs/trait/shop/ItemAction.java @@ -62,6 +62,8 @@ public class ItemAction extends NPCShopAction { if (tooDamaged(toMatch)) continue; for (int j = 0; j < items.size(); j++) { + if (toMatch == null) + break; ItemStack item = items.get(j); if (req.get(j) <= 0 || !matches(item, toMatch)) continue; @@ -75,6 +77,7 @@ public class ItemAction extends NPCShopAction { source.setItem(i, res); } req.set(j, remaining - taken); + toMatch = res; } } return req.stream().collect(Collectors.summingInt(n -> n)) <= 0; @@ -97,14 +100,6 @@ public class ItemAction extends NPCShopAction { return description; } - private boolean tooDamaged(ItemStack toMatch) { - if (!requireUndamaged) - return false; - if (SpigotUtil.isUsing1_13API()) - return toMatch.getItemMeta() instanceof Damageable && ((Damageable) toMatch.getItemMeta()).getDamage() != 0; - return toMatch.getDurability() == toMatch.getType().getMaxDurability(); - } - @Override public int getMaxRepeats(Entity entity) { if (!(entity instanceof InventoryHolder)) @@ -216,6 +211,14 @@ public class ItemAction extends NPCShopAction { }); } + private boolean tooDamaged(ItemStack toMatch) { + if (!requireUndamaged) + return false; + if (SpigotUtil.isUsing1_13API()) + return toMatch.getItemMeta() instanceof Damageable && ((Damageable) toMatch.getItemMeta()).getDamage() != 0; + return toMatch.getDurability() == toMatch.getType().getMaxDurability(); + } + @Menu(title = "Item editor", dimensions = { 4, 9 }) public static class ItemActionEditor extends InventoryMenuPage { private ItemAction base;