From c7d38fb88e286b56bc41b98243b2b5146fbcc3ea Mon Sep 17 00:00:00 2001 From: Roch Blonndiaux Date: Thu, 27 Oct 2022 16:08:35 +0200 Subject: [PATCH] MMOItems craft repair --- .../mmoitems/listener/ItemListener.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java index 18e100b4..b14e9a4e 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/ItemListener.java @@ -22,6 +22,7 @@ import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,7 +62,7 @@ public class ItemListener implements Listener { final CraftingInventory inv = e.getInventory(); final ItemStack air = new ItemStack(Material.AIR); - inv.setResult(air); + //inv.setResult(air); Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> { List items = Arrays.stream(inv.getMatrix()) .filter(Objects::nonNull) @@ -72,11 +73,17 @@ public class ItemListener implements Listener { final NBTItem nbtItem = NBTItem.get(itemStack); return nbtItem.hasTag("MMOITEMS_DISABLE_REPAIRING") && nbtItem.getBoolean("MMOITEMS_DISABLE_REPAIRING"); }); - boolean hasDurability = items.stream().allMatch(itemStack -> new DurabilityItem(player, itemStack).isValid()); - ItemStack result; - if (repairDisabled || !hasDurability) + boolean repairPartiallyDisabled = items.stream() + .anyMatch(itemStack -> { + final NBTItem nbtItem = NBTItem.get(itemStack); + return nbtItem.hasTag("MMOITEMS_DISABLE_REPAIRING") && nbtItem.getBoolean("MMOITEMS_DISABLE_REPAIRING"); + }); + boolean hasCustomDurability = items.stream().allMatch(itemStack -> new DurabilityItem(player, itemStack).isValid()); + + ItemStack result = null; + if (repairDisabled || repairPartiallyDisabled) result = air; - else { + else if (hasCustomDurability) { result = items.get(0); DurabilityItem durabilityItem = new DurabilityItem(player, result); int durability = items.stream() @@ -86,8 +93,10 @@ public class ItemListener implements Listener { durabilityItem.addDurability(durabilityItem.getMaxDurability() - Math.min(durabilityItem.getMaxDurability(), durability)); result = durabilityItem.toItem(); } - inv.setItem(0, result); - player.updateInventory(); + if (repairDisabled || hasCustomDurability) { + inv.setResult(result); + player.updateInventory(); + } }, 1); }