Search in sources :

Example 26 with Block

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

the class ScoreboardDisplay method updateSigns.

/**
	 * Updates all signs with the current values of the stats
	 */
public void updateSigns() {
    settings = minigame.getSettings(stat);
    placeRootSign();
    List<Block> signs = getSignBlocks(true);
    int nextIndex = 0;
    for (Block sign : signs) {
        if (nextIndex <= stats.size() - 2) {
            updateSign(sign, nextIndex + 1, stats.get(nextIndex++), stats.get(nextIndex++));
        } else if (nextIndex <= stats.size() - 1) {
            updateSign(sign, nextIndex + 1, stats.get(nextIndex++));
        } else {
            clearSign(sign);
        }
    }
}
Also used : Block(org.bukkit.block.Block)

Example 27 with Block

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

the class ScoreboardDisplay method placeRootSign.

public void placeRootSign() {
    // For external calls
    if (settings == null) {
        settings = minigame.getSettings(stat);
    }
    Block root = rootBlock.getBlock();
    Sign sign = (Sign) root.getState();
    sign.setLine(0, ChatColor.BLUE + minigame.getName(true));
    sign.setLine(1, ChatColor.GREEN + settings.getDisplayName());
    sign.setLine(2, ChatColor.GREEN + field.getTitle());
    sign.setLine(3, "(" + WordUtils.capitalize(order.toString()) + ")");
    sign.update();
    sign.setMetadata("MGScoreboardSign", new FixedMetadataValue(Minigames.plugin, true));
    sign.setMetadata("Minigame", new FixedMetadataValue(Minigames.plugin, minigame));
}
Also used : Block(org.bukkit.block.Block) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Sign(org.bukkit.block.Sign)

Example 28 with Block

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

the class TreasureHuntMechanic method interactEvent.

@EventHandler
private void interactEvent(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
        Block cblock = event.getClickedBlock();
        if (cblock.getState() instanceof Chest && !event.isCancelled()) {
            for (Minigame minigame : mdata.getAllMinigames().values()) {
                if (minigame.getType() == MinigameType.GLOBAL && minigame.getMechanicName().equalsIgnoreCase(getMechanic()) && minigame.getMinigameTimer() != null) {
                    TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(minigame);
                    if (!thm.isTreasureFound() && thm.hasTreasureLocation()) {
                        int x1 = thm.getTreasureLocation().getBlockX();
                        int x2 = cblock.getLocation().getBlockX();
                        int y1 = thm.getTreasureLocation().getBlockY();
                        int y2 = cblock.getLocation().getBlockY();
                        int z1 = thm.getTreasureLocation().getBlockZ();
                        int z2 = cblock.getLocation().getBlockZ();
                        if (x2 == x1 && y2 == y1 && z2 == z1) {
                            MinigameUtils.broadcast(MinigameUtils.formStr("minigame.treasurehunt.plyFound", event.getPlayer().getDisplayName(), minigame.getName(true)), minigame, "minigame.treasure.announce");
                            event.setCancelled(true);
                            Chest chest = (Chest) cblock.getState();
                            event.getPlayer().openInventory(chest.getInventory());
                            thm.setTreasureFound(true);
                            minigame.getMinigameTimer().setTimeLeft(300);
                        }
                    }
                }
            }
        }
    }
}
Also used : Chest(org.bukkit.block.Chest) TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) Block(org.bukkit.block.Block) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 29 with Block

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

the class SwapBlockAction method executeRegionAction.

@SuppressWarnings("deprecation")
@Override
public void executeRegionAction(MinigamePlayer player, Region region) {
    for (int y = region.getFirstPoint().getBlockY(); y <= region.getSecondPoint().getBlockY(); y++) {
        for (int x = region.getFirstPoint().getBlockX(); x <= region.getSecondPoint().getBlockX(); x++) {
            for (int z = region.getFirstPoint().getBlockZ(); z <= region.getSecondPoint().getBlockZ(); z++) {
                Block block = region.getFirstPoint().getWorld().getBlockAt(x, y, z);
                if (block.getType() == Material.getMaterial(matchType.getFlag())) {
                    if (matchData.getFlag() && block.getData() != matchDataValue.getFlag().byteValue()) {
                        continue;
                    }
                    // Block matches, now replace it
                    byte data = 0;
                    BlockFace facing = null;
                    if (toData.getFlag()) {
                        // Replace data
                        data = toDataValue.getFlag().byteValue();
                    } else if (keepAttachment.getFlag()) {
                        // Keep attachments if possible
                        MaterialData mat = block.getState().getData();
                        if (mat instanceof Directional) {
                            facing = ((Directional) mat).getFacing();
                        }
                    }
                    // Update block type
                    block.setType(Material.getMaterial(toType.getFlag()), false);
                    if (facing != null) {
                        BlockState state = block.getState();
                        MaterialData mat = block.getState().getData();
                        if (mat instanceof Directional) {
                            ((Directional) mat).setFacingDirection(facing);
                        }
                        state.setData(mat);
                        state.update(true, false);
                    } else {
                        block.setData(data, false);
                    }
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData) Directional(org.bukkit.material.Directional)

Example 30 with Block

use of org.bukkit.block.Block in project Towny by ElgarL.

the class BlockWorker method buildBlock.

public void buildBlock(BlockWork blockWork) {
    Block block = blockWork.getWorld().getBlockAt(blockWork.getX(), blockWork.getY(), blockWork.getZ());
    if (blockWork.getId() == BukkitTools.getTypeId(block))
        return;
    // TODO: Set block
    BukkitTools.setTypeIdAndData(block, blockWork.getId(), blockWork.getData(), true);
}
Also used : Block(org.bukkit.block.Block)

Aggregations

Block (org.bukkit.block.Block)187 EventHandler (org.bukkit.event.EventHandler)62 Player (org.bukkit.entity.Player)42 Location (org.bukkit.Location)30 BlockState (org.bukkit.block.BlockState)28 Sign (org.bukkit.block.Sign)24 Material (org.bukkit.Material)23 BlockFace (org.bukkit.block.BlockFace)23 GlowBlock (net.glowstone.block.GlowBlock)19 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)16 MaterialData (org.bukkit.material.MaterialData)16 ArrayList (java.util.ArrayList)15 World (org.bukkit.World)14 Entity (org.bukkit.entity.Entity)14 ItemStack (org.bukkit.inventory.ItemStack)14 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)13 Vector (org.bukkit.util.Vector)13 IOException (java.io.IOException)7 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)6 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)5