block under button

Discussion in 'Plugin Development' started by jusjus112, Nov 18, 2013.

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

    jusjus112

    I saw some people haves blocks under a button and thens
    something happenis, but how do I code a gold or emerald block under a buttonnn
    not one button, but with a block under it?
     
  2. Offline

    bartboy8

  3. Offline

    jusjus112

    bartboy8
    example; if you right klick a button on a gold block you getting killed, when you right klick on a button
    on a emerald block you getting healed
     
  4. Offline

    bartboy8

    Well, I recommend either using a PlayerInteractEvent and listening if the player clicks on a button, get the block behind the button and do whatever ya want!
     
  5. Offline

    Peary

    inventorman101 bartboy8
    INGLYSH(Gibberish) to English translation:
    How would I do something to the player if they pressed a button on a specific block. Ex: If you pressed a button on a Gold Block you would be damaged, and if you pressed a button on a Emerald Block you would healed.
     
  6. Offline

    inventorman101

    jusjus112
    I can't remember if there is a method to check what block is connected to a button... I know there is one for a sign though. I am sure there is one, check the JavaDocs.
     
  7. Offline

    bartboy8

    jusjus112
    Well, try this:
    Code:
    @EventHandler
    public void buttonOnBlock(PlayerInteractEvent event)
    {
    if(event.getClickedBlock() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK)
    {
    if(event.getClickedBlock().getType() == Material.BUTTON)
    {
    Button button = event.getClickedBlock();
    Material block = event.getClickedBlock().getRealative(button.getAttatchedFace()).getType();
    if(block == Material.whatever)
    {
    //Do stuff
    }
    }
    }
    }
     
  8. Offline

    jusjus112

  9. Offline

    jusjus112

    bartboy8
    It works, but i got an eror in eclipse for event.getiteminhand by button!
    Ingame it dont work?
     
  10. Offline

    Conarnar

  11. Offline

    jusjus112

    Conarnar
    Code:java
    1. @EventHandler
    2. public void buttonOnBlock(PlayerInteractEvent event)
    3. Player p = e.getPlayer();
    4. {
    5. if(event.getClickedBlock() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK)
    6. {
    7. if(event.getClickedBlock().getType() == Material.STONE_BUTTON)
    8. {
    9. Button button = event.getClickedBlock(); //Got an error in event.getClickedBlock()
    10. Material block = event.getClickedBlock().getRealative(button.getAttatchedFace()).getType();
    11. if(block == Material.STONE)
    12. {
    13. p.sendMessage("Test succesFull");
    14. p.setHealth(20.0)
    15. }
    16. }
    17. }
    18. }
     
  12. Offline

    L33m4n123

    event.getClickedBlock() will return something of the type "Block" and not of the Type "Button"
     
  13. Offline

    beastman3226

  14. Offline

    jusjus112

    L33m4n123
    i know that, but how do so that the button or block is an stonebutton.
    If i put an block in button, i got an error in eclipse for getAttatchedFace()!
     
  15. Offline

    L33m4n123

     
  16. Offline

    jusjus112

  17. Offline

    L33m4n123

  18. Offline

    beastman3226

    Casting is a very cool thing in Java. I like to call it the epitome of polymorphism. It allows us to say that an Object (the most broad entity in programming) and say it is also a Cat. Casting also prevents us from trying to tell a Cat to do something when it is really a Dog which would be a cat-astrophe.
     
    bartboy8 likes this.
Thread Status:
Not open for further replies.

Share This Page