Package com.sk89q.craftbook.util

Examples of com.sk89q.craftbook.util.ItemInfo


        return player.getItemInHand().getDurability();
    }

    @Override
    public ItemInfo getHeldItemInfo () {
        return new ItemInfo(Material.getMaterial(getHeldItemType()), getHeldItemData());
    }
View Full Code Here


    @Override
    public void loadConfiguration (YAMLProcessor config, String path) {

        config.setComment(path + "item", "The item that the lightstone mechanic uses.");
        item = new ItemInfo(config.getString(path + "item", "GLOWSTONE_DUST"));
    }
View Full Code Here

        @Override
        public void verify(ChangedSign sign) throws ICVerificationException {

            if(sign.getLine(2) == null || sign.getLine(2).isEmpty())
                throw new ICVerificationException("A block must be provided on line 2!");
            ItemInfo item = new ItemInfo(sign.getLine(2));
            if(item.getType() == null)
                throw new ICVerificationException("An invalid block was provided on line 2!");
            if(blockBlacklist.contains(item))
                throw new ICVerificationException("A blacklisted block was provided on line 2!");
        }
View Full Code Here

    private boolean recurseColumn(LocalPlayer player, ChangedSign sign, Block block, Set<GateColumn> visitedColumns, Boolean close, boolean smallSearchSize) {

        if (limitColumns && visitedColumns.size() > columnLimit)
            return false;

        if (!isValidGateBlock(sign, smallSearchSize, new ItemInfo(block), true)) return false;

        CraftBookPlugin.logDebugMessage("Found a possible gate column at " + block.getX() + ":" + block.getY() + ":" + block.getZ(), "gates.search");

        int x = block.getX();
        int z = block.getZ();

        GateColumn column = new GateColumn(sign, block, smallSearchSize);

        // The block above the gate cannot be air -- it has to be some
        // non-fence block
        if (block.getWorld().getBlockAt(x, column.getStartingY() + 1, z).getType() == Material.AIR) return false;

        if (visitedColumns.contains(column)) return false;

        visitedColumns.add(column);

        if (close == null)
            close = !isValidGateBlock(sign, smallSearchSize, new ItemInfo(block.getWorld().getBlockAt(x, column.getStartingY() - 1, z)), true);

        CraftBookPlugin.logDebugMessage("Valid column at " + block.getX() + ":" + block.getY() + ":" + block.getZ() + " is being " + (close ? "closed" : "opened"), "gates.search");
        CraftBookPlugin.logDebugMessage("Column Top: " + column.getStartingY() + " End: " + column.getEndingY(), "gates.search");
        // Recursively go to connected fence blocks of the same level
        // and 'close' or 'open' them
View Full Code Here

    private boolean toggleColumn(LocalPlayer player, ChangedSign sign, Block block, GateColumn column, boolean close, Set<GateColumn> visitedColumns, boolean smallSearchSize) {

        // If we want to close the gate then we replace air/water blocks
        // below with fence blocks; otherwise, we want to replace fence
        // blocks below with air
        ItemInfo item;
        if (close)
            item = new ItemInfo(column.getStartingPoint());
        else
            item = new ItemInfo(Material.AIR, 0);

        CraftBookPlugin.logDebugMessage("Setting column at " + block.getX() + ":" + block.getY() + ":" + block.getZ() + " to " + item.toString(), "gates.search");

        for (Vector bl : column.getRegion()) {

            Block blo = BukkitUtil.toBlock(new BlockWorldVector(BukkitUtil.toWorldVector(block).getWorld(), bl));

            //sign = BukkitUtil.toChangedSign(sign.getSign().getBlock());

            if(sign == null) {
                CraftBookPlugin.logDebugMessage("Invalid Sign!", "gates.search");
                return false;
            }

            ChangedSign otherSign = null;

            Block ot = SignUtil.getNextSign(BukkitUtil.toSign(sign).getBlock(), sign.getLine(1), 4);
            if(ot != null)
                otherSign = BukkitUtil.toChangedSign(ot);

            if (sign.getLine(2).equalsIgnoreCase("NoReplace")) {
                // If NoReplace is on line 3 of sign, do not replace blocks.
                if (blo.getType() != Material.AIR && !isValidGateBlock(sign, smallSearchSize, new ItemInfo(blo), true))
                    break;
            } else // Allowing water allows the use of gates as flood gates
                if (!canPassThrough(sign, smallSearchSize, blo))
                    break;

            // bag.setBlockID(w, x, y1, z, ID);
            if (CraftBookPlugin.inst().getConfiguration().safeDestruction) {
                if (!close || hasEnoughBlocks(sign, otherSign)) {
                    if (!close && isValidGateBlock(sign, smallSearchSize, new ItemInfo(blo), true))
                        addBlocks(sign, 1);
                    else if (close && canPassThrough(sign, smallSearchSize, blo) && isValidGateBlock(sign, smallSearchSize, item, true) && !item.isSame(blo))
                        removeBlocks(sign, 1);
                    blo.setTypeIdAndData(item.getId(), (byte) item.getData(), true);
                } else if (close && !hasEnoughBlocks(sign, otherSign) && isValidGateBlock(sign, smallSearchSize, item, true))
                    if (player != null) {
                        player.printError("mech.not-enough-blocks");
                        return false;
                    }
            } else
                blo.setTypeIdAndData(item.getId(), (byte) item.getData(), true);

            CraftBookPlugin.logDebugMessage("Set block " + bl.getX() + ":" + bl.getY() + ":" + bl.getZ() + " to " + item.toString(), "gates.search");

            recurseColumn(player, sign, blo.getRelative(1, 0, 0), visitedColumns, close, smallSearchSize);
            recurseColumn(player, sign, blo.getRelative(-1, 0, 0), visitedColumns, close, smallSearchSize);
            recurseColumn(player, sign, blo.getRelative(0, 0, 1), visitedColumns, close, smallSearchSize);
            recurseColumn(player, sign, blo.getRelative(0, 0, -1), visitedColumns, close, smallSearchSize);
View Full Code Here

        if (!sign.getLine(1).equals("[Gate]") && !sign.getLine(1).equals("[DGate]")) return;

        boolean smallSearchSize = sign.getLine(1).equals("[DGate]");

        ItemInfo gateBlock = getGateBlock(sign, smallSearchSize);

        if (CraftBookPlugin.inst().getConfiguration().safeDestruction && (gateBlock == null || gateBlock.getType() == Material.AIR || gateBlock.getType() == player.getHeldItemInfo().getType()) && isValidGateBlock(sign, smallSearchSize, player.getHeldItemInfo(), false)) {

            if (!player.hasPermission("craftbook.mech.gate.restock")) {
                if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
                    player.printError("mech.restock-permission");
                return;
View Full Code Here

                return;
            }
            // get the material that this gate should toggle and verify it
            String line0 = event.getLine(0).trim();
            if (line0 != null && !line0.isEmpty()) {
                if (!isValidGateBlock(new ItemInfo(line0))) {
                    player.printError("Line 1 needs to be a valid block id.");
                    SignUtil.cancelSign(event);
                    return;
                }
            }
            event.setLine(1, "[Gate]");
            if (event.getLine(3).equalsIgnoreCase("infinite") && !player.hasPermission("craftbook.mech.gate.infinite"))
                event.setLine(3, "0");
            else if (!event.getLine(3).equalsIgnoreCase("infinite"))
                event.setLine(3, "0");
            player.print("mech.gate.create");
        } else if (event.getLine(1).equalsIgnoreCase("[DGate]")) {
            if (!player.hasPermission("craftbook.mech.gate") && !player.hasPermission("craftbook.mech.dgate")) {
                if(CraftBookPlugin.inst().getConfiguration().showPermissionMessages)
                    player.printError("mech.create-permission");
                SignUtil.cancelSign(event);
                return;
            }
            // get the material that this gate should toggle and verify it
            String line0 = event.getLine(0).trim();
            if (line0 != null && !line0.isEmpty()) {
                if (!isValidGateBlock(new ItemInfo(line0))) {
                    player.printError("mech.gate.valid-item");
                    SignUtil.cancelSign(event);
                    return;
                }
            }
View Full Code Here

     * @param check Should search.
     * @return
     */
    public boolean isValidGateBlock(ChangedSign sign, boolean smallSearchSize, ItemInfo block, boolean check) {

        ItemInfo type;

        if (sign != null && !sign.getLine(0).isEmpty()) {
            try {
                ItemInfo def = new ItemInfo(sign.getLine(0));
                return block.equals(def);
            } catch (Exception e) {
                if (check) {
                    type = getGateBlock(sign, smallSearchSize);
                    if(type == null || type.getType() == Material.AIR)
View Full Code Here

            return;
        }

        int amount = getBlocks(sign);
        if (amount > 0) {
            ItemInfo type = getGateBlock(sign, sign.getLine(1).equals("[DGate]"));
            if(type == null || type.getType() == Material.AIR)
                type = new ItemInfo(Material.FENCE, 0);
            ItemStack toDrop = new ItemStack(type.getType(), amount, (short) type.getData());
            event.getBlock().getWorld().dropItemNaturally(BlockUtil.getBlockCentre(event.getBlock()), toDrop);
        }
    }
View Full Code Here

        passableBlocks[7] = Material.DEAD_BUSH;
        passableBlocks[8] = Material.AIR;

        for (Material aPassableBlock : passableBlocks) { if (aPassableBlock == t.getType()) return true; }

        return isValidGateBlock(sign, smallSearchSize, new ItemInfo(t), true);
    }
View Full Code Here

TOP

Related Classes of com.sk89q.craftbook.util.ItemInfo

Copyright © 2018 www.massapicom. 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.