Checking for right click?

Discussion in 'Plugin Development' started by CaveBoy36, Aug 25, 2015.

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

    CaveBoy36

    Hia! I am trying to figure out how to detect if the player is RIGHT clicking a block, so far I have
    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = (Player) event.getPlayer();
            Block block = (Block) event.getClickedBlock();
            if (block.getType() == Material.STONE) {
            player.sendMessage("Lol.  Stone.");
            }
        }
    It works fine and says "Lol. Stone." but it also says it when I left click. Can someone help? Thank you!

    Oh! I got it! I just added
    Code:
    Action action = (Action) event.getAction();
    if (action = Action.RIGHT_CLICK_BLOCK) {
    player.sendMessage("You're good at life");
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  2. Offline

    SuperSniper

    check the Action.

    Code:
    if(e.getAction() == ActionType.RIGHT_CLICK_BLOCK)) {
    
     
  3. Offline

    MCMatters

  4. Offline

    au2001

    @SuperSniper ActionType? Nope, that doesn't seem to exist. Did you mean Action.RIGHT_CLICK_BLOCK?

    @MCMatters He wants to check for a click on a block (stone apparently), not in mid air :)
     
  5. Offline

    SuperSniper

    @au2001 Yes, I did mean that. I've been dealing with a lot of things at end with "Type" so Im really used to doing that.
     
  6. Offline

    The_BloodHound

    If your problem was solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page