[Question] Is Their Some Sort Of "OnClick" Event?

Discussion in 'Plugin Development' started by Bc1151, Aug 11, 2012.

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

    Bc1151

    Is Their Some Sort Of "OnClick" Event?

    while searching i found this:

    public void onButtonClick(ButtonClickEvent event) {
    //do click stuff
    }
    }


    but it dosent seem to work..

    please reply..

    -Bc1151
     
  2. Offline

    RingOfStorms

    PlayerInteractEvent

    event.getAction() == Action.LEFT_CLICK_AIR
     
  3. Offline

    Monowii

    Use PlayerInteractEvent :

    Code:text
    1. @EventHandler
    2. public void onClick(PlayerInteractEvent e)
    3. {
    4. if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
    5. {
    6. Block block = e.getClickedBlock();
    7. Player p = e.getPlayer();
    8. if (block.getType().equals(Material.STONE_BUTTON))
    9. {
    10. //Code Here
    11. }
    12. }
    13. }
    14.  
    15.  
     
  4. Offline

    Bc1151

    thanks!

    how
    how would i put this into command form but instead of what he clicked on - what he clicked with?,.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  5. Offline

    CorrieKay

    you cant listen for an event within a command.

    if you wished to, lets say, listen for someone left clicking air with a stick in their hand:

    public void onClick(PlayerInteractEvent event){
    if(event.getAction() == Action.LEFT_CLICK_AIR&&event.getPlayer().getItemInHand().getType() == Material.STICK){
    //they have left clicked air with a stick in their hand. Code here.
    }
    }

    edit: for other types of actions, type Action. into eclipse (if thats the ide youre using) or visit this page to see the different types of actions.
     
    Bc1151 likes this.
  6. Offline

    Bc1151

    thanks!
     
Thread Status:
Not open for further replies.

Share This Page