package cc.lukatown.icefox.plugincore.Functions;

import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

/**
 * *******************************************
 * Created by Icefox on 14-8-14.
 * Just for LukaTownMinecraftServer
 * Web: LukaTown.cc  E-Mail: icefox@LukaTown.cc
 * ********************************************
 */
public class PluginCoreFunction_Inventory {

    public static boolean API_CheckPlayerInventoryContent(Inventory inventory, int num) {
        /**
         判断某个背包空间是否足够

         使用时直接传递背包<inventory>与需要的空间数量<num>
         如果该背包<inventory>剩余空间满足数量<num>  返回真
         否则返回假

         通常多用于发放物品前的检测
         */

        ItemStack[] itemStacks = inventory.getContents();
        int tempnum = 0;

        for (int i = 0; i < 36; i++) {
            if (itemStacks[i] == null) {
                tempnum++;
                if (tempnum >= num) {
                    return true;
                }
            }
        }

        return false;
    }
}
