Bukkit snippets

Some useful code-snippets for the well-known Minecraft servermod Bukkit.

You might also like tUtils, a powerful Bukkit library.

Check if a player’s inventory is empty

/**
 * checks if player inventory is empty
 * @param p the player
 * @return true if empty
 */
 public static boolean playerInvIsEmpty(Player p){
    for(ItemStack item : p.getInventory().getContents()){
        if(item != null){
            if(item.getType() != Material.AIR){
                return false;
            }
        }
    }
    for(ItemStack item : p.getInventory().getArmorContents()){
        if(item != null){
              if(item.getType() != Material.AIR){
                  return false;
              }
         }
    }
    return true;
 }