Skip to content

Commit

Permalink
More use of Material instead of ids...
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Jun 14, 2014
1 parent c23e5e1 commit ae9415a
Showing 1 changed file with 8 additions and 3 deletions.
@@ -1,5 +1,6 @@
package fr.neatmonster.nocheatplus.utilities;

import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
Expand All @@ -14,6 +15,10 @@
*/
public class InventoryUtil {

private static boolean isEmpty(Material mat) {
return mat == null || mat == Material.AIR;
}

/**
* Does not account for special slots like armor.
* @param inventory
Expand All @@ -24,7 +29,7 @@ public static int getFreeSlots(final Inventory inventory){
int count = 0;
for (int i = 0; i < contents.length; i++){
final ItemStack stack = contents[i];
if (stack == null || stack.getTypeId() == 0){
if (stack == null || isEmpty(stack.getType())){
count ++;
}
}
Expand All @@ -40,7 +45,7 @@ public static int getFreeSlots(final Inventory inventory){
public static int getStackCount(final Inventory inventory, final ItemStack reference) {
if (inventory == null) return 0;
if (reference == null) return getFreeSlots(inventory);
final int id = reference.getTypeId();
final Material mat = reference.getType();
final int durability = reference.getDurability();
final ItemStack[] contents = inventory.getContents();
int count = 0;
Expand All @@ -49,7 +54,7 @@ public static int getStackCount(final Inventory inventory, final ItemStack refer
if (stack == null){
continue;
}
else if (stack.getTypeId() == id && stack.getDurability() == durability){
else if (stack.getType() == mat && stack.getDurability() == durability){
count ++;
}
}
Expand Down

0 comments on commit ae9415a

Please sign in to comment.