Search in sources :

Example 31 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 32 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 33 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 34 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)

Example 35 with BlockFace

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

the class BlockButton method extraUpdate.

private void extraUpdate(GlowBlock block) {
    Button button = (Button) block.getState().getData();
    ItemTable itemTable = ItemTable.instance();
    GlowBlock target = block.getRelative(button.getAttachedFace());
    if (target.getType().isSolid()) {
        for (BlockFace face2 : ADJACENT) {
            GlowBlock target2 = target.getRelative(face2);
            BlockType notifyType = itemTable.getBlock(target2.getTypeId());
            if (notifyType != null) {
                if (target2.getFace(block) == null) {
                    notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
                }
                notifyType.onRedstoneUpdate(target2);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Button(org.bukkit.material.Button) ItemTable(net.glowstone.block.ItemTable) BlockFace(org.bukkit.block.BlockFace)

Aggregations

BlockFace (org.bukkit.block.BlockFace)58 GlowBlock (net.glowstone.block.GlowBlock)20 Block (org.bukkit.block.Block)20 MaterialData (org.bukkit.material.MaterialData)10 Vector (org.bukkit.util.Vector)9 BlockState (org.bukkit.block.BlockState)8 ArrayList (java.util.ArrayList)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 ItemTable (net.glowstone.block.ItemTable)5 Sign (org.bukkit.block.Sign)5 BlockType (net.glowstone.block.blocktype.BlockType)4 PulseTask (net.glowstone.scheduler.PulseTask)4 Material (org.bukkit.Material)4 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)3 List (java.util.List)3 GlowPlayer (net.glowstone.entity.GlowPlayer)3 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)2