Examples of Chest


Examples of org.bukkit.block.Chest

    }

    public boolean damageHoe() {

        if (getBackBlock().getRelative(0, 1, 0).getType() == Material.CHEST) {
            Chest c = (Chest) getBackBlock().getRelative(0, 1, 0).getState();
            for (int i = 290; i <= 294; i++) {
                for (int slot = 0; slot < c.getInventory().getSize(); slot++) {
                    if (c.getInventory().getItem(slot) == null || c.getInventory().getItem(slot).getTypeId() != i)
                        continue;
                    if (ItemUtil.isStackValid(c.getInventory().getItem(slot))) {
                        ItemStack item = c.getInventory().getItem(slot);
                        item.setDurability((short) (item.getDurability() + 1));
                        if(item.getDurability() > ItemUtil.getMaxDurability(item.getType()))
                            item = null;
                        c.getInventory().setItem(slot, item);
                        return true;
                    }
                }
            }
        }
View Full Code Here

Examples of org.bukkit.block.Chest

        }
        BlockState state = bl.getState();
        if (!(state instanceof Chest)) {
            return false;
        }
        Chest c = (Chest) state;
        ItemStack[] is = c.getInventory().getContents();
        for (int i = 0; i < is.length; i++) {
            final ItemStack stack = is[i];
            if (stack == null) {
                continue;
            }
            if (stack.getAmount() > 0 && stack.getType() == item.getType()) {
                if (item.getData() != -1 && stack.getData().getData() != item.getData()) {
                    continue;
                }
                if (stack.getAmount() == 1) {
                    is[i] = new ItemStack(Material.AIR, 0);
                } else {
                    stack.setAmount(stack.getAmount() - 1);
                }
                c.getInventory().setContents(is);
                c.update();
                return true;
            }
        }
        return false;
    }
View Full Code Here

