Search in sources :

Example 1 with Button

use of org.bukkit.material.Button in project Glowstone by GlowstoneMC.

the class BlockButton 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 Button)) {
        warnMaterialData(Button.class, data);
        return;
    }
    setAttachedFace(state, face.getOppositeFace());
}
Also used : Button(org.bukkit.material.Button) MaterialData(org.bukkit.material.MaterialData)

Example 2 with Button

use of org.bukkit.material.Button 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)

Example 3 with Button

use of org.bukkit.material.Button in project Glowstone by GlowstoneMC.

the class BlockButton method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Button)) {
        warnMaterialData(Button.class, data);
        return false;
    }
    Button button = (Button) data;
    if (button.isPowered()) {
        return true;
    }
    button.setPowered(true);
    state.update();
    extraUpdate(block);
    // todo: switch to block scheduling system when one is available
    new BukkitRunnable() {

        @Override
        public void run() {
            button.setPowered(false);
            state.update();
            if (block.getType() == Material.WOOD_BUTTON || block.getType() == Material.STONE_BUTTON) {
                extraUpdate(block);
                block.getWorld().playSound(block.getLocation(), block.getType() == Material.WOOD_BUTTON ? Sound.BLOCK_WOOD_BUTTON_CLICK_OFF : Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 0.3f, 0.5f);
            }
        }
    }.runTaskLater(null, block.getType() == Material.STONE_BUTTON ? 20 : 30);
    return true;
}
Also used : Button(org.bukkit.material.Button) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Aggregations

Button (org.bukkit.material.Button)3 MaterialData (org.bukkit.material.MaterialData)2 GlowBlock (net.glowstone.block.GlowBlock)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 ItemTable (net.glowstone.block.ItemTable)1 BlockFace (org.bukkit.block.BlockFace)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1