Search in sources :

Example 26 with BlockFace

use of org.bukkit.block.BlockFace in project Bukkit by Bukkit.

the class Lever method setFacingDirection.

/**
     * Sets the direction this lever is pointing in
     */
public void setFacingDirection(BlockFace face) {
    byte data = (byte) (getData() & 0x8);
    BlockFace attach = getAttachedFace();
    if (attach == BlockFace.DOWN) {
        switch(face) {
            case SOUTH:
            case NORTH:
                data |= 0x5;
                break;
            case EAST:
            case WEST:
                data |= 0x6;
                break;
        }
    } else if (attach == BlockFace.UP) {
        switch(face) {
            case SOUTH:
            case NORTH:
                data |= 0x7;
                break;
            case EAST:
            case WEST:
                data |= 0x0;
                break;
        }
    } else {
        switch(face) {
            case EAST:
                data |= 0x1;
                break;
            case WEST:
                data |= 0x2;
                break;
            case SOUTH:
                data |= 0x3;
                break;
            case NORTH:
                data |= 0x4;
                break;
        }
    }
    setData(data);
}
Also used : BlockFace(org.bukkit.block.BlockFace)

Example 27 with BlockFace

use of org.bukkit.block.BlockFace in project Minigames by AddstarMC.

the class ScoreboardDisplay method load.

@SuppressWarnings("deprecation")
public static ScoreboardDisplay load(Minigame minigame, ConfigurationSection section) {
    int width = section.getInt("width");
    int height = section.getInt("height");
    Location location = MinigameUtils.loadShortLocation(section.getConfigurationSection("location"));
    BlockFace facing = BlockFace.valueOf(section.getString("dir"));
    // from invalid world
    if (location == null) {
        return null;
    }
    ScoreboardDisplay display = new ScoreboardDisplay(minigame, width, height, location, facing);
    display.setOrder(ScoreboardOrder.valueOf(section.getString("order")));
    // Convert type to new stat
    if (section.contains("type")) {
        ScoreboardType type = ScoreboardType.valueOf(section.getString("type"));
        switch(type) {
            case BEST_KILLS:
                display.setStat(MinigameStats.Kills, StatValueField.Max);
                break;
            case BEST_SCORE:
                display.setStat(MinigameStats.Score, StatValueField.Max);
                break;
            case COMPLETIONS:
                display.setStat(MinigameStats.Wins, StatValueField.Total);
                break;
            case FAILURES:
                display.setStat(MinigameStats.Losses, StatValueField.Total);
                break;
            case LEAST_DEATHS:
                display.setStat(MinigameStats.Deaths, StatValueField.Min);
                break;
            case LEAST_REVERTS:
                display.setStat(MinigameStats.Reverts, StatValueField.Min);
                break;
            case LEAST_TIME:
                display.setStat(MinigameStats.CompletionTime, StatValueField.Min);
                break;
            case TOTAL_DEATHS:
                display.setStat(MinigameStats.Deaths, StatValueField.Total);
                break;
            case TOTAL_KILLS:
                display.setStat(MinigameStats.Kills, StatValueField.Total);
                break;
            case TOTAL_REVERTS:
                display.setStat(MinigameStats.Reverts, StatValueField.Total);
                break;
            case TOTAL_SCORE:
                display.setStat(MinigameStats.Score, StatValueField.Total);
                break;
            case TOTAL_TIME:
                display.setStat(MinigameStats.CompletionTime, StatValueField.Total);
                break;
            default:
                break;
        }
        section.set("type", null);
    // Load stat
    } else {
        MinigameStat stat = MinigameStats.getStat(section.getString("stat", "wins"));
        StatValueField field = StatValueField.valueOf(section.getString("field", "Total"));
        display.setStat(stat, field);
    }
    Block block = location.getBlock();
    block.setMetadata("MGScoreboardSign", new FixedMetadataValue(Minigames.plugin, true));
    block.setMetadata("Minigame", new FixedMetadataValue(Minigames.plugin, minigame));
    return display;
}
Also used : StatValueField(au.com.mineauz.minigames.stats.StatValueField) MinigameStat(au.com.mineauz.minigames.stats.MinigameStat) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Location(org.bukkit.Location)

