PlayerInteractEvent (RIGHT_CLICK_BLOCK) doesn't work while holding a block item?

Discussion in 'Plugin Development' started by ThunderWaffeMC, Apr 29, 2014.

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

    ThunderWaffeMC

    Hi. I've stumbled upon something strange with PlayerInteractEvent that I can't work out. When using:

    Code:java
    1.  
    2. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    3. //do something when you right click a block
    4. }
    5.  


    it will allow you to right click a block while holding items but not blocks. For example:

    You can click a sign with your hands, clay, diamond sword, stick, diamond leggings (items) but not with a block (dirt, slab, cactus etc.).

    Not sure if this is just bad coding on my behalf or an error with the craftbukkit version I'm using. It is very odd :confused:.

    Thanks!
     
  2. Offline

    ZeusAllMighty11

    Hmm.. Have you tried checking BlockPlaceEvent even though you aren't placing a block?
     
  3. Offline

    ThunderWaffeMC

    Not sure how I can check a BlockPlaceEvent for this?

    Code:java
    1.  
    2. public void playerInteractEvent(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. player.sendMessage("1"); //stops here when having a block in hand
    5. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block block = event.getClickedBlock();
    7. player.sendMessage("2"); //executes here when having an item or nothing in hand
    8. if(block.getType() == Material.SIGN || block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
    9. }
    10. }
    11. }
    12.  


    No idea why!
     
  4. Offline

    ZeusAllMighty11

    The clicked block would be event.getPlacedAgainst() which returns a Block.


    I see the issue, though. You are missing the '@EventHandler' annotation above your method.
     
  5. ThunderWaffeMC Does that mean you get the 1 message when you have a block in hand, or no message at all? If you do get the 1 message, I would suggest you output the event.getAction() so that you can see what's going on
     
  6. Offline

    ThunderWaffeMC

    Not the issue here. That was just an example ^.
     
  7. ThunderWaffeMC It's good practice to copy the @EventHandler too, so that then other developers don't do what ZeusAllMighty11 did and assume that's the problem :p No discredit to Zeus of course, it's such a common mistake that it's an easy assumption to make.
     
  8. Offline

    ThunderWaffeMC

    Hmm.... It executed clicking a sign with a block as right click air but clicking another block with a block as right click block. Any ideas?

    Edit: Can ZeusAllMighty11 look into this?
     
  9. ThunderWaffeMC Hmm. Are you sure that the block you were right clicking on is actually selected?
     
  10. Offline

    ThunderWaffeMC

    Without moving, clicking with a diamond sword on a sign returns right click block. Clicking with a dirt block on a sign returns right click air. Although, clicking another block with a dirt block returns right click block.
     
  11. Offline

    ZeusAllMighty11

    The event fires just fine for me when I have a block inhand.


    Code:
    @EventHandler
    public void onClick(PlayerInteractEvent e)
    {
        Player p = e.getPlayer();
        
        if(p.getItemInHand() != null && p.getItemInHand().getType() == Material.DIRT)
        {
            System.out.println("Woohoo");
        }
     
    }
    
     
  12. Offline

    ThunderWaffeMC

    This only fires when the block I'm clicking is a sign.

    So in conclusion....
    Right clicking a block while holding a block triggers right click block - working
    Right clicking a sign while holding an item triggers right click block - working
    Right clicking a sign while holding a block triggers right click air - BAD (not working, should trigger right click block)

    ZeusAllMighty11 AdamQpzm

    Edit: tried with latest recommended build and latest beta build. Same thing for both. I really don't understand but I'm taking a guess that there's something wrong with CraftBukkit.
     
  13. Offline

    BillyGalbreath

    Might be unrelated, but I saw strange behavior with right clicking signs while holding blocks too. What I noticed is if the block cannot be placed (standing too close, or object in the way) I wasnt getting expected results. If the block could be placed it would trigger.

    Just something for you to test against your situation.
     
  14. ThunderWaffeMC I'm not able to test it out right now, so I don't know what to tell you. It's possible that it's a bug, or maybe you'll need to go with the BlockPlaceEvent suggestion as above. In my mind though, the RIGHT_CLICK_BLOCK should happen
     
  15. Offline

    ThunderWaffeMC

    ZeusAllMighty11 Something new as well: if I stand back away from the sign a block or two then it returns right click block. It's just when I'm up close to the sign while holding a block it returns as right clicking air (that's when the block doesn't place when you right click because there's no room between you and the sign for a new block BUT if I right click with a sign up close (still a block) then it returns as right click block no matter how far away I am from the sign). Hopefully you can do something about this!

    Edit: So apparently it's only returning as right clicking air when I'm in the way of the block being placed if you right click a sign. That's why it only works a block or two away but it also works when I'm standing right on the sign because the block is placed behind me.
     
  16. Offline

    BillyGalbreath

    I had a feeling thats what was up. I have no solution, I just learned to live with it. :p

    Maybe someone else can help with a workaround fix.
     
  17. Offline

    ThunderWaffeMC

    Well I would definitely like a solution (if not a fix) for this in the future :/
     
  18. ThunderWaffeMC Maybe you could check that, when they click on air, whether there's a sign within a certain range of their line of sight? Or maybe you'll have to learn to live with it, as BillyGalbreath suggested.
     
    ThunderWaffeMC likes this.
Thread Status:
Not open for further replies.

Share This Page