Java Code Examples for org.bukkit.inventory.Inventory#contains()

The following examples show how to use org.bukkit.inventory.Inventory#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WandCommand.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;
    if (RedProtect.get().config.getWorldClaimType(player.getWorld().getName()).equalsIgnoreCase("BLOCK") && !RedProtect.get().ph.hasPerm(player, "redprotect.command.admin.wand"))
        return true;

    if (args.length == 0) {
        Inventory inv = player.getInventory();
        Material mat = Material.getMaterial(RedProtect.get().config.configRoot().wands.adminWandID);
        ItemStack item = new ItemStack(mat);
        if (!inv.contains(mat) && inv.firstEmpty() != -1) {
            inv.addItem(item);
            RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.given").replace("{item}", item.getType().name()));
        } else {
            RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("cmdmanager.wand.nospace").replace("{item}", item.getType().name()));
        }
        return true;
    }

    RedProtect.get().lang.sendCommandHelp(sender, "wand", true);
    return true;
}
 
Example 2
Source File: Resident.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean takeItemInHand(int itemId, int itemData, int amount) throws CivException {
	Player player = CivGlobal.getPlayer(this);
	Inventory inv = player.getInventory();

	if (!inv.contains(itemId)) {
		return false;
	}

	if ((player.getItemInHand().getTypeId() != itemId) &&
			(player.getItemInHand().getTypeId() != itemData)) {
		return false;
	}
	
	ItemStack stack = player.getItemInHand();
	
	if (stack.getAmount() < amount) {
		return false;
	} else if (stack.getAmount() == amount) {
		inv.removeItem(stack);
	} else {
		stack.setAmount(stack.getAmount() - amount);
	}
	
	player.updateInventory();
	return true;
}
 
Example 3
Source File: Resident.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean takeItem(int itemId, int itemData, int amount) throws CivException {
	Player player = CivGlobal.getPlayer(this);
	Inventory inv = player.getInventory();

	if (!inv.contains(itemId)) {
		return false;
	}
	
	HashMap<Integer, ? extends ItemStack> stacks;
	stacks = inv.all(itemId);
	
	for (ItemStack stack : stacks.values()) {
		if (stack.getData().getData() != (byte)itemData) {
			continue;
		}
		
		if (stack.getAmount() <= 0)
			continue;
		
		if (stack.getAmount() < amount) {
			amount -= stack.getAmount();
			stack.setAmount(0);
			inv.removeItem(stack);
			continue;
		}
		else {			
			stack.setAmount(stack.getAmount()-amount);
			break;
		}
	}
	
	player.updateInventory();
	return true;
}
 
Example 4
Source File: BookPlayerShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
private boolean hasChestBlankBooks() {
	Block chest = this.getChest();
	if (Utils.isChest(chest.getType())) {
		Inventory chestInventory = ((Chest) chest.getState()).getInventory();
		return chestInventory.contains(Material.BOOK_AND_QUILL);
	}
	return false;
}