Example 28 with BlockFace

use of org.bukkit.block.BlockFace in project Minigames by AddstarMC.

the class ScoreboardDisplay method getSignBlocks.

private List<Block> getSignBlocks(boolean onlySigns) {
    // Find the horizontal direction (going across the the signs, left to right) 
    BlockFace horizontal;
    switch(facing) {
        case NORTH:
            horizontal = BlockFace.WEST;
            break;
        case SOUTH:
            horizontal = BlockFace.EAST;
            break;
        case WEST:
            horizontal = BlockFace.SOUTH;
            break;
        case EAST:
            horizontal = BlockFace.NORTH;
            break;
        default:
            throw new AssertionError("Invalid facing " + facing);
    }
    List<Block> blocks = Lists.newArrayListWithCapacity(width * height);
    // Find the corner that is the top left part of the scoreboard
    Location min = rootBlock.clone();
    min.add(-horizontal.getModX() * (width / 2), -1, -horizontal.getModZ() * (width / 2));
    // Grab each sign of the scoreboards in order 
    Block block = min.getBlock();
    for (int y = 0; y < height; ++y) {
        Block start = block;
        for (int x = 0; x < width; ++x) {
            // Only add signs
            if (block.getType() == Material.WALL_SIGN || (!onlySigns && block.getType() == Material.AIR)) {
                blocks.add(block);
            }
            block = block.getRelative(horizontal);
        }
        block = start.getRelative(BlockFace.DOWN);
    }
    return blocks;
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Location(org.bukkit.Location)

Example 29 with BlockFace

use of org.bukkit.block.BlockFace in project Minigames by AddstarMC.

the class RecorderData method addBlock.

public BlockData addBlock(BlockState block, MinigamePlayer modifier) {
    BlockData bdata = new BlockData(block, modifier);
    String sloc = String.valueOf(bdata.getLocation().getBlockX()) + ":" + bdata.getLocation().getBlockY() + ":" + bdata.getLocation().getBlockZ();
    if (!blockdata.containsKey(sloc)) {
        if (block.getType() == Material.CHEST) {
            Chest chest = (Chest) block;
            if (chest.getInventory().getSize() > 27) {
                Location loc = block.getLocation().clone();
                boolean isRight = false;
                BlockFace dir = ((org.bukkit.material.Chest) chest.getData()).getFacing();
                BlockData secondChest = null;
                //West = -z; East = +z; North = +x; South = -x;
                if (dir == BlockFace.NORTH) {
                    loc.setX(loc.getX() + 1);
                    if (loc.getBlock().getType() == Material.CHEST) {
                        isRight = true;
                    }
                    secondChest = addBlock(loc.getBlock().getState(), modifier);
                } else if (dir == BlockFace.SOUTH) {
                    loc.setX(loc.getX() - 1);
                    if (loc.getBlock().getType() == Material.CHEST) {
                        isRight = true;
                    }
                    secondChest = addBlock(loc.getBlock().getState(), modifier);
                } else if (dir == BlockFace.WEST) {
                    loc.setZ(loc.getZ() - 1);
                    if (loc.getBlock().getType() == Material.CHEST) {
                        isRight = true;
                    }
                    secondChest = addBlock(loc.getBlock().getState(), modifier);
                } else if (dir == BlockFace.EAST) {
                    loc.setZ(loc.getZ() + 1);
                    if (loc.getBlock().getType() == Material.CHEST) {
                        isRight = true;
                    }
                    secondChest = addBlock(loc.getBlock().getState(), modifier);
                }
                if (!isRight) {
                    ItemStack[] items = new ItemStack[chest.getInventory().getContents().length];
                    for (int i = 0; i < items.length; i++) {
                        if (chest.getInventory().getContents()[i] != null)
                            items[i] = chest.getInventory().getContents()[i].clone();
                    }
                    bdata.setItems(items);
                    if (minigame.isRandomizeChests())
                        bdata.randomizeContents(minigame.getMinChestRandom(), minigame.getMaxChestRandom());
                } else {
                    if (secondChest.getItems() == null) {
                        ItemStack[] items = new ItemStack[chest.getInventory().getContents().length];
                        for (int i = 0; i < items.length; i++) {
                            if (chest.getInventory().getContents()[i] != null)
                                items[i] = chest.getInventory().getContents()[i].clone();
                        }
                        secondChest.setItems(items);
                        if (minigame.isRandomizeChests())
                            secondChest.randomizeContents(minigame.getMinChestRandom(), minigame.getMaxChestRandom());
                    }
                }
            } else {
                ItemStack[] items = new ItemStack[chest.getInventory().getContents().length];
                for (int i = 0; i < items.length; i++) {
                    if (chest.getInventory().getContents()[i] != null)
                        items[i] = chest.getInventory().getContents()[i].clone();
                }
                bdata.setItems(items);
                if (minigame.isRandomizeChests())
                    bdata.randomizeContents(minigame.getMinChestRandom(), minigame.getMaxChestRandom());
            }
        } else if (block instanceof InventoryHolder) {
            InventoryHolder inv = (InventoryHolder) block;
            ItemStack[] items = new ItemStack[inv.getInventory().getContents().length];
            for (int i = 0; i < items.length; i++) {
                if (inv.getInventory().getContents()[i] != null)
                    items[i] = inv.getInventory().getContents()[i].clone();
            }
            bdata.setItems(items);
        } else if (block.getType() == Material.FLOWER_POT) {
            bdata.setSpecialData("contents", block.getData());
        }
        blockdata.put(sloc, bdata);
        return bdata;
    } else {
        if (block.getType() != Material.CHEST || !blockdata.get(sloc).hasRandomized())
            blockdata.get(sloc).setModifier(modifier);
        return blockdata.get(sloc);
    }
}
Also used : Chest(org.bukkit.block.Chest) BlockFace(org.bukkit.block.BlockFace) ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location)

