Search in sources :

Example 1 with Sign

use of org.bukkit.block.data.type.Sign in project BuildSystem by einTosti.

the class CustomBlocks_1_14_R1 method rotate.

@Override
public void rotate(Block block, Player player, BlockFace blockFace) {
    BlockFace direction = blockFace != null ? blockFace : getDirection(player);
    BlockData blockData = block.getBlockData();
    if (blockData instanceof Directional) {
        Directional directional = (Directional) blockData;
        directional.setFacing(direction);
        block.setBlockData(directional);
    } else if (blockData instanceof Sign) {
        Sign sign = (Sign) blockData;
        sign.setRotation(direction);
        block.setBlockData(sign);
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Sign(org.bukkit.block.data.type.Sign) BlockData(org.bukkit.block.data.BlockData) Directional(org.bukkit.block.data.Directional)

Example 2 with Sign

use of org.bukkit.block.data.type.Sign in project BuildSystem by einTosti.

the class CustomBlocks_1_13_R1 method rotate.

@Override
public void rotate(Block block, Player player, BlockFace blockFace) {
    BlockFace direction = blockFace != null ? blockFace : getDirection(player);
    BlockData blockData = block.getBlockData();
    if (blockData instanceof Directional) {
        Directional directional = (Directional) blockData;
        directional.setFacing(direction);
        block.setBlockData(directional);
    } else if (blockData instanceof Sign) {
        Sign sign = (Sign) blockData;
        sign.setRotation(direction);
        block.setBlockData(sign);
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Sign(org.bukkit.block.data.type.Sign) BlockData(org.bukkit.block.data.BlockData) Directional(org.bukkit.block.data.Directional)

Example 3 with Sign

use of org.bukkit.block.data.type.Sign in project BuildSystem by Trichtern.

the class CustomBlocks_1_13_R1 method rotate.

@Override
public void rotate(Block block, Player player, BlockFace blockFace) {
    BlockFace direction = blockFace != null ? blockFace : getDirection(player);
    BlockData blockData = block.getBlockData();
    if (blockData instanceof Directional) {
        Directional directional = (Directional) blockData;
        directional.setFacing(direction);
        block.setBlockData(directional);
    } else if (blockData instanceof Sign) {
        Sign sign = (Sign) blockData;
        sign.setRotation(direction);
        block.setBlockData(sign);
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Sign(org.bukkit.block.data.type.Sign) BlockData(org.bukkit.block.data.BlockData) Directional(org.bukkit.block.data.Directional)

Example 4 with Sign

use of org.bukkit.block.data.type.Sign in project SignShop by wargamer.

the class SignShopBlockListener method getAttachables.

private List<Block> getAttachables(Block originalBlock) {
    List<Block> attachables = new ArrayList<>();
    List<BlockFace> checkFaces = new ArrayList<>();
    checkFaces.add(BlockFace.UP);
    checkFaces.add(BlockFace.NORTH);
    checkFaces.add(BlockFace.EAST);
    checkFaces.add(BlockFace.SOUTH);
    checkFaces.add(BlockFace.WEST);
    Block relativeBlock;
    BlockData relativeBlockData;
    for (BlockFace face : checkFaces) {
        relativeBlock = originalBlock.getRelative(face);
        relativeBlockData = relativeBlock.getBlockData();
        if (relativeBlockData instanceof Switch) {
            Switch switchData = (Switch) relativeBlockData;
            if (switchData.getFace() == Switch.Face.FLOOR && relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
                attachables.add(relativeBlock);
            }
        } else if (relativeBlockData instanceof WallSign) {
            WallSign wallSign = (WallSign) relativeBlockData;
            if (relativeBlock.getRelative(wallSign.getFacing().getOppositeFace()).equals(originalBlock)) {
                // may need to add getOppositeFace
                attachables.add(relativeBlock);
            }
        } else if (relativeBlockData instanceof Sign)
            if (relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
                attachables.add(relativeBlock);
            }
    }
    return attachables;
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Switch(org.bukkit.block.data.type.Switch) BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) BlockData(org.bukkit.block.data.BlockData)

Example 5 with Sign

use of org.bukkit.block.data.type.Sign in project Towny by TownyAdvanced.

the class TownyPlayerListener method onAdminToolUseOnBlocks.

/*
	 *  Handles AdminTool use on Blocks
	 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAdminToolUseOnBlocks(PlayerInteractEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld()))
        return;
    if (event.hasItem() && event.getPlayer().getInventory().getItemInMainHand().getType() == Material.getMaterial(TownySettings.getTool()) && TownyUniverse.getInstance().getPermissionSource().isTownyAdmin(event.getPlayer()) && event.getClickedBlock() != null) {
        Player player = event.getPlayer();
        Block block = event.getClickedBlock();
        if (Tag.SIGNS.isTagged(block.getType())) {
            BlockFace facing = null;
            if (block.getBlockData() instanceof Sign) {
                org.bukkit.block.data.type.Sign sign = (org.bukkit.block.data.type.Sign) block.getBlockData();
                facing = sign.getRotation();
            }
            if (block.getBlockData() instanceof WallSign) {
                org.bukkit.block.data.type.WallSign sign = (org.bukkit.block.data.type.WallSign) block.getBlockData();
                facing = sign.getFacing();
            }
            TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Sign Info"), ChatTools.formatCommand("", "Sign Type", "", block.getType().name()), ChatTools.formatCommand("", "Facing", "", facing.toString())));
        } else if (Tag.DOORS.isTagged(block.getType())) {
            org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
            TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Door Info"), ChatTools.formatCommand("", "Door Type", "", block.getType().name()), ChatTools.formatCommand("", "hinged on ", "", String.valueOf(door.getHinge())), ChatTools.formatCommand("", "isOpen", "", String.valueOf(door.isOpen())), ChatTools.formatCommand("", "getFacing", "", door.getFacing().name())));
        } else {
            TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Block Info"), ChatTools.formatCommand("", "Material", "", block.getType().name()), ChatTools.formatCommand("", "MaterialData", "", block.getBlockData().getAsString())));
        }
        event.setUseInteractedBlock(Event.Result.DENY);
        event.setCancelled(true);
    }
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Player(org.bukkit.entity.Player) BlockFace(org.bukkit.block.BlockFace) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Sign (org.bukkit.block.data.type.Sign)8 BlockData (org.bukkit.block.data.BlockData)7 BlockFace (org.bukkit.block.BlockFace)5 WallSign (org.bukkit.block.data.type.WallSign)5 BlockState (org.bukkit.block.BlockState)3 Directional (org.bukkit.block.data.Directional)3 Block (org.bukkit.block.Block)2 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)1 ArrayList (java.util.ArrayList)1 Switch (org.bukkit.block.data.type.Switch)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1