Slightly cleaner way to handle a few of our repair functions.

This commit is contained in:
GJ 2013-02-19 08:34:08 -05:00
parent 19292c8007
commit d28794a587

View File

@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
@ -161,16 +160,10 @@ public class SimpleRepairManager implements RepairManager {
* @param index Item index to decrement * @param index Item index to decrement
*/ */
private void removeOneFrom(PlayerInventory inventory, int index) { private void removeOneFrom(PlayerInventory inventory, int index) {
ItemStack item = inventory.getItem(index); ItemStack item = inventory.getItem(index).clone();
if (item.getAmount() > 1) { item.setAmount(1);
item.setAmount(item.getAmount() - 1);
}
else {
item = new ItemStack(Material.AIR);
}
// I suspect this may not be needed, but I don't think it hurts inventory.removeItem(item);
inventory.setItem(index, item);
} }
/** /**
@ -201,8 +194,8 @@ public class SimpleRepairManager implements RepairManager {
*/ */
private int findInInventory(PlayerInventory inventory, int itemId, byte metadata) { private int findInInventory(PlayerInventory inventory, int itemId, byte metadata) {
int location = -1; int location = -1;
ItemStack[] contents = inventory.getContents(); ItemStack[] contents = inventory.getContents();
for (int i = 0; i < contents.length; i++) { for (int i = 0; i < contents.length; i++) {
ItemStack item = contents[i]; ItemStack item = contents[i];
@ -210,14 +203,8 @@ public class SimpleRepairManager implements RepairManager {
continue; continue;
} }
if (item.getTypeId() == itemId) { if (item.getTypeId() == itemId && item.getData().getData() == metadata) {
if (item.getData().getData() == metadata) { return location;
location = i;
}
}
if (location != -1) {
break;
} }
} }