getClickedBlock is null in PlayerInteractEvent

Discussion in 'Plugin Development' started by ZephireNZ, Dec 8, 2013.

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

    ZephireNZ

    For my plugin, I'm detecting when a player clicks on a sign (either left/right click). Most of this time, this works. I use event.getClickedBlock(), which returns the block the clicked - as expected.

    However, in certain circumstances, this doesn't actually work. the clicked block will be null, despite me obviously clicking it.

    It only happens when I'm holding a placeable item, and obstructing it from being place. Any other case (actually placing the block, and holding no item) works fine.

    Is there something I'm missing?
     
  2. Offline

    Bart

    You should be doing null checks on getClickedBlock() - it will return null when you are left or right clicking on air.
     
  3. Offline

    ZephireNZ

    I know that's the case, I've already adapted to it.
    The problem is that I'm obviously clicking the sign, but it believes I'm clicking air. It'll confuse some people when they go to click the sign with item in hand, only to find out it didn't work for them in some situations
     
  4. Offline

    RawCode

    display chat message that explain situation on fail, this will help users.
     
  5. Offline

    ZephireNZ

    I can't do that, either. The nature of PlayerInteractEvent means that *any* time the player right-clicked air intentionally, it would tell them they didn't click a sign. Not an option either.
     
  6. Offline

    iiHeroo

  7. Offline

    xTrollxDudex

    ZephireNZ
    Make sure the action is Action.RIGHT/LEFT_CLICK_BLOCK instead of air
     
Thread Status:
Not open for further replies.

Share This Page