Example 30 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class BlockChest method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Chest) {
        Chest chest = (Chest) data;
        GlowBlock chestBlock = state.getBlock();
        BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
        Collection<BlockFace> attachedChests = searchChests(chestBlock);
        if (attachedChests.isEmpty()) {
            chest.setFacingDirection(normalFacing);
            state.setData(chest);
            return;
        } else if (attachedChests.size() > 1) {
            GlowServer.logger.warning("Chest placed near two other chests!");
            return;
        }
        BlockFace otherPart = attachedChests.iterator().next();
        GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
        if (getAttachedChest(otherPartBlock) != null) {
            GlowServer.logger.warning("Chest placed near already attached chest!");
            return;
        }
        BlockState otherPartState = otherPartBlock.getState();
        MaterialData otherPartData = otherPartState.getData();
        if (otherPartData instanceof Chest) {
            Chest otherChest = (Chest) otherPartData;
            BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
            chest.setFacingDirection(facing);
            state.setData(chest);
            otherChest.setFacingDirection(facing);
            otherPartState.setData(otherChest);
            otherPartState.update();
        } else {
            warnMaterialData(Chest.class, otherPartData);
        }
    } else {
        warnMaterialData(Chest.class, data);
    }
}
Also used : Chest(org.bukkit.material.Chest) GlowBlock(net.glowstone.block.GlowBlock) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Aggregations

BlockFace (org.bukkit.block.BlockFace)50 GlowBlock (net.glowstone.block.GlowBlock)20 Block (org.bukkit.block.Block)17 MaterialData (org.bukkit.material.MaterialData)9 BlockState (org.bukkit.block.BlockState)8 Vector (org.bukkit.util.Vector)8 GlowBlockState (net.glowstone.block.GlowBlockState)6 Location (org.bukkit.Location)6 ItemStack (org.bukkit.inventory.ItemStack)6 ItemTable (net.glowstone.block.ItemTable)5 BlockType (net.glowstone.block.blocktype.BlockType)4 PulseTask (net.glowstone.scheduler.PulseTask)4 Sign (org.bukkit.block.Sign)4 ArrayList (java.util.ArrayList)3 GlowPlayer (net.glowstone.entity.GlowPlayer)3 GlowWorld (net.glowstone.GlowWorld)2 BlockLiquid (net.glowstone.block.blocktype.BlockLiquid)2 ItemType (net.glowstone.block.itemtype.ItemType)2 Material (org.bukkit.Material)2 Action (org.bukkit.event.block.Action)2