From d28794a58760b47b267b5ea1d10b0f3902bf2c4e Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 19 Feb 2013 08:34:08 -0500 Subject: [PATCH] Slightly cleaner way to handle a few of our repair functions. --- .../skills/repair/SimpleRepairManager.java | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairManager.java b/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairManager.java index 94e7c3a23..1f7fb2935 100644 --- a/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairManager.java +++ b/src/main/java/com/gmail/nossr50/skills/repair/SimpleRepairManager.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.List; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -161,16 +160,10 @@ public class SimpleRepairManager implements RepairManager { * @param index Item index to decrement */ private void removeOneFrom(PlayerInventory inventory, int index) { - ItemStack item = inventory.getItem(index); - if (item.getAmount() > 1) { - item.setAmount(item.getAmount() - 1); - } - else { - item = new ItemStack(Material.AIR); - } + ItemStack item = inventory.getItem(index).clone(); + item.setAmount(1); - // I suspect this may not be needed, but I don't think it hurts - inventory.setItem(index, item); + inventory.removeItem(item); } /** @@ -201,8 +194,8 @@ public class SimpleRepairManager implements RepairManager { */ private int findInInventory(PlayerInventory inventory, int itemId, byte metadata) { int location = -1; - ItemStack[] contents = inventory.getContents(); + for (int i = 0; i < contents.length; i++) { ItemStack item = contents[i]; @@ -210,14 +203,8 @@ public class SimpleRepairManager implements RepairManager { continue; } - if (item.getTypeId() == itemId) { - if (item.getData().getData() == metadata) { - location = i; - } - } - - if (location != -1) { - break; + if (item.getTypeId() == itemId && item.getData().getData() == metadata) { + return location; } }