Examples of org.bukkit.block.Chest

            final BlockState blockState = block.getState();
            boolean fake = false;
            switch (block.getType()) {
                case TRAPPED_CHEST:
                case CHEST:
                    final Chest chest = (Chest) blockState;
                    inventory = this.plugin.getServer().createInventory(player, chest.getInventory().getSize());
                    inventory.setContents(chest.getInventory().getContents());
                    fake = true;
                    break;
                case ENDER_CHEST:
                    if (this.plugin.getServer().getPluginManager().isPluginEnabled("EnderChestPlus") && VanishPerms.canNotInteract(player)) {
                        event.setCancelled(true);
View Full Code Here

Examples of org.bukkit.block.Chest

        int z = b.getZ();
        Block bl = BukkitUtil.toSign(getSign()).getBlock().getWorld().getBlockAt(x, y, z);
        ItemStack stack = null;
        Inventory inv = null;
        if (bl.getType() == Material.CHEST) {
            Chest c = (Chest) bl.getState();
            for (ItemStack it : c.getInventory().getContents()) {
                if (ItemUtil.isStackValid(it)) {
                    if(item == null || ItemUtil.areItemsIdentical(it, item)) {
                        stack = it;
                        inv = c.getInventory();
                        break;
                    }
                }
            }
        } else if (bl.getType() == Material.FURNACE || bl.getType() == Material.BURNING_FURNACE) {
            Furnace c = (Furnace) bl.getState();
            stack = c.getInventory().getResult();
            inv = c.getInventory();
        } else if (bl.getType() == Material.BREWING_STAND) {
            BrewingStand c = (BrewingStand) bl.getState();
            for (ItemStack it : c.getInventory().getContents()) {
                if (ItemUtil.isStackValid(it)) {
                    if (ItemUtil.areItemsIdentical(it, c.getInventory().getIngredient())) {
                        continue;
                    }
                    if(item == null || ItemUtil.areItemsIdentical(it, item)) {
                        stack = it;
                        inv = c.getInventory();
                        break;
                    }
                }
            }
        } else if (bl.getType() == Material.DISPENSER) {
            Dispenser c = (Dispenser) bl.getState();
            for (ItemStack it : c.getInventory().getContents()) {
                if (ItemUtil.isStackValid(it)) {
                    if(item == null || ItemUtil.areItemsIdentical(it, item)) {
                        stack = it;
                        inv = c.getInventory();
                        break;
                    }
                }
            }
        }
View Full Code Here

Examples of org.bukkit.block.Chest

        m = parse(m);
        Block chest = getBackBlock().getRelative(0, -1, 0);

        if (chest.getTypeId() == BlockID.CHEST) {
            Chest c = (Chest) chest.getState();

            if (((Factory) getFactory()).buckets) {

                HashMap<Integer, ItemStack> over = c.getInventory().removeItem(
                        new ItemStack(m == BlockID.LAVA ? ItemID.LAVA_BUCKET : ItemID.WATER_BUCKET, 1));
                if (over.isEmpty()) return m;
            } else {

                HashMap<Integer, ItemStack> over = c.getInventory().removeItem(new ItemStack(m, 1));
                if (over.isEmpty()) return m;

                over = c.getInventory().removeItem(new ItemStack(unparse(m), 1));
                if (over.isEmpty()) return m;
            }
        }

        return BlockID.AIR;
View Full Code Here

Examples of org.bukkit.block.Chest

    public boolean consumeWater() {

        Block chest = getBackBlock().getRelative(0, 1, 0);
        if (chest.getType() == Material.CHEST) {
            Chest c = (Chest) chest.getState();
            HashMap<Integer, ItemStack> over = c.getInventory().removeItem(new ItemStack(Material.WATER, 1));
            if (over.isEmpty()) return true;
            over = c.getInventory().removeItem(new ItemStack(Material.STATIONARY_WATER, 1));
            if (over.isEmpty()) return true;
            over = c.getInventory().removeItem(new ItemStack(Material.WATER_BUCKET, 1));
            if (over.isEmpty()) {
                c.getInventory().addItem(new ItemStack(Material.BUCKET, 1));
                return true;
            }
        } else if (chest.getType() == Material.WATER || chest.getType() == Material.STATIONARY_WATER) {
            chest.setType(Material.AIR);
            return true;
View Full Code Here

Examples of org.bukkit.block.Chest

        if (item != null && !plantableItem(item)) return false;

        if (getBackBlock().getRelative(0, 1, 0).getType() == Material.CHEST || getBackBlock().getRelative(0, 1, 0).getType() == Material.TRAPPED_CHEST) {

            Chest c = (Chest) getBackBlock().getRelative(0, 1, 0).getState();
            for (ItemStack it : c.getInventory().getContents()) {

                if (!ItemUtil.isStackValid(it)) continue;
                if (!plantableItem(it)) continue;

                if (item != null && !ItemUtil.areItemsIdentical(it, item)) continue;

                Block b;

                if ((b = searchBlocks(it)) != null) {
                    if (c.getInventory().removeItem(new ItemStack(it.getType(), 1, it.getDurability())).isEmpty()) {
                        return plantBlockAt(it, b);
                    }
                }
            }
        } else {
View Full Code Here

Examples of org.bukkit.block.Chest

        Block b = SignUtil.getBackBlock(event.getBlock());
        Block fire = b.getRelative(0, 1, 0);
        Block cb = b.getRelative(0, 2, 0);
        if (cb.getType() == Material.CHEST) {
            if (fire.getType() == Material.FIRE) {
                Chest chest = (Chest) cb.getState();
                List<ItemStack> items;
                if(cookingPotOres)
                    items = ItemUtil.getRawMaterials(chest.getInventory());
                else
                    items = ItemUtil.getRawFood(chest.getInventory());

                if(items.size() == 0) return;

                if(lastTick < 500) {
                    lastTick = cookingPotSuperFast ? lastTick + getMultiplier(sign) : lastTick + Math.min(getMultiplier(sign), 5);
                    if(getMultiplier(sign) > 0)
                        decreaseMultiplier(sign, 1);
                }
                if (lastTick >= 50) {
                    for (ItemStack i : items) {

                        if (!ItemUtil.isStackValid(i)) continue;
                        ItemStack cooked = ItemUtil.getCookedResult(i);
                        if (cooked == null) {
                            if (cookingPotOres)
                                cooked = ItemUtil.getSmeletedResult(i);
                            if (cooked == null) continue;
                        }
                        if (chest.getInventory().addItem(cooked).isEmpty()) {
                            ItemStack toRemove = i.clone();
                            toRemove.setAmount(1);
                            chest.getInventory().removeItem(toRemove);
                            chest.update();
                            lastTick -= 50;
                            break;
                        }
                    }
                }
View Full Code Here

Examples of org.bukkit.block.Chest

    public int getFromChest() {

        Block chest = getBackBlock().getRelative(0, -1, 0);

        if (chest.getTypeId() == BlockID.CHEST) {
            Chest c = (Chest) chest.getState();
            if (((Factory) getFactory()).buckets) {
                HashMap<Integer, ItemStack> over = c.getInventory().removeItem(new ItemStack(ItemID.WATER_BUCKET, 1));
                if (over.isEmpty()) return BlockID.WATER;
                over = c.getInventory().removeItem(new ItemStack(ItemID.LAVA_BUCKET, 1));
                if (over.isEmpty()) return BlockID.LAVA;
            } else {
                HashMap<Integer, ItemStack> over = c.getInventory().removeItem(new ItemStack(BlockID.WATER, 1));
                if (over.isEmpty()) return BlockID.WATER;
                over = c.getInventory().removeItem(new ItemStack(BlockID.STATIONARY_WATER, 1));
                if (over.isEmpty()) return BlockID.WATER;
                over = c.getInventory().removeItem(new ItemStack(BlockID.LAVA, 1));
                if (over.isEmpty()) return BlockID.LAVA;
                over = c.getInventory().removeItem(new ItemStack(BlockID.STATIONARY_LAVA, 1));
                if (over.isEmpty()) return BlockID.LAVA;
            }
        }

        return BlockID.AIR;
View Full Code Here

Examples of org.bukkit.block.Chest

    public boolean doesChestContain(Material item) {

        if (chest.getType() == Material.CHEST) {

            Chest c = (Chest) chest.getState();
            return c.getInventory().contains(item);
        }

        return false;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.