Get Block that button is on?

Discussion in 'Plugin Development' started by Codisimus, Sep 29, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Codisimus

    I want to be able to find out the direction a button is facing. I don't think there is a method for that but if I could at least get the block/blockface that the button is attached to.

    If anyone can help me I'd appreciate it

    -Codisimus
     
  2. Offline

    Darkman2412

    Last edited by a moderator: May 20, 2016
  3. Offline

    Codisimus

    Didn't think to cast it to Button for more methods.

    Thanks @Darkman2412
    *have some Internets on me :)
     
  4. Offline

    Darkman2412

    There's also a getAttachedFace() method so you can use getRelative on the button (as block).
    Code:
    BlockFace bf = button.getAttachedFace();
    Block ab = ((Block)button).getRelative(bf);
     
  5. Offline

    Codisimus

    @Darkman2412
    Neither are working... is this for bukkit build #855?
     
  6. Offline

    nisovin

    Here's some example code for you:
    Code:
        @Override
        public void onPlayerInteract(PlayerInteractEvent event) {
            if (event.hasBlock() && event.getClickedBlock().getType() == Material.STONE_BUTTON) {
                Block block = event.getClickedBlock();
                Button button = (Button)block.getState().getData();
                Block attached = block.getRelative(button.getAttachedFace());
                attached.setType(Material.GLOWSTONE);
            }
        }
    
     
  7. Offline

    Codisimus

    ya that wasn't working either but I found out why...
    I mistakenly imported 'java.awt.Button' instead of 'org.bukkit.material.Button'
    duhhh lol.

    Thanks for the help guys!

    EDIT: Don't suppose you can see which way a chest is facing too?
     
Thread Status:
Not open for further replies.

Share This Page